summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-18 17:32:27 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-18 17:32:27 +0000
commit85622cd0710947ec6418ee865fd9687000dd9f82 (patch)
treecb3a8cdedb5a19c36e8c8a96a5bbc755f6953e80
parent31a7fb0a3f7bec9db975db7b2526dac9624c0dc5 (diff)
downloadchromium_src-85622cd0710947ec6418ee865fd9687000dd9f82.zip
chromium_src-85622cd0710947ec6418ee865fd9687000dd9f82.tar.gz
chromium_src-85622cd0710947ec6418ee865fd9687000dd9f82.tar.bz2
sync: make sessions sync v2 work
Summary of work: - get tests passing with or without --enable-sync-sessions-v2 (unit_tests, browser_tests, sync_integration_tests) - did not deal with the disabled sessions perf test. requires non-trival changes, and I'm not sure it's worthwhile yet. - impelement StopSyncing, GetAllSyncData - fixed a bug discovered by manual testing where the client tag for a tab node was using an invalid tab_node_id on update. - remove most remaining references to SessionModelAssociator - ran some manual coverage of backwards compatibility with v1 This patch does add temporary complexity to a few tests, namely WrenchMenuControllerTest and RecentTabsSubMenuModelTest. The goal was to make things work with or without the flag to minimize diffs during rollout, if we have to swap flag values. I'll remove the extra code once SessionModelAssociator is no more. BUG=98892 Review URL: https://codereview.chromium.org/110583002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241582 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/android/foreign_session_helper.h1
-rw-r--r--chrome/browser/extensions/api/sessions/sessions_apitest.cc67
-rw-r--r--chrome/browser/sessions/session_types.cc23
-rw-r--r--chrome/browser/sessions/session_types.h5
-rw-r--r--chrome/browser/sync/glue/session_model_associator.h5
-rw-r--r--chrome/browser/sync/glue/synced_session.cc36
-rw-r--r--chrome/browser/sync/glue/synced_session.h5
-rw-r--r--chrome/browser/sync/glue/synced_session_tracker.cc11
-rw-r--r--chrome/browser/sync/glue/synced_session_tracker.h4
-rw-r--r--chrome/browser/sync/open_tabs_ui_delegate.h5
-rw-r--r--chrome/browser/sync/profile_sync_service.h4
-rw-r--r--chrome/browser/sync/profile_sync_service_mock.cc4
-rw-r--r--chrome/browser/sync/profile_sync_service_mock.h11
-rw-r--r--chrome/browser/sync/sessions2/sessions_sync_manager.cc63
-rw-r--r--chrome/browser/sync/sessions2/sessions_sync_manager.h1
-rw-r--r--chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc13
-rw-r--r--chrome/browser/sync/test/integration/sessions_helper.cc9
-rw-r--r--chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm98
-rw-r--r--chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc42
-rw-r--r--chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h8
-rw-r--r--chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc99
-rw-r--r--sync/api/fake_sync_change_processor.cc24
-rw-r--r--sync/api/fake_sync_change_processor.h27
-rw-r--r--sync/sync_tests.gypi2
24 files changed, 500 insertions, 67 deletions
diff --git a/chrome/browser/android/foreign_session_helper.h b/chrome/browser/android/foreign_session_helper.h
index e2be270..4e02440 100644
--- a/chrome/browser/android/foreign_session_helper.h
+++ b/chrome/browser/android/foreign_session_helper.h
@@ -17,7 +17,6 @@ using base::android::ScopedJavaLocalRef;
struct SessionWindow;
namespace browser_sync {
-class SessionModelAssociator;
struct SyncedSession;
} // namespace browser_sync
diff --git a/chrome/browser/extensions/api/sessions/sessions_apitest.cc b/chrome/browser/extensions/api/sessions/sessions_apitest.cc
index 276a338..633d681 100644
--- a/chrome/browser/extensions/api/sessions/sessions_apitest.cc
+++ b/chrome/browser/extensions/api/sessions/sessions_apitest.cc
@@ -17,9 +17,12 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "sync/api/fake_sync_change_processor.h"
+#include "sync/api/sync_error_factory_mock.h"
namespace utils = extension_function_test_utils;
@@ -114,20 +117,35 @@ void ExtensionSessionsTest::CreateTestProfileSyncService() {
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
profile, &ProfileSyncServiceMock::BuildMockProfileSyncService));
- associator_ = new browser_sync::SessionModelAssociator(
- static_cast<ProfileSyncService*>(service), true);
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ associator_ = new browser_sync::SessionModelAssociator(
+ static_cast<ProfileSyncService*>(service), true);
+ associator_->SetCurrentMachineTagForTesting(kSessionTags[0]);
+ ON_CALL(*service, GetSessionModelAssociatorDeprecated())
+ .WillByDefault(testing::Return(associator_));
+ }
+
syncer::ModelTypeSet preferred_types;
preferred_types.Put(syncer::SESSIONS);
GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE);
-
- ON_CALL(*service, GetOpenTabsUIDelegate()).WillByDefault(
- testing::Return(associator_));
+ ON_CALL(*service, IsSessionsDataTypeControllerRunning())
+ .WillByDefault(testing::Return(true));
ON_CALL(*service, GetPreferredDataTypes()).WillByDefault(
testing::Return(preferred_types));
EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(
testing::ReturnRef(no_error));
ON_CALL(*service, GetActiveDataTypes()).WillByDefault(
testing::Return(preferred_types));
+ ON_CALL(*service, GetLocalDeviceInfoMock()).WillByDefault(
+ testing::Return(new browser_sync::DeviceInfo(
+ std::string(kSessionTags[0]),
+ "machine name",
+ "Chromium 10k",
+ "Chrome 10k",
+ sync_pb::SyncEnums_DeviceType_TYPE_LINUX)));
+ ON_CALL(*service, GetLocalSyncCacheGUID()).WillByDefault(
+ testing::Return(std::string(kSessionTags[0])));
EXPECT_CALL(*service, AddObserver(testing::_)).Times(testing::AnyNumber());
EXPECT_CALL(*service, RemoveObserver(testing::_)).Times(testing::AnyNumber());
@@ -143,6 +161,7 @@ void ExtensionSessionsTest::CreateTestExtension() {
}
void ExtensionSessionsTest::CreateSessionModels() {
+ syncer::SyncDataList initial_data;
for (size_t index = 0; index < kNumSessions; ++index) {
// Fill an instance of session specifics with a foreign session's data.
sync_pb::SessionSpecifics meta;
@@ -157,15 +176,39 @@ void ExtensionSessionsTest::CreateSessionModels() {
BuildTabSpecifics(kSessionTags[index], 0, tab_list1[i], &tabs1[i]);
}
- associator_->SetCurrentMachineTagForTesting(kSessionTags[index]);
- // Update associator with the session's meta node containing one window.
- associator_->AssociateForeignSpecifics(meta, base::Time());
- // Add tabs for the window.
- for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs1.begin();
- iter != tabs1.end(); ++iter) {
- associator_->AssociateForeignSpecifics(*iter, base::Time());
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ sync_pb::EntitySpecifics entity;
+ entity.mutable_session()->CopyFrom(meta);
+ initial_data.push_back(
+ syncer::SyncData::CreateRemoteData(1, entity, base::Time()));
+ for (size_t i = 0; i < tabs1.size(); i++) {
+ sync_pb::EntitySpecifics entity;
+ entity.mutable_session()->CopyFrom(tabs1[i]);
+ initial_data.push_back(syncer::SyncData::CreateRemoteData(
+ i + 2, entity, base::Time()));
+ }
+ } else {
+ // Update associator with the session's meta node containing one window.
+ associator_->AssociateForeignSpecifics(meta, base::Time());
+ // Add tabs for the window.
+ std::vector<sync_pb::SessionSpecifics>::iterator iter;
+ for (iter = tabs1.begin(); iter != tabs1.end(); ++iter) {
+ associator_->AssociateForeignSpecifics(*iter, base::Time());
+ }
}
}
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ ProfileSyncServiceFactory::GetForProfile(browser_->profile())->
+ GetSessionsSyncableService()->
+ MergeDataAndStartSyncing(syncer::SESSIONS, initial_data,
+ scoped_ptr<syncer::SyncChangeProcessor>(
+ new syncer::FakeSyncChangeProcessor()),
+ scoped_ptr<syncer::SyncErrorFactory>(
+ new syncer::SyncErrorFactoryMock()));
+ }
}
IN_PROC_BROWSER_TEST_F(ExtensionSessionsTest, GetDevices) {
diff --git a/chrome/browser/sessions/session_types.cc b/chrome/browser/sessions/session_types.cc
index 89dc829..a7ec022 100644
--- a/chrome/browser/sessions/session_types.cc
+++ b/chrome/browser/sessions/session_types.cc
@@ -67,3 +67,26 @@ SessionWindow::SessionWindow()
SessionWindow::~SessionWindow() {
STLDeleteElements(&tabs);
}
+
+sync_pb::SessionWindow SessionWindow::ToSyncData() const {
+ sync_pb::SessionWindow sync_data;
+ sync_data.set_window_id(window_id.id());
+ sync_data.set_selected_tab_index(selected_tab_index);
+ switch (type) {
+ case Browser::TYPE_TABBED:
+ sync_data.set_browser_type(
+ sync_pb::SessionWindow_BrowserType_TYPE_TABBED);
+ break;
+ case Browser::TYPE_POPUP:
+ sync_data.set_browser_type(
+ sync_pb::SessionWindow_BrowserType_TYPE_POPUP);
+ break;
+ default:
+ NOTREACHED() << "Unhandled browser type.";
+ }
+
+ for (size_t i = 0; i < tabs.size(); i++)
+ sync_data.add_tab(tabs[i]->tab_id.id());
+
+ return sync_data;
+}
diff --git a/chrome/browser/sessions/session_types.h b/chrome/browser/sessions/session_types.h
index ac664d6..8f10d98 100644
--- a/chrome/browser/sessions/session_types.h
+++ b/chrome/browser/sessions/session_types.h
@@ -110,6 +110,11 @@ struct SessionWindow {
SessionWindow();
~SessionWindow();
+ // Convert this object into its sync protocol buffer equivalent. Note that
+ // not all fields are synced here, because they don't all make sense or
+ // translate when restoring a SessionWindow on another device.
+ sync_pb::SessionWindow ToSyncData() const;
+
// Identifier of the window.
SessionID window_id;
diff --git a/chrome/browser/sync/glue/session_model_associator.h b/chrome/browser/sync/glue/session_model_associator.h
index a4d500b..fceb6bd 100644
--- a/chrome/browser/sync/glue/session_model_associator.h
+++ b/chrome/browser/sync/glue/session_model_associator.h
@@ -145,10 +145,6 @@ class SessionModelAssociator
// trigger a sync cycle.
void AttemptSessionsDataRefresh() const;
- // Sets |*local_session| to point to the associator's representation of the
- // local machine. Used primarily for testing.
- bool GetLocalSession(const SyncedSession* * local_session);
-
// Triggers garbage collection of stale sessions (as defined by
// |stale_session_threshold_days_|). This is called automatically every
// time we start up (via AssociateModels).
@@ -188,6 +184,7 @@ class SessionModelAssociator
const SessionID::id_type tab_id,
const SessionTab** tab) OVERRIDE;
virtual void DeleteForeignSession(const std::string& tag) OVERRIDE;
+ virtual bool GetLocalSession(const SyncedSession* * local_session) OVERRIDE;
void SetCurrentMachineTagForTesting(const std::string& machine_tag) {
current_machine_tag_ = machine_tag;
diff --git a/chrome/browser/sync/glue/synced_session.cc b/chrome/browser/sync/glue/synced_session.cc
index 7f51b59..07e769b 100644
--- a/chrome/browser/sync/glue/synced_session.cc
+++ b/chrome/browser/sync/glue/synced_session.cc
@@ -19,6 +19,42 @@ SyncedSession::~SyncedSession() {
STLDeleteContainerPairSecondPointers(windows.begin(), windows.end());
}
+sync_pb::SessionHeader SyncedSession::ToSessionHeader() const {
+ sync_pb::SessionHeader header;
+ SyncedWindowMap::const_iterator iter;
+ for (iter = windows.begin(); iter != windows.end(); ++iter) {
+ sync_pb::SessionWindow* w = header.add_window();
+ w->CopyFrom(iter->second->ToSyncData());
+ }
+ header.set_client_name(session_name);
+ switch (device_type) {
+ case SyncedSession::TYPE_WIN:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN);
+ break;
+ case SyncedSession::TYPE_MACOSX:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_MAC);
+ break;
+ case SyncedSession::TYPE_LINUX:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_LINUX);
+ break;
+ case SyncedSession::TYPE_CHROMEOS:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_CROS);
+ break;
+ case SyncedSession::TYPE_PHONE:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_PHONE);
+ break;
+ case SyncedSession::TYPE_TABLET:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_TABLET);
+ break;
+ case SyncedSession::TYPE_OTHER:
+ // Intentionally fall-through
+ default:
+ header.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_OTHER);
+ break;
+ }
+ return header;
+}
+
// Note: if you modify this, make sure you modify
// SessionModelAssociator::ShouldSyncTab to ensure the logic matches.
bool ShouldSyncSessionTab(const SessionTab& tab) {
diff --git a/chrome/browser/sync/glue/synced_session.h b/chrome/browser/sync/glue/synced_session.h
index ec99bce..96eee9ab 100644
--- a/chrome/browser/sync/glue/synced_session.h
+++ b/chrome/browser/sync/glue/synced_session.h
@@ -11,6 +11,7 @@
#include "base/time/time.h"
#include "chrome/browser/sessions/session_id.h"
#include "chrome/browser/sessions/session_types.h"
+#include "sync/protocol/session_specifics.pb.h"
namespace content {
class NavigationEntry;
@@ -79,6 +80,10 @@ struct SyncedSession {
}
}
+ // Convert this object to its protocol buffer equivalent. Shallow conversion,
+ // does not create SessionTab protobufs.
+ sync_pb::SessionHeader ToSessionHeader() const;
+
private:
DISALLOW_COPY_AND_ASSIGN(SyncedSession);
};
diff --git a/chrome/browser/sync/glue/synced_session_tracker.cc b/chrome/browser/sync/glue/synced_session_tracker.cc
index 083aac40..6f6f3e4 100644
--- a/chrome/browser/sync/glue/synced_session_tracker.cc
+++ b/chrome/browser/sync/glue/synced_session_tracker.cc
@@ -104,6 +104,17 @@ bool SyncedSessionTracker::LookupTabNodeIds(
return true;
}
+bool SyncedSessionTracker::LookupLocalSession(const SyncedSession** output)
+ const {
+ SyncedSessionMap::const_iterator it =
+ synced_session_map_.find(local_session_tag_);
+ if (it != synced_session_map_.end()) {
+ *output = it->second;
+ return true;
+ }
+ return false;
+}
+
SyncedSession* SyncedSessionTracker::GetSession(
const std::string& session_tag) {
SyncedSession* synced_session = NULL;
diff --git a/chrome/browser/sync/glue/synced_session_tracker.h b/chrome/browser/sync/glue/synced_session_tracker.h
index 4ef7db2..6ff2b46 100644
--- a/chrome/browser/sync/glue/synced_session_tracker.h
+++ b/chrome/browser/sync/glue/synced_session_tracker.h
@@ -59,6 +59,10 @@ class SyncedSessionTracker {
SessionID::id_type tab_id,
const SessionTab** tab) const;
+ // Allows retrieval of existing data for the local session. Unlike GetSession
+ // this won't create-if-not-present.
+ bool LookupLocalSession(const SyncedSession** output) const;
+
// Returns a pointer to the SyncedSession object associated with
// |session_tag|. If none exists, creates one. Ownership of the
// SyncedSession remains within the SyncedSessionTracker.
diff --git a/chrome/browser/sync/open_tabs_ui_delegate.h b/chrome/browser/sync/open_tabs_ui_delegate.h
index eb21c9d..8663f6c 100644
--- a/chrome/browser/sync/open_tabs_ui_delegate.h
+++ b/chrome/browser/sync/open_tabs_ui_delegate.h
@@ -47,6 +47,11 @@ class OpenTabsUIDelegate {
virtual bool GetForeignSession(
const std::string& tag,
std::vector<const SessionWindow*>* windows) = 0;
+
+ // Sets |*local| to point to the sessions sync representation of the
+ // local machine.
+ virtual bool GetLocalSession(const SyncedSession** local) = 0;
+
protected:
virtual ~OpenTabsUIDelegate();
};
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index 7732d0c..23736e6 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -705,6 +705,8 @@ class ProfileSyncService
void OverrideNetworkResourcesForTest(
scoped_ptr<syncer::NetworkResources> network_resources);
+ virtual bool IsSessionsDataTypeControllerRunning() const;
+
protected:
// Helper to configure the priority data types.
void ConfigurePriorityDataTypes();
@@ -875,8 +877,6 @@ class ProfileSyncService
bool delete_sync_database,
UnrecoverableErrorReason reason);
- bool IsSessionsDataTypeControllerRunning() const;
-
// Returns the username (in form of an email address) that should be used in
// the credentials.
std::string GetEffectiveUsername();
diff --git a/chrome/browser/sync/profile_sync_service_mock.cc b/chrome/browser/sync/profile_sync_service_mock.cc
index 54c5b9c..8d6202f 100644
--- a/chrome/browser/sync/profile_sync_service_mock.cc
+++ b/chrome/browser/sync/profile_sync_service_mock.cc
@@ -45,3 +45,7 @@ ScopedVector<browser_sync::DeviceInfo>
return devices.Pass();
}
+scoped_ptr<browser_sync::DeviceInfo>
+ ProfileSyncServiceMock::GetLocalDeviceInfo() const {
+ return scoped_ptr<browser_sync::DeviceInfo>(GetLocalDeviceInfoMock()).Pass();
+}
diff --git a/chrome/browser/sync/profile_sync_service_mock.h b/chrome/browser/sync/profile_sync_service_mock.h
index 7979a74..18832df 100644
--- a/chrome/browser/sync/profile_sync_service_mock.h
+++ b/chrome/browser/sync/profile_sync_service_mock.h
@@ -95,15 +95,22 @@ class ProfileSyncServiceMock : public ProfileSyncService {
MOCK_METHOD1(OnActionableError, void(
const syncer::SyncProtocolError&));
MOCK_METHOD1(SetSetupInProgress, void(bool));
+ MOCK_CONST_METHOD0(IsSessionsDataTypeControllerRunning, bool());
- MOCK_METHOD0(GetOpenTabsUIDelegate,
- browser_sync::OpenTabsUIDelegate*());
+ MOCK_METHOD0(GetSessionModelAssociatorDeprecated,
+ browser_sync::SessionModelAssociator*());
MOCK_CONST_METHOD0(GetAllSignedInDevicesMock,
std::vector<browser_sync::DeviceInfo*>* ());
// This is to get around the fact that GMOCK does not handle Scoped*.
virtual ScopedVector<browser_sync::DeviceInfo>
GetAllSignedInDevices() const OVERRIDE;
+ virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo()
+ const OVERRIDE;
+ MOCK_CONST_METHOD0(GetLocalDeviceInfoMock,
+ browser_sync::DeviceInfo*());
+ MOCK_CONST_METHOD0(GetLocalSyncCacheGUID, std::string());
+
// DataTypeManagerObserver mocks.
MOCK_METHOD0(OnConfigureBlocked, void());
MOCK_METHOD1(OnConfigureDone,
diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager.cc b/chrome/browser/sync/sessions2/sessions_sync_manager.cc
index ebbebd8..db9a9a3 100644
--- a/chrome/browser/sync/sessions2/sessions_sync_manager.cc
+++ b/chrome/browser/sync/sessions2/sessions_sync_manager.cc
@@ -262,10 +262,9 @@ void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab,
TabLinksMap::iterator local_tab_map_iter = local_tab_map_.find(tab_id);
TabLink* tab_link = NULL;
- int tab_node_id(TabNodePool2::kInvalidTabNodeID);
if (local_tab_map_iter == local_tab_map_.end()) {
- tab_node_id = tab->GetSyncId();
+ int tab_node_id = tab->GetSyncId();
// If there is an old sync node for the tab, reuse it. If this is a new
// tab, get a sync node for it.
if (!local_tab_pool_.IsUnassociatedTabNode(tab_node_id)) {
@@ -292,7 +291,7 @@ void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab,
LocalTabDelegateToSpecifics(*tab, specifics.mutable_session());
syncer::SyncData data = syncer::SyncData::CreateLocalData(
TabNodePool2::TabIdToTag(current_machine_tag_,
- tab_node_id),
+ tab_link->tab_node_id()),
current_session_name_,
specifics);
change_output->push_back(syncer::SyncChange(
@@ -391,13 +390,65 @@ bool SessionsSyncManager::ShouldSyncWindow(
}
void SessionsSyncManager::StopSyncing(syncer::ModelType type) {
- NOTIMPLEMENTED();
+ sync_processor_.reset(NULL);
+ error_handler_.reset();
+ session_tracker_.Clear();
+ local_tab_map_.clear();
+ local_tab_pool_.Clear();
+ current_machine_tag_.clear();
+ current_session_name_.clear();
+ local_session_header_node_id_ = TabNodePool2::kInvalidTabNodeID;
}
syncer::SyncDataList SessionsSyncManager::GetAllSyncData(
syncer::ModelType type) const {
- NOTIMPLEMENTED();
- return syncer::SyncDataList();
+ syncer::SyncDataList list;
+ const SyncedSession* session = NULL;
+ if (!session_tracker_.LookupLocalSession(&session))
+ return syncer::SyncDataList();
+
+ // First construct the header node.
+ sync_pb::EntitySpecifics header_entity;
+ header_entity.mutable_session()->set_session_tag(current_machine_tag());
+ sync_pb::SessionHeader* header_specifics =
+ header_entity.mutable_session()->mutable_header();
+ header_specifics->MergeFrom(session->ToSessionHeader());
+ syncer::SyncData data = syncer::SyncData::CreateLocalData(
+ current_machine_tag(), current_session_name_, header_entity);
+ list.push_back(data);
+
+ SyncedSession::SyncedWindowMap::const_iterator win_iter;
+ for (win_iter = session->windows.begin();
+ win_iter != session->windows.end(); ++win_iter) {
+ std::vector<SessionTab*>::const_iterator tabs_iter;
+ for (tabs_iter = win_iter->second->tabs.begin();
+ tabs_iter != win_iter->second->tabs.end(); ++tabs_iter) {
+ sync_pb::EntitySpecifics entity;
+ sync_pb::SessionSpecifics* specifics = entity.mutable_session();
+ specifics->mutable_tab()->MergeFrom((*tabs_iter)->ToSyncData());
+ specifics->set_session_tag(current_machine_tag_);
+
+ TabLinksMap::const_iterator tab_map_iter = local_tab_map_.find(
+ (*tabs_iter)->tab_id.id());
+ DCHECK(tab_map_iter != local_tab_map_.end());
+ specifics->set_tab_node_id(tab_map_iter->second->tab_node_id());
+ syncer::SyncData data = syncer::SyncData::CreateLocalData(
+ TabNodePool2::TabIdToTag(current_machine_tag_,
+ specifics->tab_node_id()),
+ current_session_name_,
+ entity);
+ list.push_back(data);
+ }
+ }
+ return list;
+}
+
+bool SessionsSyncManager::GetLocalSession(
+ const SyncedSession* * local_session) {
+ if (current_machine_tag_.empty())
+ return false;
+ *local_session = session_tracker_.GetSession(current_machine_tag());
+ return true;
}
syncer::SyncError SessionsSyncManager::ProcessSyncChanges(
diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager.h b/chrome/browser/sync/sessions2/sessions_sync_manager.h
index 1da847f..e580304 100644
--- a/chrome/browser/sync/sessions2/sessions_sync_manager.h
+++ b/chrome/browser/sync/sessions2/sessions_sync_manager.h
@@ -125,6 +125,7 @@ class SessionsSyncManager : public syncer::SyncableService,
const SessionID::id_type tab_id,
const SessionTab** tab) OVERRIDE;
virtual void DeleteForeignSession(const std::string& tag) OVERRIDE;
+ virtual bool GetLocalSession(const SyncedSession* * local_session) OVERRIDE;
// LocalSessionEventHandler implementation.
virtual void OnLocalTabModified(SyncedTabDelegate* modified_tab) OVERRIDE;
diff --git a/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc b/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc
index 122747b..599b75c 100644
--- a/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc
+++ b/chrome/browser/sync/sessions2/sessions_sync_manager_unittest.cc
@@ -1075,12 +1075,21 @@ TEST_F(SessionsSyncManagerTest, OnLocalTabModified) {
// First thing on an AddTab is a no-op header update for parented tab.
EXPECT_EQ(header.SerializeAsString(),
data.GetSpecifics().SerializeAsString());
+ EXPECT_EQ(manager()->current_machine_tag(), data.GetTag());
} else if (i % 6 == 1) {
// Next, the TabNodePool should create the tab node.
EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type());
+ EXPECT_EQ(TabNodePool2::TabIdToTag(
+ manager()->current_machine_tag(),
+ data.GetSpecifics().session().tab_node_id()),
+ data.GetTag());
} else if (i % 6 == 2) {
// Then we see the tab update to the URL.
EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type());
+ EXPECT_EQ(TabNodePool2::TabIdToTag(
+ manager()->current_machine_tag(),
+ data.GetSpecifics().session().tab_node_id()),
+ data.GetTag());
ASSERT_TRUE(specifics.has_tab());
} else if (i % 6 == 3) {
// The header needs to be updated to reflect the new window state.
@@ -1089,6 +1098,10 @@ TEST_F(SessionsSyncManagerTest, OnLocalTabModified) {
} else if (i % 6 == 4) {
// Now we move on to NavigateAndCommit. Update the tab.
EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type());
+ EXPECT_EQ(TabNodePool2::TabIdToTag(
+ manager()->current_machine_tag(),
+ data.GetSpecifics().session().tab_node_id()),
+ data.GetTag());
ASSERT_TRUE(specifics.has_tab());
} else if (i % 6 == 5) {
// The header needs to be updated to reflect the new window state.
diff --git a/chrome/browser/sync/test/integration/sessions_helper.cc b/chrome/browser/sync/test/integration/sessions_helper.cc
index 70b9eee..e862ee7 100644
--- a/chrome/browser/sync/test/integration/sessions_helper.cc
+++ b/chrome/browser/sync/test/integration/sessions_helper.cc
@@ -11,6 +11,7 @@
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
+#include "chrome/browser/sync/open_tabs_ui_delegate.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
@@ -51,7 +52,7 @@ void ScopedWindowMap::Reset(SessionWindowMap* windows) {
bool GetLocalSession(int index, const browser_sync::SyncedSession** session) {
return ProfileSyncServiceFactory::GetInstance()->GetForProfile(
- test()->GetProfile(index))->GetSessionModelAssociatorDeprecated()->
+ test()->GetProfile(index))->GetOpenTabsUIDelegate()->
GetLocalSession(session);
}
@@ -200,7 +201,7 @@ int GetNumForeignSessions(int index) {
SyncedSessionVector sessions;
if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile(
test()->GetProfile(index))->
- GetSessionModelAssociatorDeprecated()->GetAllForeignSessions(
+ GetOpenTabsUIDelegate()->GetAllForeignSessions(
&sessions)) {
return 0;
}
@@ -210,7 +211,7 @@ int GetNumForeignSessions(int index) {
bool GetSessionData(int index, SyncedSessionVector* sessions) {
if (!ProfileSyncServiceFactory::GetInstance()->GetForProfile(
test()->GetProfile(index))->
- GetSessionModelAssociatorDeprecated()->GetAllForeignSessions(
+ GetOpenTabsUIDelegate()->GetAllForeignSessions(
sessions)) {
return false;
}
@@ -317,7 +318,7 @@ bool CheckForeignSessionsAgainst(
void DeleteForeignSession(int index, std::string session_tag) {
ProfileSyncServiceFactory::GetInstance()->GetForProfile(
test()->GetProfile(index))->
- GetSessionModelAssociatorDeprecated()->DeleteForeignSession(session_tag);
+ GetOpenTabsUIDelegate()->DeleteForeignSession(session_tag);
}
} // namespace sessions_helper
diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm
index 29472bc..146e395 100644
--- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm
@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
+#include "chrome/browser/sync/glue/device_info.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
+#include "chrome/browser/sync/sessions2/sessions_sync_manager.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "chrome/browser/ui/cocoa/run_loop_testing.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
@@ -16,9 +19,12 @@
#include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h"
#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
#include "chrome/browser/ui/toolbar/wrench_menu_model.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#include "sync/api/fake_sync_change_processor.h"
+#include "sync/api/sync_error_factory_mock.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
@@ -42,7 +48,17 @@ class MockWrenchMenuModel : public WrenchMenuModel {
MOCK_METHOD2(ExecuteCommand, void(int command_id, int event_flags));
};
-class WrenchMenuControllerTest : public CocoaProfileTest {
+class DummyRouter : public browser_sync::LocalSessionEventRouter {
+ public:
+ virtual ~DummyRouter() {}
+ virtual void StartRoutingTo(
+ browser_sync::LocalSessionEventHandler* handler) OVERRIDE {}
+ virtual void Stop() OVERRIDE {}
+};
+
+class WrenchMenuControllerTest
+ : public CocoaProfileTest,
+ public browser_sync::SessionsSyncManager::SyncInternalApiDelegate {
public:
virtual void SetUp() OVERRIDE {
CocoaProfileTest::SetUp();
@@ -50,11 +66,68 @@ class WrenchMenuControllerTest : public CocoaProfileTest {
controller_.reset([[WrenchMenuController alloc] initWithBrowser:browser()]);
fake_model_.reset(new MockWrenchMenuModel);
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ manager_.reset(new browser_sync::SessionsSyncManager(
+ profile(),
+ this,
+ scoped_ptr<browser_sync::LocalSessionEventRouter>(
+ new DummyRouter())));
+ manager_->MergeDataAndStartSyncing(
+ syncer::SESSIONS,
+ syncer::SyncDataList(),
+ scoped_ptr<syncer::SyncChangeProcessor>(
+ new syncer::FakeSyncChangeProcessor),
+ scoped_ptr<syncer::SyncErrorFactory>(
+ new syncer::SyncErrorFactoryMock));
+ } else {
+ ProfileSyncService* sync_service =
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
+ associator_.reset(new browser_sync::SessionModelAssociator(
+ sync_service, true));
+ associator_->SetCurrentMachineTagForTesting(
+ GetLocalSyncCacheGUID());
+ }
+ }
+
+ virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo()
+ const OVERRIDE {
+ return scoped_ptr<browser_sync::DeviceInfo>(
+ new browser_sync::DeviceInfo(GetLocalSyncCacheGUID(),
+ "Test Machine",
+ "Chromium 10k",
+ "Chrome 10k",
+ sync_pb::SyncEnums_DeviceType_TYPE_LINUX));
+ }
+
+ virtual std::string GetLocalSyncCacheGUID() const OVERRIDE {
+ return "WrenchMenuControllerTest";
+ }
+
+ void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ helper->ExportToSessionsSyncManager(manager_.get());
+ } else {
+ helper->ExportToSessionModelAssociator(associator_.get());
+ }
+ }
+
+ browser_sync::OpenTabsUIDelegate* GetOpenTabsDelegate() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ return manager_.get();
+ } else {
+ return associator_.get();
+ }
}
virtual void TearDown() OVERRIDE {
fake_model_.reset();
controller_.reset();
+ associator_.reset();
+ manager_.reset();
CocoaProfileTest::TearDown();
}
@@ -65,6 +138,11 @@ class WrenchMenuControllerTest : public CocoaProfileTest {
base::scoped_nsobject<WrenchMenuController> controller_;
scoped_ptr<MockWrenchMenuModel> fake_model_;
+
+ private:
+ // TODO(tim): Bug 98892. Remove associator_ once sessions2 is the default.
+ scoped_ptr<browser_sync::SessionModelAssociator> associator_;
+ scoped_ptr<browser_sync::SessionsSyncManager> manager_;
};
TEST_F(WrenchMenuControllerTest, Initialized) {
@@ -85,19 +163,14 @@ TEST_F(WrenchMenuControllerTest, DispatchSimple) {
}
TEST_F(WrenchMenuControllerTest, RecentTabsFavIcon) {
- ProfileSyncService* sync_service =
- ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
- browser_sync::SessionModelAssociator associator_(sync_service, true);
- associator_.SetCurrentMachineTagForTesting("WrenchMenuControllerTest");
-
RecentTabsBuilderTestHelper recent_tabs_builder;
recent_tabs_builder.AddSession();
recent_tabs_builder.AddWindow(0);
recent_tabs_builder.AddTab(0, 0);
- recent_tabs_builder.RegisterRecentTabs(&associator_);
+ RegisterRecentTabs(&recent_tabs_builder);
RecentTabsSubMenuModel recent_tabs_sub_menu_model(
- NULL, browser(), &associator_);
+ NULL, browser(), GetOpenTabsDelegate());
fake_model_->AddSubMenuWithStringId(
IDC_RECENT_TABS_MENU, IDS_RECENT_TABS_MENU,
&recent_tabs_sub_menu_model);
@@ -125,11 +198,6 @@ TEST_F(WrenchMenuControllerTest, RecentTabsFavIcon) {
}
TEST_F(WrenchMenuControllerTest, RecentTabsElideTitle) {
- ProfileSyncService* sync_service =
- ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
- browser_sync::SessionModelAssociator associator_(sync_service, true);
- associator_.SetCurrentMachineTagForTesting("WrenchMenuControllerTest");
-
// Add 1 session with 1 window and 2 tabs.
RecentTabsBuilderTestHelper recent_tabs_builder;
recent_tabs_builder.AddSession();
@@ -140,10 +208,10 @@ TEST_F(WrenchMenuControllerTest, RecentTabsElideTitle) {
"very very very very very very long");
recent_tabs_builder.AddTabWithInfo(0, 0,
base::Time::Now() - base::TimeDelta::FromMinutes(10), tab2_long_title);
- recent_tabs_builder.RegisterRecentTabs(&associator_);
+ RegisterRecentTabs(&recent_tabs_builder);
RecentTabsSubMenuModel recent_tabs_sub_menu_model(
- NULL, browser(), &associator_);
+ NULL, browser(), GetOpenTabsDelegate());
fake_model_->AddSubMenuWithStringId(
IDC_RECENT_TABS_MENU, IDS_RECENT_TABS_MENU,
&recent_tabs_sub_menu_model);
diff --git a/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc b/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc
index 8aa81ee..dc691f4 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc
@@ -9,6 +9,8 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
+#include "chrome/browser/sync/open_tabs_ui_delegate.h"
+#include "chrome/browser/sync/sessions2/sessions_sync_manager.h"
#include "sync/protocol/session_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -177,7 +179,35 @@ base::string16 RecentTabsBuilderTestHelper::GetTabTitle(int session_index,
return title;
}
-void RecentTabsBuilderTestHelper::RegisterRecentTabs(
+void RecentTabsBuilderTestHelper::ExportToSessionsSyncManager(
+ browser_sync::SessionsSyncManager* manager) {
+ syncer::SyncChangeList changes;
+ for (int s = 0; s < GetSessionCount(); ++s) {
+ sync_pb::EntitySpecifics session_entity;
+ sync_pb::SessionSpecifics* meta = session_entity.mutable_session();
+ BuildSessionSpecifics(s, meta);
+ for (int w = 0; w < GetWindowCount(s); ++w) {
+ BuildWindowSpecifics(s, w, meta);
+ for (int t = 0; t < GetTabCount(s, w); ++t) {
+ sync_pb::EntitySpecifics entity;
+ sync_pb::SessionSpecifics* tab_base = entity.mutable_session();
+ BuildTabSpecifics(s, w, t, tab_base);
+ changes.push_back(syncer::SyncChange(
+ FROM_HERE, syncer::SyncChange::ACTION_ADD,
+ syncer::SyncData::CreateRemoteData(
+ tab_base->tab_node_id(), entity, GetTabTimestamp(s, w, t))));
+ }
+ }
+ changes.push_back(syncer::SyncChange(
+ FROM_HERE, syncer::SyncChange::ACTION_ADD,
+ syncer::SyncData::CreateRemoteData(1, session_entity,
+ GetSessionTimestamp(s))));
+ }
+ manager->ProcessSyncChanges(FROM_HERE, changes);
+ VerifyExport(manager);
+}
+
+void RecentTabsBuilderTestHelper::ExportToSessionModelAssociator(
browser_sync::SessionModelAssociator* associator) {
for (int s = 0; s < GetSessionCount(); ++s) {
sync_pb::SessionSpecifics meta;
@@ -193,15 +223,19 @@ void RecentTabsBuilderTestHelper::RegisterRecentTabs(
}
associator->AssociateForeignSpecifics(meta, GetSessionTimestamp(s));
}
+ VerifyExport(associator);
+}
+void RecentTabsBuilderTestHelper::VerifyExport(
+ browser_sync::OpenTabsUIDelegate* delegate) {
// Make sure data is populated correctly in SessionModelAssociator.
std::vector<const browser_sync::SyncedSession*> sessions;
- ASSERT_TRUE(associator->GetAllForeignSessions(&sessions));
+ ASSERT_TRUE(delegate->GetAllForeignSessions(&sessions));
ASSERT_EQ(GetSessionCount(), static_cast<int>(sessions.size()));
for (int s = 0; s < GetSessionCount(); ++s) {
std::vector<const SessionWindow*> windows;
- ASSERT_TRUE(associator->GetForeignSession(ToSessionTag(GetSessionID(s)),
- &windows));
+ ASSERT_TRUE(delegate->GetForeignSession(ToSessionTag(GetSessionID(s)),
+ &windows));
ASSERT_EQ(GetWindowCount(s), static_cast<int>(windows.size()));
for (int w = 0; w < GetWindowCount(s); ++w)
ASSERT_EQ(GetTabCount(s, w), static_cast<int>(windows[w]->tabs.size()));
diff --git a/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h b/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h
index f80d30f..4c093a0 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h
+++ b/chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h
@@ -12,7 +12,9 @@
#include "chrome/browser/sessions/session_id.h"
namespace browser_sync {
+class OpenTabsUIDelegate;
class SessionModelAssociator;
+class SessionsSyncManager;
}
namespace sync_pb {
class SessionSpecifics;
@@ -49,7 +51,10 @@ class RecentTabsBuilderTestHelper {
int window_index,
int tab_index);
- void RegisterRecentTabs(browser_sync::SessionModelAssociator* associator);
+ void ExportToSessionModelAssociator(
+ browser_sync::SessionModelAssociator* associator);
+ void ExportToSessionsSyncManager(
+ browser_sync::SessionsSyncManager* manager);
std::vector<base::string16> GetTabTitlesSortedByRecency();
@@ -63,6 +68,7 @@ class RecentTabsBuilderTestHelper {
int window_index,
int tab_index,
sync_pb::SessionSpecifics* tab_base);
+ void VerifyExport(browser_sync::OpenTabsUIDelegate* delegate);
struct TabInfo;
struct WindowInfo;
diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc
index 385379c..af65a87 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
+#include "base/command_line.h"
#include "base/run_loop.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/sessions/session_service.h"
@@ -14,15 +15,19 @@
#include "chrome/browser/sync/glue/session_model_associator.h"
#include "chrome/browser/sync/glue/synced_session.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
+#include "chrome/browser/sync/sessions2/sessions_sync_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/menu_model_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/sessions/serialized_navigation_entry_test_helper.h"
#include "grit/generated_resources.h"
+#include "sync/api/fake_sync_change_processor.h"
+#include "sync/api/sync_error_factory_mock.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -35,8 +40,8 @@ class TestRecentTabsSubMenuModel : public RecentTabsSubMenuModel {
public:
TestRecentTabsSubMenuModel(ui::AcceleratorProvider* provider,
Browser* browser,
- browser_sync::SessionModelAssociator* associator)
- : RecentTabsSubMenuModel(provider, browser, associator),
+ browser_sync::OpenTabsUIDelegate* delegate)
+ : RecentTabsSubMenuModel(provider, browser, delegate),
execute_count_(0),
enable_count_(0) {
}
@@ -93,14 +98,42 @@ class TestRecentTabsMenuModelDelegate : public ui::MenuModelDelegate {
DISALLOW_COPY_AND_ASSIGN(TestRecentTabsMenuModelDelegate);
};
+class DummyRouter : public browser_sync::LocalSessionEventRouter {
+ public:
+ virtual ~DummyRouter() {}
+ virtual void StartRoutingTo(
+ browser_sync::LocalSessionEventHandler* handler) OVERRIDE {}
+ virtual void Stop() OVERRIDE {}
+};
+
} // namespace
-class RecentTabsSubMenuModelTest : public BrowserWithTestWindowTest {
+class RecentTabsSubMenuModelTest
+ : public BrowserWithTestWindowTest,
+ public browser_sync::SessionsSyncManager::SyncInternalApiDelegate {
public:
RecentTabsSubMenuModelTest()
- : sync_service_(&testing_profile_),
- associator_(&sync_service_, true) {
- associator_.SetCurrentMachineTagForTesting("RecentTabsSubMenuModelTest");
+ : sync_service_(&testing_profile_) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ manager_.reset(new browser_sync::SessionsSyncManager(
+ &testing_profile_,
+ this,
+ scoped_ptr<browser_sync::LocalSessionEventRouter>(
+ new DummyRouter())));
+ manager_->MergeDataAndStartSyncing(
+ syncer::SESSIONS,
+ syncer::SyncDataList(),
+ scoped_ptr<syncer::SyncChangeProcessor>(
+ new syncer::FakeSyncChangeProcessor),
+ scoped_ptr<syncer::SyncErrorFactory>(
+ new syncer::SyncErrorFactoryMock));
+ } else {
+ associator_.reset(new browser_sync::SessionModelAssociator(
+ &sync_service_, true));
+ associator_->SetCurrentMachineTagForTesting(
+ GetLocalSyncCacheGUID());
+ }
}
void WaitForLoadFromLastSession() {
@@ -116,12 +149,46 @@ class RecentTabsSubMenuModelTest : public BrowserWithTestWindowTest {
Profile::FromBrowserContext(browser_context), NULL);;
}
+
+ browser_sync::OpenTabsUIDelegate* GetOpenTabsDelegate() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ return manager_.get();
+ } else {
+ return associator_.get();
+ }
+ }
+
+ void RegisterRecentTabs(RecentTabsBuilderTestHelper* helper) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsV2)) {
+ helper->ExportToSessionsSyncManager(manager_.get());
+ } else {
+ helper->ExportToSessionModelAssociator(associator_.get());
+ }
+ }
+
+ virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo()
+ const OVERRIDE {
+ return scoped_ptr<browser_sync::DeviceInfo>(
+ new browser_sync::DeviceInfo(GetLocalSyncCacheGUID(),
+ "Test Machine",
+ "Chromium 10k",
+ "Chrome 10k",
+ sync_pb::SyncEnums_DeviceType_TYPE_LINUX));
+ }
+
+ virtual std::string GetLocalSyncCacheGUID() const OVERRIDE {
+ return "RecentTabsSubMenuModelTest";
+ }
+
private:
TestingProfile testing_profile_;
testing::NiceMock<ProfileSyncServiceMock> sync_service_;
- protected:
- browser_sync::SessionModelAssociator associator_;
+ // TODO(tim): Remove associator_ when sessions V2 is the default, bug 98892.
+ scoped_ptr<browser_sync::SessionModelAssociator> associator_;
+ scoped_ptr<browser_sync::SessionsSyncManager> manager_;
};
// Test disabled "Recently closed" header with no foreign tabs.
@@ -337,7 +404,7 @@ TEST_F(RecentTabsSubMenuModelTest, OtherDevices) {
timestamp -= time_delta;
recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, base::string16());
- recent_tabs_builder.RegisterRecentTabs(&associator_);
+ RegisterRecentTabs(&recent_tabs_builder);
// Verify that data is populated correctly in RecentTabsSubMenuModel.
// Expected menu:
@@ -355,7 +422,7 @@ TEST_F(RecentTabsSubMenuModelTest, OtherDevices) {
// 11 <separator>
// 12 More...
- TestRecentTabsSubMenuModel model(NULL, browser(), &associator_);
+ TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate());
int num_items = model.GetItemCount();
EXPECT_EQ(13, num_items);
model.ActivatedAt(0);
@@ -415,7 +482,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxSessionsAndRecency) {
recent_tabs_builder.AddWindow(s);
recent_tabs_builder.AddTab(s, 0);
}
- recent_tabs_builder.RegisterRecentTabs(&associator_);
+ RegisterRecentTabs(&recent_tabs_builder);
// Verify that data is populated correctly in RecentTabsSubMenuModel.
// Expected menu:
@@ -435,7 +502,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxSessionsAndRecency) {
// 10 <separator>
// 11 More...
- TestRecentTabsSubMenuModel model(NULL, browser(), &associator_);
+ TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate());
int num_items = model.GetItemCount();
EXPECT_EQ(12, num_items);
@@ -455,7 +522,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) {
for (int t = 0; t < 5; ++t)
recent_tabs_builder.AddTab(0, w);
}
- recent_tabs_builder.RegisterRecentTabs(&associator_);
+ RegisterRecentTabs(&recent_tabs_builder);
// Verify that data is populated correctly in RecentTabsSubMenuModel.
// Expected menu:
@@ -470,7 +537,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) {
// 7 <separator>
// 8 More...
- TestRecentTabsSubMenuModel model(NULL, browser(), &associator_);
+ TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate());
int num_items = model.GetItemCount();
EXPECT_EQ(9, num_items);
@@ -486,7 +553,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxWidth) {
recent_tabs_builder.AddSession();
recent_tabs_builder.AddWindow(0);
recent_tabs_builder.AddTab(0, 0);
- recent_tabs_builder.RegisterRecentTabs(&associator_);
+ RegisterRecentTabs(&recent_tabs_builder);
// Menu index Menu items
// ----------------------------------------------------------
@@ -497,7 +564,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxWidth) {
// 4 <separator>
// 5 More...
- TestRecentTabsSubMenuModel model(NULL, browser(), &associator_);
+ TestRecentTabsSubMenuModel model(NULL, browser(), GetOpenTabsDelegate());
EXPECT_EQ(6, model.GetItemCount());
EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0));
EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1));
diff --git a/sync/api/fake_sync_change_processor.cc b/sync/api/fake_sync_change_processor.cc
new file mode 100644
index 0000000..f8d2f40
--- /dev/null
+++ b/sync/api/fake_sync_change_processor.cc
@@ -0,0 +1,24 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/api/fake_sync_change_processor.h"
+
+namespace syncer {
+
+FakeSyncChangeProcessor::FakeSyncChangeProcessor() {}
+
+FakeSyncChangeProcessor::~FakeSyncChangeProcessor() {}
+
+syncer::SyncError FakeSyncChangeProcessor::ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) {
+ return syncer::SyncError();
+}
+
+syncer::SyncDataList FakeSyncChangeProcessor::GetAllSyncData(
+ syncer::ModelType type) const {
+ return syncer::SyncDataList();
+}
+
+} // namespace syncer
diff --git a/sync/api/fake_sync_change_processor.h b/sync/api/fake_sync_change_processor.h
new file mode 100644
index 0000000..7ec8084
--- /dev/null
+++ b/sync/api/fake_sync_change_processor.h
@@ -0,0 +1,27 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_API_FAKE_SYNC_CHANGE_PROCESSOR_H_
+#define SYNC_API_FAKE_SYNC_CHANGE_PROCESSOR_H_
+
+#include "sync/api/sync_change_processor.h"
+
+namespace syncer {
+
+class FakeSyncChangeProcessor : public SyncChangeProcessor {
+ public:
+ FakeSyncChangeProcessor();
+ virtual ~FakeSyncChangeProcessor();
+
+ virtual syncer::SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) OVERRIDE;
+
+ virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type)
+ const OVERRIDE;
+};
+
+} // namespace syncer
+
+#endif // SYNC_API_FAKE_SYNC_CHANGE_PROCESSOR_H_
diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi
index 683ca52..eaa01aa 100644
--- a/sync/sync_tests.gypi
+++ b/sync/sync_tests.gypi
@@ -187,6 +187,8 @@
'sources': [
'api/fake_syncable_service.cc',
'api/fake_syncable_service.h',
+ 'api/fake_sync_change_processor.cc',
+ 'api/fake_sync_change_processor.h',
'api/sync_error_factory_mock.cc',
'api/sync_error_factory_mock.h',
],