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 "chrome/browser/sync/sync_setup_wizard.h" | 5 #include "chrome/browser/sync/sync_setup_wizard.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 user_chose_data_types_ = false; | 139 user_chose_data_types_ = false; |
140 keep_everything_synced_ = false; | 140 keep_everything_synced_ = false; |
141 chosen_data_types_.clear(); | 141 chosen_data_types_.clear(); |
142 } | 142 } |
143 | 143 |
144 // Use this to have the service act as if it were running under CrOS. | 144 // Use this to have the service act as if it were running under CrOS. |
145 void set_cros_mode() { | 145 void set_cros_mode() { |
146 cros_user_ = kTestUser; | 146 cros_user_ = kTestUser; |
147 } | 147 } |
148 | 148 |
| 149 virtual void ShowSyncSetup(const std::string& sub_page) { |
| 150 // Do Nothing. |
| 151 } |
| 152 |
| 153 void ClearObservers() { |
| 154 observers_.Clear(); |
| 155 } |
| 156 |
| 157 SyncSetupWizard* GetWizard() { |
| 158 return &wizard_; |
| 159 } |
| 160 |
149 std::string username_; | 161 std::string username_; |
150 std::string password_; | 162 std::string password_; |
151 std::string captcha_; | 163 std::string captcha_; |
152 bool user_cancelled_dialog_; | 164 bool user_cancelled_dialog_; |
153 bool user_chose_data_types_; | 165 bool user_chose_data_types_; |
154 bool keep_everything_synced_; | 166 bool keep_everything_synced_; |
155 bool is_using_secondary_passphrase_; | 167 bool is_using_secondary_passphrase_; |
156 bool encrypt_everything_; | 168 bool encrypt_everything_; |
157 syncable::ModelTypeSet chosen_data_types_; | 169 syncable::ModelTypeSet chosen_data_types_; |
158 | |
159 std::string passphrase_; | 170 std::string passphrase_; |
160 | 171 |
161 private: | 172 private: |
162 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); | 173 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); |
163 }; | 174 }; |
164 | 175 |
165 class TestingProfileWithSyncService : public TestingProfile { | 176 class TestingProfileWithSyncService : public TestingProfile { |
166 public: | 177 public: |
167 TestingProfileWithSyncService() { | 178 TestingProfileWithSyncService() { |
168 sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this)); | 179 sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this)); |
(...skipping 19 matching lines...) Expand all Loading... |
188 virtual void SetUp() { | 199 virtual void SetUp() { |
189 set_profile(new TestingProfileWithSyncService()); | 200 set_profile(new TestingProfileWithSyncService()); |
190 profile()->CreateBookmarkModel(false); | 201 profile()->CreateBookmarkModel(false); |
191 // Wait for the bookmarks model to load. | 202 // Wait for the bookmarks model to load. |
192 profile()->BlockUntilBookmarkModelLoaded(); | 203 profile()->BlockUntilBookmarkModelLoaded(); |
193 set_browser(new Browser(Browser::TYPE_TABBED, profile())); | 204 set_browser(new Browser(Browser::TYPE_TABBED, profile())); |
194 browser()->set_window(window()); | 205 browser()->set_window(window()); |
195 BrowserList::SetLastActive(browser()); | 206 BrowserList::SetLastActive(browser()); |
196 service_ = static_cast<ProfileSyncServiceForWizardTest*>( | 207 service_ = static_cast<ProfileSyncServiceForWizardTest*>( |
197 profile()->GetProfileSyncService()); | 208 profile()->GetProfileSyncService()); |
198 wizard_.reset(new SyncSetupWizard(service_)); | 209 wizard_ = service_->GetWizard(); |
199 } | 210 } |
200 | 211 |
201 virtual void TearDown() { | 212 virtual void TearDown() { |
202 wizard_.reset(); | 213 wizard_ = NULL; |
203 service_ = NULL; | 214 service_ = NULL; |
204 flow_ = NULL; | 215 flow_ = NULL; |
205 } | 216 } |
206 | 217 |
207 protected: | 218 protected: |
208 void AttachSyncSetupHandler() { | 219 void AttachSyncSetupHandler() { |
209 flow_ = wizard_->AttachSyncSetupHandler(&handler_); | 220 flow_ = wizard_->AttachSyncSetupHandler(&handler_); |
210 } | 221 } |
211 | 222 |
212 void CompleteSetup() { | 223 void CompleteSetup() { |
213 // For a discrete run, we need to have ran through setup once. | 224 // For a discrete run, we need to have ran through setup once. |
214 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 225 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
215 AttachSyncSetupHandler(); | 226 AttachSyncSetupHandler(); |
216 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 227 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
217 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING); | 228 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING); |
218 wizard_->Step(SyncSetupWizard::SETTING_UP); | 229 wizard_->Step(SyncSetupWizard::SETTING_UP); |
219 wizard_->Step(SyncSetupWizard::DONE); | 230 wizard_->Step(SyncSetupWizard::DONE); |
220 } | 231 } |
221 | 232 |
222 void CloseSetupUI() { | 233 void CloseSetupUI() { |
223 handler_.CloseSetupUI(); | 234 handler_.CloseSetupUI(); |
224 } | 235 } |
225 | 236 |
226 scoped_ptr<SyncSetupWizard> wizard_; | 237 // This pointer is owned by the |Service_|. |
| 238 SyncSetupWizard* wizard_; |
227 ProfileSyncServiceForWizardTest* service_; | 239 ProfileSyncServiceForWizardTest* service_; |
228 SyncSetupFlow* flow_; | 240 SyncSetupFlow* flow_; |
229 MockSyncSetupHandler handler_; | 241 MockSyncSetupHandler handler_; |
230 }; | 242 }; |
231 | 243 |
232 TEST_F(SyncSetupWizardTest, InitialStepLogin) { | 244 TEST_F(SyncSetupWizardTest, InitialStepLogin) { |
233 ListValue credentials; | 245 ListValue credentials; |
234 std::string auth = "{\"user\":\""; | 246 std::string auth = "{\"user\":\""; |
235 auth += std::string(kTestUser) + "\",\"pass\":\""; | 247 auth += std::string(kTestUser) + "\",\"pass\":\""; |
236 auth += std::string(kTestPassword) + "\",\"captcha\":\""; | 248 auth += std::string(kTestPassword) + "\",\"captcha\":\""; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::PASSWORDS)); | 342 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::PASSWORDS)); |
331 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::AUTOFILL)); | 343 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::AUTOFILL)); |
332 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::EXTENSIONS)); | 344 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::EXTENSIONS)); |
333 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::TYPED_URLS)); | 345 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::TYPED_URLS)); |
334 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::APPS)); | 346 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::APPS)); |
335 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::SEARCH_ENGINES)); | 347 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::SEARCH_ENGINES)); |
336 EXPECT_EQ(0U, service_->chosen_data_types_.count( | 348 EXPECT_EQ(0U, service_->chosen_data_types_.count( |
337 syncable::APP_NOTIFICATIONS)); | 349 syncable::APP_NOTIFICATIONS)); |
338 } | 350 } |
339 | 351 |
| 352 TEST_F(SyncSetupWizardTest, ShowErrorUIForPasswordTest) { |
| 353 service_->ClearObservers(); |
| 354 CompleteSetup(); |
| 355 |
| 356 // Simulate an auth error and make sure the start and end state are set |
| 357 // right. |
| 358 service_->set_last_auth_error( |
| 359 AuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
| 360 service_->ShowErrorUI(); |
| 361 AttachSyncSetupHandler(); |
| 362 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); |
| 363 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, flow_->end_state_); |
| 364 ASSERT_TRUE(wizard_->IsVisible()); |
| 365 |
| 366 // Make sure the wizard is dismissed. |
| 367 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
| 368 ASSERT_FALSE(wizard_->IsVisible()); |
| 369 } |
| 370 |
| 371 TEST_F(SyncSetupWizardTest, ShowErrorUIForPassphraseTest) { |
| 372 service_->ClearObservers(); |
| 373 CompleteSetup(); |
| 374 |
| 375 // Simulate a passphrase error and make sure the start and end state are set |
| 376 // right and wizard is shown. |
| 377 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION); |
| 378 service_->set_is_using_secondary_passphrase(true); |
| 379 service_->ShowErrorUI(); |
| 380 AttachSyncSetupHandler(); |
| 381 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE, flow_->current_state_); |
| 382 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); |
| 383 ASSERT_TRUE(wizard_->IsVisible()); |
| 384 |
| 385 // Make sure the wizard is dismissed. |
| 386 wizard_->Step(SyncSetupWizard::DONE); |
| 387 ASSERT_FALSE(wizard_->IsVisible()); |
| 388 } |
| 389 |
340 TEST_F(SyncSetupWizardTest, EnterPassphraseRequired) { | 390 TEST_F(SyncSetupWizardTest, EnterPassphraseRequired) { |
341 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 391 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
342 AttachSyncSetupHandler(); | 392 AttachSyncSetupHandler(); |
343 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 393 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
344 wizard_->Step(SyncSetupWizard::CONFIGURE); | 394 wizard_->Step(SyncSetupWizard::CONFIGURE); |
345 wizard_->Step(SyncSetupWizard::SETTING_UP); | 395 wizard_->Step(SyncSetupWizard::SETTING_UP); |
346 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION); | 396 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION); |
347 wizard_->Step(SyncSetupWizard::ENTER_PASSPHRASE); | 397 wizard_->Step(SyncSetupWizard::ENTER_PASSPHRASE); |
348 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE, flow_->current_state_); | 398 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE, flow_->current_state_); |
349 | 399 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 609 |
560 service_->set_last_auth_error( | 610 service_->set_last_auth_error( |
561 AuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | 611 AuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
562 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR); | 612 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR); |
563 AttachSyncSetupHandler(); | 613 AttachSyncSetupHandler(); |
564 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); | 614 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); |
565 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); | 615 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); |
566 CloseSetupUI(); | 616 CloseSetupUI(); |
567 EXPECT_FALSE(wizard_->IsVisible()); | 617 EXPECT_FALSE(wizard_->IsVisible()); |
568 } | 618 } |
OLD | NEW |