| 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 // Verify that cleanup post-merge cleanup correctly removes all tabs objects. |
| 1592 const sessions::SessionTab* tab; |
| 1593 ASSERT_FALSE( |
| 1594 manager()->session_tracker_.LookupSessionTab(session_tag, 1, &tab)); |
| 1595 ASSERT_FALSE( |
| 1596 manager()->session_tracker_.LookupSessionTab(session_tag, 2, &tab)); |
| 1597 |
| 1598 std::set<int> tab_node_ids; |
| 1599 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1600 EXPECT_EQ(6U, tab_node_ids.size()); |
| 1601 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); |
| 1602 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); |
| 1603 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1604 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1605 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1606 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); |
| 1607 |
| 1608 syncer::SyncChangeList changes; |
| 1609 changes.push_back(MakeRemoteChange(1, tab1A, SyncChange::ACTION_DELETE)); |
| 1610 changes.push_back(MakeRemoteChange(1, tab1B, SyncChange::ACTION_DELETE)); |
| 1611 changes.push_back(MakeRemoteChange(1, tab2C, SyncChange::ACTION_DELETE)); |
| 1612 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1613 |
| 1614 tab_node_ids.clear(); |
| 1615 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1616 EXPECT_EQ(3U, tab_node_ids.size()); |
| 1617 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1618 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1619 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1620 |
| 1621 manager()->DoGarbageCollection(); |
| 1622 ASSERT_EQ(3U, output.size()); |
| 1623 } |
| 1624 |
| 1625 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithReusedNodeIds) { |
| 1626 syncer::SyncDataList foreign_data; |
| 1627 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(16); |
| 1628 std::string session_tag = "tag1"; |
| 1629 int tab_node_id_shared = 13; |
| 1630 int tab_node_id_unique = 14; |
| 1631 |
| 1632 sync_pb::SessionSpecifics tab1A; |
| 1633 helper()->BuildTabSpecifics(session_tag, 0, 1, tab_node_id_shared, &tab1A); |
| 1634 AddToSyncDataList(tab1A, &foreign_data, |
| 1635 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1636 |
| 1637 sync_pb::SessionSpecifics tab1B; |
| 1638 helper()->BuildTabSpecifics(session_tag, 0, 1, tab_node_id_unique, &tab1B); |
| 1639 AddToSyncDataList(tab1B, &foreign_data, |
| 1640 stale_mtime + base::TimeDelta::FromMinutes(2)); |
| 1641 |
| 1642 sync_pb::SessionSpecifics tab2A; |
| 1643 helper()->BuildTabSpecifics(session_tag, 0, 2, tab_node_id_shared, &tab2A); |
| 1644 AddToSyncDataList(tab2A, &foreign_data, |
| 1645 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1646 |
| 1647 syncer::SyncChangeList output; |
| 1648 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1649 ASSERT_EQ(2U, output.size()); |
| 1650 output.clear(); |
| 1651 |
| 1652 std::set<int> tab_node_ids; |
| 1653 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1654 EXPECT_EQ(2U, tab_node_ids.size()); |
| 1655 EXPECT_TRUE(tab_node_ids.find(tab_node_id_shared) != tab_node_ids.end()); |
| 1656 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
| 1657 |
| 1658 syncer::SyncChangeList changes; |
| 1659 changes.push_back(MakeRemoteChange(1, tab1A, SyncChange::ACTION_DELETE)); |
| 1660 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1661 |
| 1662 tab_node_ids.clear(); |
| 1663 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1664 EXPECT_EQ(1U, tab_node_ids.size()); |
| 1665 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
| 1666 |
| 1667 manager()->DoGarbageCollection(); |
| 1668 EXPECT_EQ(1U, output.size()); |
| 1669 } |
| 1670 |
| 1482 // TODO(shashishekhar): "Move this to TabNodePool unittests." | 1671 // TODO(shashishekhar): "Move this to TabNodePool unittests." |
| 1483 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { | 1672 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { |
| 1484 syncer::SyncChangeList changes; | 1673 syncer::SyncChangeList changes; |
| 1485 InitWithNoSyncData(); | 1674 InitWithNoSyncData(); |
| 1486 | 1675 |
| 1487 std::string local_tag = manager()->current_machine_tag(); | 1676 std::string local_tag = manager()->current_machine_tag(); |
| 1488 // Create a free node and then dissassociate sessions so that it ends up | 1677 // Create a free node and then dissassociate sessions so that it ends up |
| 1489 // unassociated. | 1678 // unassociated. |
| 1490 manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1679 manager()->local_tab_pool_.GetFreeTabNode(&changes); |
| 1491 | 1680 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); | 2007 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); |
| 1819 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 2008 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 1820 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | 2009 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 1821 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | 2010 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 1822 iter++; | 2011 iter++; |
| 1823 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 2012 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 1824 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | 2013 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 1825 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | 2014 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 1826 } | 2015 } |
| 1827 | 2016 |
| 2017 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { |
| 2018 syncer::SyncDataList foreign_data; |
| 2019 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 2020 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); |
| 2021 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); |
| 2022 |
| 2023 { |
| 2024 std::string session_tag = "tag1"; |
| 2025 SessionID::id_type n[] = {1, 2}; |
| 2026 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2027 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2028 sync_pb::SessionSpecifics meta( |
| 2029 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2030 AddToSyncDataList(tabs[0], &foreign_data, newest_time); |
| 2031 AddToSyncDataList(meta, &foreign_data, middle_time); |
| 2032 AddToSyncDataList(tabs[1], &foreign_data, oldest_time); |
| 2033 } |
| 2034 |
| 2035 { |
| 2036 std::string session_tag = "tag2"; |
| 2037 SessionID::id_type n[] = {3, 4}; |
| 2038 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2039 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2040 sync_pb::SessionSpecifics meta( |
| 2041 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2042 AddToSyncDataList(tabs[0], &foreign_data, middle_time); |
| 2043 AddToSyncDataList(meta, &foreign_data, newest_time); |
| 2044 AddToSyncDataList(tabs[1], &foreign_data, oldest_time); |
| 2045 } |
| 2046 |
| 2047 { |
| 2048 std::string session_tag = "tag3"; |
| 2049 SessionID::id_type n[] = {5, 6}; |
| 2050 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2051 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2052 sync_pb::SessionSpecifics meta( |
| 2053 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2054 AddToSyncDataList(tabs[0], &foreign_data, oldest_time); |
| 2055 AddToSyncDataList(meta, &foreign_data, middle_time); |
| 2056 AddToSyncDataList(tabs[1], &foreign_data, newest_time); |
| 2057 } |
| 2058 |
| 2059 syncer::SyncChangeList output; |
| 2060 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 2061 ASSERT_EQ(2U, output.size()); |
| 2062 output.clear(); |
| 2063 |
| 2064 std::vector<const SyncedSession*> foreign_sessions; |
| 2065 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2066 ASSERT_EQ(3U, foreign_sessions.size()); |
| 2067 EXPECT_EQ(newest_time, foreign_sessions[0]->modified_time); |
| 2068 EXPECT_EQ(newest_time, foreign_sessions[1]->modified_time); |
| 2069 EXPECT_EQ(newest_time, foreign_sessions[2]->modified_time); |
| 2070 } |
| 2071 |
| 1828 // Test garbage collection of stale foreign sessions. | 2072 // Test garbage collection of stale foreign sessions. |
| 1829 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { | 2073 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { |
| 1830 // Fill two instances of session specifics with a foreign session's data. | 2074 // Fill two instances of session specifics with a foreign session's data. |
| 1831 std::string tag1 = "tag1"; | 2075 std::string tag1 = "tag1"; |
| 1832 SessionID::id_type n1[] = {5, 10, 13, 17}; | 2076 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1833 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 2077 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1834 std::vector<sync_pb::SessionSpecifics> tabs1; | 2078 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1835 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 2079 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1836 tag1, tab_list1, &tabs1)); | 2080 tag1, tab_list1, &tabs1)); |
| 1837 std::string tag2 = "tag2"; | 2081 std::string tag2 = "tag2"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 } | 2132 } |
| 1889 | 2133 |
| 1890 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2134 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1891 ASSERT_EQ(1U, foreign_sessions.size()); | 2135 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1892 std::vector<std::vector<SessionID::id_type> > session_reference; | 2136 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 1893 session_reference.push_back(tab_list2); | 2137 session_reference.push_back(tab_list2); |
| 1894 helper()->VerifySyncedSession(tag2, session_reference, | 2138 helper()->VerifySyncedSession(tag2, session_reference, |
| 1895 *(foreign_sessions[0])); | 2139 *(foreign_sessions[0])); |
| 1896 } | 2140 } |
| 1897 | 2141 |
| 2142 TEST_F(SessionsSyncManagerTest, DoGarbageCollectionOrphans) { |
| 2143 syncer::SyncDataList foreign_data; |
| 2144 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(15); |
| 2145 |
| 2146 { |
| 2147 // A stale session with empty header |
| 2148 std::string session_tag = "tag1"; |
| 2149 std::vector<SessionID::id_type> tab_list; |
| 2150 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2151 sync_pb::SessionSpecifics meta( |
| 2152 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2153 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 2154 } |
| 2155 |
| 2156 { |
| 2157 // A stale session with orphans w/o header |
| 2158 std::string session_tag = "tag2"; |
| 2159 sync_pb::SessionSpecifics orphan; |
| 2160 helper()->BuildTabSpecifics(session_tag, 0, 1, &orphan); |
| 2161 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2162 } |
| 2163 |
| 2164 { |
| 2165 // A stale session with valid header/tab and an orphaned tab. |
| 2166 std::string session_tag = "tag3"; |
| 2167 SessionID::id_type n[] = {2}; |
| 2168 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2169 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2170 sync_pb::SessionSpecifics meta( |
| 2171 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2172 |
| 2173 // BuildForeignSession(...) will use a window id of 0, and we're also |
| 2174 // passing a window id of 0 to BuildTabSpecifics(...) here. It doesn't |
| 2175 // really matter what window id we use for the orphaned tab, in the real |
| 2176 // world orphans often reference real/still valid windows, but they're |
| 2177 // orphans because the window/header doesn't reference back to them. |
| 2178 sync_pb::SessionSpecifics orphan; |
| 2179 helper()->BuildTabSpecifics(session_tag, 0, 1, &orphan); |
| 2180 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2181 |
| 2182 AddToSyncDataList(tabs[0], &foreign_data, stale_mtime); |
| 2183 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2184 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 2185 } |
| 2186 |
| 2187 syncer::SyncChangeList output; |
| 2188 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 2189 ASSERT_EQ(2U, output.size()); |
| 2190 output.clear(); |
| 2191 |
| 2192 // Although we have 3 foreign sessions, only 1 is valid/clean enough. |
| 2193 std::vector<const SyncedSession*> foreign_sessions; |
| 2194 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2195 ASSERT_EQ(1U, foreign_sessions.size()); |
| 2196 foreign_sessions.clear(); |
| 2197 |
| 2198 // Everything should get removed here. |
| 2199 manager()->DoGarbageCollection(); |
| 2200 // Expect 5 deletions. tag1 header only, tag2 tab only, tag3 header + 2x tabs. |
| 2201 ASSERT_EQ(5U, output.size()); |
| 2202 } |
| 2203 |
| 1898 // Test that an update to a previously considered "stale" session, | 2204 // Test that an update to a previously considered "stale" session, |
| 1899 // prior to garbage collection, will save the session from deletion. | 2205 // prior to garbage collection, will save the session from deletion. |
| 1900 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { | 2206 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { |
| 1901 std::string tag1 = "tag1"; | 2207 std::string tag1 = "tag1"; |
| 1902 SessionID::id_type n1[] = {5, 10, 13, 17}; | 2208 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1903 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 2209 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1904 std::vector<sync_pb::SessionSpecifics> tabs1; | 2210 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1905 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 2211 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1906 tag1, tab_list1, &tabs1)); | 2212 tag1, tab_list1, &tabs1)); |
| 1907 syncer::SyncDataList foreign_data; | 2213 syncer::SyncDataList foreign_data; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 base::Time last_time; | 2622 base::Time last_time; |
| 2317 for (size_t i = 0; i < tabs.size(); ++i) { | 2623 for (size_t i = 0; i < tabs.size(); ++i) { |
| 2318 base::Time this_time = tabs[i]->timestamp; | 2624 base::Time this_time = tabs[i]->timestamp; |
| 2319 if (i > 0) | 2625 if (i > 0) |
| 2320 ASSERT_GE(last_time, this_time); | 2626 ASSERT_GE(last_time, this_time); |
| 2321 last_time = tabs[i]->timestamp; | 2627 last_time = tabs[i]->timestamp; |
| 2322 } | 2628 } |
| 2323 } | 2629 } |
| 2324 | 2630 |
| 2325 } // namespace browser_sync | 2631 } // namespace browser_sync |
| OLD | NEW |