| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 using browser_sync::TestIdFactory; | 49 using browser_sync::TestIdFactory; |
| 50 | 50 |
| 51 namespace browser_sync { | 51 namespace browser_sync { |
| 52 | 52 |
| 53 class ProfileSyncServiceSessionTest | 53 class ProfileSyncServiceSessionTest |
| 54 : public BrowserWithTestWindowTest, | 54 : public BrowserWithTestWindowTest, |
| 55 public NotificationObserver { | 55 public NotificationObserver { |
| 56 public: | 56 public: |
| 57 ProfileSyncServiceSessionTest() | 57 ProfileSyncServiceSessionTest() |
| 58 : window_bounds_(0, 1, 2, 3), | 58 : window_bounds_(0, 1, 2, 3), |
| 59 notified_of_update_(false), | 59 notified_of_update_(false) {} |
| 60 notification_sync_id_(0) {} | |
| 61 | 60 |
| 62 ProfileSyncService* sync_service() { return sync_service_.get(); } | 61 ProfileSyncService* sync_service() { return sync_service_.get(); } |
| 63 | 62 |
| 64 TestIdFactory* ids() { return &ids_; } | 63 TestIdFactory* ids() { return &ids_; } |
| 65 | 64 |
| 66 protected: | 65 protected: |
| 67 SessionService* service() { return helper_.service(); } | 66 SessionService* service() { return helper_.service(); } |
| 68 | 67 |
| 69 virtual void SetUp() { | 68 virtual void SetUp() { |
| 70 BrowserWithTestWindowTest::SetUp(); | 69 BrowserWithTestWindowTest::SetUp(); |
| 71 profile()->set_has_history_service(true); | 70 profile()->set_has_history_service(true); |
| 72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 71 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 73 SessionService* session_service = new SessionService(temp_dir_.path()); | 72 SessionService* session_service = new SessionService(temp_dir_.path()); |
| 74 helper_.set_service(session_service); | 73 helper_.set_service(session_service); |
| 75 service()->SetWindowType(window_id_, Browser::TYPE_NORMAL); | 74 service()->SetWindowType(window_id_, Browser::TYPE_NORMAL); |
| 76 service()->SetWindowBounds(window_id_, window_bounds_, false); | 75 service()->SetWindowBounds(window_id_, window_bounds_, false); |
| 77 registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED, | 76 registrar_.Add(this, NotificationType::FOREIGN_SESSION_UPDATED, |
| 78 NotificationService::AllSources()); | 77 NotificationService::AllSources()); |
| 79 registrar_.Add(this, NotificationType::FOREIGN_SESSION_DELETED, | |
| 80 NotificationService::AllSources()); | |
| 81 } | 78 } |
| 82 | 79 |
| 83 void Observe(NotificationType type, | 80 void Observe(NotificationType type, |
| 84 const NotificationSource& source, | 81 const NotificationSource& source, |
| 85 const NotificationDetails& details) { | 82 const NotificationDetails& details) { |
| 86 switch (type.value) { | 83 switch (type.value) { |
| 87 case NotificationType::FOREIGN_SESSION_UPDATED: { | 84 case NotificationType::FOREIGN_SESSION_UPDATED: |
| 88 notified_of_update_ = true; | 85 notified_of_update_ = true; |
| 89 notification_sync_id_ = *Details<int64>(details).ptr(); | |
| 90 break; | 86 break; |
| 91 } | |
| 92 case NotificationType::FOREIGN_SESSION_DELETED: { | |
| 93 notified_of_update_ = true; | |
| 94 notification_sync_id_ = -1; | |
| 95 break; | |
| 96 } | |
| 97 default: | 87 default: |
| 98 NOTREACHED(); | 88 NOTREACHED(); |
| 99 break; | 89 break; |
| 100 } | 90 } |
| 101 } | 91 } |
| 102 | 92 |
| 103 virtual void TearDown() { | 93 virtual void TearDown() { |
| 104 helper_.set_service(NULL); | 94 helper_.set_service(NULL); |
| 105 profile()->set_session_service(NULL); | 95 profile()->set_session_service(NULL); |
| 106 sync_service_.reset(); | 96 sync_service_.reset(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 ScopedTempDir temp_dir_; | 130 ScopedTempDir temp_dir_; |
| 141 SessionServiceTestHelper helper_; | 131 SessionServiceTestHelper helper_; |
| 142 SessionModelAssociator* model_associator_; | 132 SessionModelAssociator* model_associator_; |
| 143 SessionChangeProcessor* change_processor_; | 133 SessionChangeProcessor* change_processor_; |
| 144 SessionID window_id_; | 134 SessionID window_id_; |
| 145 ProfileSyncFactoryMock factory_; | 135 ProfileSyncFactoryMock factory_; |
| 146 scoped_ptr<TestProfileSyncService> sync_service_; | 136 scoped_ptr<TestProfileSyncService> sync_service_; |
| 147 TestIdFactory ids_; | 137 TestIdFactory ids_; |
| 148 const gfx::Rect window_bounds_; | 138 const gfx::Rect window_bounds_; |
| 149 bool notified_of_update_; | 139 bool notified_of_update_; |
| 150 int64 notification_sync_id_; | |
| 151 NotificationRegistrar registrar_; | 140 NotificationRegistrar registrar_; |
| 152 }; | 141 }; |
| 153 | 142 |
| 154 class CreateRootTask : public Task { | 143 class CreateRootTask : public Task { |
| 155 public: | 144 public: |
| 156 explicit CreateRootTask(ProfileSyncServiceSessionTest* test) | 145 explicit CreateRootTask(ProfileSyncServiceSessionTest* test) |
| 157 : test_(test), success_(false) { | 146 : test_(test), success_(false) { |
| 158 } | 147 } |
| 159 | 148 |
| 160 virtual ~CreateRootTask() {} | 149 virtual ~CreateRootTask() {} |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 int64 sync_id; | 218 int64 sync_id; |
| 230 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, | 219 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, |
| 231 &sync_id)); | 220 &sync_id)); |
| 232 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id); | 221 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id); |
| 233 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics( | 222 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics( |
| 234 model_associator_->GetChromeNodeFromSyncId(sync_id)); | 223 model_associator_->GetChromeNodeFromSyncId(sync_id)); |
| 235 ASSERT_TRUE(sync_specifics != NULL); | 224 ASSERT_TRUE(sync_specifics != NULL); |
| 236 | 225 |
| 237 // Check that this machine's data is not included in the foreign windows. | 226 // Check that this machine's data is not included in the foreign windows. |
| 238 ScopedVector<ForeignSession> foreign_sessions; | 227 ScopedVector<ForeignSession> foreign_sessions; |
| 239 model_associator_->GetSessionDataFromSyncModel(&foreign_sessions.get()); | 228 model_associator_->GetSessionData(&foreign_sessions.get()); |
| 240 ASSERT_EQ(foreign_sessions.size(), 0U); | 229 ASSERT_EQ(foreign_sessions.size(), 0U); |
| 241 | 230 |
| 242 // Get the windows for this machine from the node and check that they were | 231 // Get the windows for this machine from the node and check that they were |
| 243 // filled. | 232 // filled. |
| 244 sync_api::ReadTransaction trans(sync_service_-> | 233 sync_api::ReadTransaction trans(sync_service_-> |
| 245 backend()->GetUserShareHandle()); | 234 backend()->GetUserShareHandle()); |
| 246 sync_api::ReadNode node(&trans); | 235 sync_api::ReadNode node(&trans); |
| 247 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, | 236 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, |
| 248 machine_tag)); | 237 machine_tag)); |
| 249 model_associator_->AppendForeignSessionWithID(sync_id, | 238 model_associator_->AppendForeignSessionWithID(sync_id, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 navigation->set_title("title"); | 291 navigation->set_title("title"); |
| 303 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED); | 292 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED); |
| 304 | 293 |
| 305 // Update the server with the session specifics. | 294 // Update the server with the session specifics. |
| 306 { | 295 { |
| 307 sync_api::WriteTransaction trans(sync_service_-> | 296 sync_api::WriteTransaction trans(sync_service_-> |
| 308 backend()->GetUserShareHandle()); | 297 backend()->GetUserShareHandle()); |
| 309 sync_api::ReadNode root(&trans); | 298 sync_api::ReadNode root(&trans); |
| 310 ASSERT_TRUE(root.InitByTagLookup(kSessionsTag)); | 299 ASSERT_TRUE(root.InitByTagLookup(kSessionsTag)); |
| 311 model_associator_->UpdateSyncModel(&specifics, &trans, &root); | 300 model_associator_->UpdateSyncModel(&specifics, &trans, &root); |
| 301 model_associator_->UpdateFromSyncModel(&trans); |
| 312 } | 302 } |
| 313 | 303 |
| 314 // Check that the foreign session was written to a node and retrieve the data. | 304 // Check that the foreign session was written to a node and retrieve the data. |
| 315 int64 sync_id; | 305 int64 sync_id; |
| 316 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, | 306 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, |
| 317 &sync_id)); | 307 &sync_id)); |
| 318 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id); | 308 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id); |
| 319 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics( | 309 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics( |
| 320 model_associator_->GetChromeNodeFromSyncId(sync_id)); | 310 model_associator_->GetChromeNodeFromSyncId(sync_id)); |
| 321 ASSERT_TRUE(sync_specifics != NULL); | 311 ASSERT_TRUE(sync_specifics != NULL); |
| 322 ScopedVector<ForeignSession> foreign_sessions; | 312 ScopedVector<ForeignSession> foreign_sessions; |
| 323 model_associator_->GetSessionDataFromSyncModel(&foreign_sessions.get()); | 313 model_associator_->GetSessionData(&foreign_sessions.get()); |
| 324 ASSERT_EQ(foreign_sessions.size(), 1U); | 314 ASSERT_EQ(1U, foreign_sessions.size()); |
| 325 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); | 315 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); |
| 326 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs.size()); | 316 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs.size()); |
| 327 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs[0]->navigations.size()); | 317 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs[0]->navigations.size()); |
| 328 ASSERT_EQ(foreign_sessions[0]->foreign_tession_tag, machine_tag); | 318 ASSERT_EQ(foreign_sessions[0]->foreign_tession_tag, machine_tag); |
| 329 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->selected_tab_index); | 319 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->selected_tab_index); |
| 330 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->type); | 320 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->type); |
| 331 ASSERT_EQ(13, foreign_sessions[0]->windows[0]->tabs[0]->tab_visual_index); | 321 ASSERT_EQ(13, foreign_sessions[0]->windows[0]->tabs[0]->tab_visual_index); |
| 332 ASSERT_EQ(3, | 322 ASSERT_EQ(3, |
| 333 foreign_sessions[0]->windows[0]->tabs[0]->current_navigation_index); | 323 foreign_sessions[0]->windows[0]->tabs[0]->current_navigation_index); |
| 334 ASSERT_TRUE(foreign_sessions[0]->windows[0]->tabs[0]->pinned); | 324 ASSERT_TRUE(foreign_sessions[0]->windows[0]->tabs[0]->pinned); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 357 // Test the DataTypeController on update. | 347 // Test the DataTypeController on update. |
| 358 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { | 348 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { |
| 359 CreateRootTask task(this); | 349 CreateRootTask task(this); |
| 360 ASSERT_TRUE(StartSyncService(&task, false)); | 350 ASSERT_TRUE(StartSyncService(&task, false)); |
| 361 ASSERT_TRUE(task.success()); | 351 ASSERT_TRUE(task.success()); |
| 362 int64 node_id = model_associator_->GetSyncIdFromChromeId( | 352 int64 node_id = model_associator_->GetSyncIdFromChromeId( |
| 363 model_associator_->GetCurrentMachineTag()); | 353 model_associator_->GetCurrentMachineTag()); |
| 364 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | 354 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 365 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; | 355 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; |
| 366 record->id = node_id; | 356 record->id = node_id; |
| 367 ASSERT_EQ(notification_sync_id_, 0); | |
| 368 ASSERT_FALSE(notified_of_update_); | 357 ASSERT_FALSE(notified_of_update_); |
| 369 { | 358 { |
| 370 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 359 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); |
| 371 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 360 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 372 } | 361 } |
| 373 ASSERT_EQ(notification_sync_id_, node_id); | |
| 374 ASSERT_TRUE(notified_of_update_); | 362 ASSERT_TRUE(notified_of_update_); |
| 375 } | 363 } |
| 376 | 364 |
| 377 // Test the DataTypeController on add. | 365 // Test the DataTypeController on add. |
| 378 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { | 366 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { |
| 379 CreateRootTask task(this); | 367 CreateRootTask task(this); |
| 380 ASSERT_TRUE(StartSyncService(&task, false)); | 368 ASSERT_TRUE(StartSyncService(&task, false)); |
| 381 ASSERT_TRUE(task.success()); | 369 ASSERT_TRUE(task.success()); |
| 382 | 370 |
| 383 int64 node_id = model_associator_->GetSyncIdFromChromeId( | 371 int64 node_id = model_associator_->GetSyncIdFromChromeId( |
| 384 model_associator_->GetCurrentMachineTag()); | 372 model_associator_->GetCurrentMachineTag()); |
| 385 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | 373 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 386 record->action = SyncManager::ChangeRecord::ACTION_ADD; | 374 record->action = SyncManager::ChangeRecord::ACTION_ADD; |
| 387 record->id = node_id; | 375 record->id = node_id; |
| 388 ASSERT_EQ(notification_sync_id_, 0); | |
| 389 ASSERT_FALSE(notified_of_update_); | 376 ASSERT_FALSE(notified_of_update_); |
| 390 { | 377 { |
| 391 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 378 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); |
| 392 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 379 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 393 } | 380 } |
| 394 ASSERT_EQ(notification_sync_id_, node_id); | |
| 395 ASSERT_TRUE(notified_of_update_); | 381 ASSERT_TRUE(notified_of_update_); |
| 396 } | 382 } |
| 397 | 383 |
| 398 // Test the DataTypeController on delete. | 384 // Test the DataTypeController on delete. |
| 399 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { | 385 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { |
| 400 CreateRootTask task(this); | 386 CreateRootTask task(this); |
| 401 ASSERT_TRUE(StartSyncService(&task, false)); | 387 ASSERT_TRUE(StartSyncService(&task, false)); |
| 402 ASSERT_TRUE(task.success()); | 388 ASSERT_TRUE(task.success()); |
| 403 | 389 |
| 404 int64 node_id = model_associator_->GetSyncIdFromChromeId( | 390 int64 node_id = model_associator_->GetSyncIdFromChromeId( |
| 405 model_associator_->GetCurrentMachineTag()); | 391 model_associator_->GetCurrentMachineTag()); |
| 406 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | 392 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 407 record->action = SyncManager::ChangeRecord::ACTION_DELETE; | 393 record->action = SyncManager::ChangeRecord::ACTION_DELETE; |
| 408 record->id = node_id; | 394 record->id = node_id; |
| 409 ASSERT_EQ(notification_sync_id_, 0); | |
| 410 ASSERT_FALSE(notified_of_update_); | 395 ASSERT_FALSE(notified_of_update_); |
| 411 { | 396 { |
| 412 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 397 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); |
| 413 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 398 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 414 } | 399 } |
| 415 ASSERT_EQ(notification_sync_id_, -1); | |
| 416 ASSERT_TRUE(notified_of_update_); | 400 ASSERT_TRUE(notified_of_update_); |
| 417 } | 401 } |
| 418 | 402 |
| 419 } // namespace browser_sync | 403 } // namespace browser_sync |
| 420 | 404 |
| OLD | NEW |