| 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 InitWithNoSyncData(); | 1259 InitWithNoSyncData(); |
| 1257 std::string tag = "tag1"; | 1260 std::string tag = "tag1"; |
| 1258 syncer::SyncChangeList changes; | 1261 syncer::SyncChangeList changes; |
| 1259 | 1262 |
| 1260 std::vector<const SyncedSession*> foreign_sessions; | 1263 std::vector<const SyncedSession*> foreign_sessions; |
| 1261 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1264 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1262 manager()->DeleteForeignSessionInternal(tag, &changes); | 1265 manager()->DeleteForeignSessionInternal(tag, &changes); |
| 1263 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1266 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1264 EXPECT_TRUE(changes.empty()); | 1267 EXPECT_TRUE(changes.empty()); |
| 1265 | 1268 |
| 1266 // Fill an instance of session specifics with a foreign session's data. | 1269 // Fill an instance of session specifics with a foreign session's data. |
| 1267 std::vector<sync_pb::SessionSpecifics> tabs; | 1270 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1268 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1271 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1269 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); | 1272 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); |
| 1270 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1273 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1271 tag, tab_nums1, &tabs)); | 1274 tag, tab_nums1, &tabs)); |
| 1272 | 1275 |
| 1273 // Update associator with the session's meta node, window, and tabs. | 1276 // Update associator with the session's meta node, window, and tabs. |
| 1274 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); | 1277 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); |
| 1275 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); | 1278 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); |
| 1276 iter != tabs.end(); ++iter) { | 1279 iter != tabs.end(); ++iter) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 ASSERT_EQ(1U, foreign_sessions.size()); | 1473 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1471 | 1474 |
| 1472 changes.clear(); | 1475 changes.clear(); |
| 1473 foreign_sessions.clear(); | 1476 foreign_sessions.clear(); |
| 1474 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_DELETE)); | 1477 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_DELETE)); |
| 1475 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1478 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1476 | 1479 |
| 1477 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1480 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1478 } | 1481 } |
| 1479 | 1482 |
| 1483 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabs) { |
| 1484 syncer::SyncDataList foreign_data; |
| 1485 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(15); |
| 1486 std::string session_tag = "tag1"; |
| 1487 |
| 1488 // 0 will not have ownership changed. |
| 1489 // 1 will not be updated, but header will stop owning. |
| 1490 // 2 will be deleted before header stops owning. |
| 1491 // 3 will be deleted after header stops owning. |
| 1492 // 4 will be deleted before header update, but header will still try to own. |
| 1493 // 5 will be deleted after header update, but header will still try to own. |
| 1494 // 6 starts orphaned and then deleted before header update. |
| 1495 // 7 starts orphaned and then deleted after header update. |
| 1496 SessionID::id_type tab_ids[] = {0, 1, 2, 3, 4, 5}; |
| 1497 std::vector<SessionID::id_type> tab_list(tab_ids, |
| 1498 tab_ids + arraysize(tab_ids)); |
| 1499 std::vector<sync_pb::SessionSpecifics> tabs; |
| 1500 sync_pb::SessionSpecifics meta( |
| 1501 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 1502 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 1503 AddTabsToSyncDataList(tabs, &foreign_data); |
| 1504 sync_pb::SessionSpecifics orphan6; |
| 1505 helper()->BuildTabSpecifics(session_tag, 0, 6, &orphan6); |
| 1506 AddToSyncDataList(orphan6, &foreign_data, stale_mtime); |
| 1507 sync_pb::SessionSpecifics orphan7; |
| 1508 helper()->BuildTabSpecifics(session_tag, 0, 7, &orphan7); |
| 1509 AddToSyncDataList(orphan7, &foreign_data, stale_mtime); |
| 1510 |
| 1511 syncer::SyncChangeList output; |
| 1512 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1513 ASSERT_EQ(2U, output.size()); |
| 1514 output.clear(); |
| 1515 |
| 1516 SessionID::id_type update_ids[] = {0, 4, 5}; |
| 1517 std::vector<SessionID::id_type> update_list( |
| 1518 update_ids, update_ids + arraysize(update_ids)); |
| 1519 sync_pb::SessionWindow* window = meta.mutable_header()->mutable_window(0); |
| 1520 window->clear_tab(); |
| 1521 for (int i : update_ids) { |
| 1522 window->add_tab(i); |
| 1523 } |
| 1524 |
| 1525 syncer::SyncChangeList changes; |
| 1526 changes.push_back(MakeRemoteChange(1, tabs[2], SyncChange::ACTION_DELETE)); |
| 1527 changes.push_back(MakeRemoteChange(1, tabs[4], SyncChange::ACTION_DELETE)); |
| 1528 changes.push_back(MakeRemoteChange(1, orphan6, SyncChange::ACTION_DELETE)); |
| 1529 changes.push_back(MakeRemoteChange(1, meta, SyncChange::ACTION_UPDATE)); |
| 1530 changes.push_back(MakeRemoteChange(1, tabs[3], SyncChange::ACTION_DELETE)); |
| 1531 changes.push_back(MakeRemoteChange(1, tabs[5], SyncChange::ACTION_DELETE)); |
| 1532 changes.push_back(MakeRemoteChange(1, orphan7, SyncChange::ACTION_DELETE)); |
| 1533 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1534 |
| 1535 std::vector<const SyncedSession*> foreign_sessions; |
| 1536 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1537 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1538 std::vector<std::vector<SessionID::id_type>> session_reference; |
| 1539 session_reference.push_back(update_list); |
| 1540 helper()->VerifySyncedSession(session_tag, session_reference, |
| 1541 *(foreign_sessions[0])); |
| 1542 |
| 1543 // Everything except for session, tab0, and tab1 will have no node_id, and |
| 1544 // should get skipped by garbage collection. |
| 1545 manager()->DoGarbageCollection(); |
| 1546 ASSERT_EQ(3U, output.size()); |
| 1547 } |
| 1548 |
| 1549 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithShadowing) { |
| 1550 syncer::SyncDataList foreign_data; |
| 1551 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(16); |
| 1552 std::string session_tag = "tag1"; |
| 1553 |
| 1554 // Add several tabs that shadow eachother, in that they share tab_ids. They |
| 1555 // will, thanks to the helper, have unique tab_node_ids. |
| 1556 sync_pb::SessionSpecifics tab1A; |
| 1557 helper()->BuildTabSpecifics(session_tag, 0, 1, &tab1A); |
| 1558 AddToSyncDataList(tab1A, &foreign_data, |
| 1559 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1560 |
| 1561 sync_pb::SessionSpecifics tab1B; |
| 1562 helper()->BuildTabSpecifics(session_tag, 0, 1, &tab1B); |
| 1563 AddToSyncDataList(tab1B, &foreign_data, |
| 1564 stale_mtime + base::TimeDelta::FromMinutes(2)); |
| 1565 |
| 1566 sync_pb::SessionSpecifics tab1C; |
| 1567 helper()->BuildTabSpecifics(session_tag, 0, 1, &tab1C); |
| 1568 AddToSyncDataList(tab1C, &foreign_data, stale_mtime); |
| 1569 |
| 1570 sync_pb::SessionSpecifics tab2A; |
| 1571 helper()->BuildTabSpecifics(session_tag, 0, 2, &tab2A); |
| 1572 AddToSyncDataList(tab2A, &foreign_data, |
| 1573 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1574 |
| 1575 sync_pb::SessionSpecifics tab2B; |
| 1576 helper()->BuildTabSpecifics(session_tag, 0, 2, &tab2B); |
| 1577 AddToSyncDataList(tab2B, &foreign_data, |
| 1578 stale_mtime + base::TimeDelta::FromMinutes(2)); |
| 1579 |
| 1580 sync_pb::SessionSpecifics tab2C; |
| 1581 helper()->BuildTabSpecifics(session_tag, 0, 2, &tab2C); |
| 1582 AddToSyncDataList(tab2C, &foreign_data, stale_mtime); |
| 1583 |
| 1584 syncer::SyncChangeList output; |
| 1585 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1586 ASSERT_EQ(2U, output.size()); |
| 1587 output.clear(); |
| 1588 |
| 1589 // Verify that cleanup post-merge cleanup correctly removes all tabs objects. |
| 1590 const sessions::SessionTab* tab; |
| 1591 ASSERT_FALSE( |
| 1592 manager()->session_tracker_.LookupSessionTab(session_tag, 1, &tab)); |
| 1593 ASSERT_FALSE( |
| 1594 manager()->session_tracker_.LookupSessionTab(session_tag, 2, &tab)); |
| 1595 |
| 1596 std::set<int> tab_node_ids; |
| 1597 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1598 EXPECT_EQ(6U, tab_node_ids.size()); |
| 1599 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); |
| 1600 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); |
| 1601 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1602 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1603 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1604 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); |
| 1605 |
| 1606 syncer::SyncChangeList changes; |
| 1607 changes.push_back(MakeRemoteChange(1, tab1A, SyncChange::ACTION_DELETE)); |
| 1608 changes.push_back(MakeRemoteChange(1, tab1B, SyncChange::ACTION_DELETE)); |
| 1609 changes.push_back(MakeRemoteChange(1, tab2C, SyncChange::ACTION_DELETE)); |
| 1610 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1611 |
| 1612 tab_node_ids.clear(); |
| 1613 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1614 EXPECT_EQ(3U, tab_node_ids.size()); |
| 1615 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
| 1616 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
| 1617 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
| 1618 |
| 1619 manager()->DoGarbageCollection(); |
| 1620 ASSERT_EQ(3U, output.size()); |
| 1621 } |
| 1622 |
| 1623 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithReusedNodeIds) { |
| 1624 syncer::SyncDataList foreign_data; |
| 1625 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(16); |
| 1626 std::string session_tag = "tag1"; |
| 1627 int tab_node_id_shared = 13; |
| 1628 int tab_node_id_unique = 14; |
| 1629 |
| 1630 sync_pb::SessionSpecifics tab1A; |
| 1631 helper()->BuildTabSpecifics(session_tag, 0, 1, tab_node_id_shared, &tab1A); |
| 1632 AddToSyncDataList(tab1A, &foreign_data, |
| 1633 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1634 |
| 1635 sync_pb::SessionSpecifics tab1B; |
| 1636 helper()->BuildTabSpecifics(session_tag, 0, 1, tab_node_id_unique, &tab1B); |
| 1637 AddToSyncDataList(tab1B, &foreign_data, |
| 1638 stale_mtime + base::TimeDelta::FromMinutes(2)); |
| 1639 |
| 1640 sync_pb::SessionSpecifics tab2A; |
| 1641 helper()->BuildTabSpecifics(session_tag, 0, 2, tab_node_id_shared, &tab2A); |
| 1642 AddToSyncDataList(tab2A, &foreign_data, |
| 1643 stale_mtime + base::TimeDelta::FromMinutes(1)); |
| 1644 |
| 1645 syncer::SyncChangeList output; |
| 1646 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 1647 ASSERT_EQ(2U, output.size()); |
| 1648 output.clear(); |
| 1649 |
| 1650 std::set<int> tab_node_ids; |
| 1651 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1652 EXPECT_EQ(2U, tab_node_ids.size()); |
| 1653 EXPECT_TRUE(tab_node_ids.find(tab_node_id_shared) != tab_node_ids.end()); |
| 1654 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
| 1655 |
| 1656 syncer::SyncChangeList changes; |
| 1657 changes.push_back(MakeRemoteChange(1, tab1A, SyncChange::ACTION_DELETE)); |
| 1658 manager()->ProcessSyncChanges(FROM_HERE, changes); |
| 1659 |
| 1660 tab_node_ids.clear(); |
| 1661 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
| 1662 EXPECT_EQ(1U, tab_node_ids.size()); |
| 1663 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
| 1664 |
| 1665 manager()->DoGarbageCollection(); |
| 1666 EXPECT_EQ(1U, output.size()); |
| 1667 } |
| 1668 |
| 1480 // TODO(shashishekhar): "Move this to TabNodePool unittests." | 1669 // TODO(shashishekhar): "Move this to TabNodePool unittests." |
| 1481 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { | 1670 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { |
| 1482 syncer::SyncChangeList changes; | 1671 syncer::SyncChangeList changes; |
| 1483 InitWithNoSyncData(); | 1672 InitWithNoSyncData(); |
| 1484 | 1673 |
| 1485 std::string local_tag = manager()->current_machine_tag(); | 1674 std::string local_tag = manager()->current_machine_tag(); |
| 1486 // Create a free node and then dissassociate sessions so that it ends up | 1675 // Create a free node and then dissassociate sessions so that it ends up |
| 1487 // unassociated. | 1676 // unassociated. |
| 1488 manager()->local_tab_pool_.GetFreeTabNode(&changes); | 1677 manager()->local_tab_pool_.GetFreeTabNode(&changes); |
| 1489 | 1678 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); | 2004 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); |
| 1816 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 2005 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 1817 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | 2006 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 1818 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | 2007 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 1819 iter++; | 2008 iter++; |
| 1820 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); | 2009 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 1821 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); | 2010 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 1822 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); | 2011 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 1823 } | 2012 } |
| 1824 | 2013 |
| 2014 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { |
| 2015 syncer::SyncDataList foreign_data; |
| 2016 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 2017 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); |
| 2018 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); |
| 2019 |
| 2020 { |
| 2021 std::string session_tag = "tag1"; |
| 2022 SessionID::id_type n[] = {1, 2}; |
| 2023 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2024 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2025 sync_pb::SessionSpecifics meta( |
| 2026 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2027 AddToSyncDataList(tabs[0], &foreign_data, newest_time); |
| 2028 AddToSyncDataList(meta, &foreign_data, middle_time); |
| 2029 AddToSyncDataList(tabs[1], &foreign_data, oldest_time); |
| 2030 } |
| 2031 |
| 2032 { |
| 2033 std::string session_tag = "tag2"; |
| 2034 SessionID::id_type n[] = {3, 4}; |
| 2035 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2036 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2037 sync_pb::SessionSpecifics meta( |
| 2038 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2039 AddToSyncDataList(tabs[0], &foreign_data, middle_time); |
| 2040 AddToSyncDataList(meta, &foreign_data, newest_time); |
| 2041 AddToSyncDataList(tabs[1], &foreign_data, oldest_time); |
| 2042 } |
| 2043 |
| 2044 { |
| 2045 std::string session_tag = "tag3"; |
| 2046 SessionID::id_type n[] = {5, 6}; |
| 2047 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2048 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2049 sync_pb::SessionSpecifics meta( |
| 2050 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2051 AddToSyncDataList(tabs[0], &foreign_data, oldest_time); |
| 2052 AddToSyncDataList(meta, &foreign_data, middle_time); |
| 2053 AddToSyncDataList(tabs[1], &foreign_data, newest_time); |
| 2054 } |
| 2055 |
| 2056 syncer::SyncChangeList output; |
| 2057 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 2058 ASSERT_EQ(2U, output.size()); |
| 2059 output.clear(); |
| 2060 |
| 2061 std::vector<const SyncedSession*> foreign_sessions; |
| 2062 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2063 ASSERT_EQ(3U, foreign_sessions.size()); |
| 2064 EXPECT_EQ(newest_time, foreign_sessions[0]->modified_time); |
| 2065 EXPECT_EQ(newest_time, foreign_sessions[1]->modified_time); |
| 2066 EXPECT_EQ(newest_time, foreign_sessions[2]->modified_time); |
| 2067 } |
| 2068 |
| 1825 // Test garbage collection of stale foreign sessions. | 2069 // Test garbage collection of stale foreign sessions. |
| 1826 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { | 2070 TEST_F(SessionsSyncManagerTest, DoGarbageCollection) { |
| 1827 // Fill two instances of session specifics with a foreign session's data. | 2071 // Fill two instances of session specifics with a foreign session's data. |
| 1828 std::string tag1 = "tag1"; | 2072 std::string tag1 = "tag1"; |
| 1829 SessionID::id_type n1[] = {5, 10, 13, 17}; | 2073 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1830 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 2074 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1831 std::vector<sync_pb::SessionSpecifics> tabs1; | 2075 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1832 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 2076 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1833 tag1, tab_list1, &tabs1)); | 2077 tag1, tab_list1, &tabs1)); |
| 1834 std::string tag2 = "tag2"; | 2078 std::string tag2 = "tag2"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 } | 2129 } |
| 1886 | 2130 |
| 1887 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2131 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 1888 ASSERT_EQ(1U, foreign_sessions.size()); | 2132 ASSERT_EQ(1U, foreign_sessions.size()); |
| 1889 std::vector<std::vector<SessionID::id_type> > session_reference; | 2133 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 1890 session_reference.push_back(tab_list2); | 2134 session_reference.push_back(tab_list2); |
| 1891 helper()->VerifySyncedSession(tag2, session_reference, | 2135 helper()->VerifySyncedSession(tag2, session_reference, |
| 1892 *(foreign_sessions[0])); | 2136 *(foreign_sessions[0])); |
| 1893 } | 2137 } |
| 1894 | 2138 |
| 2139 TEST_F(SessionsSyncManagerTest, DoGarbageCollectionOrphans) { |
| 2140 syncer::SyncDataList foreign_data; |
| 2141 base::Time stale_mtime = base::Time::Now() - base::TimeDelta::FromDays(15); |
| 2142 |
| 2143 { |
| 2144 // A stale session with empty header |
| 2145 std::string session_tag = "tag1"; |
| 2146 std::vector<SessionID::id_type> tab_list; |
| 2147 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2148 sync_pb::SessionSpecifics meta( |
| 2149 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2150 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 2151 } |
| 2152 |
| 2153 { |
| 2154 // A stale session with orphans w/o header |
| 2155 std::string session_tag = "tag2"; |
| 2156 sync_pb::SessionSpecifics orphan; |
| 2157 helper()->BuildTabSpecifics(session_tag, 0, 1, &orphan); |
| 2158 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2159 } |
| 2160 |
| 2161 { |
| 2162 // A stale session with valid header/tab and an orphaned tab. |
| 2163 std::string session_tag = "tag3"; |
| 2164 SessionID::id_type n[] = {2}; |
| 2165 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
| 2166 std::vector<sync_pb::SessionSpecifics> tabs; |
| 2167 sync_pb::SessionSpecifics meta( |
| 2168 helper()->BuildForeignSession(session_tag, tab_list, &tabs)); |
| 2169 |
| 2170 // BuildForeignSession(...) will use a window id of 0, and we're also |
| 2171 // passing a window id of 0 to BuildTabSpecifics(...) here. It doesn't |
| 2172 // really matter what window id we use for the orphaned tab, in the real |
| 2173 // world orphans often reference real/still valid windows, but they're |
| 2174 // orphans because the window/header doesn't reference back to them. |
| 2175 sync_pb::SessionSpecifics orphan; |
| 2176 helper()->BuildTabSpecifics(session_tag, 0, 1, &orphan); |
| 2177 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2178 |
| 2179 AddToSyncDataList(tabs[0], &foreign_data, stale_mtime); |
| 2180 AddToSyncDataList(orphan, &foreign_data, stale_mtime); |
| 2181 AddToSyncDataList(meta, &foreign_data, stale_mtime); |
| 2182 } |
| 2183 |
| 2184 syncer::SyncChangeList output; |
| 2185 InitWithSyncDataTakeOutput(foreign_data, &output); |
| 2186 ASSERT_EQ(2U, output.size()); |
| 2187 output.clear(); |
| 2188 |
| 2189 // Although we have 3 foreign sessions, only 1 is valid/clean enough. |
| 2190 std::vector<const SyncedSession*> foreign_sessions; |
| 2191 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
| 2192 ASSERT_EQ(1U, foreign_sessions.size()); |
| 2193 foreign_sessions.clear(); |
| 2194 |
| 2195 // Everything should get removed here. |
| 2196 manager()->DoGarbageCollection(); |
| 2197 // Expect 5 deletions. tag1 header only, tag2 tab only, tag3 header + 2x tabs. |
| 2198 ASSERT_EQ(5U, output.size()); |
| 2199 } |
| 2200 |
| 1895 // Test that an update to a previously considered "stale" session, | 2201 // Test that an update to a previously considered "stale" session, |
| 1896 // prior to garbage collection, will save the session from deletion. | 2202 // prior to garbage collection, will save the session from deletion. |
| 1897 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { | 2203 TEST_F(SessionsSyncManagerTest, GarbageCollectionHonoursUpdate) { |
| 1898 std::string tag1 = "tag1"; | 2204 std::string tag1 = "tag1"; |
| 1899 SessionID::id_type n1[] = {5, 10, 13, 17}; | 2205 SessionID::id_type n1[] = {5, 10, 13, 17}; |
| 1900 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 2206 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1901 std::vector<sync_pb::SessionSpecifics> tabs1; | 2207 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1902 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 2208 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
| 1903 tag1, tab_list1, &tabs1)); | 2209 tag1, tab_list1, &tabs1)); |
| 1904 syncer::SyncDataList foreign_data; | 2210 syncer::SyncDataList foreign_data; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2313 base::Time last_time; | 2619 base::Time last_time; |
| 2314 for (size_t i = 0; i < tabs.size(); ++i) { | 2620 for (size_t i = 0; i < tabs.size(); ++i) { |
| 2315 base::Time this_time = tabs[i]->timestamp; | 2621 base::Time this_time = tabs[i]->timestamp; |
| 2316 if (i > 0) | 2622 if (i > 0) |
| 2317 ASSERT_GE(last_time, this_time); | 2623 ASSERT_GE(last_time, this_time); |
| 2318 last_time = tabs[i]->timestamp; | 2624 last_time = tabs[i]->timestamp; |
| 2319 } | 2625 } |
| 2320 } | 2626 } |
| 2321 | 2627 |
| 2322 } // namespace browser_sync | 2628 } // namespace browser_sync |
| OLD | NEW |