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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 TEST_F(SessionsSyncManagerTest, PopulateSessionWindow) { | 756 TEST_F(SessionsSyncManagerTest, PopulateSessionWindow) { |
757 sync_pb::SessionWindow window_s; | 757 sync_pb::SessionWindow window_s; |
758 window_s.add_tab(0); | 758 window_s.add_tab(0); |
759 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); | 759 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); |
760 window_s.set_selected_tab_index(1); | 760 window_s.set_selected_tab_index(1); |
761 | 761 |
762 SyncedSession* session = manager()->session_tracker_.GetSession(kTag1); | 762 SyncedSession* session = manager()->session_tracker_.GetSession(kTag1); |
763 manager()->session_tracker_.PutWindowInSession(kTag1, 0); | 763 manager()->session_tracker_.PutWindowInSession(kTag1, 0); |
764 manager()->BuildSyncedSessionFromSpecifics(kTag1, window_s, base::Time(), | 764 manager()->BuildSyncedSessionFromSpecifics(kTag1, window_s, base::Time(), |
765 session->windows[0].get()); | 765 session->windows[0].get()); |
766 ASSERT_EQ(1U, session->windows[0]->tabs.size()); | 766 ASSERT_EQ(1U, session->windows[0]->wrapped_window.tabs.size()); |
767 ASSERT_EQ(1, session->windows[0]->selected_tab_index); | 767 ASSERT_EQ(1, session->windows[0]->wrapped_window.selected_tab_index); |
768 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type); | 768 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, |
| 769 session->windows[0]->wrapped_window.type); |
769 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); | 770 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); |
770 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_tabs(kTag1)); | 771 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_tabs(kTag1)); |
771 } | 772 } |
772 | 773 |
773 // Populate the fake tab delegate with some data and navigation | 774 // Populate the fake tab delegate with some data and navigation |
774 // entries and make sure that setting a SessionTab from it preserves | 775 // entries and make sure that setting a SessionTab from it preserves |
775 // those entries (and clobbers any existing data). | 776 // those entries (and clobbers any existing data). |
776 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { | 777 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { |
777 // Create a tab with three valid entries. | 778 // Create a tab with three valid entries. |
778 TestSyncedTabDelegate* tab = | 779 TestSyncedTabDelegate* tab = |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 SyncChangeList changes; | 1114 SyncChangeList changes; |
1114 changes.push_back(MakeRemoteChange(meta1, SyncChange::ACTION_UPDATE)); | 1115 changes.push_back(MakeRemoteChange(meta1, SyncChange::ACTION_UPDATE)); |
1115 AddTabsToChangeList(tabs2, SyncChange::ACTION_ADD, &changes); | 1116 AddTabsToChangeList(tabs2, SyncChange::ACTION_ADD, &changes); |
1116 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1117 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1117 changes.clear(); | 1118 changes.clear(); |
1118 | 1119 |
1119 // Check that the foreign session was associated and retrieve the data. | 1120 // Check that the foreign session was associated and retrieve the data. |
1120 std::vector<const SyncedSession*> foreign_sessions; | 1121 std::vector<const SyncedSession*> foreign_sessions; |
1121 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1122 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1122 ASSERT_EQ(1U, foreign_sessions.size()); | 1123 ASSERT_EQ(1U, foreign_sessions.size()); |
1123 ASSERT_EQ(4U, foreign_sessions[0]->windows.find(0)->second->tabs.size()); | 1124 ASSERT_EQ( |
1124 ASSERT_EQ(4U, foreign_sessions[0]->windows.find(1)->second->tabs.size()); | 1125 4U, |
| 1126 foreign_sessions[0]->windows.find(0)->second->wrapped_window.tabs.size()); |
| 1127 ASSERT_EQ( |
| 1128 4U, |
| 1129 foreign_sessions[0]->windows.find(1)->second->wrapped_window.tabs.size()); |
1125 helper()->VerifySyncedSession(kTag1, meta1_reference, *(foreign_sessions[0])); | 1130 helper()->VerifySyncedSession(kTag1, meta1_reference, *(foreign_sessions[0])); |
1126 | 1131 |
1127 // Add a new foreign session. | 1132 // Add a new foreign session. |
1128 std::vector<SessionID::id_type> tag2_tab_list = {107, 115}; | 1133 std::vector<SessionID::id_type> tag2_tab_list = {107, 115}; |
1129 std::vector<sync_pb::SessionSpecifics> tag2_tabs; | 1134 std::vector<sync_pb::SessionSpecifics> tag2_tabs; |
1130 sync_pb::SessionSpecifics meta2( | 1135 sync_pb::SessionSpecifics meta2( |
1131 helper()->BuildForeignSession(kTag2, tag2_tab_list, &tag2_tabs)); | 1136 helper()->BuildForeignSession(kTag2, tag2_tab_list, &tag2_tabs)); |
1132 changes.push_back(MakeRemoteChange(meta2, SyncChange::ACTION_ADD)); | 1137 changes.push_back(MakeRemoteChange(meta2, SyncChange::ACTION_ADD)); |
1133 AddTabsToChangeList(tag2_tabs, SyncChange::ACTION_ADD, &changes); | 1138 AddTabsToChangeList(tag2_tabs, SyncChange::ACTION_ADD, &changes); |
1134 | 1139 |
1135 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1140 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1136 changes.clear(); | 1141 changes.clear(); |
1137 | 1142 |
1138 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1143 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1139 std::vector<std::vector<SessionID::id_type>> meta2_reference; | 1144 std::vector<std::vector<SessionID::id_type>> meta2_reference; |
1140 meta2_reference.push_back(tag2_tab_list); | 1145 meta2_reference.push_back(tag2_tab_list); |
1141 ASSERT_EQ(2U, foreign_sessions.size()); | 1146 ASSERT_EQ(2U, foreign_sessions.size()); |
1142 ASSERT_EQ(2U, foreign_sessions[1]->windows.find(0)->second->tabs.size()); | 1147 ASSERT_EQ( |
| 1148 2U, |
| 1149 foreign_sessions[1]->windows.find(0)->second->wrapped_window.tabs.size()); |
1143 helper()->VerifySyncedSession(kTag2, meta2_reference, *(foreign_sessions[1])); | 1150 helper()->VerifySyncedSession(kTag2, meta2_reference, *(foreign_sessions[1])); |
1144 foreign_sessions.clear(); | 1151 foreign_sessions.clear(); |
1145 | 1152 |
1146 // Remove a tab from a window. | 1153 // Remove a tab from a window. |
1147 meta1_reference[0].pop_back(); | 1154 meta1_reference[0].pop_back(); |
1148 tab_list1.pop_back(); | 1155 tab_list1.pop_back(); |
1149 sync_pb::SessionWindow* win = meta1.mutable_header()->mutable_window(0); | 1156 sync_pb::SessionWindow* win = meta1.mutable_header()->mutable_window(0); |
1150 win->clear_tab(); | 1157 win->clear_tab(); |
1151 for (std::vector<int>::const_iterator iter = tab_list1.begin(); | 1158 for (std::vector<int>::const_iterator iter = tab_list1.begin(); |
1152 iter != tab_list1.end(); ++iter) { | 1159 iter != tab_list1.end(); ++iter) { |
1153 win->add_tab(*iter); | 1160 win->add_tab(*iter); |
1154 } | 1161 } |
1155 SyncChangeList removal; | 1162 SyncChangeList removal; |
1156 removal.push_back(MakeRemoteChange(meta1, SyncChange::ACTION_UPDATE)); | 1163 removal.push_back(MakeRemoteChange(meta1, SyncChange::ACTION_UPDATE)); |
1157 AddTabsToChangeList(tabs1, SyncChange::ACTION_UPDATE, &removal); | 1164 AddTabsToChangeList(tabs1, SyncChange::ACTION_UPDATE, &removal); |
1158 manager()->ProcessSyncChanges(FROM_HERE, removal); | 1165 manager()->ProcessSyncChanges(FROM_HERE, removal); |
1159 | 1166 |
1160 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1167 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1161 ASSERT_EQ(2U, foreign_sessions.size()); | 1168 ASSERT_EQ(2U, foreign_sessions.size()); |
1162 ASSERT_EQ(3U, foreign_sessions[0]->windows.find(0)->second->tabs.size()); | 1169 ASSERT_EQ( |
| 1170 3U, |
| 1171 foreign_sessions[0]->windows.find(0)->second->wrapped_window.tabs.size()); |
1163 helper()->VerifySyncedSession(kTag1, meta1_reference, *(foreign_sessions[0])); | 1172 helper()->VerifySyncedSession(kTag1, meta1_reference, *(foreign_sessions[0])); |
1164 } | 1173 } |
1165 | 1174 |
1166 // Tests that this SyncSessionManager knows how to delete foreign sessions | 1175 // Tests that this SyncSessionManager knows how to delete foreign sessions |
1167 // if it wants to. | 1176 // if it wants to. |
1168 TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { | 1177 TEST_F(SessionsSyncManagerTest, DeleteForeignSession) { |
1169 InitWithNoSyncData(); | 1178 InitWithNoSyncData(); |
1170 SyncChangeList changes; | 1179 SyncChangeList changes; |
1171 | 1180 |
1172 std::vector<const SyncedSession*> foreign_sessions; | 1181 std::vector<const SyncedSession*> foreign_sessions; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 AddTabsToChangeList(tabs1, SyncChange::ACTION_ADD, &changes); | 1274 AddTabsToChangeList(tabs1, SyncChange::ACTION_ADD, &changes); |
1266 AddTabsToChangeList(tabs2, SyncChange::ACTION_ADD, &changes); | 1275 AddTabsToChangeList(tabs2, SyncChange::ACTION_ADD, &changes); |
1267 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1276 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1268 changes.clear(); | 1277 changes.clear(); |
1269 | 1278 |
1270 // Check that the foreign session was associated and retrieve the data. | 1279 // Check that the foreign session was associated and retrieve the data. |
1271 std::vector<const SyncedSession*> foreign_sessions; | 1280 std::vector<const SyncedSession*> foreign_sessions; |
1272 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1281 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1273 ASSERT_EQ(1U, foreign_sessions.size()); | 1282 ASSERT_EQ(1U, foreign_sessions.size()); |
1274 ASSERT_EQ(2U, foreign_sessions[0]->windows.size()); | 1283 ASSERT_EQ(2U, foreign_sessions[0]->windows.size()); |
1275 ASSERT_EQ(4U, foreign_sessions[0]->windows.find(0)->second->tabs.size()); | 1284 ASSERT_EQ( |
1276 ASSERT_EQ(4U, foreign_sessions[0]->windows.find(1)->second->tabs.size()); | 1285 4U, |
| 1286 foreign_sessions[0]->windows.find(0)->second->wrapped_window.tabs.size()); |
| 1287 ASSERT_EQ( |
| 1288 4U, |
| 1289 foreign_sessions[0]->windows.find(1)->second->wrapped_window.tabs.size()); |
1277 | 1290 |
1278 // Close the second window. | 1291 // Close the second window. |
1279 meta.mutable_header()->clear_window(); | 1292 meta.mutable_header()->clear_window(); |
1280 helper()->AddWindowSpecifics(0, tab_list1, &meta); | 1293 helper()->AddWindowSpecifics(0, tab_list1, &meta); |
1281 changes.push_back(MakeRemoteChange(meta, SyncChange::ACTION_UPDATE)); | 1294 changes.push_back(MakeRemoteChange(meta, SyncChange::ACTION_UPDATE)); |
1282 // Update associator with the session's meta node containing one window. | 1295 // Update associator with the session's meta node containing one window. |
1283 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1296 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1284 | 1297 |
1285 // Check that the foreign session was associated and retrieve the data. | 1298 // Check that the foreign session was associated and retrieve the data. |
1286 foreign_sessions.clear(); | 1299 foreign_sessions.clear(); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 initial_data.push_back( | 2147 initial_data.push_back( |
2135 CreateRemoteData(entity, base::Time::FromDoubleT(3000))); | 2148 CreateRemoteData(entity, base::Time::FromDoubleT(3000))); |
2136 | 2149 |
2137 SyncChangeList output; | 2150 SyncChangeList output; |
2138 InitWithSyncDataTakeOutput(initial_data, &output); | 2151 InitWithSyncDataTakeOutput(initial_data, &output); |
2139 | 2152 |
2140 std::vector<const SyncedSession*> foreign_sessions; | 2153 std::vector<const SyncedSession*> foreign_sessions; |
2141 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2154 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
2142 | 2155 |
2143 const std::vector<std::unique_ptr<sessions::SessionTab>>& window_tabs = | 2156 const std::vector<std::unique_ptr<sessions::SessionTab>>& window_tabs = |
2144 foreign_sessions[0]->windows.find(0)->second->tabs; | 2157 foreign_sessions[0]->windows.find(0)->second->wrapped_window.tabs; |
2145 ASSERT_EQ(4U, window_tabs.size()); | 2158 ASSERT_EQ(4U, window_tabs.size()); |
2146 // The first one is from the original set of tabs. | 2159 // The first one is from the original set of tabs. |
2147 ASSERT_EQ(1, window_tabs[0]->tab_visual_index); | 2160 ASSERT_EQ(1, window_tabs[0]->tab_visual_index); |
2148 // The one from the original set of tabs wins over duplicating_tab1. | 2161 // The one from the original set of tabs wins over duplicating_tab1. |
2149 ASSERT_EQ(1, window_tabs[1]->tab_visual_index); | 2162 ASSERT_EQ(1, window_tabs[1]->tab_visual_index); |
2150 // duplicating_tab2 wins due to the later timestamp. | 2163 // duplicating_tab2 wins due to the later timestamp. |
2151 ASSERT_EQ(3, window_tabs[2]->tab_visual_index); | 2164 ASSERT_EQ(3, window_tabs[2]->tab_visual_index); |
2152 } | 2165 } |
2153 | 2166 |
2154 // Verify that GetAllForeignSessions returns all sessions sorted by recency. | 2167 // Verify that GetAllForeignSessions returns all sessions sorted by recency. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2396 // Because tab 2 is a placeholder, tab 1's URL will be preserved. | 2409 // Because tab 2 is a placeholder, tab 1's URL will be preserved. |
2397 VerifyLocalTabChange(out[1], 1, kFoo1); | 2410 VerifyLocalTabChange(out[1], 1, kFoo1); |
2398 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); | 2411 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); |
2399 EXPECT_EQ(tab2.GetSessionId(), | 2412 EXPECT_EQ(tab2.GetSessionId(), |
2400 out[1].sync_data().GetSpecifics().session().tab().tab_id()); | 2413 out[1].sync_data().GetSpecifics().session().tab().tab_id()); |
2401 EXPECT_EQ(window2->GetSessionId(), | 2414 EXPECT_EQ(window2->GetSessionId(), |
2402 out[1].sync_data().GetSpecifics().session().tab().window_id()); | 2415 out[1].sync_data().GetSpecifics().session().tab().window_id()); |
2403 } | 2416 } |
2404 | 2417 |
2405 } // namespace sync_sessions | 2418 } // namespace sync_sessions |
OLD | NEW |