OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/sync/test/engine/test_id_factory.h" | 35 #include "chrome/browser/sync/test/engine/test_id_factory.h" |
36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
37 #include "chrome/common/net/gaia/gaia_constants.h" | 37 #include "chrome/common/net/gaia/gaia_constants.h" |
38 #include "chrome/test/base/browser_with_test_window_test.h" | 38 #include "chrome/test/base/browser_with_test_window_test.h" |
39 #include "chrome/test/base/profile_mock.h" | 39 #include "chrome/test/base/profile_mock.h" |
40 #include "chrome/test/base/testing_profile.h" | 40 #include "chrome/test/base/testing_profile.h" |
41 #include "content/browser/browser_thread.h" | 41 #include "content/browser/browser_thread.h" |
42 #include "content/common/notification_observer.h" | 42 #include "content/common/notification_observer.h" |
43 #include "content/common/notification_registrar.h" | 43 #include "content/common/notification_registrar.h" |
44 #include "content/common/notification_service.h" | 44 #include "content/common/notification_service.h" |
| 45 #include "googleurl/src/gurl.h" |
45 #include "testing/gmock/include/gmock/gmock.h" | 46 #include "testing/gmock/include/gmock/gmock.h" |
46 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
47 #include "ui/base/ui_base_types.h" | 48 #include "ui/base/ui_base_types.h" |
48 | 49 |
49 using browser_sync::SessionChangeProcessor; | 50 using browser_sync::SessionChangeProcessor; |
50 using browser_sync::SessionDataTypeController; | 51 using browser_sync::SessionDataTypeController; |
51 using browser_sync::SessionModelAssociator; | 52 using browser_sync::SessionModelAssociator; |
52 using browser_sync::SyncBackendHost; | 53 using browser_sync::SyncBackendHost; |
53 using sync_api::ChangeRecord; | 54 using sync_api::ChangeRecord; |
54 using testing::_; | 55 using testing::_; |
55 using testing::Return; | 56 using testing::Return; |
56 using browser_sync::TestIdFactory; | 57 using browser_sync::TestIdFactory; |
57 | 58 |
58 namespace browser_sync { | 59 namespace browser_sync { |
59 | 60 |
| 61 namespace { |
| 62 |
| 63 void BuildSessionSpecifics(const std::string& tag, |
| 64 sync_pb::SessionSpecifics* meta) { |
| 65 meta->set_session_tag(tag); |
| 66 sync_pb::SessionHeader* header = meta->mutable_header(); |
| 67 header->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_LINUX); |
| 68 header->set_client_name("name"); |
| 69 } |
| 70 |
| 71 void AddWindowSpecifics(int window_id, |
| 72 const std::vector<int>& tab_list, |
| 73 sync_pb::SessionSpecifics* meta) { |
| 74 sync_pb::SessionHeader* header = meta->mutable_header(); |
| 75 sync_pb::SessionWindow* window = header->add_window(); |
| 76 window->set_window_id(window_id); |
| 77 window->set_selected_tab_index(0); |
| 78 window->set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); |
| 79 for (std::vector<int>::const_iterator iter = tab_list.begin(); |
| 80 iter != tab_list.end(); ++iter) { |
| 81 window->add_tab(*iter); |
| 82 } |
| 83 } |
| 84 |
| 85 void BuildTabSpecifics(const std::string& tag, int window_id, int tab_id, |
| 86 sync_pb::SessionSpecifics* tab_base) { |
| 87 tab_base->set_session_tag(tag); |
| 88 sync_pb::SessionTab* tab = tab_base->mutable_tab(); |
| 89 tab->set_tab_id(tab_id); |
| 90 tab->set_tab_visual_index(1); |
| 91 tab->set_current_navigation_index(0); |
| 92 tab->set_pinned(true); |
| 93 tab->set_extension_app_id("app_id"); |
| 94 sync_pb::TabNavigation* navigation = tab->add_navigation(); |
| 95 navigation->set_index(12); |
| 96 navigation->set_virtual_url("http://foo/1"); |
| 97 navigation->set_referrer("referrer"); |
| 98 navigation->set_title("title"); |
| 99 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED); |
| 100 } |
| 101 |
| 102 // Verifies number of windows, number of tabs, and basic fields. |
| 103 void VerifySyncedSession( |
| 104 const std::string& tag, |
| 105 const std::vector<std::vector<SessionID::id_type> >& windows, |
| 106 const SyncedSession& session) { |
| 107 ASSERT_EQ(tag, session.session_tag); |
| 108 ASSERT_EQ(SyncedSession::TYPE_LINUX, session.device_type); |
| 109 ASSERT_EQ("name", session.session_name); |
| 110 ASSERT_EQ(windows.size(), session.windows.size()); |
| 111 |
| 112 // We assume the window id's are in increasing order. |
| 113 int i = 0; |
| 114 for (std::vector<std::vector<int> >::const_iterator win_iter = |
| 115 windows.begin(); |
| 116 win_iter != windows.end(); ++win_iter, ++i) { |
| 117 SessionWindow* win_ptr; |
| 118 SyncedSession::SyncedWindowMap::const_iterator map_iter = |
| 119 session.windows.find(i); |
| 120 if (map_iter != session.windows.end()) |
| 121 win_ptr = map_iter->second; |
| 122 else |
| 123 FAIL(); |
| 124 ASSERT_EQ(win_iter->size(), win_ptr->tabs.size()); |
| 125 ASSERT_EQ(0, win_ptr->selected_tab_index); |
| 126 ASSERT_EQ(1, win_ptr->type); |
| 127 int j = 0; |
| 128 for (std::vector<int>::const_iterator tab_iter = (*win_iter).begin(); |
| 129 tab_iter != (*win_iter).end(); ++tab_iter, ++j) { |
| 130 SessionTab* tab = win_ptr->tabs[j]; |
| 131 ASSERT_EQ(*tab_iter, tab->tab_id.id()); |
| 132 ASSERT_EQ(1U, tab->navigations.size()); |
| 133 ASSERT_EQ(1, tab->tab_visual_index); |
| 134 ASSERT_EQ(0, tab->current_navigation_index); |
| 135 ASSERT_TRUE(tab->pinned); |
| 136 ASSERT_EQ("app_id", tab->extension_app_id); |
| 137 ASSERT_EQ(1U, tab->navigations.size()); |
| 138 ASSERT_EQ(12, tab->navigations[0].index()); |
| 139 ASSERT_EQ(tab->navigations[0].virtual_url(), GURL("http://foo/1")); |
| 140 ASSERT_EQ(tab->navigations[0].referrer(), GURL("referrer")); |
| 141 ASSERT_EQ(tab->navigations[0].title(), string16(ASCIIToUTF16("title"))); |
| 142 ASSERT_EQ(tab->navigations[0].transition(), PageTransition::TYPED); |
| 143 } |
| 144 } |
| 145 } |
| 146 |
| 147 } // namespace |
| 148 |
60 class ProfileSyncServiceSessionTest | 149 class ProfileSyncServiceSessionTest |
61 : public BrowserWithTestWindowTest, | 150 : public BrowserWithTestWindowTest, |
62 public NotificationObserver { | 151 public NotificationObserver { |
63 public: | 152 public: |
64 ProfileSyncServiceSessionTest() | 153 ProfileSyncServiceSessionTest() |
65 : io_thread_(BrowserThread::IO), | 154 : io_thread_(BrowserThread::IO), |
66 window_bounds_(0, 1, 2, 3), | 155 window_bounds_(0, 1, 2, 3), |
67 notified_of_update_(false) {} | 156 notified_of_update_(false) {} |
68 ProfileSyncService* sync_service() { return sync_service_.get(); } | 157 ProfileSyncService* sync_service() { return sync_service_.get(); } |
69 | 158 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 ASSERT_EQ(machine_tag, specifics.session_tag()); | 304 ASSERT_EQ(machine_tag, specifics.session_tag()); |
216 ASSERT_TRUE(specifics.has_header()); | 305 ASSERT_TRUE(specifics.has_header()); |
217 const sync_pb::SessionHeader& header_s = specifics.header(); | 306 const sync_pb::SessionHeader& header_s = specifics.header(); |
218 ASSERT_TRUE(header_s.has_device_type()); | 307 ASSERT_TRUE(header_s.has_device_type()); |
219 ASSERT_EQ("TestSessionName", header_s.client_name()); | 308 ASSERT_EQ("TestSessionName", header_s.client_name()); |
220 ASSERT_EQ(0, header_s.window_size()); | 309 ASSERT_EQ(0, header_s.window_size()); |
221 } | 310 } |
222 | 311 |
223 // Test that we can fill this machine's session, write it to a node, | 312 // Test that we can fill this machine's session, write it to a node, |
224 // and then retrieve it. | 313 // and then retrieve it. |
225 // Experiencing random crashes on windows. http://crbug.com/81104. | 314 TEST_F(ProfileSyncServiceSessionTest, WriteFilledSessionToNode) { |
226 #if defined(OS_WIN) | |
227 #define MAYBE_WriteFilledSessionToNode DISABLED_WriteFilledSessionToNode | |
228 #else | |
229 #define MAYBE_WriteFilledSessionToNode WriteFilledSessionToNode | |
230 #endif | |
231 TEST_F(ProfileSyncServiceSessionTest, MAYBE_WriteFilledSessionToNode) { | |
232 CreateRootTask task(this); | 315 CreateRootTask task(this); |
233 ASSERT_TRUE(StartSyncService(&task, false)); | 316 ASSERT_TRUE(StartSyncService(&task, false)); |
234 ASSERT_TRUE(task.success()); | 317 ASSERT_TRUE(task.success()); |
235 | 318 |
236 // Check that the DataTypeController associated the models. | 319 // Check that the DataTypeController associated the models. |
237 bool has_nodes; | 320 bool has_nodes; |
238 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); | 321 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); |
239 ASSERT_TRUE(has_nodes); | 322 ASSERT_TRUE(has_nodes); |
240 AddTab(browser(), GURL("http://foo/1")); | 323 AddTab(browser(), GURL("http://foo/1")); |
241 NavigateAndCommitActiveTab(GURL("http://foo/2")); | 324 NavigateAndCommitActiveTab(GURL("http://foo/2")); |
242 AddTab(browser(), GURL("http://bar/1")); | 325 AddTab(browser(), GURL("http://bar/1")); |
243 NavigateAndCommitActiveTab(GURL("http://bar/2")); | 326 NavigateAndCommitActiveTab(GURL("http://bar/2")); |
244 | 327 |
245 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); | 328 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); |
246 ASSERT_TRUE(has_nodes); | 329 ASSERT_TRUE(has_nodes); |
247 std::string machine_tag = model_associator_->GetCurrentMachineTag(); | 330 std::string machine_tag = model_associator_->GetCurrentMachineTag(); |
248 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag); | 331 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag); |
249 ASSERT_NE(sync_api::kInvalidId, sync_id); | 332 ASSERT_NE(sync_api::kInvalidId, sync_id); |
250 | 333 |
251 // Check that this machine's data is not included in the foreign windows. | 334 // Check that this machine's data is not included in the foreign windows. |
252 std::vector<const SyncedSession*> foreign_sessions; | 335 std::vector<const SyncedSession*> foreign_sessions; |
253 model_associator_->GetAllForeignSessions(&foreign_sessions); | 336 ASSERT_FALSE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
254 ASSERT_EQ(foreign_sessions.size(), 0U); | 337 ASSERT_EQ(foreign_sessions.size(), 0U); |
255 | 338 |
256 // Get the tabs for this machine from the node and check that they were | 339 // Get the tabs for this machine from the node and check that they were |
257 // filled. | 340 // filled. |
258 SessionModelAssociator::TabLinksMap tab_map = model_associator_->tab_map_; | 341 SessionModelAssociator::TabLinksMap tab_map = model_associator_->tab_map_; |
259 ASSERT_EQ(2U, tab_map.size()); | 342 ASSERT_EQ(2U, tab_map.size()); |
260 // Tabs are ordered by sessionid in tab_map, so should be able to traverse | 343 // Tabs are ordered by sessionid in tab_map, so should be able to traverse |
261 // the tree based on order of tabs created | 344 // the tree based on order of tabs created |
262 SessionModelAssociator::TabLinksMap::iterator iter = tab_map.begin(); | 345 SessionModelAssociator::TabLinksMap::iterator iter = tab_map.begin(); |
263 ASSERT_EQ(2, iter->second.tab()->GetEntryCount()); | 346 ASSERT_EQ(2, iter->second.tab()->GetEntryCount()); |
(...skipping 20 matching lines...) Expand all Loading... |
284 CreateRootTask task(this); | 367 CreateRootTask task(this); |
285 ASSERT_TRUE(StartSyncService(&task, false)); | 368 ASSERT_TRUE(StartSyncService(&task, false)); |
286 ASSERT_TRUE(task.success()); | 369 ASSERT_TRUE(task.success()); |
287 | 370 |
288 // Check that the DataTypeController associated the models. | 371 // Check that the DataTypeController associated the models. |
289 bool has_nodes; | 372 bool has_nodes; |
290 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); | 373 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); |
291 ASSERT_TRUE(has_nodes); | 374 ASSERT_TRUE(has_nodes); |
292 | 375 |
293 // Fill an instance of session specifics with a foreign session's data. | 376 // Fill an instance of session specifics with a foreign session's data. |
294 sync_pb::SessionSpecifics meta_specifics; | 377 std::string tag = "tag1"; |
295 std::string machine_tag = "session_sync123"; | 378 sync_pb::SessionSpecifics meta; |
296 meta_specifics.set_session_tag(machine_tag); | 379 BuildSessionSpecifics(tag, &meta); |
297 sync_pb::SessionHeader* header_s = meta_specifics.mutable_header(); | 380 SessionID::id_type tab_nums1[] = {5, 10, 13, 17}; |
298 sync_pb::SessionWindow* window_s = header_s->add_window(); | 381 std::vector<SessionID::id_type> tab_list1( |
299 window_s->add_tab(0); | 382 tab_nums1, tab_nums1 + arraysize(tab_nums1)); |
300 window_s->set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); | 383 AddWindowSpecifics(0, tab_list1, &meta); |
301 window_s->set_selected_tab_index(1); | 384 std::vector<sync_pb::SessionSpecifics> tabs1; |
302 | 385 tabs1.resize(tab_list1.size()); |
303 sync_pb::SessionSpecifics tab_specifics; | 386 for (size_t i = 0; i < tab_list1.size(); ++i) { |
304 tab_specifics.set_session_tag(machine_tag); | 387 BuildTabSpecifics(tag, 0, tab_list1[i], &tabs1[i]); |
305 sync_pb::SessionTab* tab = tab_specifics.mutable_tab(); | 388 } |
306 tab->set_tab_visual_index(13); | 389 |
307 tab->set_current_navigation_index(3); | 390 // Update associator with the session's meta node containing two windows. |
308 tab->set_pinned(true); | 391 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
309 tab->set_extension_app_id("app_id"); | 392 // Add tabs for first window. |
310 sync_pb::TabNavigation* navigation = tab->add_navigation(); | 393 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs1.begin(); |
311 navigation->set_index(12); | 394 iter != tabs1.end(); ++iter) { |
312 navigation->set_virtual_url("http://foo/1"); | 395 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
313 navigation->set_referrer("referrer"); | 396 } |
314 navigation->set_title("title"); | 397 |
315 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED); | 398 // Check that the foreign session was associated and retrieve the data. |
316 | 399 std::vector<const SyncedSession*> foreign_sessions; |
317 // Update the server with the session specifics. | 400 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
318 { | 401 ASSERT_EQ(1U, foreign_sessions.size()); |
319 model_associator_->AssociateForeignSpecifics(meta_specifics, base::Time()); | 402 std::vector<std::vector<SessionID::id_type> > session_reference; |
320 model_associator_->AssociateForeignSpecifics(tab_specifics, base::Time()); | 403 session_reference.push_back(tab_list1); |
321 } | 404 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
322 | 405 } |
323 // Check that the foreign session was associated and retrieve the data. | 406 |
324 std::vector<const SyncedSession*> foreign_sessions; | 407 // Write a foreign session with one window to a node. Sync, then add a window. |
325 model_associator_->GetAllForeignSessions(&foreign_sessions); | 408 // Sync, then add a third window. Close the two windows. |
326 ASSERT_EQ(1U, foreign_sessions.size()); | 409 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNodeThreeWindows) { |
327 ASSERT_EQ(machine_tag, foreign_sessions[0]->session_tag); | 410 CreateRootTask task(this); |
328 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); | 411 ASSERT_TRUE(StartSyncService(&task, false)); |
329 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs.size()); | 412 ASSERT_TRUE(task.success()); |
330 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs[0]->navigations.size()); | 413 |
331 ASSERT_EQ(foreign_sessions[0]->session_tag, machine_tag); | 414 // Build a foreign session with one window and four tabs. |
332 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->selected_tab_index); | 415 std::string tag = "tag1"; |
333 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->type); | 416 sync_pb::SessionSpecifics meta; |
334 ASSERT_EQ(13, foreign_sessions[0]->windows[0]->tabs[0]->tab_visual_index); | 417 BuildSessionSpecifics(tag, &meta); |
335 ASSERT_EQ(3, | 418 SessionID::id_type tab_nums1[] = {5, 10, 13, 17}; |
336 foreign_sessions[0]->windows[0]->tabs[0]->current_navigation_index); | 419 std::vector<SessionID::id_type> tab_list1( |
337 ASSERT_TRUE(foreign_sessions[0]->windows[0]->tabs[0]->pinned); | 420 tab_nums1, tab_nums1 + arraysize(tab_nums1)); |
338 ASSERT_EQ("app_id", | 421 AddWindowSpecifics(0, tab_list1, &meta); |
339 foreign_sessions[0]->windows[0]->tabs[0]->extension_app_id); | 422 std::vector<sync_pb::SessionSpecifics> tabs1; |
340 ASSERT_EQ(12, | 423 tabs1.resize(tab_list1.size()); |
341 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].index()); | 424 for (size_t i = 0; i < tab_list1.size(); ++i) { |
342 ASSERT_EQ(GURL("referrer"), | 425 BuildTabSpecifics(tag, 0, tab_list1[i], &tabs1[i]); |
343 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].referrer()); | 426 } |
344 ASSERT_EQ(string16(ASCIIToUTF16("title")), | 427 // Update associator with the session's meta node containing one window. |
345 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].title()); | 428 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
346 ASSERT_EQ(PageTransition::TYPED, | 429 // Add tabs for first window. |
347 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].transition()); | 430 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs1.begin(); |
348 ASSERT_EQ(GURL("http://foo/1"), | 431 iter != tabs1.end(); ++iter) { |
349 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url()); | 432 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
| 433 } |
| 434 |
| 435 // Verify first window |
| 436 std::vector<const SyncedSession*> foreign_sessions; |
| 437 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 438 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 439 session_reference.push_back(tab_list1); |
| 440 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
| 441 |
| 442 // Add a second window. |
| 443 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; |
| 444 std::vector<SessionID::id_type> tab_list2( |
| 445 tab_nums2, tab_nums2 + arraysize(tab_nums2)); |
| 446 AddWindowSpecifics(1, tab_list2, &meta); |
| 447 std::vector<sync_pb::SessionSpecifics> tabs2; |
| 448 tabs2.resize(tab_list2.size()); |
| 449 for (size_t i = 0; i < tab_list2.size(); ++i) { |
| 450 BuildTabSpecifics(tag, 0, tab_list2[i], &tabs2[i]); |
| 451 } |
| 452 // Update associator with the session's meta node containing two windows. |
| 453 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 454 // Add tabs for second window. |
| 455 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs2.begin(); |
| 456 iter != tabs2.end(); ++iter) { |
| 457 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
| 458 } |
| 459 |
| 460 // Verify the two windows. |
| 461 foreign_sessions.clear(); |
| 462 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 463 ASSERT_EQ(1U, foreign_sessions.size()); |
| 464 session_reference.push_back(tab_list2); |
| 465 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
| 466 |
| 467 // Add a third window. |
| 468 SessionID::id_type tab_nums3[] = {8, 16, 19, 21}; |
| 469 std::vector<SessionID::id_type> tab_list3( |
| 470 tab_nums3, tab_nums3 + arraysize(tab_nums3)); |
| 471 AddWindowSpecifics(2, tab_list3, &meta); |
| 472 std::vector<sync_pb::SessionSpecifics> tabs3; |
| 473 tabs3.resize(tab_list3.size()); |
| 474 for (size_t i = 0; i < tab_list3.size(); ++i) { |
| 475 BuildTabSpecifics(tag, 0, tab_list3[i], &tabs3[i]); |
| 476 } |
| 477 // Update associator with the session's meta node containing three windows. |
| 478 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 479 // Add tabs for third window. |
| 480 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs3.begin(); |
| 481 iter != tabs3.end(); ++iter) { |
| 482 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
| 483 } |
| 484 |
| 485 // Verify the three windows |
| 486 foreign_sessions.clear(); |
| 487 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 488 ASSERT_EQ(1U, foreign_sessions.size()); |
| 489 session_reference.push_back(tab_list3); |
| 490 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
| 491 |
| 492 // Close third window (by clearing and then not adding it back). |
| 493 meta.mutable_header()->clear_window(); |
| 494 AddWindowSpecifics(0, tab_list1, &meta); |
| 495 AddWindowSpecifics(1, tab_list2, &meta); |
| 496 // Update associator with just the meta node, now containing only two windows. |
| 497 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 498 |
| 499 // Verify first two windows are still there. |
| 500 foreign_sessions.clear(); |
| 501 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 502 ASSERT_EQ(1U, foreign_sessions.size()); |
| 503 session_reference.pop_back(); // Pop off the data for the third window. |
| 504 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
| 505 |
| 506 // Close second window (by clearing and then not adding it back). |
| 507 meta.mutable_header()->clear_window(); |
| 508 AddWindowSpecifics(0, tab_list1, &meta); |
| 509 // Update associator with just the meta node, now containing only one windows. |
| 510 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 511 |
| 512 // Verify first window is still there. |
| 513 foreign_sessions.clear(); |
| 514 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 515 ASSERT_EQ(1U, foreign_sessions.size()); |
| 516 session_reference.pop_back(); // Pop off the data for the second window. |
| 517 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
| 518 } |
| 519 |
| 520 // Write a foreign session to a node, with the tabs arriving first, and then |
| 521 // retrieve it. |
| 522 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNodeTabsFirst) { |
| 523 CreateRootTask task(this); |
| 524 ASSERT_TRUE(StartSyncService(&task, false)); |
| 525 ASSERT_TRUE(task.success()); |
| 526 |
| 527 // Fill an instance of session specifics with a foreign session's data. |
| 528 std::string tag = "tag1"; |
| 529 sync_pb::SessionSpecifics meta; |
| 530 BuildSessionSpecifics(tag, &meta); |
| 531 SessionID::id_type tab_nums1[] = {5, 10, 13, 17}; |
| 532 std::vector<SessionID::id_type> tab_list1( |
| 533 tab_nums1, tab_nums1 + arraysize(tab_nums1)); |
| 534 AddWindowSpecifics(0, tab_list1, &meta); |
| 535 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 536 tabs1.resize(tab_list1.size()); |
| 537 for (size_t i = 0; i < tab_list1.size(); ++i) { |
| 538 BuildTabSpecifics(tag, 0, tab_list1[i], &tabs1[i]); |
| 539 } |
| 540 |
| 541 // Add tabs for first window. |
| 542 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs1.begin(); |
| 543 iter != tabs1.end(); ++iter) { |
| 544 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
| 545 } |
| 546 // Update associator with the session's meta node containing one window. |
| 547 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 548 |
| 549 // Check that the foreign session was associated and retrieve the data. |
| 550 std::vector<const SyncedSession*> foreign_sessions; |
| 551 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 552 ASSERT_EQ(1U, foreign_sessions.size()); |
| 553 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 554 session_reference.push_back(tab_list1); |
| 555 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
| 556 } |
| 557 |
| 558 // Write a foreign session to a node with some tabs that never arrive. |
| 559 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNodeMissingTabs) { |
| 560 CreateRootTask task(this); |
| 561 ASSERT_TRUE(StartSyncService(&task, false)); |
| 562 ASSERT_TRUE(task.success()); |
| 563 |
| 564 // Fill an instance of session specifics with a foreign session's data. |
| 565 std::string tag = "tag1"; |
| 566 sync_pb::SessionSpecifics meta; |
| 567 BuildSessionSpecifics(tag, &meta); |
| 568 SessionID::id_type tab_nums1[] = {5, 10, 13, 17}; |
| 569 std::vector<SessionID::id_type> tab_list1( |
| 570 tab_nums1, tab_nums1 + arraysize(tab_nums1)); |
| 571 AddWindowSpecifics(0, tab_list1, &meta); |
| 572 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 573 tabs1.resize(tab_list1.size()); // First window has all the tabs |
| 574 for (size_t i = 0; i < tab_list1.size(); ++i) { |
| 575 BuildTabSpecifics(tag, 0, tab_list1[i], &tabs1[i]); |
| 576 } |
| 577 // Add a second window, but this time only create two tab nodes, despite the |
| 578 // window expecting four tabs. |
| 579 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; |
| 580 std::vector<SessionID::id_type> tab_list2( |
| 581 tab_nums2, tab_nums2 + arraysize(tab_nums2)); |
| 582 AddWindowSpecifics(1, tab_list2, &meta); |
| 583 std::vector<sync_pb::SessionSpecifics> tabs2; |
| 584 tabs2.resize(2); |
| 585 for (size_t i = 0; i < 2; ++i) { |
| 586 BuildTabSpecifics(tag, 0, tab_list2[i], &tabs2[i]); |
| 587 } |
| 588 |
| 589 // Update associator with the session's meta node containing two windows. |
| 590 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 591 // Add tabs for first window. |
| 592 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs1.begin(); |
| 593 iter != tabs1.end(); ++iter) { |
| 594 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
| 595 } |
| 596 // Add tabs for second window. |
| 597 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs2.begin(); |
| 598 iter != tabs2.end(); ++iter) { |
| 599 model_associator_->AssociateForeignSpecifics(*iter, base::Time()); |
| 600 } |
| 601 |
| 602 // Check that the foreign session was associated and retrieve the data. |
| 603 std::vector<const SyncedSession*> foreign_sessions; |
| 604 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 605 ASSERT_EQ(1U, foreign_sessions.size()); |
| 606 ASSERT_EQ(2U, foreign_sessions[0]->windows.size()); |
| 607 ASSERT_EQ(4U, foreign_sessions[0]->windows.find(0)->second->tabs.size()); |
| 608 ASSERT_EQ(4U, foreign_sessions[0]->windows.find(1)->second->tabs.size()); |
| 609 |
| 610 // Close the second window. |
| 611 meta.mutable_header()->clear_window(); |
| 612 AddWindowSpecifics(0, tab_list1, &meta); |
| 613 |
| 614 // Update associator with the session's meta node containing one window. |
| 615 model_associator_->AssociateForeignSpecifics(meta, base::Time()); |
| 616 |
| 617 // Check that the foreign session was associated and retrieve the data. |
| 618 foreign_sessions.clear(); |
| 619 ASSERT_TRUE(model_associator_->GetAllForeignSessions(&foreign_sessions)); |
| 620 ASSERT_EQ(1U, foreign_sessions.size()); |
| 621 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); |
| 622 std::vector<std::vector<SessionID::id_type> > session_reference; |
| 623 session_reference.push_back(tab_list1); |
| 624 VerifySyncedSession(tag, session_reference, *(foreign_sessions[0])); |
350 } | 625 } |
351 | 626 |
352 // Test the DataTypeController on update. | 627 // Test the DataTypeController on update. |
353 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { | 628 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { |
354 CreateRootTask task(this); | 629 CreateRootTask task(this); |
355 ASSERT_TRUE(StartSyncService(&task, false)); | 630 ASSERT_TRUE(StartSyncService(&task, false)); |
356 ASSERT_TRUE(task.success()); | 631 ASSERT_TRUE(task.success()); |
357 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 632 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
358 model_associator_->GetCurrentMachineTag()); | 633 model_associator_->GetCurrentMachineTag()); |
359 ASSERT_FALSE(notified_of_update_); | 634 ASSERT_FALSE(notified_of_update_); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 ASSERT_FALSE(model_associator_->tab_pool_.full()); | 732 ASSERT_FALSE(model_associator_->tab_pool_.full()); |
458 for (size_t i = 0; i < num_ids; ++i) { | 733 for (size_t i = 0; i < num_ids; ++i) { |
459 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); | 734 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); |
460 } | 735 } |
461 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); | 736 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); |
462 ASSERT_FALSE(model_associator_->tab_pool_.empty()); | 737 ASSERT_FALSE(model_associator_->tab_pool_.empty()); |
463 ASSERT_TRUE(model_associator_->tab_pool_.full()); | 738 ASSERT_TRUE(model_associator_->tab_pool_.full()); |
464 } | 739 } |
465 | 740 |
466 } // namespace browser_sync | 741 } // namespace browser_sync |
OLD | NEW |