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

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

Issue 81923003: sync: add garbage collection to SessionsSyncManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: undo last upload Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/sessions2/sessions_sync_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/sync/sessions2/sessions_sync_manager.h" 5 #include "chrome/browser/sync/sessions2/sessions_sync_manager.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/sessions/session_id.h" 9 #include "chrome/browser/sessions/session_id.h"
10 #include "chrome/browser/sessions/session_tab_helper.h" 10 #include "chrome/browser/sessions/session_tab_helper.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_TRUE(found); 194 EXPECT_TRUE(found);
195 return list; 195 return list;
196 } 196 }
197 197
198 private: 198 private:
199 scoped_ptr<SessionsSyncManager> manager_; 199 scoped_ptr<SessionsSyncManager> manager_;
200 SessionSyncTestHelper helper_; 200 SessionSyncTestHelper helper_;
201 TestSyncProcessorStub* test_processor_; 201 TestSyncProcessorStub* test_processor_;
202 }; 202 };
203 203
204 // Test that the SyncSessionManager can properly fill in a SessionHeader.
204 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) { 205 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) {
205 sync_pb::SessionHeader header_s; 206 sync_pb::SessionHeader header_s;
206 header_s.set_client_name("Client 1"); 207 header_s.set_client_name("Client 1");
207 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN); 208 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN);
208 209
209 SyncedSession session; 210 SyncedSession session;
210 base::Time time = base::Time::Now(); 211 base::Time time = base::Time::Now();
211 SessionsSyncManager::PopulateSessionHeaderFromSpecifics( 212 SessionsSyncManager::PopulateSessionHeaderFromSpecifics(
212 header_s, time, &session); 213 header_s, time, &session);
213 ASSERT_EQ("Client 1", session.session_name); 214 ASSERT_EQ("Client 1", session.session_name);
214 ASSERT_EQ(SyncedSession::TYPE_WIN, session.device_type); 215 ASSERT_EQ(SyncedSession::TYPE_WIN, session.device_type);
215 ASSERT_EQ(time, session.modified_time); 216 ASSERT_EQ(time, session.modified_time);
216 } 217 }
217 218
219 // Test translation between protobuf types and chrome session types.
218 TEST_F(SessionsSyncManagerTest, PopulateSessionWindow) { 220 TEST_F(SessionsSyncManagerTest, PopulateSessionWindow) {
219 sync_pb::SessionWindow window_s; 221 sync_pb::SessionWindow window_s;
220 window_s.add_tab(0); 222 window_s.add_tab(0);
221 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); 223 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED);
222 window_s.set_selected_tab_index(1); 224 window_s.set_selected_tab_index(1);
223 225
224 std::string tag = "tag"; 226 std::string tag = "tag";
225 SyncedSession* session = manager()->session_tracker_.GetSession(tag); 227 SyncedSession* session = manager()->session_tracker_.GetSession(tag);
226 manager()->session_tracker_.PutWindowInSession(tag, 0); 228 manager()->session_tracker_.PutWindowInSession(tag, 0);
227 manager()->BuildSyncedSessionFromSpecifics( 229 manager()->BuildSyncedSessionFromSpecifics(
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 EXPECT_EQ(kTime3, session_tab.navigations[2].timestamp()); 518 EXPECT_EQ(kTime3, session_tab.navigations[2].timestamp());
517 EXPECT_EQ(SerializedNavigationEntry::STATE_ALLOWED, 519 EXPECT_EQ(SerializedNavigationEntry::STATE_ALLOWED,
518 session_tab.navigations[0].blocked_state()); 520 session_tab.navigations[0].blocked_state());
519 EXPECT_EQ(SerializedNavigationEntry::STATE_BLOCKED, 521 EXPECT_EQ(SerializedNavigationEntry::STATE_BLOCKED,
520 session_tab.navigations[1].blocked_state()); 522 session_tab.navigations[1].blocked_state());
521 EXPECT_EQ(SerializedNavigationEntry::STATE_BLOCKED, 523 EXPECT_EQ(SerializedNavigationEntry::STATE_BLOCKED,
522 session_tab.navigations[2].blocked_state()); 524 session_tab.navigations[2].blocked_state());
523 EXPECT_TRUE(session_tab.session_storage_persistent_id.empty()); 525 EXPECT_TRUE(session_tab.session_storage_persistent_id.empty());
524 } 526 }
525 527
528 // Tests that the local session header objects is created properly in
529 // presence of no other session activity, once and only once.
526 TEST_F(SessionsSyncManagerTest, MergeLocalSessionNoTabs) { 530 TEST_F(SessionsSyncManagerTest, MergeLocalSessionNoTabs) {
527 syncer::SyncChangeList out; 531 syncer::SyncChangeList out;
528 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); 532 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out);
529 EXPECT_FALSE(manager()->current_machine_tag().empty()); 533 EXPECT_FALSE(manager()->current_machine_tag().empty());
530 534
531 EXPECT_EQ(2U, out.size()); 535 EXPECT_EQ(2U, out.size());
532 EXPECT_TRUE(out[0].IsValid()); 536 EXPECT_TRUE(out[0].IsValid());
533 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); 537 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type());
534 const SyncData data(out[0].sync_data()); 538 const SyncData data(out[0].sync_data());
535 EXPECT_EQ(manager()->current_machine_tag(), data.GetTag()); 539 EXPECT_EQ(manager()->current_machine_tag(), data.GetTag());
(...skipping 26 matching lines...) Expand all
562 new TestSyncProcessorStub(&out)), 566 new TestSyncProcessorStub(&out)),
563 scoped_ptr<syncer::SyncErrorFactory>( 567 scoped_ptr<syncer::SyncErrorFactory>(
564 new syncer::SyncErrorFactoryMock())); 568 new syncer::SyncErrorFactoryMock()));
565 ASSERT_FALSE(result.error().IsSet()); 569 ASSERT_FALSE(result.error().IsSet());
566 570
567 EXPECT_EQ(1U, out.size()); 571 EXPECT_EQ(1U, out.size());
568 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 572 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
569 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); 573 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header());
570 } 574 }
571 575
576 // Tests MergeDataAndStartSyncing with sync data but no local data.
572 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) { 577 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) {
573 std::string tag = "tag1"; 578 std::string tag = "tag1";
574 579
575 SessionID::id_type n1[] = {5, 10, 13, 17}; 580 SessionID::id_type n1[] = {5, 10, 13, 17};
576 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); 581 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
577 std::vector<sync_pb::SessionSpecifics> tabs1; 582 std::vector<sync_pb::SessionSpecifics> tabs1;
578 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( 583 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
579 tag, tab_list1, &tabs1)); 584 tag, tab_list1, &tabs1));
580 // Add a second window. 585 // Add a second window.
581 SessionID::id_type n2[] = {7, 15, 18, 20}; 586 SessionID::id_type n2[] = {7, 15, 18, 20};
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); 682 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
678 std::vector<std::vector<SessionID::id_type> > session_reference; 683 std::vector<std::vector<SessionID::id_type> > session_reference;
679 session_reference.push_back(tab_list1); 684 session_reference.push_back(tab_list1);
680 helper()->VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); 685 helper()->VerifySyncedSession(tag, session_reference, *(foreign_sessions[0]));
681 // There should be one and only one foreign session. If VerifySyncedSession 686 // There should be one and only one foreign session. If VerifySyncedSession
682 // was successful above this EXPECT call ensures the local session didn't 687 // was successful above this EXPECT call ensures the local session didn't
683 // get mistakenly added to foreign tracking (Similar to ExistingTabs test). 688 // get mistakenly added to foreign tracking (Similar to ExistingTabs test).
684 EXPECT_EQ(1U, foreign_sessions.size()); 689 EXPECT_EQ(1U, foreign_sessions.size());
685 } 690 }
686 691
692 // Tests the common scenario. Merge with both local and foreign session data
693 // followed by updates flowing from sync and local.
687 TEST_F(SessionsSyncManagerTest, UpdatesAfterMixedMerge) { 694 TEST_F(SessionsSyncManagerTest, UpdatesAfterMixedMerge) {
688 // Add local and foreign data. 695 // Add local and foreign data.
689 AddTab(browser(), GURL("http://foo1")); 696 AddTab(browser(), GURL("http://foo1"));
690 NavigateAndCommitActiveTab(GURL("http://foo2")); 697 NavigateAndCommitActiveTab(GURL("http://foo2"));
691 698
692 std::string tag1 = "tag1"; 699 std::string tag1 = "tag1";
693 syncer::SyncDataList foreign_data1; 700 syncer::SyncDataList foreign_data1;
694 std::vector<std::vector<SessionID::id_type> > meta1_reference; 701 std::vector<std::vector<SessionID::id_type> > meta1_reference;
695 sync_pb::SessionSpecifics meta1; 702 sync_pb::SessionSpecifics meta1;
696 703
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 removal.push_back(MakeRemoteChange(1, meta1, SyncChange::ACTION_UPDATE)); 777 removal.push_back(MakeRemoteChange(1, meta1, SyncChange::ACTION_UPDATE));
771 AddTabsToChangeList(tabs1, SyncChange::ACTION_UPDATE, &removal); 778 AddTabsToChangeList(tabs1, SyncChange::ACTION_UPDATE, &removal);
772 manager()->ProcessSyncChanges(FROM_HERE, removal); 779 manager()->ProcessSyncChanges(FROM_HERE, removal);
773 780
774 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); 781 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
775 ASSERT_EQ(2U, foreign_sessions.size()); 782 ASSERT_EQ(2U, foreign_sessions.size());
776 ASSERT_EQ(3U, foreign_sessions[0]->windows.find(0)->second->tabs.size()); 783 ASSERT_EQ(3U, foreign_sessions[0]->windows.find(0)->second->tabs.size());
777 helper()->VerifySyncedSession(tag1, meta1_reference, *(foreign_sessions[0])); 784 helper()->VerifySyncedSession(tag1, meta1_reference, *(foreign_sessions[0]));
778 } 785 }
779 786
787 // Tests that this SyncSessionManager knows how to delete foreign sessions
788 // if it wants to.
780 TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { 789 TEST_F(SessionsSyncManagerTest, DeleteForeignSession) {
781 InitWithNoSyncData(); 790 InitWithNoSyncData();
782 std::string tag = "tag1"; 791 std::string tag = "tag1";
783 syncer::SyncChangeList changes; 792 syncer::SyncChangeList changes;
784 793
785 std::vector<const SyncedSession*> foreign_sessions; 794 std::vector<const SyncedSession*> foreign_sessions;
786 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); 795 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions));
787 manager()->DeleteForeignSessionInternal(tag, &changes); 796 manager()->DeleteForeignSessionInternal(tag, &changes);
788 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); 797 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions));
789 EXPECT_TRUE(changes.empty()); 798 EXPECT_TRUE(changes.empty());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // Check that the foreign session was associated and retrieve the data. 907 // Check that the foreign session was associated and retrieve the data.
899 foreign_sessions.clear(); 908 foreign_sessions.clear();
900 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); 909 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
901 ASSERT_EQ(1U, foreign_sessions.size()); 910 ASSERT_EQ(1U, foreign_sessions.size());
902 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); 911 ASSERT_EQ(1U, foreign_sessions[0]->windows.size());
903 std::vector<std::vector<SessionID::id_type> > session_reference; 912 std::vector<std::vector<SessionID::id_type> > session_reference;
904 session_reference.push_back(tab_list1); 913 session_reference.push_back(tab_list1);
905 helper()->VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); 914 helper()->VerifySyncedSession(tag, session_reference, *(foreign_sessions[0]));
906 } 915 }
907 916
917 // Test that receiving a session delete from sync removes the session
918 // from tracking.
908 TEST_F(SessionsSyncManagerTest, ProcessForeignDelete) { 919 TEST_F(SessionsSyncManagerTest, ProcessForeignDelete) {
909 InitWithNoSyncData(); 920 InitWithNoSyncData();
910 SessionID::id_type n[] = {5}; 921 SessionID::id_type n[] = {5};
911 std::vector<sync_pb::SessionSpecifics> tabs1; 922 std::vector<sync_pb::SessionSpecifics> tabs1;
912 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); 923 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n));
913 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( 924 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
914 "tag1", tab_list, &tabs1)); 925 "tag1", tab_list, &tabs1));
915 926
916 syncer::SyncChangeList changes; 927 syncer::SyncChangeList changes;
917 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_ADD)); 928 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_ADD));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 const SyncData data(out[2].sync_data()); 1024 const SyncData data(out[2].sync_data());
1014 EXPECT_EQ(manager()->current_machine_tag(), data.GetTag()); 1025 EXPECT_EQ(manager()->current_machine_tag(), data.GetTag());
1015 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); 1026 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session());
1016 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); 1027 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag());
1017 EXPECT_TRUE(specifics.has_header()); 1028 EXPECT_TRUE(specifics.has_header());
1018 const sync_pb::SessionHeader& header_s = specifics.header(); 1029 const sync_pb::SessionHeader& header_s = specifics.header();
1019 EXPECT_EQ(1, header_s.window_size()); 1030 EXPECT_EQ(1, header_s.window_size());
1020 EXPECT_EQ(1, header_s.window(0).tab_size()); 1031 EXPECT_EQ(1, header_s.window(0).tab_size());
1021 } 1032 }
1022 1033
1034 // Tests that the SyncSessionManager responds to local tab events properly.
1023 TEST_F(SessionsSyncManagerTest, OnLocalTabModified) { 1035 TEST_F(SessionsSyncManagerTest, OnLocalTabModified) {
1024 syncer::SyncChangeList out; 1036 syncer::SyncChangeList out;
1025 // Init with no local data, relies on MergeLocalSessionNoTabs. 1037 // Init with no local data, relies on MergeLocalSessionNoTabs.
1026 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); 1038 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out);
1027 ASSERT_FALSE(manager()->current_machine_tag().empty()); 1039 ASSERT_FALSE(manager()->current_machine_tag().empty());
1028 ASSERT_EQ(2U, out.size()); 1040 ASSERT_EQ(2U, out.size());
1029 1041
1030 // Copy the original header. 1042 // Copy the original header.
1031 sync_pb::EntitySpecifics header(out[0].sync_data().GetSpecifics()); 1043 sync_pb::EntitySpecifics header(out[0].sync_data().GetSpecifics());
1032 out.clear(); 1044 out.clear();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()-> 1194 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->
1183 GetEntryAtIndex(1)->GetVirtualURL()); 1195 GetEntryAtIndex(1)->GetVirtualURL());
1184 iter++; 1196 iter++;
1185 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); 1197 ASSERT_EQ(2, iter->second->tab()->GetEntryCount());
1186 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()-> 1198 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->
1187 GetEntryAtIndex(0)->GetVirtualURL()); 1199 GetEntryAtIndex(0)->GetVirtualURL());
1188 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()-> 1200 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->
1189 GetEntryAtIndex(1)->GetVirtualURL()); 1201 GetEntryAtIndex(1)->GetVirtualURL());
1190 } 1202 }
1191 1203
1204 // Test garbage collection of stale foreign sessions.
1205 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) {
1206 // Fill two instances of session specifics with a foreign session's data.
1207 std::string tag1 = "tag1";
1208 SessionID::id_type n1[] = {5, 10, 13, 17};
1209 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
1210 std::vector<sync_pb::SessionSpecifics> tabs1;
1211 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
1212 tag1, tab_list1, &tabs1));
1213 std::string tag2 = "tag2";
1214 SessionID::id_type n2[] = {8, 15, 18, 20};
1215 std::vector<SessionID::id_type> tab_list2(n2, n2 + arraysize(n2));
1216 std::vector<sync_pb::SessionSpecifics> tabs2;
1217 sync_pb::SessionSpecifics meta2(helper()->BuildForeignSession(
1218 tag2, tab_list2, &tabs2));
1219 // Set the modification time for tag1 to be 21 days ago, tag2 to 5 days ago.
1220 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21);
1221 base::Time tag2_time = base::Time::Now() - base::TimeDelta::FromDays(5);
1222
1223 syncer::SyncDataList foreign_data;
1224 sync_pb::EntitySpecifics entity1, entity2;
1225 entity1.mutable_session()->CopyFrom(meta);
1226 entity2.mutable_session()->CopyFrom(meta2);
1227 foreign_data.push_back(SyncData::CreateRemoteData(1, entity1, tag1_time));
1228 foreign_data.push_back(SyncData::CreateRemoteData(1, entity2, tag2_time));
1229 AddTabsToSyncDataList(tabs1, &foreign_data);
1230 AddTabsToSyncDataList(tabs2, &foreign_data);
1231
1232 syncer::SyncChangeList output;
1233 InitWithSyncDataTakeOutput(foreign_data, &output);
1234 ASSERT_EQ(2U, output.size());
1235 output.clear();
1236
1237 // Check that the foreign session was associated and retrieve the data.
1238 std::vector<const SyncedSession*> foreign_sessions;
1239 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
1240 ASSERT_EQ(2U, foreign_sessions.size());
1241 foreign_sessions.clear();
1242
1243 // Now garbage collect and verify the non-stale session is still there.
1244 manager()->DoGarbageCollection();
1245 ASSERT_EQ(5U, output.size());
1246 EXPECT_EQ(SyncChange::ACTION_DELETE, output[0].change_type());
1247 const SyncData data(output[0].sync_data());
1248 EXPECT_EQ(tag1, data.GetTag());
1249 for (int i = 1; i < 5; i++) {
1250 EXPECT_EQ(SyncChange::ACTION_DELETE, output[i].change_type());
1251 const SyncData data(output[i].sync_data());
1252 EXPECT_EQ(TabNodePool2::TabIdToTag(tag1, i), data.GetTag());
1253 }
1254
1255 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
1256 ASSERT_EQ(1U, foreign_sessions.size());
1257 std::vector<std::vector<SessionID::id_type> > session_reference;
1258 session_reference.push_back(tab_list2);
1259 helper()->VerifySyncedSession(tag2, session_reference,
1260 *(foreign_sessions[0]));
1261 }
1262
1263 // Test that an update to a previously considered "stale" session,
1264 // prior to garbage collection, will save the session from deletion.
1265 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) {
1266 std::string tag1 = "tag1";
1267 SessionID::id_type n1[] = {5, 10, 13, 17};
1268 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
1269 std::vector<sync_pb::SessionSpecifics> tabs1;
1270 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
1271 tag1, tab_list1, &tabs1));
1272 syncer::SyncDataList foreign_data;
1273 sync_pb::EntitySpecifics entity1;
1274 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21);
1275 entity1.mutable_session()->CopyFrom(meta);
1276 foreign_data.push_back(SyncData::CreateRemoteData(1, entity1, tag1_time));
1277 AddTabsToSyncDataList(tabs1, &foreign_data);
1278 syncer::SyncChangeList output;
1279 InitWithSyncDataTakeOutput(foreign_data, &output);
1280 ASSERT_EQ(2U, output.size());
1281
1282 // Update to a non-stale time.
1283 sync_pb::EntitySpecifics update_entity;
1284 update_entity.mutable_session()->CopyFrom(tabs1[0]);
1285 syncer::SyncChangeList changes;
1286 changes.push_back(syncer::SyncChange(
1287 FROM_HERE,
1288 SyncChange::ACTION_UPDATE,
1289 syncer::SyncData::CreateRemoteData(1, update_entity,
1290 base::Time::Now())));
1291 manager()->ProcessSyncChanges(FROM_HERE, changes);
1292
1293 // Check that the foreign session was associated and retrieve the data.
1294 std::vector<const SyncedSession*> foreign_sessions;
1295 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
1296 ASSERT_EQ(1U, foreign_sessions.size());
1297 foreign_sessions.clear();
1298
1299 // Verify the now non-stale session does not get deleted.
1300 manager()->DoGarbageCollection();
1301 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
1302 ASSERT_EQ(1U, foreign_sessions.size());
1303 std::vector<std::vector<SessionID::id_type> > session_reference;
1304 session_reference.push_back(tab_list1);
1305 helper()->VerifySyncedSession(
1306 tag1, session_reference, *(foreign_sessions[0]));
1307 }
1308
1309 // Test that swapping WebContents for a tab is properly observed and handled
1310 // by the SessionsSyncManager.
1192 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { 1311 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) {
1193 AddTab(browser(), GURL("http://foo1")); 1312 AddTab(browser(), GURL("http://foo1"));
1194 NavigateAndCommitActiveTab(GURL("http://foo2")); 1313 NavigateAndCommitActiveTab(GURL("http://foo2"));
1195 1314
1196 syncer::SyncChangeList out; 1315 syncer::SyncChangeList out;
1197 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); 1316 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out);
1198 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE. 1317 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE.
1199 1318
1200 // To simulate WebContents swap during prerendering, create new WebContents 1319 // To simulate WebContents swap during prerendering, create new WebContents
1201 // and swap with old WebContents. 1320 // and swap with old WebContents.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 notified_of_update_ = false; 1386 notified_of_update_ = false;
1268 notified_of_refresh_ = false; 1387 notified_of_refresh_ = false;
1269 } 1388 }
1270 private: 1389 private:
1271 content::NotificationRegistrar registrar_; 1390 content::NotificationRegistrar registrar_;
1272 bool notified_of_update_; 1391 bool notified_of_update_;
1273 bool notified_of_refresh_; 1392 bool notified_of_refresh_;
1274 }; 1393 };
1275 } // namespace 1394 } // namespace
1276 1395
1396 // Test that NOTIFICATION_FOREIGN_SESSION_UPDATED is sent.
1277 TEST_F(SessionsSyncManagerTest, NotifiedOfUpdates) { 1397 TEST_F(SessionsSyncManagerTest, NotifiedOfUpdates) {
1278 SessionNotificationObserver observer; 1398 SessionNotificationObserver observer;
1279 ASSERT_FALSE(observer.notified_of_update()); 1399 ASSERT_FALSE(observer.notified_of_update());
1280 InitWithNoSyncData(); 1400 InitWithNoSyncData();
1281 1401
1282 SessionID::id_type n[] = {5}; 1402 SessionID::id_type n[] = {5};
1283 std::vector<sync_pb::SessionSpecifics> tabs1; 1403 std::vector<sync_pb::SessionSpecifics> tabs1;
1284 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); 1404 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n));
1285 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( 1405 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession(
1286 "tag1", tab_list, &tabs1)); 1406 "tag1", tab_list, &tabs1));
(...skipping 25 matching lines...) Expand all
1312 ASSERT_FALSE(observer.notified_of_refresh()); 1432 ASSERT_FALSE(observer.notified_of_refresh());
1313 InitWithNoSyncData(); 1433 InitWithNoSyncData();
1314 AddTab(browser(), GURL("http://foo1")); 1434 AddTab(browser(), GURL("http://foo1"));
1315 EXPECT_FALSE(observer.notified_of_refresh()); 1435 EXPECT_FALSE(observer.notified_of_refresh());
1316 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); 1436 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs"));
1317 EXPECT_TRUE(observer.notified_of_refresh()); 1437 EXPECT_TRUE(observer.notified_of_refresh());
1318 } 1438 }
1319 #endif // defined(OS_ANDROID) || defined(OS_IOS) 1439 #endif // defined(OS_ANDROID) || defined(OS_IOS)
1320 1440
1321 } // namespace browser_sync 1441 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions2/sessions_sync_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698