• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 // TODO(jhawkins): Rewrite these tests to handle the new inlined sync UI.
6 
7 #include "chrome/browser/sync/sync_setup_wizard.h"
8 
9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/stl_util-inl.h"
12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/sync/profile_sync_factory_mock.h"
15 #include "chrome/browser/sync/profile_sync_service.h"
16 #include "chrome/browser/sync/sync_setup_flow.h"
17 #include "chrome/browser/sync/sync_setup_flow_handler.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/common/net/gaia/google_service_auth_error.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/browser_with_test_window_test.h"
23 #include "chrome/test/test_browser_window.h"
24 #include "chrome/test/testing_profile.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 
27 static const char kTestUser[] = "chrome.p13n.test@gmail.com";
28 static const char kTestPassword[] = "passwd";
29 static const char kTestCaptcha[] = "pizzamyheart";
30 static const char kTestCaptchaUrl[] = "http://pizzamyheart/";
31 
32 typedef GoogleServiceAuthError AuthError;
33 
34 // A PSS subtype to inject.
35 class ProfileSyncServiceForWizardTest : public ProfileSyncService {
36  public:
ProfileSyncServiceForWizardTest(ProfileSyncFactory * factory,Profile * profile)37   ProfileSyncServiceForWizardTest(ProfileSyncFactory* factory, Profile* profile)
38       : ProfileSyncService(factory, profile, ""),
39         user_cancelled_dialog_(false) {
40     RegisterPreferences();
41     ResetTestStats();
42   }
43 
~ProfileSyncServiceForWizardTest()44   virtual ~ProfileSyncServiceForWizardTest() { }
45 
OnUserSubmittedAuth(const std::string & username,const std::string & password,const std::string & captcha,const std::string & access_code)46   virtual void OnUserSubmittedAuth(const std::string& username,
47                                    const std::string& password,
48                                    const std::string& captcha,
49                                    const std::string& access_code) {
50     username_ = username;
51     password_ = password;
52     captcha_ = captcha;
53   }
54 
OnUserChoseDatatypes(bool sync_everything,const syncable::ModelTypeSet & chosen_types)55   virtual void OnUserChoseDatatypes(bool sync_everything,
56       const syncable::ModelTypeSet& chosen_types) {
57     user_chose_data_types_ = true;
58     chosen_data_types_ = chosen_types;
59   }
60 
OnUserCancelledDialog()61   virtual void OnUserCancelledDialog() {
62     user_cancelled_dialog_ = true;
63   }
64 
SetPassphrase(const std::string & passphrase,bool is_explicit,bool is_creation)65   virtual void SetPassphrase(const std::string& passphrase,
66                              bool is_explicit,
67                              bool is_creation) {
68     passphrase_ = passphrase;
69   }
70 
GetAuthenticatedUsername() const71   virtual string16 GetAuthenticatedUsername() const {
72     return UTF8ToUTF16(username_);
73   }
74 
set_auth_state(const std::string & last_email,const AuthError & error)75   void set_auth_state(const std::string& last_email,
76                       const AuthError& error) {
77     last_attempted_user_email_ = last_email;
78     last_auth_error_ = error;
79   }
80 
set_passphrase_required(bool required)81   void set_passphrase_required(bool required) {
82     observed_passphrase_required_ = required;
83   }
84 
ResetTestStats()85   void ResetTestStats() {
86     username_.clear();
87     password_.clear();
88     captcha_.clear();
89     user_cancelled_dialog_ = false;
90     user_chose_data_types_ = false;
91     keep_everything_synced_ = false;
92     chosen_data_types_.clear();
93   }
94 
95   std::string username_;
96   std::string password_;
97   std::string captcha_;
98   bool user_cancelled_dialog_;
99   bool user_chose_data_types_;
100   bool keep_everything_synced_;
101   syncable::ModelTypeSet chosen_data_types_;
102 
103   std::string passphrase_;
104 
105  private:
106   DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest);
107 };
108 
109 class TestingProfileWithSyncService : public TestingProfile {
110  public:
TestingProfileWithSyncService()111   TestingProfileWithSyncService() {
112     sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this));
113   }
114 
GetProfileSyncService()115   virtual ProfileSyncService* GetProfileSyncService() {
116     return sync_service_.get();
117   }
118  private:
119   ProfileSyncFactoryMock factory_;
120   scoped_ptr<ProfileSyncService> sync_service_;
121 };
122 
123 class TestBrowserWindowForWizardTest : public TestBrowserWindow {
124  public:
TestBrowserWindowForWizardTest(Browser * browser)125   explicit TestBrowserWindowForWizardTest(Browser* browser)
126       : TestBrowserWindow(browser), flow_(NULL),
127         was_show_html_dialog_called_(false) {
128   }
129 
~TestBrowserWindowForWizardTest()130   virtual ~TestBrowserWindowForWizardTest() {
131     if (flow_.get()) {
132       // The handler contract is that they are valid for the lifetime of the
133       // sync login overlay, but are cleaned up after the dialog is closed
134       // and/or deleted.
135       flow_.reset();
136     }
137   }
138 
TestAndResetWasShowHTMLDialogCalled()139   bool TestAndResetWasShowHTMLDialogCalled() {
140     bool ret = was_show_html_dialog_called_;
141     was_show_html_dialog_called_ = false;
142     return ret;
143   }
144 
145   // Simulates the user (or browser view hierarchy) closing the html dialog.
146   // Handles cleaning up the delegate and associated handlers.
CloseDialog()147   void CloseDialog() {
148     if (flow_.get()) {
149       // The flow deletes itself here.  Don't use reset().
150       flow_.release()->OnDialogClosed("");
151     }
152   }
153 
flow()154   SyncSetupFlow* flow() { return flow_.get(); }
155 
156  private:
157   // In real life, this is owned by the view that is opened by the browser.  We
158   // mock all that out, so we need to take ownership so the flow doesn't leak.
159   scoped_ptr<SyncSetupFlow> flow_;
160 
161   bool was_show_html_dialog_called_;
162 };
163 
164 class SyncSetupWizardTest : public BrowserWithTestWindowTest {
165  public:
SyncSetupWizardTest()166   SyncSetupWizardTest()
167       : test_window_(NULL),
168         wizard_(NULL) { }
~SyncSetupWizardTest()169   virtual ~SyncSetupWizardTest() { }
SetUp()170   virtual void SetUp() {
171     set_profile(new TestingProfileWithSyncService());
172     profile()->CreateBookmarkModel(false);
173     // Wait for the bookmarks model to load.
174     profile()->BlockUntilBookmarkModelLoaded();
175     set_browser(new Browser(Browser::TYPE_NORMAL, profile()));
176     test_window_ = new TestBrowserWindowForWizardTest(browser());
177     set_window(test_window_);
178     browser()->set_window(window());
179     BrowserList::SetLastActive(browser());
180     service_ = static_cast<ProfileSyncServiceForWizardTest*>(
181         profile()->GetProfileSyncService());
182     wizard_.reset(new SyncSetupWizard(service_));
183   }
184 
TearDown()185   virtual void TearDown() {
186     test_window_ = NULL;
187     service_ = NULL;
188     wizard_.reset();
189   }
190 
191   TestBrowserWindowForWizardTest* test_window_;
192   scoped_ptr<SyncSetupWizard> wizard_;
193   ProfileSyncServiceForWizardTest* service_;
194 };
195 
196 // See http://code.google.com/p/chromium/issues/detail?id=40715 for
197 // why we skip the below tests on OS X.  We don't use DISABLED_ as we
198 // would have to change the corresponding FRIEND_TEST() declarations.
199 
200 #if defined(OS_MACOSX)
201 #define SKIP_TEST_ON_MACOSX() \
202   do { LOG(WARNING) << "Test skipped on OS X"; return; } while (0)
203 #else
204 #define SKIP_TEST_ON_MACOSX() do {} while (0)
205 #endif
206 
TEST_F(SyncSetupWizardTest,DISABLED_InitialStepLogin)207 TEST_F(SyncSetupWizardTest, DISABLED_InitialStepLogin) {
208   SKIP_TEST_ON_MACOSX();
209   DictionaryValue dialog_args;
210   SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
211   std::string json_start_args;
212   base::JSONWriter::Write(&dialog_args, false, &json_start_args);
213   ListValue credentials;
214   std::string auth = "{\"user\":\"";
215   auth += std::string(kTestUser) + "\",\"pass\":\"";
216   auth += std::string(kTestPassword) + "\",\"captcha\":\"";
217   auth += std::string(kTestCaptcha) + "\",\"access_code\":\"";
218   auth += std::string() + "\"}";
219   credentials.Append(new StringValue(auth));
220 
221   EXPECT_FALSE(wizard_->IsVisible());
222   EXPECT_FALSE(test_window_->flow());
223   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
224 
225   EXPECT_TRUE(wizard_->IsVisible());
226   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
227   EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
228   EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_);
229   EXPECT_EQ(json_start_args, test_window_->flow()->dialog_start_args_);
230 
231 #if 0
232   // Simulate the user submitting credentials.
233   test_window_->flow()->flow_handler_->HandleSubmitAuth(&credentials);
234   EXPECT_TRUE(wizard_->IsVisible());
235   EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
236   EXPECT_EQ(kTestUser, service_->username_);
237   EXPECT_EQ(kTestPassword, service_->password_);
238   EXPECT_EQ(kTestCaptcha, service_->captcha_);
239   EXPECT_FALSE(service_->user_cancelled_dialog_);
240   service_->ResetTestStats();
241 #endif
242 
243   // Simulate failed credentials.
244   AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
245   service_->set_auth_state(kTestUser, invalid_gaia);
246   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
247   EXPECT_TRUE(wizard_->IsVisible());
248   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
249   EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
250   dialog_args.Clear();
251   SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
252   EXPECT_EQ(5U, dialog_args.size());
253   std::string iframe_to_show;
254   dialog_args.GetString("iframeToShow", &iframe_to_show);
255   EXPECT_EQ("login", iframe_to_show);
256   std::string actual_user;
257   dialog_args.GetString("user", &actual_user);
258   EXPECT_EQ(kTestUser, actual_user);
259   int error = -1;
260   dialog_args.GetInteger("error", &error);
261   EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
262   service_->set_auth_state(kTestUser, AuthError::None());
263 
264   // Simulate captcha.
265   AuthError captcha_error(AuthError::FromCaptchaChallenge(
266       std::string(), GURL(kTestCaptchaUrl), GURL()));
267   service_->set_auth_state(kTestUser, captcha_error);
268   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
269   SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
270   EXPECT_EQ(5U, dialog_args.size());
271   dialog_args.GetString("iframeToShow", &iframe_to_show);
272   EXPECT_EQ("login", iframe_to_show);
273   std::string captcha_url;
274   dialog_args.GetString("captchaUrl", &captcha_url);
275   EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec());
276   error = -1;
277   dialog_args.GetInteger("error", &error);
278   EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error);
279   service_->set_auth_state(kTestUser, AuthError::None());
280 
281   // Simulate success.
282   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
283   EXPECT_TRUE(wizard_->IsVisible());
284   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
285   // In a non-discrete run, GAIA_SUCCESS immediately transitions you to
286   // SYNC_EVERYTHING.
287   EXPECT_EQ(SyncSetupWizard::SYNC_EVERYTHING,
288             test_window_->flow()->current_state_);
289 
290   // That's all we're testing here, just move on to DONE.  We'll test the
291   // "choose data types" scenarios elsewhere.
292   wizard_->Step(SyncSetupWizard::SETTING_UP);  // No merge and sync.
293   wizard_->Step(SyncSetupWizard::DONE);  // No merge and sync.
294   EXPECT_TRUE(wizard_->IsVisible());
295   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
296   EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_);
297 }
298 
TEST_F(SyncSetupWizardTest,DISABLED_ChooseDataTypesSetsPrefs)299 TEST_F(SyncSetupWizardTest, DISABLED_ChooseDataTypesSetsPrefs) {
300   SKIP_TEST_ON_MACOSX();
301   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
302   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
303   wizard_->Step(SyncSetupWizard::CONFIGURE);
304 
305   ListValue data_type_choices_value;
306   std::string data_type_choices = "{\"keepEverythingSynced\":false,";
307   data_type_choices += "\"syncBookmarks\":true,\"syncPreferences\":true,";
308   data_type_choices += "\"syncThemes\":false,\"syncPasswords\":false,";
309   data_type_choices += "\"syncAutofill\":false,\"syncExtensions\":false,";
310   data_type_choices += "\"syncTypedUrls\":true,\"syncApps\":true,";
311   data_type_choices += "\"syncSessions\":false,\"usePassphrase\":false}";
312   data_type_choices_value.Append(new StringValue(data_type_choices));
313 
314 #if 0
315   // Simulate the user choosing data types; bookmarks, prefs, typed
316   // URLS, and apps are on, the rest are off.
317   test_window_->flow()->flow_handler_->HandleConfigure(
318       &data_type_choices_value);
319   EXPECT_TRUE(wizard_->IsVisible());
320   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
321   EXPECT_FALSE(service_->keep_everything_synced_);
322   EXPECT_EQ(service_->chosen_data_types_.count(syncable::BOOKMARKS), 1U);
323   EXPECT_EQ(service_->chosen_data_types_.count(syncable::PREFERENCES), 1U);
324   EXPECT_EQ(service_->chosen_data_types_.count(syncable::THEMES), 0U);
325   EXPECT_EQ(service_->chosen_data_types_.count(syncable::PASSWORDS), 0U);
326   EXPECT_EQ(service_->chosen_data_types_.count(syncable::AUTOFILL), 0U);
327   EXPECT_EQ(service_->chosen_data_types_.count(syncable::EXTENSIONS), 0U);
328   EXPECT_EQ(service_->chosen_data_types_.count(syncable::TYPED_URLS), 1U);
329   EXPECT_EQ(service_->chosen_data_types_.count(syncable::APPS), 1U);
330 #endif
331   test_window_->CloseDialog();
332 }
333 
TEST_F(SyncSetupWizardTest,DISABLED_EnterPassphraseRequired)334 TEST_F(SyncSetupWizardTest, DISABLED_EnterPassphraseRequired) {
335   SKIP_TEST_ON_MACOSX();
336   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
337   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
338   wizard_->Step(SyncSetupWizard::CONFIGURE);
339   wizard_->Step(SyncSetupWizard::SETTING_UP);
340   service_->set_passphrase_required(true);
341   wizard_->Step(SyncSetupWizard::ENTER_PASSPHRASE);
342   EXPECT_EQ(SyncSetupWizard::ENTER_PASSPHRASE,
343             test_window_->flow()->current_state_);
344 #if 0
345   ListValue value;
346   value.Append(new StringValue("{\"passphrase\":\"myPassphrase\","
347                                 "\"mode\":\"gaia\"}"));
348   test_window_->flow()->flow_handler_->HandlePassphraseEntry(&value);
349   EXPECT_EQ("myPassphrase", service_->passphrase_);
350 #endif
351 }
352 
TEST_F(SyncSetupWizardTest,DISABLED_PassphraseMigration)353 TEST_F(SyncSetupWizardTest, DISABLED_PassphraseMigration) {
354   SKIP_TEST_ON_MACOSX();
355   wizard_->Step(SyncSetupWizard::PASSPHRASE_MIGRATION);
356 #if 0
357   ListValue value;
358   value.Append(new StringValue("{\"option\":\"explicit\","
359                                "\"passphrase\":\"myPassphrase\"}"));
360   test_window_->flow()->flow_handler_->HandleFirstPassphrase(&value);
361   EXPECT_EQ("myPassphrase", service_->passphrase_);
362 
363   ListValue value2;
364   value2.Append(new StringValue("{\"option\":\"nothanks\","
365                                 "\"passphrase\":\"myPassphrase\"}"));
366   test_window_->flow()->flow_handler_->HandleFirstPassphrase(&value2);
367   EXPECT_EQ(service_->chosen_data_types_.count(syncable::PASSWORDS), 0U);
368 #endif
369 }
370 
TEST_F(SyncSetupWizardTest,DISABLED_DialogCancelled)371 TEST_F(SyncSetupWizardTest, DISABLED_DialogCancelled) {
372   SKIP_TEST_ON_MACOSX();
373   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
374   // Simulate the user closing the dialog.
375   test_window_->CloseDialog();
376   EXPECT_FALSE(wizard_->IsVisible());
377   EXPECT_TRUE(service_->user_cancelled_dialog_);
378   EXPECT_EQ(std::string(), service_->username_);
379   EXPECT_EQ(std::string(), service_->password_);
380 
381   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
382   EXPECT_TRUE(wizard_->IsVisible());
383   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
384   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
385   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
386 
387   test_window_->CloseDialog();
388   EXPECT_FALSE(wizard_->IsVisible());
389   EXPECT_TRUE(service_->user_cancelled_dialog_);
390   EXPECT_EQ(std::string(), service_->username_);
391   EXPECT_EQ(std::string(), service_->password_);
392 }
393 
TEST_F(SyncSetupWizardTest,DISABLED_InvalidTransitions)394 TEST_F(SyncSetupWizardTest, DISABLED_InvalidTransitions) {
395   SKIP_TEST_ON_MACOSX();
396   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
397   EXPECT_FALSE(wizard_->IsVisible());
398   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
399 
400   wizard_->Step(SyncSetupWizard::DONE);
401   EXPECT_FALSE(wizard_->IsVisible());
402   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
403 
404   wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME);
405   EXPECT_FALSE(wizard_->IsVisible());
406   EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
407 
408   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
409 
410   wizard_->Step(SyncSetupWizard::DONE);
411   EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
412   wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME);
413   EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
414 
415   wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR);
416   EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN,
417             test_window_->flow()->current_state_);
418 
419   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
420   EXPECT_EQ(SyncSetupWizard::SYNC_EVERYTHING,
421             test_window_->flow()->current_state_);
422 
423   wizard_->Step(SyncSetupWizard::FATAL_ERROR);
424   EXPECT_EQ(SyncSetupWizard::FATAL_ERROR, test_window_->flow()->current_state_);
425 }
426 
TEST_F(SyncSetupWizardTest,DISABLED_FullSuccessfulRunSetsPref)427 TEST_F(SyncSetupWizardTest, DISABLED_FullSuccessfulRunSetsPref) {
428   SKIP_TEST_ON_MACOSX();
429   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
430   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
431   wizard_->Step(SyncSetupWizard::SETTING_UP);
432   wizard_->Step(SyncSetupWizard::DONE);
433   test_window_->CloseDialog();
434   EXPECT_FALSE(wizard_->IsVisible());
435   EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean(
436       prefs::kSyncHasSetupCompleted));
437 }
438 
TEST_F(SyncSetupWizardTest,DISABLED_FirstFullSuccessfulRunSetsPref)439 TEST_F(SyncSetupWizardTest, DISABLED_FirstFullSuccessfulRunSetsPref) {
440   SKIP_TEST_ON_MACOSX();
441   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
442   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
443   wizard_->Step(SyncSetupWizard::SETTING_UP);
444   wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME);
445   test_window_->CloseDialog();
446   EXPECT_FALSE(wizard_->IsVisible());
447   EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean(
448       prefs::kSyncHasSetupCompleted));
449 }
450 
TEST_F(SyncSetupWizardTest,DISABLED_AbortedByPendingClear)451 TEST_F(SyncSetupWizardTest, DISABLED_AbortedByPendingClear) {
452   SKIP_TEST_ON_MACOSX();
453   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
454   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
455   wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR);
456   EXPECT_EQ(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR,
457             test_window_->flow()->current_state_);
458   test_window_->CloseDialog();
459   EXPECT_FALSE(wizard_->IsVisible());
460 }
461 
TEST_F(SyncSetupWizardTest,DISABLED_DiscreteRunChooseDataTypes)462 TEST_F(SyncSetupWizardTest, DISABLED_DiscreteRunChooseDataTypes) {
463   SKIP_TEST_ON_MACOSX();
464   // For a discrete run, we need to have ran through setup once.
465   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
466   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
467   wizard_->Step(SyncSetupWizard::DONE);
468   test_window_->CloseDialog();
469   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
470 
471   wizard_->Step(SyncSetupWizard::CONFIGURE);
472   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
473   EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_);
474 
475   wizard_->Step(SyncSetupWizard::DONE);
476   test_window_->CloseDialog();
477   EXPECT_FALSE(wizard_->IsVisible());
478 }
479 
TEST_F(SyncSetupWizardTest,DISABLED_DiscreteRunChooseDataTypesAbortedByPendingClear)480 TEST_F(SyncSetupWizardTest,
481        DISABLED_DiscreteRunChooseDataTypesAbortedByPendingClear) {
482   SKIP_TEST_ON_MACOSX();
483   // For a discrete run, we need to have ran through setup once.
484   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
485   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
486   wizard_->Step(SyncSetupWizard::DONE);
487   test_window_->CloseDialog();
488   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
489 
490   wizard_->Step(SyncSetupWizard::CONFIGURE);
491   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
492   EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_);
493    wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR);
494   EXPECT_EQ(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR,
495             test_window_->flow()->current_state_);
496 
497   test_window_->CloseDialog();
498   EXPECT_FALSE(wizard_->IsVisible());
499 }
500 
TEST_F(SyncSetupWizardTest,DISABLED_DiscreteRunGaiaLogin)501 TEST_F(SyncSetupWizardTest, DISABLED_DiscreteRunGaiaLogin) {
502   SKIP_TEST_ON_MACOSX();
503   DictionaryValue dialog_args;
504   // For a discrete run, we need to have ran through setup once.
505   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
506   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
507   wizard_->Step(SyncSetupWizard::SETTING_UP);
508   wizard_->Step(SyncSetupWizard::DONE);
509   test_window_->CloseDialog();
510   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
511 
512   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
513   EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_);
514 
515   AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
516   service_->set_auth_state(kTestUser, invalid_gaia);
517   wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
518   EXPECT_TRUE(wizard_->IsVisible());
519   SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
520   EXPECT_EQ(5U, dialog_args.size());
521   std::string iframe_to_show;
522   dialog_args.GetString("iframeToShow", &iframe_to_show);
523   EXPECT_EQ("login", iframe_to_show);
524   std::string actual_user;
525   dialog_args.GetString("user", &actual_user);
526   EXPECT_EQ(kTestUser, actual_user);
527   int error = -1;
528   dialog_args.GetInteger("error", &error);
529   EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
530   service_->set_auth_state(kTestUser, AuthError::None());
531 
532   wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
533   EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
534 }
535 
536 #undef SKIP_TEST_ON_MACOSX
537