| 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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "base/tracked.h" | 13 #include "base/tracked.h" |
| 14 #include "chrome/browser/sessions/session_service_factory.h" | 14 #include "chrome/browser/sessions/session_service_factory.h" |
| 15 #include "chrome/browser/sessions/session_service.h" | 15 #include "chrome/browser/sessions/session_service.h" |
| 16 #include "chrome/browser/sessions/session_service_test_helper.h" | 16 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 17 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 17 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 18 #include "chrome/browser/sync/glue/session_change_processor.h" | 18 #include "chrome/browser/sync/glue/session_change_processor.h" |
| 19 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 19 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 20 #include "chrome/browser/sync/glue/session_model_associator.h" | 20 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 21 #include "chrome/browser/sync/glue/sync_backend_host.h" | 21 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 22 #include "chrome/browser/sync/internal_api/change_record.h" |
| 22 #include "chrome/browser/sync/internal_api/read_node.h" | 23 #include "chrome/browser/sync/internal_api/read_node.h" |
| 23 #include "chrome/browser/sync/internal_api/read_transaction.h" | 24 #include "chrome/browser/sync/internal_api/read_transaction.h" |
| 24 #include "chrome/browser/sync/internal_api/sync_manager.h" | |
| 25 #include "chrome/browser/sync/internal_api/write_transaction.h" | 25 #include "chrome/browser/sync/internal_api/write_transaction.h" |
| 26 #include "chrome/browser/sync/profile_sync_factory_mock.h" | 26 #include "chrome/browser/sync/profile_sync_factory_mock.h" |
| 27 #include "chrome/browser/sync/profile_sync_test_util.h" | 27 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 28 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 28 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
| 29 #include "chrome/browser/sync/protocol/sync.pb.h" | 29 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 30 #include "chrome/browser/sync/syncable/directory_manager.h" | 30 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 31 #include "chrome/browser/sync/syncable/model_type.h" | 31 #include "chrome/browser/sync/syncable/model_type.h" |
| 32 #include "chrome/browser/sync/syncable/syncable.h" | 32 #include "chrome/browser/sync/syncable/syncable.h" |
| 33 #include "chrome/browser/sync/test_profile_sync_service.h" | 33 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 34 #include "chrome/browser/sync/test/engine/test_id_factory.h" | 34 #include "chrome/browser/sync/test/engine/test_id_factory.h" |
| 35 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 36 #include "chrome/common/net/gaia/gaia_constants.h" | 36 #include "chrome/common/net/gaia/gaia_constants.h" |
| 37 #include "chrome/test/base/browser_with_test_window_test.h" | 37 #include "chrome/test/base/browser_with_test_window_test.h" |
| 38 #include "chrome/test/base/profile_mock.h" | 38 #include "chrome/test/base/profile_mock.h" |
| 39 #include "chrome/test/base/testing_profile.h" | 39 #include "chrome/test/base/testing_profile.h" |
| 40 #include "content/browser/browser_thread.h" | 40 #include "content/browser/browser_thread.h" |
| 41 #include "content/common/notification_observer.h" | 41 #include "content/common/notification_observer.h" |
| 42 #include "content/common/notification_registrar.h" | 42 #include "content/common/notification_registrar.h" |
| 43 #include "content/common/notification_service.h" | 43 #include "content/common/notification_service.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 44 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| 46 #include "ui/base/ui_base_types.h" | 46 #include "ui/base/ui_base_types.h" |
| 47 | 47 |
| 48 using browser_sync::SessionChangeProcessor; | 48 using browser_sync::SessionChangeProcessor; |
| 49 using browser_sync::SessionDataTypeController; | 49 using browser_sync::SessionDataTypeController; |
| 50 using browser_sync::SessionModelAssociator; | 50 using browser_sync::SessionModelAssociator; |
| 51 using browser_sync::SyncBackendHost; | 51 using browser_sync::SyncBackendHost; |
| 52 using sync_api::SyncManager; | 52 using sync_api::ChangeRecord; |
| 53 using testing::_; | 53 using testing::_; |
| 54 using testing::Return; | 54 using testing::Return; |
| 55 using browser_sync::TestIdFactory; | 55 using browser_sync::TestIdFactory; |
| 56 | 56 |
| 57 namespace browser_sync { | 57 namespace browser_sync { |
| 58 | 58 |
| 59 class ProfileSyncServiceSessionTest | 59 class ProfileSyncServiceSessionTest |
| 60 : public BrowserWithTestWindowTest, | 60 : public BrowserWithTestWindowTest, |
| 61 public NotificationObserver { | 61 public NotificationObserver { |
| 62 public: | 62 public: |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url()); | 348 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 // Test the DataTypeController on update. | 351 // Test the DataTypeController on update. |
| 352 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { | 352 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { |
| 353 CreateRootTask task(this); | 353 CreateRootTask task(this); |
| 354 ASSERT_TRUE(StartSyncService(&task, false)); | 354 ASSERT_TRUE(StartSyncService(&task, false)); |
| 355 ASSERT_TRUE(task.success()); | 355 ASSERT_TRUE(task.success()); |
| 356 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 356 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
| 357 model_associator_->GetCurrentMachineTag()); | 357 model_associator_->GetCurrentMachineTag()); |
| 358 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | |
| 359 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; | |
| 360 record->id = node_id; | |
| 361 ASSERT_FALSE(notified_of_update_); | 358 ASSERT_FALSE(notified_of_update_); |
| 362 { | 359 { |
| 363 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 360 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 364 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 361 change_processor_->ApplyChangesFromSyncModel( |
| 362 &trans, |
| 363 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( |
| 364 node_id, ChangeRecord::ACTION_UPDATE)); |
| 365 } | 365 } |
| 366 ASSERT_TRUE(notified_of_update_); | 366 ASSERT_TRUE(notified_of_update_); |
| 367 } | 367 } |
| 368 | 368 |
| 369 // Test the DataTypeController on add. | 369 // Test the DataTypeController on add. |
| 370 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { | 370 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { |
| 371 CreateRootTask task(this); | 371 CreateRootTask task(this); |
| 372 ASSERT_TRUE(StartSyncService(&task, false)); | 372 ASSERT_TRUE(StartSyncService(&task, false)); |
| 373 ASSERT_TRUE(task.success()); | 373 ASSERT_TRUE(task.success()); |
| 374 | 374 |
| 375 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 375 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
| 376 model_associator_->GetCurrentMachineTag()); | 376 model_associator_->GetCurrentMachineTag()); |
| 377 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | |
| 378 record->action = SyncManager::ChangeRecord::ACTION_ADD; | |
| 379 record->id = node_id; | |
| 380 ASSERT_FALSE(notified_of_update_); | 377 ASSERT_FALSE(notified_of_update_); |
| 381 { | 378 { |
| 382 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 379 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 383 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 380 change_processor_->ApplyChangesFromSyncModel( |
| 381 &trans, |
| 382 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( |
| 383 node_id, ChangeRecord::ACTION_ADD)); |
| 384 } | 384 } |
| 385 ASSERT_TRUE(notified_of_update_); | 385 ASSERT_TRUE(notified_of_update_); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // Test the DataTypeController on delete. | 388 // Test the DataTypeController on delete. |
| 389 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { | 389 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { |
| 390 CreateRootTask task(this); | 390 CreateRootTask task(this); |
| 391 ASSERT_TRUE(StartSyncService(&task, false)); | 391 ASSERT_TRUE(StartSyncService(&task, false)); |
| 392 ASSERT_TRUE(task.success()); | 392 ASSERT_TRUE(task.success()); |
| 393 | 393 |
| 394 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 394 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
| 395 model_associator_->GetCurrentMachineTag()); | 395 model_associator_->GetCurrentMachineTag()); |
| 396 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | |
| 397 record->action = SyncManager::ChangeRecord::ACTION_DELETE; | |
| 398 record->id = node_id; | |
| 399 ASSERT_FALSE(notified_of_update_); | 396 ASSERT_FALSE(notified_of_update_); |
| 400 { | 397 { |
| 401 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 398 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 402 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 399 change_processor_->ApplyChangesFromSyncModel( |
| 400 &trans, |
| 401 ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList( |
| 402 node_id, ChangeRecord::ACTION_DELETE)); |
| 403 } | 403 } |
| 404 ASSERT_TRUE(notified_of_update_); | 404 ASSERT_TRUE(notified_of_update_); |
| 405 } | 405 } |
| 406 // Test the TabNodePool when it starts off empty. | 406 // Test the TabNodePool when it starts off empty. |
| 407 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) { | 407 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) { |
| 408 CreateRootTask task(this); | 408 CreateRootTask task(this); |
| 409 ASSERT_TRUE(StartSyncService(&task, false)); | 409 ASSERT_TRUE(StartSyncService(&task, false)); |
| 410 ASSERT_TRUE(task.success()); | 410 ASSERT_TRUE(task.success()); |
| 411 | 411 |
| 412 std::vector<int64> node_ids; | 412 std::vector<int64> node_ids; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 ASSERT_FALSE(model_associator_->tab_pool_.full()); | 456 ASSERT_FALSE(model_associator_->tab_pool_.full()); |
| 457 for (size_t i = 0; i < num_ids; ++i) { | 457 for (size_t i = 0; i < num_ids; ++i) { |
| 458 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); | 458 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); |
| 459 } | 459 } |
| 460 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); | 460 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); |
| 461 ASSERT_FALSE(model_associator_->tab_pool_.empty()); | 461 ASSERT_FALSE(model_associator_->tab_pool_.empty()); |
| 462 ASSERT_TRUE(model_associator_->tab_pool_.full()); | 462 ASSERT_TRUE(model_associator_->tab_pool_.full()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 } // namespace browser_sync | 465 } // namespace browser_sync |
| OLD | NEW |