| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 type, | 220 type, |
| 221 syncer::SyncData::CreateRemoteData( | 221 syncer::SyncData::CreateRemoteData( |
| 222 iter->tab_node_id(), | 222 iter->tab_node_id(), |
| 223 entity, | 223 entity, |
| 224 base::Time(), | 224 base::Time(), |
| 225 syncer::AttachmentIdList(), | 225 syncer::AttachmentIdList(), |
| 226 syncer::AttachmentServiceProxyForTest::Create()))); | 226 syncer::AttachmentServiceProxyForTest::Create()))); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 void AddToSyncDataList(const sync_pb::SessionSpecifics& specifics, |
| 231 syncer::SyncDataList* list, |
| 232 base::Time mtime) { |
| 233 sync_pb::EntitySpecifics entity; |
| 234 entity.mutable_session()->CopyFrom(specifics); |
| 235 list->push_back(SyncData::CreateRemoteData( |
| 236 1, entity, mtime, syncer::AttachmentIdList(), |
| 237 syncer::AttachmentServiceProxyForTest::Create())); |
| 238 } |
| 239 |
| 230 void AddTabsToSyncDataList(const std::vector<sync_pb::SessionSpecifics> tabs, | 240 void AddTabsToSyncDataList(const std::vector<sync_pb::SessionSpecifics> tabs, |
| 231 syncer::SyncDataList* list) { | 241 syncer::SyncDataList* list) { |
| 232 for (size_t i = 0; i < tabs.size(); i++) { | 242 for (size_t i = 0; i < tabs.size(); i++) { |
| 233 sync_pb::EntitySpecifics entity; | 243 AddToSyncDataList(tabs[i], list, base::Time::FromInternalValue(i + 1)); |
| 234 entity.mutable_session()->CopyFrom(tabs[i]); | |
| 235 list->push_back(SyncData::CreateRemoteData( | |
| 236 i + 2, | |
| 237 entity, | |
| 238 base::Time::FromInternalValue(i + 1), | |
| 239 syncer::AttachmentIdList(), | |
| 240 syncer::AttachmentServiceProxyForTest::Create())); | |
| 241 } | 244 } |
| 242 } | 245 } |
| 243 | 246 |
| 244 // Creates a field trial with the specified |trial_name| and |group_name| and | 247 // Creates a field trial with the specified |trial_name| and |group_name| and |
| 245 // registers an associated |variation_id| for it for the given |service|. | 248 // registers an associated |variation_id| for it for the given |service|. |
| 246 void CreateAndActivateFieldTrial(const std::string& trial_name, | 249 void CreateAndActivateFieldTrial(const std::string& trial_name, |
| 247 const std::string& group_name, | 250 const std::string& group_name, |
| 248 variations::VariationID variation_id, | 251 variations::VariationID variation_id, |
| 249 variations::IDCollectionKey service) { | 252 variations::IDCollectionKey service) { |
| 250 base::FieldTrialList::CreateFieldTrial(trial_name, group_name); | 253 base::FieldTrialList::CreateFieldTrial(trial_name, group_name); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 return false; | 558 return false; |
| 556 } | 559 } |
| 557 | 560 |
| 558 void reset() { | 561 void reset() { |
| 559 current_entry_index_ = 0; | 562 current_entry_index_ = 0; |
| 560 sync_id_ = -1; | 563 sync_id_ = -1; |
| 561 entries_.clear(); | 564 entries_.clear(); |
| 562 } | 565 } |
| 563 | 566 |
| 564 private: | 567 private: |
| 565 int current_entry_index_; | 568 int current_entry_index_; |
| 566 bool is_supervised_; | 569 bool is_supervised_; |
| 567 int sync_id_; | 570 int sync_id_; |
| 568 ScopedVector<const sessions::SerializedNavigationEntry> blocked_navigations_; | 571 ScopedVector<const sessions::SerializedNavigationEntry> blocked_navigations_; |
| 569 ScopedVector<content::NavigationEntry> entries_; | 572 ScopedVector<content::NavigationEntry> entries_; |
| 570 }; | 573 }; |
| 571 | 574 |
| 572 } // namespace | 575 } // namespace |
| 573 | 576 |
| 574 static const base::Time kTime0 = base::Time::FromInternalValue(100); | 577 static const base::Time kTime0 = base::Time::FromInternalValue(100); |
| 575 static const base::Time kTime1 = base::Time::FromInternalValue(110); | 578 static const base::Time kTime1 = base::Time::FromInternalValue(110); |
| 576 static const base::Time kTime2 = base::Time::FromInternalValue(120); | 579 static const base::Time kTime2 = base::Time::FromInternalValue(120); |
| 577 static const base::Time kTime3 = base::Time::FromInternalValue(130); | 580 static const base::Time kTime3 = base::Time::FromInternalValue(130); |
| 578 static const base::Time kTime4 = base::Time::FromInternalValue(140); | 581 static const base::Time kTime4 = base::Time::FromInternalValue(140); |
| 579 static const base::Time kTime5 = base::Time::FromInternalValue(150); | 582 static const base::Time kTime5 = base::Time::FromInternalValue(150); |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 InitWithNoSyncData(); | 1261 InitWithNoSyncData(); |
| 1259 std::string tag = "tag1"; | 1262 std::string tag = "tag1"; |
| 1260 syncer::SyncChangeList changes; | 1263 syncer::SyncChangeList changes; |
| 1261 | 1264 |
| 1262 std::vector<const SyncedSession*> foreign_sessions; | 1265 std::vector<const SyncedSession*> foreign_sessions; |
| 1263 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1266 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1264 manager()->DeleteForeignSessionInternal(tag, &changes); | 1267 manager()->DeleteForeignSessionInternal(tag, &changes); |
| 1265 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1268 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1266 EXPECT_TRUE(changes.empty()); | 1269 EXPECT_TRUE(changes.empty()); |
| 1267 | 1270 |
| 1268 // Fill an instance of session specifics with a foreign session's data. | 1271 // Fill an instance of session specifics with a foreign session's data. |
| 1269 std::vector<sync_pb::SessionSpecifics> tabs; | 1272 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1270 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1273 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1271 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); | 1274 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); |
| 1272 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1275 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1273 tag, tab_nums1, &tabs)); | 1276 tag, tab_nums1, &tabs)); |
| 1274 | 1277 |
| 1275 // Update associator with the session's meta node, window, and tabs. | 1278 // Update associator with the session's meta node, window, and tabs. |
| 1276 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); | 1279 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); |
| 1277 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); | 1280 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); |
| 1278 iter != tabs.end(); ++iter) { | 1281 iter != tabs.end(); ++iter) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 ASSERT_EQ(1U, foreign_sessions.size()); | 1475 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1473 | 1476 |
| 1474 changes.clear(); | 1477 changes.clear(); |
| 1475 foreign_sessions.clear(); | 1478 foreign_sessions.clear(); |
| 1476 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_DELETE)); | 1479 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_DELETE)); |
| 1477 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1480 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1478 | 1481 |
| 1479 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1482 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1480 } | 1483 } |
| 1481 | 1484 |
| 1485 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabs) { |
| 1486 syncer::SyncDataList foreign_data; |
| 1487 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(15); |
| 1488 std::string session_tag = "tag1"; |
| 1489 |
| 1490 // 0 will not have ownership changed. |
| 1491 // 1 will not be updated, but header will stop owning. |
| 1492 // 2 will be deleted before header stops owning. |
| 1493 // 3 will be deleted after header stops owning. |
| 1494 // 4 will be deleted before header update, but header will still try to own. |
| 1495 // 5 will be deleted after header update, but header will still try to own. |
| 1496 // 6 starts orphaned and then deleted before header update. |
| 1497 // 7 starts orphaned and then deleted after header update. |
| 1498 SessionID::id_type tab_ids[] = {0, 1, 2, 3, 4, 5}; |
| 1499 std::vector<SessionID::id_type> tab_list(tab_ids, |
| 1500 tab_ids + arraysize(tab_ids)); |
| 1501 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1502 sync_pb::SessionSpecifics meta( |
| 1503 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 1504 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 1505 AddTabsToSyncDataList(tabs, &foreign_data); |
| 1506 sync_pb::SessionSpecifics orphan6; |
| 1507 helper()->BuildTabSpecifics(session_tag, 0, 6, &orphan6); |
| 1508 AddToSyncDataList(orphan6, &foreign_data, stale_mtime); |
| 1509 sync_pb::SessionSpecifics orphan7; |
| 1510 helper()->BuildTabSpecifics(session_tag, 0, 7, &orphan7); |
| 1511 AddToSyncDataList(orphan7, &foreign_data, stale_mtime); |
| 1512 |
| 1513 syncer::SyncChangeList output; |
| 1514 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1515 ASSERT_EQ(2U, output.size()); |
| 1516 output.clear(); |
| 1517 |
| 1518 SessionID::id_type update_ids[] = {0, 4, 5}; |
| 1519 std::vector<SessionID::id_type> update_list( |
| 1520 update_ids, update_ids + arraysize(update_ids)); |
| 1521 sync_pb::SessionWindow* window = meta.mutable_header()->mutable_window(0); |
| 1522 window->clear_tab(); |
| 1523 for (int i : update_ids) { |
| 1524 window->add_tab(i); |
| 1525 } |
| 1526 |
| 1527 syncer::SyncChangeList changes; |
| 1528 changes.push_back(MakeRemoteChange(1, tabs[2], SyncChange::ACTION_DELETE)); |
| 1529 changes.push_back(MakeRemoteChange(1, tabs[4], SyncChange::ACTION_DELETE)); |
| 1530 changes.push_back(MakeRemoteChange(1, orphan6, SyncChange::ACTION_DELETE)); |
| 1531 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_UPDATE)); |
| 1532 changes.push_back(MakeRemoteChange(1, tabs[3], SyncChange::ACTION_DELETE)); |
| 1533 changes.push_back(MakeRemoteChange(1, tabs[5], SyncChange::ACTION_DELETE)); |
| 1534 changes.push_back(MakeRemoteChange(1, orphan7, SyncChange::ACTION_DELETE)); |
| 1535 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1536 |
| 1537 std::vector<const SyncedSession*> foreign_sessions; |
| 1538 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1539 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1540 std::vector<std::vector<SessionID::id_type>> session_reference; |
| 1541 session_reference.push_back(update_list); |
| 1542 helper()->VerifySyncedSession(session_tag, session_reference, |
| 1543 *(foreign_sessions[0])); |
| 1544 |
| 1545 // Everything except for session, tab0, and tab1 will have no node_id, and |
| 1546 // should get skipped by garbage collection. |
| 1547 manager()->DoGarbageCollection(); |
| 1548 ASSERT_EQ(3U, output.size()); |
| 1549 } |
| 1550 |
| 1551 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithShadowing) { |
| 1552 syncer::SyncDataList foreign_data; |
| 1553 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(16); |
| 1554 std::string session_tag = "tag1"; |
| 1555 |
| 1556 // Add several tabs that shadow eachother, in that they share tab_ids. They |
| 1557 // will, thanks to the helper, have unique tab_node_ids. |
| 1558 sync_pb::SessionSpecifics tab1A; |
| 1559 helper()->BuildTabSpecifics(session_tag, 0, 1, &tab1A); |
| 1560 AddToSyncDataList(tab1A, &foreign_data, |
| 1561 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1562 |
| 1563 sync_pb::SessionSpecifics tab1B; |
| 1564 helper()->BuildTabSpecifics(session_tag, 0, 1, &tab1B); |
| 1565 AddToSyncDataList(tab1B, &foreign_data, |
| 1566 stale_mtime + base::TimeDelta::FromMinutes(2)); |
| 1567 |
| 1568 sync_pb::SessionSpecifics tab1C; |
| 1569 helper()->BuildTabSpecifics(session_tag, 0, 1, &tab1C); |
| 1570 AddToSyncDataList(tab1C, &foreign_data, stale_mtime); |
| 1571 |
| 1572 sync_pb::SessionSpecifics tab2A; |
| 1573 helper()->BuildTabSpecifics(session_tag, 0, 2, &tab2A); |
| 1574 AddToSyncDataList(tab2A, &foreign_data, |
| 1575 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1576 |
| 1577 sync_pb::SessionSpecifics tab2B; |
| 1578 helper()->BuildTabSpecifics(session_tag, 0, 2, &tab2B); |
| 1579 AddToSyncDataList(tab2B, &foreign_data, |
| 1580 stale_mtime + base::TimeDelta::FromMinutes(2)); |
| 1581 |
| 1582 sync_pb::SessionSpecifics tab2C; |
| 1583 helper()->BuildTabSpecifics(session_tag, 0, 2, &tab2C); |
| 1584 AddToSyncDataList(tab2C, &foreign_data, stale_mtime); |
| 1585 |
| 1586 syncer::SyncChangeList output; |
| 1587 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1588 ASSERT_EQ(2U, output.size()); |
| 1589 output.clear(); |
| 1590 |
| 1591 std::set<int> tab_node_ids; |
| 1592 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1593 EXPECT_EQ(6U, tab_node_ids.size()); |
| 1594 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); |
| 1595 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); |
| 1596 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1597 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1598 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1599 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); |
| 1600 |
| 1601 syncer::SyncChangeList changes; |
| 1602 changes.push_back(MakeRemoteChange(1, tab1A, SyncChange::ACTION_DELETE)); |
| 1603 changes.push_back(MakeRemoteChange(1, tab1B, SyncChange::ACTION_DELETE)); |
| 1604 changes.push_back(MakeRemoteChange(1, tab2C, SyncChange::ACTION_DELETE)); |
| 1605 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1606 |
| 1607 tab_node_ids.clear(); |
| 1608 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1609 EXPECT_EQ(3U, tab_node_ids.size()); |
| 1610 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1611 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1612 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1613 |
| 1614 manager()->DoGarbageCollection(); |
| 1615 ASSERT_EQ(3U, output.size()); |
| 1616 } |
| 1617 |
| 1482 // TODO(shashishekhar): "Move this to TabNodePool unittests." | 1618 // TODO(shashishekhar): "Move this to TabNodePool unittests." |
| 1483 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { | 1619 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { |
| 1484 syncer::SyncChangeList changes; | 1620 syncer::SyncChangeList changes; |
| 1485 InitWithNoSyncData(); | 1621 InitWithNoSyncData(); |
| 1486 | 1622 |
| 1487 std::string local_tag = manager()->current_machine_tag(); | 1623 std::string local_tag = manager()->current_machine_tag(); |
| 1488 // Create a free node and then dissassociate sessions so that it ends up | 1624 // Create a free node and then dissassociate sessions so that it ends up |
| 1489 // unassociated. | 1625 // unassociated. |
| 1490 manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1626 manager()->local_tab_pool_.GetFreeTabNode(&changes); |
| 1491 | 1627 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); | 1954 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); |
| 1819 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 1955 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 1820 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | 1956 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 1821 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | 1957 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 1822 iter++; | 1958 iter++; |
| 1823 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 1959 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 1824 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | 1960 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 1825 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | 1961 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 1826 } | 1962 } |
| 1827 | 1963 |
| 1964 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { |
| 1965 syncer::SyncDataList foreign_data; |
| 1966 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 1967 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); |
| 1968 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); |
| 1969 |
| 1970 { |
| 1971 std::string session_tag = "tag1"; |
| 1972 SessionID::id_type n[] = {1, 2}; |
| 1973 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 1974 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1975 sync_pb::SessionSpecifics meta( |
| 1976 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 1977 AddToSyncDataList(tabs[0], &foreign_data, newest_time); |
| 1978 AddToSyncDataList(meta, &foreign_data, middle_time); |
| 1979 AddToSyncDataList(tabs[1], &foreign_data, oldest_time); |
| 1980 } |
| 1981 |
| 1982 { |
| 1983 std::string session_tag = "tag2"; |
| 1984 SessionID::id_type n[] = {3, 4}; |
| 1985 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 1986 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1987 sync_pb::SessionSpecifics meta( |
| 1988 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 1989 AddToSyncDataList(tabs[0], &foreign_data, middle_time); |
| 1990 AddToSyncDataList(meta, &foreign_data, newest_time); |
| 1991 AddToSyncDataList(tabs[1], &foreign_data, oldest_time); |
| 1992 } |
| 1993 |
| 1994 { |
| 1995 std::string session_tag = "tag3"; |
| 1996 SessionID::id_type n[] = {5, 6}; |
| 1997 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 1998 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1999 sync_pb::SessionSpecifics meta( |
| 2000 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2001 AddToSyncDataList(tabs[0], &foreign_data, oldest_time); |
| 2002 AddToSyncDataList(meta, &foreign_data, middle_time); |
| 2003 AddToSyncDataList(tabs[1], &foreign_data, newest_time); |
| 2004 } |
| 2005 |
| 2006 syncer::SyncChangeList output; |
| 2007 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 2008 ASSERT_EQ(2U, output.size()); |
| 2009 output.clear(); |
| 2010 |
| 2011 std::vector<const SyncedSession*> foreign_sessions; |
| 2012 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2013 ASSERT_EQ(3U, foreign_sessions.size()); |
| 2014 EXPECT_EQ(newest_time, foreign_sessions[0]->modified_time); |
| 2015 EXPECT_EQ(newest_time, foreign_sessions[1]->modified_time); |
| 2016 EXPECT_EQ(newest_time, foreign_sessions[2]->modified_time); |
| 2017 } |
| 2018 |
| 1828 // Test garbage collection of stale foreign sessions. | 2019 // Test garbage collection of stale foreign sessions. |
| 1829 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { | 2020 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { |
| 1830 // Fill two instances of session specifics with a foreign session's data. | 2021 // Fill two instances of session specifics with a foreign session's data. |
| 1831 std::string tag1 = "tag1"; | 2022 std::string tag1 = "tag1"; |
| 1832 SessionID::id_type n1[] = {5, 10, 13, 17}; | 2023 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1833 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 2024 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1834 std::vector<sync_pb::SessionSpecifics> tabs1; | 2025 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1835 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 2026 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1836 tag1, tab_list1, &tabs1)); | 2027 tag1, tab_list1, &tabs1)); |
| 1837 std::string tag2 = "tag2"; | 2028 std::string tag2 = "tag2"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 } | 2079 } |
| 1889 | 2080 |
| 1890 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2081 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1891 ASSERT_EQ(1U, foreign_sessions.size()); | 2082 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1892 std::vector<std::vector<SessionID::id_type> > session_reference; | 2083 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 1893 session_reference.push_back(tab_list2); | 2084 session_reference.push_back(tab_list2); |
| 1894 helper()->VerifySyncedSession(tag2, session_reference, | 2085 helper()->VerifySyncedSession(tag2, session_reference, |
| 1895 *(foreign_sessions[0])); | 2086 *(foreign_sessions[0])); |
| 1896 } | 2087 } |
| 1897 | 2088 |
| 2089 TEST_F(SessionsSyncManagerTest, DoGarbageCollectionOrphans) { |
| 2090 syncer::SyncDataList foreign_data; |
| 2091 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(15); |
| 2092 |
| 2093 { |
| 2094 // A stale session with empty header |
| 2095 std::string session_tag = "tag1"; |
| 2096 std::vector<SessionID::id_type> tab_list; |
| 2097 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2098 sync_pb::SessionSpecifics meta( |
| 2099 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2100 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 2101 } |
| 2102 |
| 2103 { |
| 2104 // A stale session with orphans w/o header |
| 2105 std::string session_tag = "tag2"; |
| 2106 sync_pb::SessionSpecifics orphan; |
| 2107 helper()->BuildTabSpecifics(session_tag, 0, 1, &orphan); |
| 2108 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2109 } |
| 2110 |
| 2111 { |
| 2112 // A stale session with valid header/tab and an orphaned tab. |
| 2113 std::string session_tag = "tag3"; |
| 2114 SessionID::id_type n[] = {2}; |
| 2115 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2116 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2117 sync_pb::SessionSpecifics meta( |
| 2118 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2119 |
| 2120 // BuildForeignSession(...) will use a window id of 0, and we're also |
| 2121 // passing a window id of 0 to BuildTabSpecifics(...) here. It doesn't |
| 2122 // really matter what window id we use for the orphaned tab, in the real |
| 2123 // world orphans often reference real/still valid windows, but they're |
| 2124 // orphans because the window/header doesn't reference back to them. |
| 2125 sync_pb::SessionSpecifics orphan; |
| 2126 helper()->BuildTabSpecifics(session_tag, 0, 1, &orphan); |
| 2127 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2128 |
| 2129 AddToSyncDataList(tabs[0], &foreign_data, stale_mtime); |
| 2130 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2131 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 2132 } |
| 2133 |
| 2134 syncer::SyncChangeList output; |
| 2135 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 2136 ASSERT_EQ(2U, output.size()); |
| 2137 output.clear(); |
| 2138 |
| 2139 // Although we have 3 foreign sessions, only 1 is valid/clean enough. |
| 2140 std::vector<const SyncedSession*> foreign_sessions; |
| 2141 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2142 ASSERT_EQ(1U, foreign_sessions.size()); |
| 2143 foreign_sessions.clear(); |
| 2144 |
| 2145 // Everything should get removed here. |
| 2146 manager()->DoGarbageCollection(); |
| 2147 // Expect 5 deletions. tag1 header only, tag2 tab only, tag3 header + 2x tabs. |
| 2148 ASSERT_EQ(5U, output.size()); |
| 2149 } |
| 2150 |
| 1898 // Test that an update to a previously considered "stale" session, | 2151 // Test that an update to a previously considered "stale" session, |
| 1899 // prior to garbage collection, will save the session from deletion. | 2152 // prior to garbage collection, will save the session from deletion. |
| 1900 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { | 2153 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { |
| 1901 std::string tag1 = "tag1"; | 2154 std::string tag1 = "tag1"; |
| 1902 SessionID::id_type n1[] = {5, 10, 13, 17}; | 2155 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1903 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 2156 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1904 std::vector<sync_pb::SessionSpecifics> tabs1; | 2157 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1905 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 2158 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1906 tag1, tab_list1, &tabs1)); | 2159 tag1, tab_list1, &tabs1)); |
| 1907 syncer::SyncDataList foreign_data; | 2160 syncer::SyncDataList foreign_data; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 base::Time last_time; | 2569 base::Time last_time; |
| 2317 for (size_t i = 0; i < tabs.size(); ++i) { | 2570 for (size_t i = 0; i < tabs.size(); ++i) { |
| 2318 base::Time this_time = tabs[i]->timestamp; | 2571 base::Time this_time = tabs[i]->timestamp; |
| 2319 if (i > 0) | 2572 if (i > 0) |
| 2320 ASSERT_GE(last_time, this_time); | 2573 ASSERT_GE(last_time, this_time); |
| 2321 last_time = tabs[i]->timestamp; | 2574 last_time = tabs[i]->timestamp; |
| 2322 } | 2575 } |
| 2323 } | 2576 } |
| 2324 | 2577 |
| 2325 } // namespace browser_sync | 2578 } // namespace browser_sync |
| OLD | NEW |