| Index: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
|
| diff --git a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
|
| index c0cc2fcc8ea7958c9d578c5ee577ea256a0eab7e..0d8a6c93fbc0eabe27a1c134b77ea0ffb5c31d04 100644
|
| --- a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
|
| +++ b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc
|
| @@ -7,13 +7,14 @@
|
| #include "base/strings/string_util.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/sessions/session_tab_helper.h"
|
| +#include "chrome/browser/sync/chrome_sync_client.h"
|
| #include "chrome/browser/sync/glue/session_sync_test_helper.h"
|
| -#include "chrome/browser/sync/glue/synced_tab_delegate.h"
|
| #include "chrome/browser/sync/sessions/notification_service_sessions_router.h"
|
| #include "chrome/browser/ui/sync/browser_synced_window_delegates_getter.h"
|
| #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/test/base/browser_with_test_window_test.h"
|
| +#include "components/sessions/content/content_serialized_navigation_builder.h"
|
| #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
|
| #include "components/sessions/core/session_id.h"
|
| #include "components/sessions/core/session_types.h"
|
| @@ -21,6 +22,8 @@
|
| #include "components/sync_driver/glue/synced_window_delegate.h"
|
| #include "components/sync_driver/local_device_info_provider_mock.h"
|
| #include "components/sync_driver/sessions/synced_window_delegates_getter.h"
|
| +#include "components/sync_driver/sync_api_component_factory.h"
|
| +#include "components/sync_sessions/synced_tab_delegate.h"
|
| #include "content/public/browser/navigation_entry.h"
|
| #include "content/public/browser/notification_details.h"
|
| #include "content/public/browser/notification_service.h"
|
| @@ -261,10 +264,10 @@ class SessionsSyncManagerTest
|
| browser_sync::NotificationServiceSessionsRouter* router(
|
| new browser_sync::NotificationServiceSessionsRouter(
|
| profile(), syncer::SyncableService::StartSyncFlare()));
|
| + sync_client_.reset(new browser_sync::ChromeSyncClient(profile(), nullptr));
|
| manager_.reset(new SessionsSyncManager(
|
| - profile(), local_device_.get(),
|
| - scoped_ptr<LocalSessionEventRouter>(router),
|
| - NewBrowserWindowGetter()));
|
| + GetSyncSessionsClient(), profile(), local_device_.get(),
|
| + scoped_ptr<LocalSessionEventRouter>(router), NewBrowserWindowGetter()));
|
| }
|
|
|
| void TearDown() override {
|
| @@ -326,7 +329,12 @@ class SessionsSyncManagerTest
|
| return list;
|
| }
|
|
|
| + sync_sessions::SyncSessionsClient* GetSyncSessionsClient() {
|
| + return sync_client_->GetSyncSessionsClient();
|
| + }
|
| +
|
| private:
|
| + scoped_ptr<browser_sync::ChromeSyncClient> sync_client_;
|
| scoped_ptr<SessionsSyncManager> manager_;
|
| SessionSyncTestHelper helper_;
|
| TestSyncProcessorStub* test_processor_;
|
| @@ -372,11 +380,10 @@ namespace {
|
|
|
| class SyncedTabDelegateFake : public SyncedTabDelegate {
|
| public:
|
| - SyncedTabDelegateFake() : current_entry_index_(0),
|
| - pending_entry_index_(-1),
|
| - is_supervised_(false),
|
| - sync_id_(-1),
|
| - blocked_navigations_(NULL) {}
|
| + SyncedTabDelegateFake()
|
| + : current_entry_index_(0),
|
| + is_supervised_(false),
|
| + sync_id_(-1) {}
|
| ~SyncedTabDelegateFake() override {}
|
|
|
| bool IsInitialBlankNavigation() const override {
|
| @@ -389,22 +396,36 @@ class SyncedTabDelegateFake : public SyncedTabDelegate {
|
| current_entry_index_ = i;
|
| }
|
|
|
| - content::NavigationEntry* GetEntryAtIndex(int i) const override {
|
| - const int size = entries_.size();
|
| - return (size < i + 1) ? NULL : entries_[i];
|
| - }
|
| -
|
| void AppendEntry(scoped_ptr<content::NavigationEntry> entry) {
|
| entries_.push_back(entry.Pass());
|
| }
|
|
|
| - int GetEntryCount() const override { return entries_.size(); }
|
| + GURL GetVirtualURLAtIndex(int i) const override {
|
| + if (static_cast<size_t>(i) >= entries_.size())
|
| + return GURL();
|
| + return entries_[i]->GetVirtualURL();
|
| + }
|
|
|
| - int GetPendingEntryIndex() const override { return pending_entry_index_; }
|
| - void set_pending_entry_index(int i) {
|
| - pending_entry_index_ = i;
|
| + GURL GetFaviconURLAtIndex(int i) const override { return GURL(); }
|
| +
|
| + ui::PageTransition GetTransitionAtIndex(int i) const override {
|
| + if (static_cast<size_t>(i) >= entries_.size())
|
| + return ui::PAGE_TRANSITION_LINK;
|
| + return entries_[i]->GetTransitionType();
|
| }
|
|
|
| + void GetSerializedNavigationAtIndex(
|
| + int i,
|
| + sessions::SerializedNavigationEntry* serialized_entry) const override {
|
| + if (static_cast<size_t>(i) >= entries_.size())
|
| + return;
|
| + *serialized_entry =
|
| + sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
|
| + i, *entries_[i]);
|
| + }
|
| +
|
| + int GetEntryCount() const override { return entries_.size(); }
|
| +
|
| SessionID::id_type GetWindowId() const override {
|
| return SessionID::id_type();
|
| }
|
| @@ -414,23 +435,26 @@ class SyncedTabDelegateFake : public SyncedTabDelegate {
|
| }
|
|
|
| bool IsBeingDestroyed() const override { return false; }
|
| - Profile* profile() const override { return NULL; }
|
| std::string GetExtensionAppId() const override { return std::string(); }
|
| - content::NavigationEntry* GetPendingEntry() const override { return NULL; }
|
| - content::NavigationEntry* GetActiveEntry() const override { return NULL; }
|
| bool ProfileIsSupervised() const override { return is_supervised_; }
|
| void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; }
|
| - const std::vector<const content::NavigationEntry*>* GetBlockedNavigations()
|
| - const override {
|
| - return blocked_navigations_;
|
| + const std::vector<const sessions::SerializedNavigationEntry*>*
|
| + GetBlockedNavigations() const override {
|
| + return &blocked_navigations_.get();
|
| }
|
| void set_blocked_navigations(
|
| std::vector<const content::NavigationEntry*>* navs) {
|
| - blocked_navigations_ = navs;
|
| + for (auto* entry : *navs) {
|
| + scoped_ptr<sessions::SerializedNavigationEntry> serialized_entry(
|
| + new sessions::SerializedNavigationEntry());
|
| + *serialized_entry =
|
| + sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
|
| + blocked_navigations_.size(), *entry);
|
| + blocked_navigations_.push_back(serialized_entry.release());
|
| + }
|
| }
|
| bool IsPinned() const override { return false; }
|
| bool HasWebContents() const override { return false; }
|
| - content::WebContents* GetWebContents() const override { return NULL; }
|
|
|
| // Session sync related methods.
|
| int GetSyncId() const override { return sync_id_; }
|
| @@ -438,46 +462,20 @@ class SyncedTabDelegateFake : public SyncedTabDelegate {
|
|
|
| void reset() {
|
| current_entry_index_ = 0;
|
| - pending_entry_index_ = -1;
|
| sync_id_ = -1;
|
| entries_.clear();
|
| }
|
|
|
| private:
|
| int current_entry_index_;
|
| - int pending_entry_index_;
|
| bool is_supervised_;
|
| int sync_id_;
|
| - std::vector<const content::NavigationEntry*>* blocked_navigations_;
|
| + ScopedVector<const sessions::SerializedNavigationEntry> blocked_navigations_;
|
| ScopedVector<content::NavigationEntry> entries_;
|
| };
|
|
|
| } // namespace
|
|
|
| -// Make sure GetCurrentVirtualURL() returns the virtual URL of the pending
|
| -// entry if the current entry is pending.
|
| -TEST_F(SessionsSyncManagerTest, GetCurrentVirtualURLPending) {
|
| - SyncedTabDelegateFake tab;
|
| - scoped_ptr<content::NavigationEntry> entry(
|
| - content::NavigationEntry::Create());
|
| - GURL url("http://www.google.com/");
|
| - entry->SetVirtualURL(url);
|
| - tab.AppendEntry(entry.Pass());
|
| - EXPECT_EQ(url, manager()->GetCurrentVirtualURL(tab));
|
| -}
|
| -
|
| -// Make sure GetCurrentVirtualURL() returns the virtual URL of the current
|
| -// entry if the current entry is non-pending.
|
| -TEST_F(SessionsSyncManagerTest, GetCurrentVirtualURLNonPending) {
|
| - SyncedTabDelegateFake tab;
|
| - scoped_ptr<content::NavigationEntry> entry(
|
| - content::NavigationEntry::Create());
|
| - GURL url("http://www.google.com/");
|
| - entry->SetVirtualURL(url);
|
| - tab.AppendEntry(entry.Pass());
|
| - EXPECT_EQ(url, manager()->GetCurrentVirtualURL(tab));
|
| -}
|
| -
|
| static const base::Time kTime0 = base::Time::FromInternalValue(100);
|
| static const base::Time kTime1 = base::Time::FromInternalValue(110);
|
| static const base::Time kTime2 = base::Time::FromInternalValue(120);
|
| @@ -818,7 +816,8 @@ TEST_F(SessionsSyncManagerTest, MergeLocalSessionNoTabs) {
|
| syncer::AttachmentServiceProxyForTest::Create()));
|
| syncer::SyncDataList in(&d, &d + 1);
|
| out.clear();
|
| - SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(),
|
| + SessionsSyncManager manager2(GetSyncSessionsClient(), profile(),
|
| + local_device(), NewDummyRouter(),
|
| NewBrowserWindowGetter());
|
| syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
|
| syncer::SESSIONS, in,
|
| @@ -1320,30 +1319,28 @@ TEST_F(SessionsSyncManagerTest, ProcessRemoteDeleteOfLocalSession) {
|
|
|
| // AddTab triggers two notifications, one for the tab insertion and one for
|
| // committing the NavigationEntry. The first notification results in a tab
|
| - // we don't associate although we do update the header node. The second
|
| - // notification triggers association of the tab, and the subsequent window
|
| - // update. So we should see 4 changes at the SyncChangeProcessor.
|
| - ASSERT_EQ(4U, out.size());
|
| + // with a pending entry, which we ignore. The second notification triggers
|
| + // association of the tab, and the subsequent window update. So we should see
|
| + // 3 changes at the SyncChangeProcessor.
|
| + EXPECT_EQ(3U, out.size());
|
|
|
| - EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
|
| - ASSERT_TRUE(out[0].sync_data().GetSpecifics().session().has_header());
|
| - EXPECT_EQ(SyncChange::ACTION_ADD, out[1].change_type());
|
| - int tab_node_id = out[1].sync_data().GetSpecifics().session().tab_node_id();
|
| + EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type());
|
| + int tab_node_id = out[0].sync_data().GetSpecifics().session().tab_node_id();
|
| EXPECT_EQ(TabNodePool::TabIdToTag(
|
| manager()->current_machine_tag(), tab_node_id),
|
| - syncer::SyncDataLocal(out[1].sync_data()).GetTag());
|
| + syncer::SyncDataLocal(out[0].sync_data()).GetTag());
|
| + EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type());
|
| + ASSERT_TRUE(out[1].sync_data().GetSpecifics().session().has_tab());
|
| EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type());
|
| - ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_tab());
|
| - EXPECT_EQ(SyncChange::ACTION_UPDATE, out[3].change_type());
|
| - ASSERT_TRUE(out[3].sync_data().GetSpecifics().session().has_header());
|
| + ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_header());
|
|
|
| // Verify the actual content.
|
| const sync_pb::SessionHeader& session_header =
|
| - out[3].sync_data().GetSpecifics().session().header();
|
| + out[2].sync_data().GetSpecifics().session().header();
|
| ASSERT_EQ(1, session_header.window_size());
|
| EXPECT_EQ(1, session_header.window(0).tab_size());
|
| const sync_pb::SessionTab& tab1 =
|
| - out[2].sync_data().GetSpecifics().session().tab();
|
| + out[1].sync_data().GetSpecifics().session().tab();
|
| ASSERT_EQ(1, tab1.navigation_size());
|
| EXPECT_EQ(foo1.spec(), tab1.navigation(0).virtual_url());
|
|
|
| @@ -1354,7 +1351,7 @@ TEST_F(SessionsSyncManagerTest, ProcessRemoteDeleteOfLocalSession) {
|
| // Verify TabLinks.
|
| SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_;
|
| ASSERT_EQ(1U, tab_map.size());
|
| - int tab_id = out[2].sync_data().GetSpecifics().session().tab().tab_id();
|
| + int tab_id = out[1].sync_data().GetSpecifics().session().tab().tab_id();
|
| EXPECT_EQ(tab_node_id, tab_map.find(tab_id)->second->tab_node_id());
|
| }
|
|
|
| @@ -1408,7 +1405,8 @@ TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) {
|
| syncer::AttachmentServiceProxyForTest::Create()));
|
| syncer::SyncDataList in(&d, &d + 1);
|
| changes.clear();
|
| - SessionsSyncManager manager2(profile(), local_device(), NewDummyRouter(),
|
| + SessionsSyncManager manager2(GetSyncSessionsClient(), profile(),
|
| + local_device(), NewDummyRouter(),
|
| NewBrowserWindowGetter());
|
| syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
|
| syncer::SESSIONS, in,
|
| @@ -1511,17 +1509,17 @@ TEST_F(SessionsSyncManagerTest, OnLocalTabModified) {
|
| AddTab(browser(), bar1);
|
| NavigateAndCommitActiveTab(bar2);
|
|
|
| - // One add, one update for each AddTab.
|
| + // One add, one update changes for each AddTab.
|
| // One update for each NavigateAndCommit.
|
| // = 6 total tab updates.
|
| - // One header update corresponding to each of those.
|
| - // = 6 total header updates.
|
| - // 12 total updates.
|
| - ASSERT_EQ(12U, out.size());
|
| + // One header update corresponding to each navigation.
|
| + // = 4 total header updates.
|
| + // 10 total updates.
|
| + ASSERT_EQ(10U, out.size());
|
|
|
| // Verify the tab node creations and updates to ensure the SyncProcessor
|
| // sees the right operations.
|
| - for (int i = 0; i < 12; i++) {
|
| + for (int i = 0; i < 10; i++) {
|
| SCOPED_TRACE(i);
|
| EXPECT_TRUE(out[i].IsValid());
|
| const SyncData data(out[i].sync_data());
|
| @@ -1530,43 +1528,37 @@ TEST_F(SessionsSyncManagerTest, OnLocalTabModified) {
|
| base::CompareCase::SENSITIVE));
|
| const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session());
|
| EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag());
|
| - if (i % 6 == 0) {
|
| - // 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(),
|
| - syncer::SyncDataLocal(data).GetTag());
|
| - } else if (i % 6 == 1) {
|
| + if (i % 5 == 0) {
|
| // Next, the TabNodePool should create the tab node.
|
| EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type());
|
| EXPECT_EQ(TabNodePool::TabIdToTag(
|
| manager()->current_machine_tag(),
|
| data.GetSpecifics().session().tab_node_id()),
|
| syncer::SyncDataLocal(data).GetTag());
|
| - } else if (i % 6 == 2) {
|
| + } else if (i % 5 == 1) {
|
| // Then we see the tab update to the URL.
|
| EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type());
|
| EXPECT_EQ(TabNodePool::TabIdToTag(
|
| manager()->current_machine_tag(),
|
| data.GetSpecifics().session().tab_node_id()),
|
| syncer::SyncDataLocal(data).GetTag());
|
| - ASSERT_TRUE(specifics.has_tab());
|
| - } else if (i % 6 == 3) {
|
| + EXPECT_TRUE(specifics.has_tab());
|
| + } else if (i % 5 == 2) {
|
| // The header needs to be updated to reflect the new window state.
|
| EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type());
|
| EXPECT_TRUE(specifics.has_header());
|
| - } else if (i % 6 == 4) {
|
| + } else if (i % 5 == 3) {
|
| // Now we move on to NavigateAndCommit. Update the tab.
|
| EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type());
|
| EXPECT_EQ(TabNodePool::TabIdToTag(
|
| manager()->current_machine_tag(),
|
| data.GetSpecifics().session().tab_node_id()),
|
| syncer::SyncDataLocal(data).GetTag());
|
| - ASSERT_TRUE(specifics.has_tab());
|
| - } else if (i % 6 == 5) {
|
| + EXPECT_TRUE(specifics.has_tab());
|
| + } else if (i % 5 == 4) {
|
| // The header needs to be updated to reflect the new window state.
|
| EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type());
|
| - ASSERT_TRUE(specifics.has_header());
|
| + EXPECT_TRUE(specifics.has_header());
|
| header = data.GetSpecifics();
|
| }
|
| }
|
| @@ -1580,22 +1572,22 @@ TEST_F(SessionsSyncManagerTest, OnLocalTabModified) {
|
| // ASSERT_TRUEs above allow us to dive in freely here.
|
| // Verify first tab.
|
| const sync_pb::SessionTab& tab1_1 =
|
| - out[2].sync_data().GetSpecifics().session().tab();
|
| + out[1].sync_data().GetSpecifics().session().tab();
|
| ASSERT_EQ(1, tab1_1.navigation_size());
|
| EXPECT_EQ(foo1.spec(), tab1_1.navigation(0).virtual_url());
|
| const sync_pb::SessionTab& tab1_2 =
|
| - out[4].sync_data().GetSpecifics().session().tab();
|
| + out[3].sync_data().GetSpecifics().session().tab();
|
| ASSERT_EQ(2, tab1_2.navigation_size());
|
| EXPECT_EQ(foo1.spec(), tab1_2.navigation(0).virtual_url());
|
| EXPECT_EQ(foo2.spec(), tab1_2.navigation(1).virtual_url());
|
|
|
| // Verify second tab.
|
| const sync_pb::SessionTab& tab2_1 =
|
| - out[8].sync_data().GetSpecifics().session().tab();
|
| + out[6].sync_data().GetSpecifics().session().tab();
|
| ASSERT_EQ(1, tab2_1.navigation_size());
|
| EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url());
|
| const sync_pb::SessionTab& tab2_2 =
|
| - out[10].sync_data().GetSpecifics().session().tab();
|
| + out[8].sync_data().GetSpecifics().session().tab();
|
| ASSERT_EQ(2, tab2_2.navigation_size());
|
| EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url());
|
| EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url());
|
| @@ -1666,16 +1658,12 @@ TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) {
|
| // the tree based on order of tabs created
|
| SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin();
|
| ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
|
| - EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->
|
| - GetEntryAtIndex(0)->GetVirtualURL());
|
| - EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->
|
| - GetEntryAtIndex(1)->GetVirtualURL());
|
| + EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0));
|
| + EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1));
|
| iter++;
|
| ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
|
| - EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->
|
| - GetEntryAtIndex(0)->GetVirtualURL());
|
| - EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->
|
| - GetEntryAtIndex(1)->GetVirtualURL());
|
| + EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0));
|
| + EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1));
|
| }
|
|
|
| // Test garbage collection of stale foreign sessions.
|
| @@ -1849,7 +1837,7 @@ TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) {
|
|
|
| AddTab(browser(), GURL("http://bar4"));
|
| NavigateAndCommitActiveTab(GURL("http://bar5"));
|
| - ASSERT_EQ(19U, out.size());
|
| + ASSERT_EQ(18U, out.size());
|
| }
|
|
|
| namespace {
|
|
|