Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc

Issue 2507543002: Revert of [Sync] Put session tracker in charge of maintaining local state. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/sync_sessions/sessions_sync_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync_sessions/sessions_sync_manager.h" 5 #include "components/sync_sessions/sessions_sync_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 if (static_cast<size_t>(i) >= entries_.size()) 542 if (static_cast<size_t>(i) >= entries_.size())
543 return; 543 return;
544 *serialized_entry = 544 *serialized_entry =
545 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( 545 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
546 i, *entries_[i]); 546 i, *entries_[i]);
547 } 547 }
548 548
549 int GetEntryCount() const override { return entries_.size(); } 549 int GetEntryCount() const override { return entries_.size(); }
550 550
551 SessionID::id_type GetWindowId() const override { 551 SessionID::id_type GetWindowId() const override {
552 return window_id_; 552 return SessionID::id_type();
553 }
554 void SetWindowId(SessionID::id_type window_id) {
555 window_id_ = window_id;
556 } 553 }
557 554
558 SessionID::id_type GetSessionId() const override { 555 SessionID::id_type GetSessionId() const override {
559 return tab_id_; 556 return SessionID::id_type();
560 }
561 void SetSessionId(SessionID::id_type id) {
562 tab_id_ = id;
563 } 557 }
564 558
565 bool IsBeingDestroyed() const override { return false; } 559 bool IsBeingDestroyed() const override { return false; }
566 std::string GetExtensionAppId() const override { return std::string(); } 560 std::string GetExtensionAppId() const override { return std::string(); }
567 bool ProfileIsSupervised() const override { return is_supervised_; } 561 bool ProfileIsSupervised() const override { return is_supervised_; }
568 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } 562 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; }
569 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* 563 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>*
570 GetBlockedNavigations() const override { 564 GetBlockedNavigations() const override {
571 return &blocked_navigations_; 565 return &blocked_navigations_;
572 } 566 }
(...skipping 20 matching lines...) Expand all
593 void reset() { 587 void reset() {
594 current_entry_index_ = 0; 588 current_entry_index_ = 0;
595 sync_id_ = -1; 589 sync_id_ = -1;
596 entries_.clear(); 590 entries_.clear();
597 } 591 }
598 592
599 private: 593 private:
600 int current_entry_index_; 594 int current_entry_index_;
601 bool is_supervised_; 595 bool is_supervised_;
602 int sync_id_; 596 int sync_id_;
603 SessionID::id_type tab_id_ = 0;
604 SessionID::id_type window_id_ = 0;
605 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> 597 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>
606 blocked_navigations_; 598 blocked_navigations_;
607 std::vector<std::unique_ptr<content::NavigationEntry>> entries_; 599 std::vector<std::unique_ptr<content::NavigationEntry>> entries_;
608 }; 600 };
609 601
610 } // namespace 602 } // namespace
611 603
612 static const base::Time kTime0 = base::Time::FromInternalValue(100); 604 static const base::Time kTime0 = base::Time::FromInternalValue(100);
613 static const base::Time kTime1 = base::Time::FromInternalValue(110); 605 static const base::Time kTime1 = base::Time::FromInternalValue(110);
614 static const base::Time kTime2 = base::Time::FromInternalValue(120); 606 static const base::Time kTime2 = base::Time::FromInternalValue(120);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 in.push_back(CreateRemoteData(t1_entity)); 981 in.push_back(CreateRemoteData(t1_entity));
990 in.push_back(CreateRemoteData(t2_entity)); 982 in.push_back(CreateRemoteData(t2_entity));
991 out.clear(); 983 out.clear();
992 manager()->StopSyncing(syncer::SESSIONS); 984 manager()->StopSyncing(syncer::SESSIONS);
993 985
994 const std::set<const SyncedWindowDelegate*>& windows = 986 const std::set<const SyncedWindowDelegate*>& windows =
995 manager()->synced_window_delegates_getter()->GetSyncedWindowDelegates(); 987 manager()->synced_window_delegates_getter()->GetSyncedWindowDelegates();
996 ASSERT_EQ(1U, windows.size()); 988 ASSERT_EQ(1U, windows.size());
997 SyncedTabDelegateFake t1_override, t2_override; 989 SyncedTabDelegateFake t1_override, t2_override;
998 t1_override.SetSyncId(1); // No WebContents by default. 990 t1_override.SetSyncId(1); // No WebContents by default.
999 t1_override.SetSessionId(kNewTabId);
1000 t2_override.SetSyncId(2); // No WebContents by default. 991 t2_override.SetSyncId(2); // No WebContents by default.
1001 t2_override.SetSessionId(t2_entity.session().tab().tab_id());
1002 SyncedWindowDelegateOverride window_override(*windows.begin()); 992 SyncedWindowDelegateOverride window_override(*windows.begin());
1003 window_override.OverrideTabAt(1, &t1_override, kNewTabId); 993 window_override.OverrideTabAt(1, &t1_override, kNewTabId);
1004 window_override.OverrideTabAt(2, &t2_override, 994 window_override.OverrideTabAt(2, &t2_override,
1005 t2_entity.session().tab().tab_id()); 995 t2_entity.session().tab().tab_id());
1006 std::set<const SyncedWindowDelegate*> delegates; 996 std::set<const SyncedWindowDelegate*> delegates;
1007 delegates.insert(&window_override); 997 delegates.insert(&window_override);
1008 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( 998 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter(
1009 new TestSyncedWindowDelegatesGetter(delegates)); 999 new TestSyncedWindowDelegatesGetter(delegates));
1010 set_synced_window_getter(getter.get()); 1000 set_synced_window_getter(getter.get());
1011 1001
1012 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( 1002 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing(
1013 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( 1003 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>(
1014 new TestSyncProcessorStub(&out)), 1004 new TestSyncProcessorStub(&out)),
1015 std::unique_ptr<syncer::SyncErrorFactory>( 1005 std::unique_ptr<syncer::SyncErrorFactory>(
1016 new syncer::SyncErrorFactoryMock())); 1006 new syncer::SyncErrorFactoryMock()));
1017 1007
1018 // There should be two changes, one for the fully associated tab, and 1008 // There should be two changes, one for the fully associated tab, and
1019 // one each for the tab_id updates to t1 and t2. 1009 // one for the tab_id update to t1. t2 shouldn't need to be updated.
1020 ASSERT_EQ(3U, FilterOutLocalHeaderChanges(&out)->size()); 1010 ASSERT_EQ(2U, FilterOutLocalHeaderChanges(&out)->size());
1021 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 1011 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
1022 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); 1012 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type());
1023 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type());
1024 EXPECT_EQ(kNewTabId, 1013 EXPECT_EQ(kNewTabId,
1025 out[1].sync_data().GetSpecifics().session().tab().tab_id()); 1014 out[1].sync_data().GetSpecifics().session().tab().tab_id());
1026 EXPECT_EQ(t2_entity.session().tab().tab_id(),
1027 out[2].sync_data().GetSpecifics().session().tab().tab_id());
1028 1015
1029 // Verify TabLinks. 1016 // Verify TabLinks.
1030 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; 1017 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_;
1031 ASSERT_EQ(3U, tab_map.size()); 1018 ASSERT_EQ(3U, tab_map.size());
1032 int t2_tab_id = t2_entity.session().tab().tab_id(); 1019 int t2_tab_id = t2_entity.session().tab().tab_id();
1033 EXPECT_EQ(2, tab_map.find(t2_tab_id)->second->tab_node_id()); 1020 EXPECT_EQ(2, tab_map.find(t2_tab_id)->second->tab_node_id());
1034 EXPECT_EQ(1, tab_map.find(kNewTabId)->second->tab_node_id()); 1021 EXPECT_EQ(1, tab_map.find(kNewTabId)->second->tab_node_id());
1035 int t0_tab_id = out[0].sync_data().GetSpecifics().session().tab().tab_id(); 1022 int t0_tab_id = out[0].sync_data().GetSpecifics().session().tab().tab_id();
1036 EXPECT_EQ(0, tab_map.find(t0_tab_id)->second->tab_node_id()); 1023 EXPECT_EQ(0, tab_map.find(t0_tab_id)->second->tab_node_id());
1024 // TODO(tim): Once bug 337057 is fixed, we can issue an OnLocalTabModified
1025 // from here (using an override similar to above) to return a new tab id
1026 // and verify that we don't see any node creations in the SyncChangeProcessor
1027 // (similar to how SessionsSyncManagerTest.OnLocalTabModified works.)
1037 } 1028 }
1038 1029
1039 // Ensure model association updates the window ID for tabs whose window's ID has 1030 // Ensure model association updates the window ID for tabs whose window's ID has
1040 // changed. 1031 // changed.
1041 TEST_F(SessionsSyncManagerTest, WindowIdUpdatedOnRestore) { 1032 TEST_F(SessionsSyncManagerTest, WindowIdUpdatedOnRestore) {
1042 const int kNewWindowId = 1337; 1033 const int kNewWindowId = 1337;
1043 syncer::SyncDataList in; 1034 syncer::SyncDataList in;
1044 syncer::SyncChangeList out; 1035 syncer::SyncChangeList out;
1045 1036
1046 // Set up one tab and start sync with it. 1037 // Set up one tab and start sync with it.
1047 AddTab(browser(), GURL("http://foo1")); 1038 AddTab(browser(), GURL("http://foo1"));
1048 NavigateAndCommitActiveTab(GURL("http://foo2")); 1039 NavigateAndCommitActiveTab(GURL("http://foo2"));
1049 InitWithSyncDataTakeOutput(in, &out); 1040 InitWithSyncDataTakeOutput(in, &out);
1050 1041
1051 // Should be one header add, 1 tab add/update pair, and one header update. 1042 // Should be one header add, 1 tab add/update pair, and one header update.
1052 ASSERT_EQ(4U, out.size()); 1043 ASSERT_EQ(4U, out.size());
1053 const sync_pb::EntitySpecifics t0_entity = out[2].sync_data().GetSpecifics(); 1044 const sync_pb::EntitySpecifics t0_entity = out[2].sync_data().GetSpecifics();
1054 1045
1055 in.push_back(CreateRemoteData(t0_entity)); 1046 in.push_back(CreateRemoteData(t0_entity));
1056 out.clear(); 1047 out.clear();
1057 manager()->StopSyncing(syncer::SESSIONS); 1048 manager()->StopSyncing(syncer::SESSIONS);
1058 1049
1059 // SyncedTabDelegateFake is a placeholder (no WebContents) by default. 1050 // SyncedTabDelegateFake is a placeholder (no WebContents) by default.
1060 SyncedTabDelegateFake t0_override; 1051 SyncedTabDelegateFake t0_override;
1061 t0_override.SetSyncId(t0_entity.session().tab_node_id()); 1052 t0_override.SetSyncId(t0_entity.session().tab_node_id());
1062 t0_override.SetWindowId(kNewWindowId);
1063 1053
1064 // Set up the window override with the new window ID and placeholder tab. 1054 // Set up the window override with the new window ID and placeholder tab.
1065 const std::set<const SyncedWindowDelegate*>& windows = 1055 const std::set<const SyncedWindowDelegate*>& windows =
1066 get_synced_window_getter()->GetSyncedWindowDelegates(); 1056 get_synced_window_getter()->GetSyncedWindowDelegates();
1067 ASSERT_EQ(1U, windows.size()); 1057 ASSERT_EQ(1U, windows.size());
1068 SyncedWindowDelegateOverride window_override(*windows.begin()); 1058 SyncedWindowDelegateOverride window_override(*windows.begin());
1069 window_override.OverrideSessionId(kNewWindowId); 1059 window_override.OverrideSessionId(kNewWindowId);
1070 window_override.OverrideTabAt(0, &t0_override, 1060 window_override.OverrideTabAt(0, &t0_override,
1071 t0_entity.session().tab().tab_id()); 1061 t0_entity.session().tab().tab_id());
1072 1062
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 EXPECT_TRUE(changes.empty()); 1300 EXPECT_TRUE(changes.empty());
1311 1301
1312 // Fill an instance of session specifics with a foreign session's data. 1302 // Fill an instance of session specifics with a foreign session's data.
1313 std::vector<sync_pb::SessionSpecifics> tabs; 1303 std::vector<sync_pb::SessionSpecifics> tabs;
1314 SessionID::id_type n1[] = {5, 10, 13, 17}; 1304 SessionID::id_type n1[] = {5, 10, 13, 17};
1315 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); 1305 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1));
1316 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( 1306 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
1317 tag, tab_nums1, &tabs)); 1307 tag, tab_nums1, &tabs));
1318 1308
1319 // Update associator with the session's meta node, window, and tabs. 1309 // Update associator with the session's meta node, window, and tabs.
1320 manager()->UpdateTrackerWithSpecifics(meta, base::Time()); 1310 manager()->UpdateTrackerWithForeignSession(meta, base::Time());
1321 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); 1311 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin();
1322 iter != tabs.end(); ++iter) { 1312 iter != tabs.end(); ++iter) {
1323 manager()->UpdateTrackerWithSpecifics(*iter, base::Time()); 1313 manager()->UpdateTrackerWithForeignSession(*iter, base::Time());
1324 } 1314 }
1325 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); 1315 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
1326 ASSERT_EQ(1U, foreign_sessions.size()); 1316 ASSERT_EQ(1U, foreign_sessions.size());
1327 1317
1328 // Now delete the foreign session. 1318 // Now delete the foreign session.
1329 manager()->DeleteForeignSessionInternal(tag, &changes); 1319 manager()->DeleteForeignSessionInternal(tag, &changes);
1330 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); 1320 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions));
1331 1321
1332 EXPECT_EQ(5U, changes.size()); 1322 EXPECT_EQ(5U, changes.size());
1333 std::set<std::string> expected_tags(&tag, &tag + 1); 1323 std::set<std::string> expected_tags(&tag, &tag + 1);
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 EXPECT_TRUE(specifics2.has_header()); 2063 EXPECT_TRUE(specifics2.has_header());
2074 const sync_pb::SessionHeader& header_s2 = specifics2.header(); 2064 const sync_pb::SessionHeader& header_s2 = specifics2.header();
2075 EXPECT_EQ(1, header_s2.window_size()); 2065 EXPECT_EQ(1, header_s2.window_size());
2076 2066
2077 // Verify TabLinks. 2067 // Verify TabLinks.
2078 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; 2068 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_;
2079 ASSERT_EQ(2U, tab_map.size()); 2069 ASSERT_EQ(2U, tab_map.size());
2080 // Tabs are ordered by sessionid in tab_map, so should be able to traverse 2070 // Tabs are ordered by sessionid in tab_map, so should be able to traverse
2081 // the tree based on order of tabs created 2071 // the tree based on order of tabs created
2082 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); 2072 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin();
2083 EXPECT_EQ(GURL("http://foo2"), iter->second->url()); 2073 ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
2074 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0));
2075 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1));
2084 iter++; 2076 iter++;
2085 EXPECT_EQ(GURL("http://bar2"), iter->second->url()); 2077 ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
2078 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0));
2079 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1));
2086 } 2080 }
2087 2081
2088 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { 2082 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) {
2089 syncer::SyncDataList foreign_data; 2083 syncer::SyncDataList foreign_data;
2090 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); 2084 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1);
2091 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); 2085 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2);
2092 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); 2086 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3);
2093 2087
2094 { 2088 {
2095 std::string session_tag = "tag1"; 2089 std::string session_tag = "tag1";
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 base::Time last_time; 2603 base::Time last_time;
2610 for (size_t i = 0; i < tabs.size(); ++i) { 2604 for (size_t i = 0; i < tabs.size(); ++i) {
2611 base::Time this_time = tabs[i]->timestamp; 2605 base::Time this_time = tabs[i]->timestamp;
2612 if (i > 0) 2606 if (i > 0)
2613 ASSERT_GE(last_time, this_time); 2607 ASSERT_GE(last_time, this_time);
2614 last_time = tabs[i]->timestamp; 2608 last_time = tabs[i]->timestamp;
2615 } 2609 }
2616 } 2610 }
2617 2611
2618 } // namespace sync_sessions 2612 } // namespace sync_sessions
OLDNEW
« no previous file with comments | « no previous file | components/sync_sessions/sessions_sync_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698