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

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

Issue 2878012: Revert 50902 - New HTML Sync Setup UI.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/450/src/
Patch Set: Created 10 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
« no previous file with comments | « chrome/browser/sync/sync_setup_wizard.cc ('k') | chrome/browser/sync/syncable/model_type.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 17 matching lines...) Expand all
28 typedef GoogleServiceAuthError AuthError; 28 typedef GoogleServiceAuthError AuthError;
29 29
30 // A PSS subtype to inject. 30 // A PSS subtype to inject.
31 class ProfileSyncServiceForWizardTest : public ProfileSyncService { 31 class ProfileSyncServiceForWizardTest : public ProfileSyncService {
32 public: 32 public:
33 ProfileSyncServiceForWizardTest(ProfileSyncFactory* factory, Profile* profile) 33 ProfileSyncServiceForWizardTest(ProfileSyncFactory* factory, Profile* profile)
34 : ProfileSyncService(factory, profile, false), 34 : ProfileSyncService(factory, profile, false),
35 user_accepted_merge_and_sync_(false), 35 user_accepted_merge_and_sync_(false),
36 user_cancelled_dialog_(false) { 36 user_cancelled_dialog_(false) {
37 RegisterPreferences(); 37 RegisterPreferences();
38 ResetTestStats();
39 } 38 }
40 39
41 virtual ~ProfileSyncServiceForWizardTest() { } 40 virtual ~ProfileSyncServiceForWizardTest() { }
42 41
43 virtual void OnUserSubmittedAuth(const std::string& username, 42 virtual void OnUserSubmittedAuth(const std::string& username,
44 const std::string& password, 43 const std::string& password,
45 const std::string& captcha) { 44 const std::string& captcha) {
46 username_ = username; 45 username_ = username;
47 password_ = password; 46 password_ = password;
48 captcha_ = captcha; 47 captcha_ = captcha;
49 } 48 }
50
51 virtual void OnUserChoseDatatypes(bool sync_everything,
52 const syncable::ModelTypeSet& chosen_types) {
53 user_chose_data_types_ = true;
54 chosen_data_types_ = chosen_types;
55 }
56
57 virtual void OnUserAcceptedMergeAndSync() { 49 virtual void OnUserAcceptedMergeAndSync() {
58 user_accepted_merge_and_sync_ = true; 50 user_accepted_merge_and_sync_ = true;
59 } 51 }
60 virtual void OnUserCancelledDialog() { 52 virtual void OnUserCancelledDialog() {
61 user_cancelled_dialog_ = true; 53 user_cancelled_dialog_ = true;
62 } 54 }
63 55
64 virtual string16 GetAuthenticatedUsername() const { 56 virtual string16 GetAuthenticatedUsername() const {
65 return UTF8ToUTF16(username_); 57 return UTF8ToUTF16(username_);
66 } 58 }
67 59
68 void set_auth_state(const std::string& last_email, 60 void set_auth_state(const std::string& last_email,
69 const AuthError& error) { 61 const AuthError& error) {
70 last_attempted_user_email_ = last_email; 62 last_attempted_user_email_ = last_email;
71 last_auth_error_ = error; 63 last_auth_error_ = error;
72 } 64 }
73 65
74 void ResetTestStats() { 66 void ResetTestStats() {
75 username_.clear(); 67 username_.clear();
76 password_.clear(); 68 password_.clear();
77 captcha_.clear(); 69 captcha_.clear();
78 user_accepted_merge_and_sync_ = false; 70 user_accepted_merge_and_sync_ = false;
79 user_cancelled_dialog_ = false; 71 user_cancelled_dialog_ = false;
80 user_chose_data_types_ = false;
81 keep_everything_synced_ = false;
82 chosen_data_types_.clear();
83 } 72 }
84 73
85 std::string username_; 74 std::string username_;
86 std::string password_; 75 std::string password_;
87 std::string captcha_; 76 std::string captcha_;
88 bool user_accepted_merge_and_sync_; 77 bool user_accepted_merge_and_sync_;
89 bool user_cancelled_dialog_; 78 bool user_cancelled_dialog_;
90 bool user_chose_data_types_;
91 bool keep_everything_synced_;
92 syncable::ModelTypeSet chosen_data_types_;
93 79
94 private: 80 private:
95 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); 81 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest);
96 }; 82 };
97 83
98 class TestingProfileWithSyncService : public TestingProfile { 84 class TestingProfileWithSyncService : public TestingProfile {
99 public: 85 public:
100 TestingProfileWithSyncService() { 86 TestingProfileWithSyncService() {
101 sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this)); 87 sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this));
102 } 88 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 236
251 // Simulate failed credentials. 237 // Simulate failed credentials.
252 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); 238 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
253 service_->set_auth_state(kTestUser, invalid_gaia); 239 service_->set_auth_state(kTestUser, invalid_gaia);
254 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 240 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
255 EXPECT_TRUE(wizard_->IsVisible()); 241 EXPECT_TRUE(wizard_->IsVisible());
256 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 242 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
257 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); 243 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
258 dialog_args.Clear(); 244 dialog_args.Clear();
259 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); 245 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
260 EXPECT_EQ(5U, dialog_args.size()); 246 EXPECT_EQ(4U, dialog_args.size());
261 std::string iframe_to_show;
262 dialog_args.GetString(L"iframeToShow", &iframe_to_show);
263 EXPECT_EQ("login", iframe_to_show);
264 std::string actual_user; 247 std::string actual_user;
265 dialog_args.GetString(L"user", &actual_user); 248 dialog_args.GetString(L"user", &actual_user);
266 EXPECT_EQ(kTestUser, actual_user); 249 EXPECT_EQ(kTestUser, actual_user);
267 int error = -1; 250 int error = -1;
268 dialog_args.GetInteger(L"error", &error); 251 dialog_args.GetInteger(L"error", &error);
269 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); 252 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
270 service_->set_auth_state(kTestUser, AuthError::None()); 253 service_->set_auth_state(kTestUser, AuthError::None());
271 254
272 // Simulate captcha. 255 // Simulate captcha.
273 AuthError captcha_error(AuthError::FromCaptchaChallenge( 256 AuthError captcha_error(AuthError::FromCaptchaChallenge(
274 std::string(), GURL(kTestCaptchaUrl), GURL())); 257 std::string(), GURL(kTestCaptchaUrl), GURL()));
275 service_->set_auth_state(kTestUser, captcha_error); 258 service_->set_auth_state(kTestUser, captcha_error);
276 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 259 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
277 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); 260 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
278 EXPECT_EQ(5U, dialog_args.size()); 261 EXPECT_EQ(4U, dialog_args.size());
279 dialog_args.GetString(L"iframeToShow", &iframe_to_show);
280 EXPECT_EQ("login", iframe_to_show);
281 std::string captcha_url; 262 std::string captcha_url;
282 dialog_args.GetString(L"captchaUrl", &captcha_url); 263 dialog_args.GetString(L"captchaUrl", &captcha_url);
283 EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec()); 264 EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec());
284 error = -1; 265 error = -1;
285 dialog_args.GetInteger(L"error", &error); 266 dialog_args.GetInteger(L"error", &error);
286 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error); 267 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error);
287 service_->set_auth_state(kTestUser, AuthError::None()); 268 service_->set_auth_state(kTestUser, AuthError::None());
288 269
289 // Simulate success. 270 // Simulate success.
290 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); 271 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
291 EXPECT_TRUE(wizard_->IsVisible()); 272 EXPECT_TRUE(wizard_->IsVisible());
292 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 273 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
293 // In a non-discrete run, GAIA_SUCCESS immediately transitions you to 274 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS,
294 // CHOOSE_DATA_TYPES.
295 EXPECT_EQ(SyncSetupWizard::CHOOSE_DATA_TYPES,
296 test_window_->flow()->current_state_); 275 test_window_->flow()->current_state_);
297 276
298 // That's all we're testing here, just move on to DONE. We'll test the
299 // "choose data types" scenarios elsewhere.
300 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync. 277 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync.
301 EXPECT_TRUE(wizard_->IsVisible()); 278 EXPECT_TRUE(wizard_->IsVisible());
302 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 279 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
303 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_); 280 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_);
304 } 281 }
305 282
306 TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) {
307 SKIP_TEST_ON_MACOSX();
308 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
309 wizard_->Step(SyncSetupWizard::CHOOSE_DATA_TYPES);
310
311 ListValue data_type_choices_value;
312 std::string data_type_choices = "{\"keepEverythingSynced\":false,";
313 data_type_choices += "\"syncBookmarks\":true,\"syncPreferences\":true,";
314 data_type_choices += "\"syncThemes\":false,\"syncPasswords\":false,";
315 data_type_choices += "\"syncAutofill\":false,\"syncExtensions\":false,";
316 data_type_choices += "\"syncTypedUrls\":true}";
317 data_type_choices_value.Append(new StringValue(data_type_choices));
318
319 // Simulate the user choosing data types; bookmarks and prefs are on, the rest
320 // are off.
321 test_window_->flow()->flow_handler_->HandleChooseDataTypes(
322 &data_type_choices_value);
323 EXPECT_TRUE(wizard_->IsVisible());
324 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
325 EXPECT_FALSE(service_->keep_everything_synced_);
326 EXPECT_EQ(service_->chosen_data_types_.count(syncable::BOOKMARKS), 1U);
327 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PREFERENCES), 1U);
328 EXPECT_EQ(service_->chosen_data_types_.count(syncable::THEMES), 0U);
329 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PASSWORDS), 0U);
330 EXPECT_EQ(service_->chosen_data_types_.count(syncable::AUTOFILL), 0U);
331 EXPECT_EQ(service_->chosen_data_types_.count(syncable::EXTENSIONS), 0U);
332 EXPECT_EQ(service_->chosen_data_types_.count(syncable::TYPED_URLS), 1U);
333
334 test_window_->CloseDialog();
335 }
336
337 TEST_F(SyncSetupWizardTest, DialogCancelled) { 283 TEST_F(SyncSetupWizardTest, DialogCancelled) {
338 SKIP_TEST_ON_MACOSX(); 284 SKIP_TEST_ON_MACOSX();
339 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 285 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
340 // Simulate the user closing the dialog. 286 // Simulate the user closing the dialog.
341 test_window_->CloseDialog(); 287 test_window_->CloseDialog();
342 EXPECT_FALSE(wizard_->IsVisible()); 288 EXPECT_FALSE(wizard_->IsVisible());
343 EXPECT_TRUE(service_->user_cancelled_dialog_); 289 EXPECT_TRUE(service_->user_cancelled_dialog_);
344 EXPECT_EQ(std::string(), service_->username_); 290 EXPECT_EQ(std::string(), service_->username_);
345 EXPECT_EQ(std::string(), service_->password_); 291 EXPECT_EQ(std::string(), service_->password_);
346 EXPECT_FALSE(service_->user_accepted_merge_and_sync_); 292 EXPECT_FALSE(service_->user_accepted_merge_and_sync_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 365 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
420 366
421 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 367 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
422 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_); 368 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_);
423 369
424 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); 370 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
425 service_->set_auth_state(kTestUser, invalid_gaia); 371 service_->set_auth_state(kTestUser, invalid_gaia);
426 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 372 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
427 EXPECT_TRUE(wizard_->IsVisible()); 373 EXPECT_TRUE(wizard_->IsVisible());
428 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); 374 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
429 EXPECT_EQ(5U, dialog_args.size()); 375 EXPECT_EQ(4U, dialog_args.size());
430 std::string iframe_to_show;
431 dialog_args.GetString(L"iframeToShow", &iframe_to_show);
432 EXPECT_EQ("login", iframe_to_show);
433 std::string actual_user; 376 std::string actual_user;
434 dialog_args.GetString(L"user", &actual_user); 377 dialog_args.GetString(L"user", &actual_user);
435 EXPECT_EQ(kTestUser, actual_user); 378 EXPECT_EQ(kTestUser, actual_user);
436 int error = -1; 379 int error = -1;
437 dialog_args.GetInteger(L"error", &error); 380 dialog_args.GetInteger(L"error", &error);
438 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); 381 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
439 service_->set_auth_state(kTestUser, AuthError::None()); 382 service_->set_auth_state(kTestUser, AuthError::None());
440 383
441 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); 384 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
442 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 385 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
443 } 386 }
444 387
445 #undef SKIP_TEST_ON_MACOSX 388 #undef SKIP_TEST_ON_MACOSX
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_setup_wizard.cc ('k') | chrome/browser/sync/syncable/model_type.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698