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

Side by Side Diff: components/sync_sessions/sessions_sync_manager_unittest.cc

Issue 2856913007: [Sync] Handle reassociation of tabs where the old tab is already mapped. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 &tab_node_ids); 1688 &tab_node_ids);
1689 EXPECT_EQ(1U, tab_node_ids.size()); 1689 EXPECT_EQ(1U, tab_node_ids.size());
1690 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); 1690 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end());
1691 1691
1692 manager()->DoGarbageCollection(); 1692 manager()->DoGarbageCollection();
1693 EXPECT_EQ(1U, output.size()); 1693 EXPECT_EQ(1U, output.size());
1694 } 1694 }
1695 1695
1696 TEST_F(SessionsSyncManagerTest, AssociationReusesNodes) { 1696 TEST_F(SessionsSyncManagerTest, AssociationReusesNodes) {
1697 SyncChangeList changes; 1697 SyncChangeList changes;
1698 AddTab(AddWindow()->GetSessionId(), kFoo1); 1698 TestSyncedWindowDelegate* window = AddWindow();
1699 TestSyncedTabDelegate* tab = AddTab(window->GetSessionId(), kFoo1);
1699 InitWithSyncDataTakeOutput(SyncDataList(), &changes); 1700 InitWithSyncDataTakeOutput(SyncDataList(), &changes);
1700 ASSERT_TRUE(ChangeTypeMatches(changes, 1701 ASSERT_TRUE(ChangeTypeMatches(changes,
1701 {SyncChange::ACTION_ADD, SyncChange::ACTION_ADD, 1702 {SyncChange::ACTION_ADD, SyncChange::ACTION_ADD,
1702 SyncChange::ACTION_UPDATE})); 1703 SyncChange::ACTION_UPDATE}));
1703 ASSERT_TRUE(changes[1].sync_data().GetSpecifics().session().has_tab()); 1704 ASSERT_TRUE(changes[1].sync_data().GetSpecifics().session().has_tab());
1704 int tab_node_id = 1705 int tab_node_id =
1705 changes[1].sync_data().GetSpecifics().session().tab_node_id(); 1706 changes[1].sync_data().GetSpecifics().session().tab_node_id();
1706 1707
1707 // Pass back the previous tab and header nodes at association, along with a 1708 // Pass back the previous tab and header nodes at association, along with a
1708 // second tab node (with a rewritten tab node id). 1709 // second tab node (with a rewritten tab node id).
(...skipping 12 matching lines...) Expand all
1721 manager()->StopSyncing(syncer::SESSIONS); 1722 manager()->StopSyncing(syncer::SESSIONS);
1722 InitWithSyncDataTakeOutput(in, &changes); 1723 InitWithSyncDataTakeOutput(in, &changes);
1723 1724
1724 // No tab entities should be deleted. The original (lower) tab node id should 1725 // No tab entities should be deleted. The original (lower) tab node id should
1725 // be reused for association. 1726 // be reused for association.
1726 FilterOutLocalHeaderChanges(&changes); 1727 FilterOutLocalHeaderChanges(&changes);
1727 ASSERT_TRUE(ChangeTypeMatches(changes, {SyncChange::ACTION_UPDATE})); 1728 ASSERT_TRUE(ChangeTypeMatches(changes, {SyncChange::ACTION_UPDATE}));
1728 VerifyLocalTabChange(changes[0], 1, kFoo1); 1729 VerifyLocalTabChange(changes[0], 1, kFoo1);
1729 EXPECT_EQ(tab_node_id, 1730 EXPECT_EQ(tab_node_id,
1730 changes[0].sync_data().GetSpecifics().session().tab_node_id()); 1731 changes[0].sync_data().GetSpecifics().session().tab_node_id());
1732 changes.clear();
1733
1734 // Update the original tab. Ensure the same tab node is updated.
1735 NavigateTab(tab, kFoo2);
1736 FilterOutLocalHeaderChanges(&changes);
1737 ASSERT_TRUE(ChangeTypeMatches(changes, {SyncChange::ACTION_UPDATE}));
1738 VerifyLocalTabChange(changes[0], 2, kFoo2);
1739 EXPECT_EQ(tab_node_id,
1740 changes[0].sync_data().GetSpecifics().session().tab_node_id());
1741 changes.clear();
1742
1743 // Add a new tab. It should reuse the second tab node.
1744 AddTab(window->GetSessionId(), kBar1);
1745 FilterOutLocalHeaderChanges(&changes);
1746 ASSERT_TRUE(ChangeTypeMatches(changes, {SyncChange::ACTION_UPDATE}));
1747 VerifyLocalTabChange(changes[0], 1, kBar1);
1748 EXPECT_EQ(tab_node_id + 1,
1749 changes[0].sync_data().GetSpecifics().session().tab_node_id());
1731 } 1750 }
1732 1751
1733 // Ensure that the merge process deletes a tab node without a tab id. 1752 // Ensure that the merge process deletes a tab node without a tab id.
1734 TEST_F(SessionsSyncManagerTest, MergeDeletesTabMissingTabId) { 1753 TEST_F(SessionsSyncManagerTest, MergeDeletesTabMissingTabId) {
1735 SyncChangeList changes; 1754 SyncChangeList changes;
1736 InitWithNoSyncData(); 1755 InitWithNoSyncData();
1737 1756
1738 std::string local_tag = manager()->current_machine_tag(); 1757 std::string local_tag = manager()->current_machine_tag();
1739 int tab_node_id = 0; 1758 int tab_node_id = 0;
1740 sync_pb::SessionSpecifics specifics; 1759 sync_pb::SessionSpecifics specifics;
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
2588 EXPECT_EQ(tab.navigation_size(), 2); 2607 EXPECT_EQ(tab.navigation_size(), 2);
2589 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); 2608 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id());
2590 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); 2609 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty());
2591 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); 2610 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id());
2592 // navigation(1) is a subtask of navigation(0). 2611 // navigation(1) is a subtask of navigation(0).
2593 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); 2612 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1);
2594 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); 2613 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id());
2595 } 2614 }
2596 2615
2597 } // namespace sync_sessions 2616 } // namespace sync_sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698