Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/sync/profile_sync_service_session_unittest.cc

Issue 7918001: [Sync] Move ChangeRecord into its own file (change_record.{h,cc}) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 new SessionDataTypeController(&factory_, 148 new SessionDataTypeController(&factory_,
149 profile(), 149 profile(),
150 sync_service_.get())); 150 sync_service_.get()));
151 profile()->GetTokenService()->IssueAuthTokenForTest( 151 profile()->GetTokenService()->IssueAuthTokenForTest(
152 GaiaConstants::kSyncService, "token"); 152 GaiaConstants::kSyncService, "token");
153 sync_service_->Initialize(); 153 sync_service_->Initialize();
154 MessageLoop::current()->Run(); 154 MessageLoop::current()->Run();
155 return true; 155 return true;
156 } 156 }
157 157
158 sync_api::ImmutableChangeRecordList MakeSingletonChangeRecordList(
159 int64 node_id, ChangeRecord::Action action) {
160 ChangeRecord record;
161 record.action = action;
162 record.id = node_id;
163 sync_api::ChangeRecordList records(1, record);
164 return sync_api::ImmutableChangeRecordList(&records);
165 }
166
158 BrowserThread io_thread_; 167 BrowserThread io_thread_;
159 // Path used in testing. 168 // Path used in testing.
160 ScopedTempDir temp_dir_; 169 ScopedTempDir temp_dir_;
161 SessionServiceTestHelper helper_; 170 SessionServiceTestHelper helper_;
162 SessionModelAssociator* model_associator_; 171 SessionModelAssociator* model_associator_;
163 SessionChangeProcessor* change_processor_; 172 SessionChangeProcessor* change_processor_;
164 SessionID window_id_; 173 SessionID window_id_;
165 ProfileSyncFactoryMock factory_; 174 ProfileSyncFactoryMock factory_;
166 scoped_ptr<TestProfileSyncService> sync_service_; 175 scoped_ptr<TestProfileSyncService> sync_service_;
167 const gfx::Rect window_bounds_; 176 const gfx::Rect window_bounds_;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url()); 357 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url());
349 } 358 }
350 359
351 // Test the DataTypeController on update. 360 // Test the DataTypeController on update.
352 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { 361 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) {
353 CreateRootTask task(this); 362 CreateRootTask task(this);
354 ASSERT_TRUE(StartSyncService(&task, false)); 363 ASSERT_TRUE(StartSyncService(&task, false));
355 ASSERT_TRUE(task.success()); 364 ASSERT_TRUE(task.success());
356 int64 node_id = model_associator_->GetSyncIdFromSessionTag( 365 int64 node_id = model_associator_->GetSyncIdFromSessionTag(
357 model_associator_->GetCurrentMachineTag()); 366 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_); 367 ASSERT_FALSE(notified_of_update_);
362 { 368 {
363 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 369 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
364 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 370 change_processor_->ApplyChangesFromSyncModel(
371 &trans,
372 MakeSingletonChangeRecordList(node_id, ChangeRecord::ACTION_UPDATE));
365 } 373 }
366 ASSERT_TRUE(notified_of_update_); 374 ASSERT_TRUE(notified_of_update_);
367 } 375 }
368 376
369 // Test the DataTypeController on add. 377 // Test the DataTypeController on add.
370 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { 378 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) {
371 CreateRootTask task(this); 379 CreateRootTask task(this);
372 ASSERT_TRUE(StartSyncService(&task, false)); 380 ASSERT_TRUE(StartSyncService(&task, false));
373 ASSERT_TRUE(task.success()); 381 ASSERT_TRUE(task.success());
374 382
375 int64 node_id = model_associator_->GetSyncIdFromSessionTag( 383 int64 node_id = model_associator_->GetSyncIdFromSessionTag(
376 model_associator_->GetCurrentMachineTag()); 384 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_); 385 ASSERT_FALSE(notified_of_update_);
381 { 386 {
382 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 387 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
383 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 388 change_processor_->ApplyChangesFromSyncModel(
389 &trans,
390 MakeSingletonChangeRecordList(node_id, ChangeRecord::ACTION_ADD));
384 } 391 }
385 ASSERT_TRUE(notified_of_update_); 392 ASSERT_TRUE(notified_of_update_);
386 } 393 }
387 394
388 // Test the DataTypeController on delete. 395 // Test the DataTypeController on delete.
389 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { 396 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) {
390 CreateRootTask task(this); 397 CreateRootTask task(this);
391 ASSERT_TRUE(StartSyncService(&task, false)); 398 ASSERT_TRUE(StartSyncService(&task, false));
392 ASSERT_TRUE(task.success()); 399 ASSERT_TRUE(task.success());
393 400
394 int64 node_id = model_associator_->GetSyncIdFromSessionTag( 401 int64 node_id = model_associator_->GetSyncIdFromSessionTag(
395 model_associator_->GetCurrentMachineTag()); 402 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_); 403 ASSERT_FALSE(notified_of_update_);
400 { 404 {
401 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 405 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
402 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 406 change_processor_->ApplyChangesFromSyncModel(
407 &trans,
408 MakeSingletonChangeRecordList(node_id, ChangeRecord::ACTION_DELETE));
403 } 409 }
404 ASSERT_TRUE(notified_of_update_); 410 ASSERT_TRUE(notified_of_update_);
405 } 411 }
406 // Test the TabNodePool when it starts off empty. 412 // Test the TabNodePool when it starts off empty.
407 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) { 413 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) {
408 CreateRootTask task(this); 414 CreateRootTask task(this);
409 ASSERT_TRUE(StartSyncService(&task, false)); 415 ASSERT_TRUE(StartSyncService(&task, false));
410 ASSERT_TRUE(task.success()); 416 ASSERT_TRUE(task.success());
411 417
412 std::vector<int64> node_ids; 418 std::vector<int64> node_ids;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 ASSERT_FALSE(model_associator_->tab_pool_.full()); 462 ASSERT_FALSE(model_associator_->tab_pool_.full());
457 for (size_t i = 0; i < num_ids; ++i) { 463 for (size_t i = 0; i < num_ids; ++i) {
458 model_associator_->tab_pool_.FreeTabNode(node_ids[i]); 464 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
459 } 465 }
460 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity()); 466 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
461 ASSERT_FALSE(model_associator_->tab_pool_.empty()); 467 ASSERT_FALSE(model_associator_->tab_pool_.empty());
462 ASSERT_TRUE(model_associator_->tab_pool_.full()); 468 ASSERT_TRUE(model_associator_->tab_pool_.full());
463 } 469 }
464 470
465 } // namespace browser_sync 471 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698