| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 sync_service_->set_num_expected_resumes(will_fail_association ? 0 : 1); | 116 sync_service_->set_num_expected_resumes(will_fail_association ? 0 : 1); |
| 117 sync_service_->RegisterDataTypeController( | 117 sync_service_->RegisterDataTypeController( |
| 118 new SessionDataTypeController(&factory_, sync_service_.get())); | 118 new SessionDataTypeController(&factory_, sync_service_.get())); |
| 119 profile()->GetTokenService()->IssueAuthTokenForTest( | 119 profile()->GetTokenService()->IssueAuthTokenForTest( |
| 120 GaiaConstants::kSyncService, "token"); | 120 GaiaConstants::kSyncService, "token"); |
| 121 sync_service_->Initialize(); | 121 sync_service_->Initialize(); |
| 122 MessageLoop::current()->Run(); | 122 MessageLoop::current()->Run(); |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 SyncBackendHost* backend() { return sync_service_->backend(); } | |
| 127 | |
| 128 // Path used in testing. | 126 // Path used in testing. |
| 129 ScopedTempDir temp_dir_; | 127 ScopedTempDir temp_dir_; |
| 130 SessionServiceTestHelper helper_; | 128 SessionServiceTestHelper helper_; |
| 131 SessionModelAssociator* model_associator_; | 129 SessionModelAssociator* model_associator_; |
| 132 SessionChangeProcessor* change_processor_; | 130 SessionChangeProcessor* change_processor_; |
| 133 SessionID window_id_; | 131 SessionID window_id_; |
| 134 ProfileSyncFactoryMock factory_; | 132 ProfileSyncFactoryMock factory_; |
| 135 scoped_ptr<TestProfileSyncService> sync_service_; | 133 scoped_ptr<TestProfileSyncService> sync_service_; |
| 136 const gfx::Rect window_bounds_; | 134 const gfx::Rect window_bounds_; |
| 137 bool notified_of_update_; | 135 bool notified_of_update_; |
| 138 NotificationRegistrar registrar_; | 136 NotificationRegistrar registrar_; |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 class CreateRootTask : public Task { | 139 class CreateRootTask : public Task { |
| 142 public: | 140 public: |
| 143 explicit CreateRootTask(ProfileSyncServiceSessionTest* test) | 141 explicit CreateRootTask(ProfileSyncServiceSessionTest* test) |
| 144 : test_(test), success_(false) { | 142 : test_(test), success_(false) { |
| 145 } | 143 } |
| 146 | 144 |
| 147 virtual ~CreateRootTask() {} | 145 virtual ~CreateRootTask() {} |
| 148 virtual void Run() { | 146 virtual void Run() { |
| 149 success_ = ProfileSyncServiceTestHelper::CreateRoot(syncable::SESSIONS, | 147 success_ = ProfileSyncServiceTestHelper::CreateRoot( |
| 150 test_->sync_service(), test_->ids()); | 148 syncable::SESSIONS, |
| 149 test_->sync_service()->GetUserShare(), |
| 150 test_->ids()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool success() { return success_; } | 153 bool success() { return success_; } |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 ProfileSyncServiceSessionTest* test_; | 156 ProfileSyncServiceSessionTest* test_; |
| 157 bool success_; | 157 bool success_; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 // Test that we can write this machine's session to a node and retrieve it. | 160 // Test that we can write this machine's session to a node and retrieve it. |
| 161 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { | 161 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { |
| 162 CreateRootTask task(this); | 162 CreateRootTask task(this); |
| 163 ASSERT_TRUE(StartSyncService(&task, false)); | 163 ASSERT_TRUE(StartSyncService(&task, false)); |
| 164 ASSERT_TRUE(task.success()); | 164 ASSERT_TRUE(task.success()); |
| 165 ASSERT_EQ(model_associator_->GetSessionService(), helper_.service()); | 165 ASSERT_EQ(model_associator_->GetSessionService(), helper_.service()); |
| 166 | 166 |
| 167 // Check that the DataTypeController associated the models. | 167 // Check that the DataTypeController associated the models. |
| 168 bool has_nodes; | 168 bool has_nodes; |
| 169 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); | 169 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); |
| 170 ASSERT_TRUE(has_nodes); | 170 ASSERT_TRUE(has_nodes); |
| 171 std::string machine_tag = model_associator_->GetCurrentMachineTag(); | 171 std::string machine_tag = model_associator_->GetCurrentMachineTag(); |
| 172 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag); | 172 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag); |
| 173 ASSERT_NE(sync_api::kInvalidId, sync_id); | 173 ASSERT_NE(sync_api::kInvalidId, sync_id); |
| 174 | 174 |
| 175 // Check that we can get the correct session specifics back from the node. | 175 // Check that we can get the correct session specifics back from the node. |
| 176 sync_api::ReadTransaction trans(sync_service_-> | 176 sync_api::ReadTransaction trans(sync_service_->GetUserShare()); |
| 177 backend()->GetUserShareHandle()); | |
| 178 sync_api::ReadNode node(&trans); | 177 sync_api::ReadNode node(&trans); |
| 179 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, | 178 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, |
| 180 machine_tag)); | 179 machine_tag)); |
| 181 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics()); | 180 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics()); |
| 182 ASSERT_EQ(machine_tag, specifics.session_tag()); | 181 ASSERT_EQ(machine_tag, specifics.session_tag()); |
| 183 ASSERT_TRUE(specifics.has_header()); | 182 ASSERT_TRUE(specifics.has_header()); |
| 184 const sync_pb::SessionHeader& header_s = specifics.header(); | 183 const sync_pb::SessionHeader& header_s = specifics.header(); |
| 185 ASSERT_EQ(0, header_s.window_size()); | 184 ASSERT_EQ(0, header_s.window_size()); |
| 186 } | 185 } |
| 187 | 186 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 CreateRootTask task(this); | 312 CreateRootTask task(this); |
| 314 ASSERT_TRUE(StartSyncService(&task, false)); | 313 ASSERT_TRUE(StartSyncService(&task, false)); |
| 315 ASSERT_TRUE(task.success()); | 314 ASSERT_TRUE(task.success()); |
| 316 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 315 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
| 317 model_associator_->GetCurrentMachineTag()); | 316 model_associator_->GetCurrentMachineTag()); |
| 318 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | 317 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 319 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; | 318 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; |
| 320 record->id = node_id; | 319 record->id = node_id; |
| 321 ASSERT_FALSE(notified_of_update_); | 320 ASSERT_FALSE(notified_of_update_); |
| 322 { | 321 { |
| 323 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 322 sync_api::WriteTransaction trans(sync_service_->GetUserShare()); |
| 324 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 323 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 325 } | 324 } |
| 326 ASSERT_TRUE(notified_of_update_); | 325 ASSERT_TRUE(notified_of_update_); |
| 327 } | 326 } |
| 328 | 327 |
| 329 // Test the DataTypeController on add. | 328 // Test the DataTypeController on add. |
| 330 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { | 329 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { |
| 331 CreateRootTask task(this); | 330 CreateRootTask task(this); |
| 332 ASSERT_TRUE(StartSyncService(&task, false)); | 331 ASSERT_TRUE(StartSyncService(&task, false)); |
| 333 ASSERT_TRUE(task.success()); | 332 ASSERT_TRUE(task.success()); |
| 334 | 333 |
| 335 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 334 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
| 336 model_associator_->GetCurrentMachineTag()); | 335 model_associator_->GetCurrentMachineTag()); |
| 337 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | 336 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 338 record->action = SyncManager::ChangeRecord::ACTION_ADD; | 337 record->action = SyncManager::ChangeRecord::ACTION_ADD; |
| 339 record->id = node_id; | 338 record->id = node_id; |
| 340 ASSERT_FALSE(notified_of_update_); | 339 ASSERT_FALSE(notified_of_update_); |
| 341 { | 340 { |
| 342 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 341 sync_api::WriteTransaction trans(sync_service_->GetUserShare()); |
| 343 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 342 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 344 } | 343 } |
| 345 ASSERT_TRUE(notified_of_update_); | 344 ASSERT_TRUE(notified_of_update_); |
| 346 } | 345 } |
| 347 | 346 |
| 348 // Test the DataTypeController on delete. | 347 // Test the DataTypeController on delete. |
| 349 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { | 348 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { |
| 350 CreateRootTask task(this); | 349 CreateRootTask task(this); |
| 351 ASSERT_TRUE(StartSyncService(&task, false)); | 350 ASSERT_TRUE(StartSyncService(&task, false)); |
| 352 ASSERT_TRUE(task.success()); | 351 ASSERT_TRUE(task.success()); |
| 353 | 352 |
| 354 int64 node_id = model_associator_->GetSyncIdFromSessionTag( | 353 int64 node_id = model_associator_->GetSyncIdFromSessionTag( |
| 355 model_associator_->GetCurrentMachineTag()); | 354 model_associator_->GetCurrentMachineTag()); |
| 356 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); | 355 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 357 record->action = SyncManager::ChangeRecord::ACTION_DELETE; | 356 record->action = SyncManager::ChangeRecord::ACTION_DELETE; |
| 358 record->id = node_id; | 357 record->id = node_id; |
| 359 ASSERT_FALSE(notified_of_update_); | 358 ASSERT_FALSE(notified_of_update_); |
| 360 { | 359 { |
| 361 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 360 sync_api::WriteTransaction trans(sync_service_->GetUserShare()); |
| 362 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 361 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 363 } | 362 } |
| 364 ASSERT_TRUE(notified_of_update_); | 363 ASSERT_TRUE(notified_of_update_); |
| 365 } | 364 } |
| 366 // Test the TabNodePool when it starts off empty. | 365 // Test the TabNodePool when it starts off empty. |
| 367 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) { | 366 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) { |
| 368 CreateRootTask task(this); | 367 CreateRootTask task(this); |
| 369 ASSERT_TRUE(StartSyncService(&task, false)); | 368 ASSERT_TRUE(StartSyncService(&task, false)); |
| 370 ASSERT_TRUE(task.success()); | 369 ASSERT_TRUE(task.success()); |
| 371 | 370 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 ASSERT_FALSE(model_associator_->tab_pool_.full()); | 415 ASSERT_FALSE(model_associator_->tab_pool_.full()); |
| 417 for (size_t i = 0; i < num_ids; ++i) { | 416 for (size_t i = 0; i < num_ids; ++i) { |
| 418 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); | 417 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); |
| 419 } | 418 } |
| 420 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); | 419 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); |
| 421 ASSERT_FALSE(model_associator_->tab_pool_.empty()); | 420 ASSERT_FALSE(model_associator_->tab_pool_.empty()); |
| 422 ASSERT_TRUE(model_associator_->tab_pool_.full()); | 421 ASSERT_TRUE(model_associator_->tab_pool_.full()); |
| 423 } | 422 } |
| 424 | 423 |
| 425 } // namespace browser_sync | 424 } // namespace browser_sync |
| OLD | NEW |