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

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

Issue 9295044: Start moving signin code out of browser/sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up unnecessary inclusions of signin_manager.h Created 8 years, 10 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 "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"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/prefs/pref_service_mock_builder.h" 12 #include "chrome/browser/prefs/pref_service_mock_builder.h"
13 #include "chrome/browser/prefs/testing_pref_store.h" 13 #include "chrome/browser/prefs/testing_pref_store.h"
14 #include "chrome/browser/signin/signin_manager_fake.h" 14 #include "chrome/browser/signin/signin_manager_fake.h"
15 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 15 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h" 17 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/browser/sync/sync_setup_flow.h" 18 #include "chrome/browser/sync/sync_setup_flow.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 20 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
21 #include "chrome/browser/ui/webui/options/options_sync_setup_handler.h" 22 #include "chrome/browser/ui/webui/options/options_sync_setup_handler.h"
22 #include "chrome/common/net/gaia/google_service_auth_error.h" 23 #include "chrome/common/net/gaia/google_service_auth_error.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/browser_with_test_window_test.h" 25 #include "chrome/test/base/browser_with_test_window_test.h"
25 #include "chrome/test/base/test_browser_window.h" 26 #include "chrome/test/base/test_browser_window.h"
26 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 static const char kTestUser[] = "chrome.p13n.test@gmail.com"; 30 static const char kTestUser[] = "chrome.p13n.test@gmail.com";
30 static const char kTestPassword[] = "passwd"; 31 static const char kTestPassword[] = "passwd";
31 static const char kTestCaptcha[] = "pizzamyheart"; 32 static const char kTestCaptcha[] = "pizzamyheart";
32 static const char kTestCaptchaUrl[] = "http://pizzamyheart/"; 33 static const char kTestCaptchaUrl[] = "http://pizzamyheart/";
33 34
34 typedef GoogleServiceAuthError AuthError; 35 typedef GoogleServiceAuthError AuthError;
35 36
36 class MockSyncSetupHandler : public OptionsSyncSetupHandler { 37 class MockSyncSetupHandler : public OptionsSyncSetupHandler {
37 public: 38 public:
38 MockSyncSetupHandler() : OptionsSyncSetupHandler(NULL) {} 39 MockSyncSetupHandler()
40 : OptionsSyncSetupHandler(NULL),
41 login_ui_(new LoginUIService(NULL)) {}
39 42
40 // SyncSetupFlowHandler implementation. 43 // SyncSetupFlowHandler implementation.
41 virtual void ShowGaiaLogin(const DictionaryValue& args) OVERRIDE {} 44 virtual void ShowFatalError() OVERRIDE {
42 virtual void ShowGaiaSuccessAndClose() OVERRIDE { 45 ShowSetupDone(string16());
43 flow()->OnDialogClosed("");
44 } 46 }
45 virtual void ShowGaiaSuccessAndSettingUp() OVERRIDE {}
46 virtual void ShowConfigure(const DictionaryValue& args) OVERRIDE {} 47 virtual void ShowConfigure(const DictionaryValue& args) OVERRIDE {}
47 virtual void ShowPassphraseEntry(const DictionaryValue& args) OVERRIDE {} 48 virtual void ShowPassphraseEntry(const DictionaryValue& args) OVERRIDE {}
48 virtual void ShowSettingUp() OVERRIDE {} 49 virtual void ShowSettingUp() OVERRIDE {}
49 virtual void ShowSetupDone(const string16& user) OVERRIDE { 50 virtual void ShowSetupDone(const string16& user) OVERRIDE {
50 flow()->OnDialogClosed(""); 51 if (flow())
52 flow()->OnDialogClosed("");
53 }
54
55 SyncSetupFlow* GetFlow() {
56 return flow();
51 } 57 }
52 58
53 void CloseSetupUI() { 59 void CloseSetupUI() {
54 ShowSetupDone(string16()); 60 ShowSetupDone(string16());
55 } 61 }
56 62
63 virtual LoginUIService* GetLoginUIService() const OVERRIDE {
64 return login_ui_.get();
65 }
66
57 private: 67 private:
68 scoped_ptr<LoginUIService> login_ui_;
58 DISALLOW_COPY_AND_ASSIGN(MockSyncSetupHandler); 69 DISALLOW_COPY_AND_ASSIGN(MockSyncSetupHandler);
59 }; 70 };
60 71
61 class SigninManagerMock : public FakeSigninManager { 72 class SigninManagerMock : public FakeSigninManager {
62 public: 73 public:
63 SigninManagerMock() : auth_error_(AuthError::None()) {} 74 SigninManagerMock() : auth_error_(AuthError::None()) {}
64 75
65 virtual void StartSignIn(const std::string& username, 76 virtual void StartSignIn(const std::string& username,
66 const std::string& password, 77 const std::string& password,
67 const std::string& token, 78 const std::string& token,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 203
193 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); 204 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest);
194 }; 205 };
195 206
196 // TODO(jhawkins): Subclass Browser (specifically, ShowOptionsTab) and inject it 207 // TODO(jhawkins): Subclass Browser (specifically, ShowOptionsTab) and inject it
197 // here to test the visibility of the Sync UI. 208 // here to test the visibility of the Sync UI.
198 class SyncSetupWizardTest : public BrowserWithTestWindowTest { 209 class SyncSetupWizardTest : public BrowserWithTestWindowTest {
199 public: 210 public:
200 SyncSetupWizardTest() 211 SyncSetupWizardTest()
201 : wizard_(NULL), 212 : wizard_(NULL),
202 service_(NULL), 213 service_(NULL) {}
203 flow_(NULL) {}
204 virtual ~SyncSetupWizardTest() {} 214 virtual ~SyncSetupWizardTest() {}
205 virtual TestingProfile* BuildProfile() { 215 virtual TestingProfile* BuildProfile() {
206 TestingProfile* profile = new TestingProfile(); 216 TestingProfile* profile = new TestingProfile();
207 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile, 217 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile,
208 ProfileSyncServiceForWizardTest::BuildManual); 218 ProfileSyncServiceForWizardTest::BuildManual);
209 return profile; 219 return profile;
210 } 220 }
211 virtual void SetUp() { 221 virtual void SetUp() {
212 set_profile(BuildProfile()); 222 set_profile(BuildProfile());
213 profile()->CreateBookmarkModel(false); 223 profile()->CreateBookmarkModel(false);
214 // Wait for the bookmarks model to load. 224 // Wait for the bookmarks model to load.
215 profile()->BlockUntilBookmarkModelLoaded(); 225 profile()->BlockUntilBookmarkModelLoaded();
216 PrefService* prefs = profile()->GetPrefs(); 226 PrefService* prefs = profile()->GetPrefs();
217 prefs->SetString(prefs::kGoogleServicesUsername, kTestUser); 227 prefs->SetString(prefs::kGoogleServicesUsername, kTestUser);
218 228
219 set_browser(new Browser(Browser::TYPE_TABBED, profile())); 229 set_browser(new Browser(Browser::TYPE_TABBED, profile()));
220 browser()->SetWindowForTesting(window()); 230 browser()->SetWindowForTesting(window());
221 BrowserList::SetLastActive(browser()); 231 BrowserList::SetLastActive(browser());
222 service_ = static_cast<ProfileSyncServiceForWizardTest*>( 232 service_ = static_cast<ProfileSyncServiceForWizardTest*>(
223 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile())); 233 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()));
224 wizard_ = service_->GetWizard(); 234 wizard_ = service_->GetWizard();
225 } 235 }
226 236
227 virtual void TearDown() { 237 virtual void TearDown() {
228 wizard_ = NULL; 238 wizard_ = NULL;
229 service_ = NULL; 239 service_ = NULL;
230 flow_ = NULL;
231 } 240 }
232 241
233 protected: 242 protected:
234 void AttachSyncSetupHandler() { 243 void AttachSyncSetupHandler() {
235 flow_ = wizard_->AttachSyncSetupHandler(&handler_); 244 wizard_->AttachSyncSetupHandler(&handler_);
236 } 245 }
237 246
238 void CompleteSetup() { 247 void CompleteSetup() {
239 // For a discrete run, we need to have ran through setup once. 248 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING);
240 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
241 AttachSyncSetupHandler(); 249 AttachSyncSetupHandler();
242 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
243 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING);
244 wizard_->Step(SyncSetupWizard::SETTING_UP); 250 wizard_->Step(SyncSetupWizard::SETTING_UP);
245 wizard_->Step(SyncSetupWizard::DONE); 251 wizard_->Step(SyncSetupWizard::DONE);
246 } 252 }
247 253
248 void CloseSetupUI() { 254 void CloseSetupUI() {
249 handler_.CloseSetupUI(); 255 handler_.CloseSetupUI();
250 } 256 }
251 257
252 // This pointer is owned by the |Service_|. 258 // This pointer is owned by the |Service_|.
253 SyncSetupWizard* wizard_; 259 SyncSetupWizard* wizard_;
254 ProfileSyncServiceForWizardTest* service_; 260 ProfileSyncServiceForWizardTest* service_;
255 SyncSetupFlow* flow_;
256 MockSyncSetupHandler handler_; 261 MockSyncSetupHandler handler_;
257 }; 262 };
258 263
259 TEST_F(SyncSetupWizardTest, InitialStepLogin) { 264 TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) {
260 ListValue credentials; 265 wizard_->Step(SyncSetupWizard::CONFIGURE);
261 std::string auth = "{\"user\":\"";
262 auth += std::string(kTestUser) + "\",\"pass\":\"";
263 auth += std::string(kTestPassword) + "\",\"captcha\":\"";
264 auth += std::string(kTestCaptcha) + "\",\"access_code\":\"";
265 auth += std::string() + "\"}";
266 credentials.Append(new StringValue(auth));
267
268 EXPECT_FALSE(wizard_->IsVisible());
269 EXPECT_EQ(static_cast<SyncSetupFlow*>(NULL), flow_);
270 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
271 AttachSyncSetupHandler(); 266 AttachSyncSetupHandler();
272 267
273 EXPECT_TRUE(wizard_->IsVisible());
274 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
275 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_);
276
277 // Simulate the user submitting credentials.
278 handler_.HandleSubmitAuth(&credentials);
279 EXPECT_TRUE(wizard_->IsVisible());
280 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
281 EXPECT_EQ(kTestUser, service_->mock_signin_.username_);
282 EXPECT_EQ(kTestPassword, service_->mock_signin_.password_);
283 EXPECT_EQ(kTestCaptcha, service_->mock_signin_.captcha_);
284 EXPECT_FALSE(service_->user_cancelled_dialog_);
285 service_->ResetTestStats();
286
287 // Simulate failed credentials.
288 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
289 flow_->last_attempted_user_email_ = kTestUser;
290 service_->set_last_auth_error(invalid_gaia);
291 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
292 EXPECT_TRUE(wizard_->IsVisible());
293 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
294 DictionaryValue dialog_args;
295 flow_->GetArgsForGaiaLogin(&dialog_args);
296 EXPECT_EQ(4U, dialog_args.size());
297 std::string actual_user;
298 dialog_args.GetString("user", &actual_user);
299 EXPECT_EQ(kTestUser, actual_user);
300 int error = -1;
301 dialog_args.GetInteger("error", &error);
302 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
303 flow_->last_attempted_user_email_ = kTestUser;
304 service_->set_last_auth_error(AuthError::None());
305
306 // Simulate captcha.
307 AuthError captcha_error(AuthError::FromCaptchaChallenge(
308 std::string(), GURL(kTestCaptchaUrl), GURL()));
309 flow_->last_attempted_user_email_ = kTestUser;
310 service_->set_last_auth_error(captcha_error);
311 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
312 flow_->GetArgsForGaiaLogin(&dialog_args);
313 EXPECT_EQ(4U, dialog_args.size());
314 std::string captcha_url;
315 dialog_args.GetString("captchaUrl", &captcha_url);
316 EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec());
317 error = -1;
318 dialog_args.GetInteger("error", &error);
319 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error);
320 flow_->last_attempted_user_email_ = kTestUser;
321 service_->set_last_auth_error(AuthError::None());
322
323 // Simulate success.
324 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
325 EXPECT_TRUE(wizard_->IsVisible());
326 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING);
327 EXPECT_EQ(SyncSetupWizard::SYNC_EVERYTHING, flow_->current_state_);
328
329 // That's all we're testing here, just move on to DONE. We'll test the
330 // "choose data types" scenarios elsewhere.
331 wizard_->Step(SyncSetupWizard::SETTING_UP); // No merge and sync.
332 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync.
333 EXPECT_FALSE(wizard_->IsVisible());
334 }
335
336 TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) {
337 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
338 AttachSyncSetupHandler();
339 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
340 wizard_->Step(SyncSetupWizard::CONFIGURE);
341
342 ListValue data_type_choices_value; 268 ListValue data_type_choices_value;
343 std::string data_type_choices = 269 std::string data_type_choices =
344 "{\"syncAllDataTypes\":false,\"syncBookmarks\":true," 270 "{\"syncAllDataTypes\":false,\"syncBookmarks\":true,"
345 "\"syncPreferences\":true,\"syncThemes\":false,\"syncPasswords\":false," 271 "\"syncPreferences\":true,\"syncThemes\":false,\"syncPasswords\":false,"
346 "\"syncAutofill\":false,\"syncExtensions\":false,\"syncTypedUrls\":true," 272 "\"syncAutofill\":false,\"syncExtensions\":false,\"syncTypedUrls\":true,"
347 "\"syncApps\":true,\"syncSessions\":false,\"usePassphrase\":false," 273 "\"syncApps\":true,\"syncSessions\":false,\"usePassphrase\":false,"
348 "\"encryptAllData\":false}"; 274 "\"encryptAllData\":false}";
349 data_type_choices_value.Append(new StringValue(data_type_choices)); 275 data_type_choices_value.Append(new StringValue(data_type_choices));
350 276
351 // Simulate the user choosing data types; bookmarks, prefs, typed URLS, and 277 // Simulate the user choosing data types; bookmarks, prefs, typed URLS, and
352 // apps are on, the rest are off. 278 // apps are on, the rest are off.
353 handler_.HandleConfigure(&data_type_choices_value); 279 handler_.HandleConfigure(&data_type_choices_value);
354 // Since we don't need a passphrase, wizard should have transitioned to 280 // Since we don't need a passphrase, wizard should have transitioned to
355 // DONE state and closed the UI. 281 // DONE state and closed the UI.
356 EXPECT_FALSE(wizard_->IsVisible()); 282 EXPECT_FALSE(wizard_->IsVisible());
357 EXPECT_FALSE(service_->keep_everything_synced_); 283 EXPECT_FALSE(service_->keep_everything_synced_);
358 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::BOOKMARKS)); 284 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::BOOKMARKS));
359 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::PREFERENCES)); 285 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::PREFERENCES));
360 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::THEMES)); 286 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::THEMES));
361 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::PASSWORDS)); 287 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::PASSWORDS));
362 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::AUTOFILL)); 288 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::AUTOFILL));
363 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::EXTENSIONS)); 289 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::EXTENSIONS));
364 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::TYPED_URLS)); 290 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::TYPED_URLS));
365 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::APPS)); 291 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::APPS));
366 EXPECT_FALSE(service_->chosen_data_types_.Has( 292 EXPECT_FALSE(service_->chosen_data_types_.Has(
367 syncable::APP_NOTIFICATIONS)); 293 syncable::APP_NOTIFICATIONS));
368 } 294 }
369 295
370 TEST_F(SyncSetupWizardTest, ShowErrorUIForPasswordTest) {
371 service_->ClearObservers();
372 CompleteSetup();
373
374 // Simulate an auth error and make sure the start and end state are set
375 // right.
376 service_->set_last_auth_error(
377 AuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
378 service_->ShowErrorUI();
379 AttachSyncSetupHandler();
380 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
381 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, flow_->end_state_);
382 ASSERT_TRUE(wizard_->IsVisible());
383
384 // Make sure the wizard is dismissed.
385 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
386 ASSERT_FALSE(wizard_->IsVisible());
387 }
388
389 TEST_F(SyncSetupWizardTest, ShowErrorUIForPassphraseTest) { 296 TEST_F(SyncSetupWizardTest, ShowErrorUIForPassphraseTest) {
390 service_->ClearObservers(); 297 service_->ClearObservers();
391 CompleteSetup(); 298 CompleteSetup();
392 299
393 // Simulate a passphrase error and make sure the start and end state are set 300 // Simulate a passphrase error and make sure the start and end state are set
394 // right and wizard is shown. 301 // right and wizard is shown.
395 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION); 302 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION);
396 service_->set_is_using_secondary_passphrase(true); 303 service_->set_is_using_secondary_passphrase(true);
397 service_->ShowErrorUI(); 304 service_->ShowErrorUI();
398 AttachSyncSetupHandler(); 305 AttachSyncSetupHandler();
399 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE, flow_->current_state_); 306 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE,
400 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); 307 handler_.GetFlow()->current_state_);
308 EXPECT_EQ(SyncSetupWizard::DONE, handler_.GetFlow()->end_state_);
401 ASSERT_TRUE(wizard_->IsVisible()); 309 ASSERT_TRUE(wizard_->IsVisible());
402 310
403 // Make sure the wizard is dismissed. 311 // Make sure the wizard is dismissed.
404 wizard_->Step(SyncSetupWizard::DONE); 312 wizard_->Step(SyncSetupWizard::DONE);
405 ASSERT_FALSE(wizard_->IsVisible()); 313 ASSERT_FALSE(wizard_->IsVisible());
406 } 314 }
407 315
408 TEST_F(SyncSetupWizardTest, EnterPassphraseRequired) { 316 TEST_F(SyncSetupWizardTest, EnterPassphraseRequired) {
409 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 317 wizard_->Step(SyncSetupWizard::CONFIGURE);
410 AttachSyncSetupHandler(); 318 AttachSyncSetupHandler();
411 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
412 wizard_->Step(SyncSetupWizard::CONFIGURE);
413 wizard_->Step(SyncSetupWizard::SETTING_UP); 319 wizard_->Step(SyncSetupWizard::SETTING_UP);
414 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION); 320 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION);
415 wizard_->Step(SyncSetupWizard::ENTER_PASSPHRASE); 321 wizard_->Step(SyncSetupWizard::ENTER_PASSPHRASE);
416 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE, flow_->current_state_); 322 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE,
323 handler_.GetFlow()->current_state_);
417 324
418 ListValue value; 325 ListValue value;
419 value.Append(new StringValue("{\"passphrase\":\"myPassphrase\"," 326 value.Append(new StringValue("{\"passphrase\":\"myPassphrase\","
420 "\"mode\":\"gaia\"}")); 327 "\"mode\":\"gaia\"}"));
421 handler_.HandlePassphraseEntry(&value); 328 handler_.HandlePassphraseEntry(&value);
422 EXPECT_EQ("myPassphrase", service_->passphrase_); 329 EXPECT_EQ("myPassphrase", service_->passphrase_);
423 CloseSetupUI(); 330 CloseSetupUI();
424 } 331 }
425 332
426 TEST_F(SyncSetupWizardTest, DialogCancelled) {
427 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
428 AttachSyncSetupHandler();
429 // Simulate the user closing the dialog.
430 CloseSetupUI();
431 EXPECT_FALSE(wizard_->IsVisible());
432 EXPECT_TRUE(service_->user_cancelled_dialog_);
433 EXPECT_EQ(std::string(), service_->mock_signin_.username_);
434 EXPECT_EQ(std::string(), service_->mock_signin_.password_);
435
436 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
437 AttachSyncSetupHandler();
438 EXPECT_TRUE(wizard_->IsVisible());
439 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
440
441 CloseSetupUI();
442 EXPECT_FALSE(wizard_->IsVisible());
443 EXPECT_TRUE(service_->user_cancelled_dialog_);
444 EXPECT_EQ(std::string(), service_->mock_signin_.username_);
445 EXPECT_EQ(std::string(), service_->mock_signin_.password_);
446 }
447
448 TEST_F(SyncSetupWizardTest, InvalidTransitions) { 333 TEST_F(SyncSetupWizardTest, InvalidTransitions) {
449 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
450 EXPECT_FALSE(wizard_->IsVisible());
451
452 wizard_->Step(SyncSetupWizard::DONE); 334 wizard_->Step(SyncSetupWizard::DONE);
453 EXPECT_FALSE(wizard_->IsVisible()); 335 EXPECT_FALSE(wizard_->IsVisible());
454 336
455 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 337 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING);
456 AttachSyncSetupHandler(); 338 AttachSyncSetupHandler();
457 339 EXPECT_EQ(SyncSetupWizard::SYNC_EVERYTHING,
458 wizard_->Step(SyncSetupWizard::DONE); 340 handler_.GetFlow()->current_state_);
459 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); 341 EXPECT_TRUE(wizard_->IsVisible());
460
461 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
462 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING);
463 EXPECT_EQ(SyncSetupWizard::SYNC_EVERYTHING, flow_->current_state_);
464 342
465 wizard_->Step(SyncSetupWizard::FATAL_ERROR); 343 wizard_->Step(SyncSetupWizard::FATAL_ERROR);
466 // Stepping to FATAL_ERROR sends us back to GAIA_LOGIN. 344 // Stepping to FATAL_ERROR leaves us in a FATAL_ERROR state and blows away
467 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); 345 // the SyncSetupFlow.
468 CloseSetupUI(); 346 EXPECT_FALSE(wizard_->IsVisible());
347 EXPECT_TRUE(handler_.GetFlow() == NULL);
469 } 348 }
470 349
471 TEST_F(SyncSetupWizardTest, FullSuccessfulRunSetsPref) { 350 TEST_F(SyncSetupWizardTest, FullSuccessfulRunSetsPref) {
472 CompleteSetup(); 351 CompleteSetup();
473 EXPECT_FALSE(wizard_->IsVisible()); 352 EXPECT_FALSE(wizard_->IsVisible());
474 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean( 353 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean(
475 prefs::kSyncHasSetupCompleted)); 354 prefs::kSyncHasSetupCompleted));
476 } 355 }
477 356
478 TEST_F(SyncSetupWizardTest, AbortedByPendingClear) { 357 TEST_F(SyncSetupWizardTest, AbortedByPendingClear) {
479 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 358 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING);
480 AttachSyncSetupHandler(); 359 AttachSyncSetupHandler();
481 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); 360 EXPECT_TRUE(wizard_->IsVisible());
482 wizard_->Step(SyncSetupWizard::SYNC_EVERYTHING); 361 wizard_->Step(SyncSetupWizard::ABORT);
483 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); 362 // Stepping to ABORT should leave us in ABORT state, and should close the
484 // Stepping to SETUP_ABORTED should redirect us to GAIA_LOGIN state, since 363 // wizard.
485 // that's where we display the error.
486 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
487 CloseSetupUI();
488 EXPECT_FALSE(wizard_->IsVisible()); 364 EXPECT_FALSE(wizard_->IsVisible());
489 } 365 }
490 366
491 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypes) { 367 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypes) {
492 CompleteSetup(); 368 CompleteSetup();
493 369
494 wizard_->Step(SyncSetupWizard::CONFIGURE); 370 wizard_->Step(SyncSetupWizard::CONFIGURE);
495 AttachSyncSetupHandler(); 371 AttachSyncSetupHandler();
496 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); 372 EXPECT_EQ(SyncSetupWizard::DONE, handler_.GetFlow()->end_state_);
497 373
498 wizard_->Step(SyncSetupWizard::SETTING_UP); 374 wizard_->Step(SyncSetupWizard::SETTING_UP);
499 wizard_->Step(SyncSetupWizard::DONE); 375 wizard_->Step(SyncSetupWizard::DONE);
500 EXPECT_FALSE(wizard_->IsVisible()); 376 EXPECT_FALSE(wizard_->IsVisible());
501 } 377 }
502 378
503 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypesAbortedByPendingClear) { 379 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypesAbortedByPendingClear) {
504 CompleteSetup(); 380 CompleteSetup();
505 381
506 wizard_->Step(SyncSetupWizard::CONFIGURE); 382 wizard_->Step(SyncSetupWizard::CONFIGURE);
507 AttachSyncSetupHandler(); 383 AttachSyncSetupHandler();
508 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); 384 EXPECT_TRUE(wizard_->IsVisible());
509 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); 385 EXPECT_EQ(SyncSetupWizard::DONE, handler_.GetFlow()->end_state_);
510 // Stepping to SETUP_ABORTED should redirect us to GAIA_LOGIN state, since 386 wizard_->Step(SyncSetupWizard::ABORT);
511 // that's where we display the error. 387 // Stepping to ABORT should leave us in the ABORT state and close the dialog.
512 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
513
514 CloseSetupUI();
515 EXPECT_FALSE(wizard_->IsVisible()); 388 EXPECT_FALSE(wizard_->IsVisible());
516 } 389 }
517 390
518 TEST_F(SyncSetupWizardTest, DiscreteRunGaiaLogin) { 391 TEST_F(SyncSetupWizardTest, EnterPassphrase) {
519 CompleteSetup();
520
521 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
522 AttachSyncSetupHandler();
523 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, flow_->end_state_);
524
525 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
526 flow_->last_attempted_user_email_ = kTestUser;
527 service_->set_last_auth_error(invalid_gaia);
528 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
529 EXPECT_TRUE(wizard_->IsVisible());
530
531 DictionaryValue dialog_args;
532 flow_->GetArgsForGaiaLogin(&dialog_args);
533 EXPECT_EQ(4U, dialog_args.size());
534 std::string actual_user;
535 dialog_args.GetString("user", &actual_user);
536 EXPECT_EQ(kTestUser, actual_user);
537 int error = -1;
538 dialog_args.GetInteger("error", &error);
539 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
540 flow_->last_attempted_user_email_ = kTestUser;
541 service_->set_last_auth_error(AuthError::None());
542
543 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
544 }
545
546 TEST_F(SyncSetupWizardTest, NonFatalError) {
547 CompleteSetup(); 392 CompleteSetup();
548 393
549 // Set up the ENTER_PASSPHRASE case. 394 // Set up the ENTER_PASSPHRASE case.
550 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION); 395 service_->set_passphrase_required_reason(sync_api::REASON_ENCRYPTION);
551 service_->set_is_using_secondary_passphrase(true); 396 service_->set_is_using_secondary_passphrase(true);
552 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR); 397 wizard_->Step(SyncSetupWizard::ENTER_PASSPHRASE);
553 AttachSyncSetupHandler(); 398 AttachSyncSetupHandler();
554 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE, flow_->current_state_); 399 EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE,
555 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); 400 handler_.GetFlow()->current_state_);
556 CloseSetupUI(); 401 EXPECT_EQ(SyncSetupWizard::DONE, handler_.GetFlow()->end_state_);
557 EXPECT_FALSE(wizard_->IsVisible());
558
559 // Reset.
560 service_->set_passphrase_required_reason(
561 sync_api::REASON_PASSPHRASE_NOT_REQUIRED);
562 service_->set_is_using_secondary_passphrase(false);
563
564 // Test the various auth error states that lead to GAIA_LOGIN.
565
566 service_->set_last_auth_error(
567 AuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
568 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR);
569 AttachSyncSetupHandler();
570 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
571 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_);
572 CloseSetupUI();
573 EXPECT_FALSE(wizard_->IsVisible());
574
575 service_->set_last_auth_error(
576 AuthError(GoogleServiceAuthError::CAPTCHA_REQUIRED));
577 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR);
578 AttachSyncSetupHandler();
579 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
580 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_);
581 CloseSetupUI();
582 EXPECT_FALSE(wizard_->IsVisible());
583
584 service_->set_last_auth_error(
585 AuthError(GoogleServiceAuthError::ACCOUNT_DELETED));
586 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR);
587 AttachSyncSetupHandler();
588 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
589 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_);
590 CloseSetupUI();
591 EXPECT_FALSE(wizard_->IsVisible());
592
593 service_->set_last_auth_error(
594 AuthError(GoogleServiceAuthError::ACCOUNT_DISABLED));
595 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR);
596 AttachSyncSetupHandler();
597 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
598 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_);
599 CloseSetupUI();
600 EXPECT_FALSE(wizard_->IsVisible());
601
602 service_->set_last_auth_error(
603 AuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
604 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR);
605 AttachSyncSetupHandler();
606 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_);
607 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_);
608 CloseSetupUI(); 402 CloseSetupUI();
609 EXPECT_FALSE(wizard_->IsVisible()); 403 EXPECT_FALSE(wizard_->IsVisible());
610 } 404 }
611 405
406 TEST_F(SyncSetupWizardTest, FatalErrorDuringConfigure) {
407 CompleteSetup();
408
409 wizard_->Step(SyncSetupWizard::CONFIGURE);
410 AttachSyncSetupHandler();
411 EXPECT_EQ(SyncSetupWizard::DONE, handler_.GetFlow()->end_state_);
412 wizard_->Step(SyncSetupWizard::FATAL_ERROR);
413 EXPECT_TRUE(handler_.GetFlow() == NULL);
414 EXPECT_FALSE(wizard_->IsVisible());
415 }
416
612 class SyncSetupWizardCrosTest : public SyncSetupWizardTest { 417 class SyncSetupWizardCrosTest : public SyncSetupWizardTest {
613 public: 418 public:
614 virtual TestingProfile* BuildProfile() { 419 virtual TestingProfile* BuildProfile() {
615 TestingProfile* profile = new TestingProfile(); 420 TestingProfile* profile = new TestingProfile();
616 ProfileSyncServiceFactory* f = ProfileSyncServiceFactory::GetInstance(); 421 ProfileSyncServiceFactory* f = ProfileSyncServiceFactory::GetInstance();
617 f->SetTestingFactory(profile, ProfileSyncServiceForWizardTest::BuildAuto); 422 f->SetTestingFactory(profile, ProfileSyncServiceForWizardTest::BuildAuto);
618 f->GetForProfile(profile)->signin()->SetAuthenticatedUsername(kTestUser); 423 f->GetForProfile(profile)->signin()->SetAuthenticatedUsername(kTestUser);
619 return profile; 424 return profile;
620 } 425 }
621 }; 426 };
622
623 // Tests a scenario where sync is disabled on chrome os on startup due to
624 // an auth error (application specific password is needed).
625 TEST_F(SyncSetupWizardCrosTest, CrosAuthSetup) {
626 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
627
628 AttachSyncSetupHandler();
629 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, flow_->end_state_);
630
631 DictionaryValue dialog_args;
632 flow_->GetArgsForGaiaLogin(&dialog_args);
633 EXPECT_EQ(4U, dialog_args.size());
634 std::string actual_user;
635 dialog_args.GetString("user", &actual_user);
636 EXPECT_EQ(kTestUser, actual_user);
637 int error = -1;
638 dialog_args.GetInteger("error", &error);
639 EXPECT_EQ(0, error);
640 bool editable = true;
641 dialog_args.GetBoolean("editable_user", &editable);
642 EXPECT_FALSE(editable);
643 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
644 EXPECT_TRUE(service_->user_cancelled_dialog_);
645 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean(
646 prefs::kSyncHasSetupCompleted));
647 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_setup_wizard.cc ('k') | chrome/browser/ui/webui/options/options_sync_setup_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698