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

Side by Side Diff: chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc

Issue 408003002: [Sync] Fix namespace for sync_driver component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/tracked_objects.h" 10 #include "base/tracked_objects.h"
(...skipping 22 matching lines...) Expand all
33 public: 33 public:
34 SyncSearchEngineDataTypeControllerTest() : test_util_(&profile_) { } 34 SyncSearchEngineDataTypeControllerTest() : test_util_(&profile_) { }
35 35
36 virtual void SetUp() { 36 virtual void SetUp() {
37 service_.reset(new ProfileSyncServiceMock(&profile_)); 37 service_.reset(new ProfileSyncServiceMock(&profile_));
38 profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock()); 38 profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock());
39 // Feed the DTC the profile so it is reused later. 39 // Feed the DTC the profile so it is reused later.
40 // This allows us to control the associated TemplateURLService. 40 // This allows us to control the associated TemplateURLService.
41 search_engine_dtc_ = new SearchEngineDataTypeController( 41 search_engine_dtc_ = new SearchEngineDataTypeController(
42 profile_sync_factory_.get(), &profile_, 42 profile_sync_factory_.get(), &profile_,
43 DataTypeController::DisableTypeCallback()); 43 sync_driver::DataTypeController::DisableTypeCallback());
44 } 44 }
45 45
46 virtual void TearDown() { 46 virtual void TearDown() {
47 // Must be done before we pump the loop. 47 // Must be done before we pump the loop.
48 syncable_service_.StopSyncing(syncer::SEARCH_ENGINES); 48 syncable_service_.StopSyncing(syncer::SEARCH_ENGINES);
49 search_engine_dtc_ = NULL; 49 search_engine_dtc_ = NULL;
50 service_.reset(); 50 service_.reset();
51 } 51 }
52 52
53 protected: 53 protected:
54 // Pre-emptively get the TURL Service and make sure it is loaded. 54 // Pre-emptively get the TURL Service and make sure it is loaded.
55 void PreloadTemplateURLService() { 55 void PreloadTemplateURLService() {
56 test_util_.VerifyLoad(); 56 test_util_.VerifyLoad();
57 } 57 }
58 58
59 void SetStartExpectations() { 59 void SetStartExpectations() {
60 search_engine_dtc_->SetGenericChangeProcessorFactoryForTest( 60 search_engine_dtc_->SetGenericChangeProcessorFactoryForTest(
61 make_scoped_ptr<GenericChangeProcessorFactory>( 61 make_scoped_ptr<sync_driver::GenericChangeProcessorFactory>(
62 new FakeGenericChangeProcessorFactory(make_scoped_ptr( 62 new sync_driver::FakeGenericChangeProcessorFactory(
63 new FakeGenericChangeProcessor(profile_sync_factory_.get()))))); 63 make_scoped_ptr(new sync_driver::FakeGenericChangeProcessor(
64 profile_sync_factory_.get())))));
64 EXPECT_CALL(model_load_callback_, Run(_, _)); 65 EXPECT_CALL(model_load_callback_, Run(_, _));
65 EXPECT_CALL(*profile_sync_factory_, 66 EXPECT_CALL(*profile_sync_factory_,
66 GetSyncableServiceForType(syncer::SEARCH_ENGINES)). 67 GetSyncableServiceForType(syncer::SEARCH_ENGINES)).
67 WillOnce(Return(syncable_service_.AsWeakPtr())); 68 WillOnce(Return(syncable_service_.AsWeakPtr()));
68 } 69 }
69 70
70 void Start() { 71 void Start() {
71 search_engine_dtc_->LoadModels( 72 search_engine_dtc_->LoadModels(
72 base::Bind(&ModelLoadCallbackMock::Run, 73 base::Bind(&sync_driver::ModelLoadCallbackMock::Run,
73 base::Unretained(&model_load_callback_))); 74 base::Unretained(&model_load_callback_)));
74 search_engine_dtc_->StartAssociating( 75 search_engine_dtc_->StartAssociating(
75 base::Bind(&StartCallbackMock::Run, 76 base::Bind(&sync_driver::StartCallbackMock::Run,
76 base::Unretained(&start_callback_))); 77 base::Unretained(&start_callback_)));
77 } 78 }
78 79
79 content::TestBrowserThreadBundle thread_bundle_; 80 content::TestBrowserThreadBundle thread_bundle_;
80 TestingProfile profile_; 81 TestingProfile profile_;
81 TemplateURLServiceFactoryTestUtil test_util_; 82 TemplateURLServiceFactoryTestUtil test_util_;
82 scoped_refptr<SearchEngineDataTypeController> search_engine_dtc_; 83 scoped_refptr<SearchEngineDataTypeController> search_engine_dtc_;
83 scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_; 84 scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_;
84 scoped_ptr<ProfileSyncServiceMock> service_; 85 scoped_ptr<ProfileSyncServiceMock> service_;
85 syncer::FakeSyncableService syncable_service_; 86 syncer::FakeSyncableService syncable_service_;
86 StartCallbackMock start_callback_; 87 sync_driver::StartCallbackMock start_callback_;
87 ModelLoadCallbackMock model_load_callback_; 88 sync_driver::ModelLoadCallbackMock model_load_callback_;
88 }; 89 };
89 90
90 TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceReady) { 91 TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceReady) {
91 SetStartExpectations(); 92 SetStartExpectations();
92 // We want to start ready. 93 // We want to start ready.
93 PreloadTemplateURLService(); 94 PreloadTemplateURLService();
94 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _)); 95 EXPECT_CALL(start_callback_, Run(sync_driver::DataTypeController::OK, _, _));
95 96
96 EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); 97 EXPECT_EQ(sync_driver::DataTypeController::NOT_RUNNING,
98 search_engine_dtc_->state());
97 EXPECT_FALSE(syncable_service_.syncing()); 99 EXPECT_FALSE(syncable_service_.syncing());
98 Start(); 100 Start();
99 EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state()); 101 EXPECT_EQ(sync_driver::DataTypeController::RUNNING,
102 search_engine_dtc_->state());
100 EXPECT_TRUE(syncable_service_.syncing()); 103 EXPECT_TRUE(syncable_service_.syncing());
101 } 104 }
102 105
103 TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceNotReady) { 106 TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceNotReady) {
104 EXPECT_CALL(model_load_callback_, Run(_, _)); 107 EXPECT_CALL(model_load_callback_, Run(_, _));
105 EXPECT_FALSE(syncable_service_.syncing()); 108 EXPECT_FALSE(syncable_service_.syncing());
106 search_engine_dtc_->LoadModels( 109 search_engine_dtc_->LoadModels(
107 base::Bind(&ModelLoadCallbackMock::Run, 110 base::Bind(&sync_driver::ModelLoadCallbackMock::Run,
108 base::Unretained(&model_load_callback_))); 111 base::Unretained(&model_load_callback_)));
109 EXPECT_TRUE(search_engine_dtc_->GetSubscriptionForTesting()); 112 EXPECT_TRUE(search_engine_dtc_->GetSubscriptionForTesting());
110 EXPECT_EQ(DataTypeController::MODEL_STARTING, search_engine_dtc_->state()); 113 EXPECT_EQ(sync_driver::DataTypeController::MODEL_STARTING,
114 search_engine_dtc_->state());
111 EXPECT_FALSE(syncable_service_.syncing()); 115 EXPECT_FALSE(syncable_service_.syncing());
112 116
113 // Send the notification that the TemplateURLService has started. 117 // Send the notification that the TemplateURLService has started.
114 PreloadTemplateURLService(); 118 PreloadTemplateURLService();
115 EXPECT_EQ(NULL, search_engine_dtc_->GetSubscriptionForTesting()); 119 EXPECT_EQ(NULL, search_engine_dtc_->GetSubscriptionForTesting());
116 EXPECT_EQ(DataTypeController::MODEL_LOADED, search_engine_dtc_->state()); 120 EXPECT_EQ(sync_driver::DataTypeController::MODEL_LOADED,
121 search_engine_dtc_->state());
117 122
118 // Wait until WebDB is loaded before we shut it down. 123 // Wait until WebDB is loaded before we shut it down.
119 base::RunLoop().RunUntilIdle(); 124 base::RunLoop().RunUntilIdle();
120 } 125 }
121 126
122 TEST_F(SyncSearchEngineDataTypeControllerTest, StartAssociationFailed) { 127 TEST_F(SyncSearchEngineDataTypeControllerTest, StartAssociationFailed) {
123 SetStartExpectations(); 128 SetStartExpectations();
124 PreloadTemplateURLService(); 129 PreloadTemplateURLService();
125 EXPECT_CALL(start_callback_, 130 EXPECT_CALL(start_callback_,
126 Run(DataTypeController::ASSOCIATION_FAILED, _, _)); 131 Run(sync_driver::DataTypeController::ASSOCIATION_FAILED, _, _));
127 syncable_service_.set_merge_data_and_start_syncing_error( 132 syncable_service_.set_merge_data_and_start_syncing_error(
128 syncer::SyncError(FROM_HERE, 133 syncer::SyncError(FROM_HERE,
129 syncer::SyncError::DATATYPE_ERROR, 134 syncer::SyncError::DATATYPE_ERROR,
130 "Error", 135 "Error",
131 syncer::SEARCH_ENGINES)); 136 syncer::SEARCH_ENGINES));
132 137
133 Start(); 138 Start();
134 EXPECT_EQ(DataTypeController::DISABLED, search_engine_dtc_->state()); 139 EXPECT_EQ(sync_driver::DataTypeController::DISABLED,
140 search_engine_dtc_->state());
135 EXPECT_FALSE(syncable_service_.syncing()); 141 EXPECT_FALSE(syncable_service_.syncing());
136 search_engine_dtc_->Stop(); 142 search_engine_dtc_->Stop();
137 EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); 143 EXPECT_EQ(sync_driver::DataTypeController::NOT_RUNNING,
144 search_engine_dtc_->state());
138 EXPECT_FALSE(syncable_service_.syncing()); 145 EXPECT_FALSE(syncable_service_.syncing());
139 } 146 }
140 147
141 TEST_F(SyncSearchEngineDataTypeControllerTest, Stop) { 148 TEST_F(SyncSearchEngineDataTypeControllerTest, Stop) {
142 SetStartExpectations(); 149 SetStartExpectations();
143 PreloadTemplateURLService(); 150 PreloadTemplateURLService();
144 EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _, _)); 151 EXPECT_CALL(start_callback_, Run(sync_driver::DataTypeController::OK, _, _));
145 152
146 EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); 153 EXPECT_EQ(sync_driver::DataTypeController::NOT_RUNNING,
154 search_engine_dtc_->state());
147 EXPECT_FALSE(syncable_service_.syncing()); 155 EXPECT_FALSE(syncable_service_.syncing());
148 Start(); 156 Start();
149 EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state()); 157 EXPECT_EQ(sync_driver::DataTypeController::RUNNING,
158 search_engine_dtc_->state());
150 EXPECT_TRUE(syncable_service_.syncing()); 159 EXPECT_TRUE(syncable_service_.syncing());
151 search_engine_dtc_->Stop(); 160 search_engine_dtc_->Stop();
152 EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); 161 EXPECT_EQ(sync_driver::DataTypeController::NOT_RUNNING,
162 search_engine_dtc_->state());
153 EXPECT_FALSE(syncable_service_.syncing()); 163 EXPECT_FALSE(syncable_service_.syncing());
154 } 164 }
155 165
156 TEST_F(SyncSearchEngineDataTypeControllerTest, StopBeforeLoaded) { 166 TEST_F(SyncSearchEngineDataTypeControllerTest, StopBeforeLoaded) {
157 EXPECT_CALL(model_load_callback_, Run(_, _)); 167 EXPECT_CALL(model_load_callback_, Run(_, _));
158 EXPECT_FALSE(syncable_service_.syncing()); 168 EXPECT_FALSE(syncable_service_.syncing());
159 search_engine_dtc_->LoadModels( 169 search_engine_dtc_->LoadModels(
160 base::Bind(&ModelLoadCallbackMock::Run, 170 base::Bind(&sync_driver::ModelLoadCallbackMock::Run,
161 base::Unretained(&model_load_callback_))); 171 base::Unretained(&model_load_callback_)));
162 EXPECT_TRUE(search_engine_dtc_->GetSubscriptionForTesting()); 172 EXPECT_TRUE(search_engine_dtc_->GetSubscriptionForTesting());
163 EXPECT_EQ(DataTypeController::MODEL_STARTING, search_engine_dtc_->state()); 173 EXPECT_EQ(sync_driver::DataTypeController::MODEL_STARTING,
174 search_engine_dtc_->state());
164 EXPECT_FALSE(syncable_service_.syncing()); 175 EXPECT_FALSE(syncable_service_.syncing());
165 search_engine_dtc_->Stop(); 176 search_engine_dtc_->Stop();
166 EXPECT_EQ(NULL, search_engine_dtc_->GetSubscriptionForTesting()); 177 EXPECT_EQ(NULL, search_engine_dtc_->GetSubscriptionForTesting());
167 EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); 178 EXPECT_EQ(sync_driver::DataTypeController::NOT_RUNNING,
179 search_engine_dtc_->state());
168 EXPECT_FALSE(syncable_service_.syncing()); 180 EXPECT_FALSE(syncable_service_.syncing());
169 } 181 }
170 182
171 } // namespace 183 } // namespace
172 } // namespace browser_sync 184 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/search_engine_data_type_controller.cc ('k') | chrome/browser/sync/glue/sync_backend_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698