OLD | NEW |
---|---|
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 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1182 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()-> | 1182 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()-> |
1183 GetEntryAtIndex(1)->GetVirtualURL()); | 1183 GetEntryAtIndex(1)->GetVirtualURL()); |
1184 iter++; | 1184 iter++; |
1185 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 1185 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
1186 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()-> | 1186 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()-> |
1187 GetEntryAtIndex(0)->GetVirtualURL()); | 1187 GetEntryAtIndex(0)->GetVirtualURL()); |
1188 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()-> | 1188 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()-> |
1189 GetEntryAtIndex(1)->GetVirtualURL()); | 1189 GetEntryAtIndex(1)->GetVirtualURL()); |
1190 } | 1190 } |
1191 | 1191 |
1192 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { | |
rlarocque
2013/11/22 01:42:06
nit: Comment on the purpose of this test. And the
| |
1193 // Fill two instances of session specifics with a foreign session's data. | |
1194 std::string tag1 = "tag1"; | |
1195 SessionID::id_type n1[] = {5, 10, 13, 17}; | |
1196 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | |
1197 std::vector<sync_pb::SessionSpecifics> tabs1; | |
1198 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | |
1199 tag1, tab_list1, &tabs1)); | |
1200 std::string tag2 = "tag2"; | |
1201 SessionID::id_type n2[] = {8, 15, 18, 20}; | |
1202 std::vector<SessionID::id_type> tab_list2(n2, n2 + arraysize(n2)); | |
1203 std::vector<sync_pb::SessionSpecifics> tabs2; | |
1204 sync_pb::SessionSpecifics meta2(helper()->BuildForeignSession( | |
1205 tag2, tab_list2, &tabs2)); | |
1206 // Set the modification time for tag1 to be 21 days ago, tag2 to 5 days ago. | |
1207 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21); | |
1208 base::Time tag2_time = base::Time::Now() - base::TimeDelta::FromDays(5); | |
1209 | |
1210 syncer::SyncDataList foreign_data; | |
1211 sync_pb::EntitySpecifics entity1, entity2; | |
1212 entity1.mutable_session()->CopyFrom(meta); | |
1213 entity2.mutable_session()->CopyFrom(meta2); | |
1214 foreign_data.push_back(SyncData::CreateRemoteData(1, entity1, tag1_time)); | |
1215 foreign_data.push_back(SyncData::CreateRemoteData(1, entity2, tag2_time)); | |
1216 AddTabsToSyncDataList(tabs1, &foreign_data); | |
1217 AddTabsToSyncDataList(tabs2, &foreign_data); | |
1218 | |
1219 syncer::SyncChangeList output; | |
1220 InitWithSyncDataTakeOutput(foreign_data, &output); | |
1221 ASSERT_EQ(2U, output.size()); | |
1222 output.clear(); | |
1223 | |
1224 // Check that the foreign session was associated and retrieve the data. | |
1225 std::vector<const SyncedSession*> foreign_sessions; | |
1226 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | |
1227 ASSERT_EQ(2U, foreign_sessions.size()); | |
1228 foreign_sessions.clear(); | |
1229 | |
1230 // Now garbage collect and verify the non-stale session is still there. | |
1231 manager()->DoGarbageCollection(); | |
1232 ASSERT_EQ(5U, output.size()); | |
1233 EXPECT_EQ(SyncChange::ACTION_DELETE, output[0].change_type()); | |
1234 const SyncData data(output[0].sync_data()); | |
1235 EXPECT_EQ(tag1, data.GetTag()); | |
1236 for (int i = 1; i < 5; i++) { | |
1237 EXPECT_EQ(SyncChange::ACTION_DELETE, output[i].change_type()); | |
1238 const SyncData data(output[i].sync_data()); | |
1239 EXPECT_EQ(TabNodePool2::TabIdToTag(tag1, i), data.GetTag()); | |
1240 } | |
1241 | |
1242 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | |
1243 ASSERT_EQ(1U, foreign_sessions.size()); | |
1244 std::vector<std::vector<SessionID::id_type> > session_reference; | |
1245 session_reference.push_back(tab_list2); | |
1246 helper()->VerifySyncedSession(tag2, session_reference, | |
1247 *(foreign_sessions[0])); | |
1248 } | |
1249 | |
1250 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { | |
1251 std::string tag1 = "tag1"; | |
1252 SessionID::id_type n1[] = {5, 10, 13, 17}; | |
1253 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | |
1254 std::vector<sync_pb::SessionSpecifics> tabs1; | |
1255 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | |
1256 tag1, tab_list1, &tabs1)); | |
1257 syncer::SyncDataList foreign_data; | |
1258 sync_pb::EntitySpecifics entity1; | |
1259 base::Time tag1_time = base::Time::Now() - base::TimeDelta::FromDays(21); | |
1260 entity1.mutable_session()->CopyFrom(meta); | |
1261 foreign_data.push_back(SyncData::CreateRemoteData(1, entity1, tag1_time)); | |
1262 AddTabsToSyncDataList(tabs1, &foreign_data); | |
1263 syncer::SyncChangeList output; | |
1264 InitWithSyncDataTakeOutput(foreign_data, &output); | |
1265 ASSERT_EQ(2U, output.size()); | |
1266 | |
1267 // Update to a non-stale time. | |
1268 sync_pb::EntitySpecifics update_entity; | |
1269 update_entity.mutable_session()->CopyFrom(tabs1[0]); | |
1270 syncer::SyncChangeList changes; | |
1271 changes.push_back(syncer::SyncChange( | |
1272 FROM_HERE, | |
1273 SyncChange::ACTION_UPDATE, | |
1274 syncer::SyncData::CreateRemoteData(1, update_entity, | |
1275 base::Time::Now()))); | |
1276 manager()->ProcessSyncChanges(FROM_HERE, changes); | |
1277 | |
1278 // Check that the foreign session was associated and retrieve the data. | |
1279 std::vector<const SyncedSession*> foreign_sessions; | |
1280 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | |
1281 ASSERT_EQ(1U, foreign_sessions.size()); | |
1282 foreign_sessions.clear(); | |
1283 | |
1284 // Verify the now non-stale session does not get deleted. | |
1285 manager()->DoGarbageCollection(); | |
1286 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | |
1287 ASSERT_EQ(1U, foreign_sessions.size()); | |
1288 std::vector<std::vector<SessionID::id_type> > session_reference; | |
1289 session_reference.push_back(tab_list1); | |
1290 helper()->VerifySyncedSession( | |
1291 tag1, session_reference, *(foreign_sessions[0])); | |
1292 } | |
1293 | |
1192 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { | 1294 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { |
1193 AddTab(browser(), GURL("http://foo1")); | 1295 AddTab(browser(), GURL("http://foo1")); |
1194 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1296 NavigateAndCommitActiveTab(GURL("http://foo2")); |
1195 | 1297 |
1196 syncer::SyncChangeList out; | 1298 syncer::SyncChangeList out; |
1197 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 1299 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
1198 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE. | 1300 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE. |
1199 | 1301 |
1200 // To simulate WebContents swap during prerendering, create new WebContents | 1302 // To simulate WebContents swap during prerendering, create new WebContents |
1201 // and swap with old WebContents. | 1303 // and swap with old WebContents. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1307 SessionNotificationObserver observer; | 1409 SessionNotificationObserver observer; |
1308 ASSERT_FALSE(observer.notified_of_refresh()); | 1410 ASSERT_FALSE(observer.notified_of_refresh()); |
1309 InitWithNoSyncData(); | 1411 InitWithNoSyncData(); |
1310 AddTab(browser(), GURL("http://foo1")); | 1412 AddTab(browser(), GURL("http://foo1")); |
1311 EXPECT_FALSE(observer.notified_of_refresh()); | 1413 EXPECT_FALSE(observer.notified_of_refresh()); |
1312 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); | 1414 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); |
1313 EXPECT_TRUE(observer.notified_of_refresh()); | 1415 EXPECT_TRUE(observer.notified_of_refresh()); |
1314 } | 1416 } |
1315 | 1417 |
1316 } // namespace browser_sync | 1418 } // namespace browser_sync |
OLD | NEW |