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

Side by Side Diff: chrome/browser/sync/test_profile_sync_service.h

Issue 6249006: Turn password sync on by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 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 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "chrome/browser/sync/engine/syncapi.h" 12 #include "chrome/browser/sync/engine/syncapi.h"
13 #include "chrome/browser/sync/profile_sync_factory.h" 13 #include "chrome/browser/sync/profile_sync_factory.h"
14 #include "chrome/browser/sync/profile_sync_service.h" 14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "chrome/browser/sync/glue/data_type_controller.h" 15 #include "chrome/browser/sync/glue/data_type_controller.h"
16 #include "chrome/browser/sync/glue/data_type_manager_impl.h" 16 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
17 #include "chrome/browser/sync/glue/sync_backend_host.h" 17 #include "chrome/browser/sync/glue/sync_backend_host.h"
18 #include "chrome/browser/sync/sessions/session_state.h" 18 #include "chrome/browser/sync/sessions/session_state.h"
19 #include "chrome/browser/sync/syncable/directory_manager.h" 19 #include "chrome/browser/sync/syncable/directory_manager.h"
20 #include "chrome/browser/sync/syncable/syncable.h" 20 #include "chrome/browser/sync/syncable/syncable.h"
21 #include "chrome/test/profile_mock.h" 21 #include "chrome/test/profile_mock.h"
22 #include "chrome/test/sync/test_http_bridge_factory.h" 22 #include "chrome/test/sync/test_http_bridge_factory.h"
23 #include "chrome/test/sync/engine/test_id_factory.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 25
25 class Profile; 26 class Profile;
27 class TestProfileSyncService;
26 28
27 using browser_sync::ModelSafeRoutingInfo; 29 using browser_sync::ModelSafeRoutingInfo;
28 using browser_sync::sessions::ErrorCounters; 30 using browser_sync::sessions::ErrorCounters;
29 using browser_sync::sessions::SyncerStatus; 31 using browser_sync::sessions::SyncerStatus;
30 using browser_sync::sessions::SyncSessionSnapshot; 32 using browser_sync::sessions::SyncSessionSnapshot;
31 using sync_api::UserShare; 33 using sync_api::UserShare;
32 using syncable::DirectoryManager; 34 using syncable::DirectoryManager;
33 using syncable::ModelType; 35 using syncable::ModelType;
34 using syncable::ScopedDirLookup; 36 using syncable::ScopedDirLookup;
35 37
(...skipping 17 matching lines...) Expand all
53 // download. 55 // download.
54 class SyncBackendHostForProfileSyncTest : public SyncBackendHost { 56 class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
55 public: 57 public:
56 // |initial_condition_setup_task| can be used to populate nodes before the 58 // |initial_condition_setup_task| can be used to populate nodes before the
57 // OnBackendInitialized callback fires. 59 // OnBackendInitialized callback fires.
58 // |set_initial_sync_ended_on_init| determines whether we pretend that a full 60 // |set_initial_sync_ended_on_init| determines whether we pretend that a full
59 // initial download has occurred and set bits for enabled data types. If 61 // initial download has occurred and set bits for enabled data types. If
60 // this is false, configuring data types will require a syncer nudge. 62 // this is false, configuring data types will require a syncer nudge.
61 // |synchronous_init| causes initialization to block until the syncapi has 63 // |synchronous_init| causes initialization to block until the syncapi has
62 // completed setting itself up and called us back. 64 // completed setting itself up and called us back.
63 SyncBackendHostForProfileSyncTest(SyncFrontend* frontend, 65 SyncBackendHostForProfileSyncTest(
66 TestProfileSyncService* service,
64 Profile* profile, 67 Profile* profile,
65 const FilePath& profile_path, 68 const FilePath& profile_path,
66 const DataTypeController::TypeMap& data_type_controllers, 69 const DataTypeController::TypeMap& data_type_controllers,
67 Task* initial_condition_setup_task, 70 Task* initial_condition_setup_task,
68 int num_expected_resumes, 71 int num_expected_resumes,
69 int num_expected_pauses, 72 int num_expected_pauses,
70 bool set_initial_sync_ended_on_init, 73 bool set_initial_sync_ended_on_init,
71 bool synchronous_init) 74 bool synchronous_init);
72 : browser_sync::SyncBackendHost(frontend, profile, profile_path,
73 data_type_controllers),
74 initial_condition_setup_task_(initial_condition_setup_task),
75 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init),
76 synchronous_init_(synchronous_init) {
77 // By default, the RequestPause and RequestResume methods will
78 // send the confirmation notification and return true.
79 ON_CALL(*this, RequestPause()).
80 WillByDefault(testing::DoAll(CallOnPaused(core_),
81 testing::Return(true)));
82 ON_CALL(*this, RequestResume()).
83 WillByDefault(testing::DoAll(CallOnResumed(core_),
84 testing::Return(true)));
85 ON_CALL(*this, RequestNudge()).WillByDefault(testing::Invoke(this,
86 &SyncBackendHostForProfileSyncTest::
87 SimulateSyncCycleCompletedInitialSyncEnded));
88
89 EXPECT_CALL(*this, RequestPause()).Times(num_expected_pauses);
90 EXPECT_CALL(*this, RequestResume()).Times(num_expected_resumes);
91 EXPECT_CALL(*this, RequestNudge()).
92 Times(set_initial_sync_ended_on_init ? 0 : 1);
93 }
94 75
95 MOCK_METHOD0(RequestPause, bool()); 76 MOCK_METHOD0(RequestPause, bool());
96 MOCK_METHOD0(RequestResume, bool()); 77 MOCK_METHOD0(RequestResume, bool());
97 MOCK_METHOD0(RequestNudge, void()); 78 MOCK_METHOD0(RequestNudge, void());
98 79
99 void SetInitialSyncEndedForEnabledTypes() { 80 void SetInitialSyncEndedForEnabledTypes() {
100 UserShare* user_share = core_->syncapi()->GetUserShare(); 81 UserShare* user_share = core_->syncapi()->GetUserShare();
101 DirectoryManager* dir_manager = user_share->dir_manager.get(); 82 DirectoryManager* dir_manager = user_share->dir_manager.get();
102 83
103 ScopedDirLookup dir(dir_manager, user_share->name); 84 ScopedDirLookup dir(dir_manager, user_share->name);
104 if (!dir.good()) 85 if (!dir.good())
105 FAIL(); 86 FAIL();
106 87
107 ModelSafeRoutingInfo enabled_types; 88 ModelSafeRoutingInfo enabled_types;
108 GetModelSafeRoutingInfo(&enabled_types); 89 GetModelSafeRoutingInfo(&enabled_types);
109 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); 90 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
110 i != enabled_types.end(); ++i) { 91 i != enabled_types.end(); ++i) {
111 dir->set_initial_sync_ended_for_type(i->first, true); 92 dir->set_initial_sync_ended_for_type(i->first, true);
112 } 93 }
113 } 94 }
114 95
115 virtual void ConfigureDataTypes(const syncable::ModelTypeSet& types, 96 virtual void ConfigureDataTypes(const syncable::ModelTypeSet& types,
116 CancelableTask* ready_task) { 97 CancelableTask* ready_task) {
117 SetAutofillMigrationState(syncable::MIGRATED); 98 SetAutofillMigrationState(syncable::MIGRATED);
118 SyncBackendHost::ConfigureDataTypes(types, ready_task); 99 SyncBackendHost::ConfigureDataTypes(types, ready_task);
119 } 100 }
120 101
121 virtual void HandleInitializationCompletedOnFrontendLoop() {
122 set_syncapi_initialized(); // Need to do this asap so task below works.
123
124 // Set up any nodes the test wants around before model association.
125 if (initial_condition_setup_task_) {
126 initial_condition_setup_task_->Run();
127 }
128
129 // Pretend we downloaded initial updates and set initial sync ended bits
130 // if we were asked to.
131 if (set_initial_sync_ended_on_init_)
132 SetInitialSyncEndedForEnabledTypes();
133
134 SyncBackendHost::HandleInitializationCompletedOnFrontendLoop();
135 }
136
137 // Called when a nudge comes in. 102 // Called when a nudge comes in.
138 void SimulateSyncCycleCompletedInitialSyncEnded() { 103 void SimulateSyncCycleCompletedInitialSyncEnded() {
139 syncable::ModelTypeBitSet sync_ended; 104 syncable::ModelTypeBitSet sync_ended;
140 ModelSafeRoutingInfo enabled_types; 105 ModelSafeRoutingInfo enabled_types;
141 GetModelSafeRoutingInfo(&enabled_types); 106 GetModelSafeRoutingInfo(&enabled_types);
142 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; 107 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT];
143 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); 108 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
144 i != enabled_types.end(); ++i) { 109 i != enabled_types.end(); ++i) {
145 sync_ended.set(i->first); 110 sync_ended.set(i->first);
146 } 111 }
147 core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot( 112 core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot(
148 SyncerStatus(), ErrorCounters(), 0, false, 113 SyncerStatus(), ErrorCounters(), 0, false,
149 sync_ended, download_progress_markers, false, false, 0, 0, false)); 114 sync_ended, download_progress_markers, false, false, 0, 0, false));
150 } 115 }
151 116
117 virtual void HandleInitializationCompletedOnFrontendLoop();
118
152 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( 119 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory(
153 URLRequestContextGetter* getter) { 120 URLRequestContextGetter* getter) {
154 return new browser_sync::TestHttpBridgeFactory; 121 return new browser_sync::TestHttpBridgeFactory;
155 } 122 }
156 123
157 virtual void InitCore(const Core::DoInitializeOptions& options) { 124 virtual void InitCore(const Core::DoInitializeOptions& options) {
158 std::wstring user = L"testuser"; 125 std::wstring user = L"testuser";
159 core_loop()->PostTask(FROM_HERE, 126 core_loop()->PostTask(FROM_HERE,
160 NewRunnableMethod(core_.get(), 127 NewRunnableMethod(core_.get(),
161 &SyncBackendHost::Core::DoInitializeForTest, 128 &SyncBackendHost::Core::DoInitializeForTest,
(...skipping 16 matching lines...) Expand all
178 145
179 static void SetHistoryServiceExpectations(ProfileMock* profile) { 146 static void SetHistoryServiceExpectations(ProfileMock* profile) {
180 EXPECT_CALL(*profile, GetHistoryService(testing::_)). 147 EXPECT_CALL(*profile, GetHistoryService(testing::_)).
181 WillOnce(testing::Return((HistoryService*)NULL)); 148 WillOnce(testing::Return((HistoryService*)NULL));
182 } 149 }
183 150
184 private: 151 private:
185 Task* initial_condition_setup_task_; 152 Task* initial_condition_setup_task_;
186 bool set_initial_sync_ended_on_init_; 153 bool set_initial_sync_ended_on_init_;
187 bool synchronous_init_; 154 bool synchronous_init_;
155 TestProfileSyncService* test_service_;
188 }; 156 };
189 157
190 } // namespace browser_sync 158 } // namespace browser_sync
191 159
192 class TestProfileSyncService : public ProfileSyncService { 160 class TestProfileSyncService : public ProfileSyncService {
193 public: 161 public:
194 TestProfileSyncService(ProfileSyncFactory* factory, 162 TestProfileSyncService(ProfileSyncFactory* factory,
195 Profile* profile, 163 Profile* profile,
196 const std::string& test_user, 164 const std::string& test_user,
197 bool synchronous_backend_initialization, 165 bool synchronous_backend_initialization,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void set_num_expected_pauses(int num) { 213 void set_num_expected_pauses(int num) {
246 num_expected_pauses_ = num; 214 num_expected_pauses_ = num;
247 } 215 }
248 void dont_set_initial_sync_ended_on_init() { 216 void dont_set_initial_sync_ended_on_init() {
249 set_initial_sync_ended_on_init_ = false; 217 set_initial_sync_ended_on_init_ = false;
250 } 218 }
251 void set_synchronous_sync_configuration() { 219 void set_synchronous_sync_configuration() {
252 synchronous_sync_configuration_ = true; 220 synchronous_sync_configuration_ = true;
253 } 221 }
254 222
223 browser_sync::TestIdFactory* id_factory() { return &id_factory_; }
224
255 private: 225 private:
256 // When testing under ChromiumOS, this method must not return an empty 226 // When testing under ChromiumOS, this method must not return an empty
257 // value value in order for the profile sync service to start. 227 // value value in order for the profile sync service to start.
258 virtual std::string GetLsidForAuthBootstraping() { 228 virtual std::string GetLsidForAuthBootstraping() {
259 return "foo"; 229 return "foo";
260 } 230 }
261 231
262 bool synchronous_backend_initialization_; 232 bool synchronous_backend_initialization_;
263 233
264 // Set to true when a mock data type manager is being used and the configure 234 // Set to true when a mock data type manager is being used and the configure
265 // step is performed synchronously. 235 // step is performed synchronously.
266 bool synchronous_sync_configuration_; 236 bool synchronous_sync_configuration_;
267 bool set_expect_resume_expectations_; 237 bool set_expect_resume_expectations_;
268 int num_expected_resumes_; 238 int num_expected_resumes_;
269 int num_expected_pauses_; 239 int num_expected_pauses_;
270 240
271 scoped_ptr<Task> initial_condition_setup_task_; 241 scoped_ptr<Task> initial_condition_setup_task_;
272 bool set_initial_sync_ended_on_init_; 242 bool set_initial_sync_ended_on_init_;
243 browser_sync::TestIdFactory id_factory_;
273 }; 244 };
274 245
246
247
275 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ 248 #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_test_util.h ('k') | chrome/browser/sync/test_profile_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698