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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 virtual void OnUserSubmittedAuth(const std::string& username, | 74 virtual void OnUserSubmittedAuth(const std::string& username, |
75 const std::string& password, | 75 const std::string& password, |
76 const std::string& captcha, | 76 const std::string& captcha, |
77 const std::string& access_code) { | 77 const std::string& access_code) { |
78 username_ = username; | 78 username_ = username; |
79 password_ = password; | 79 password_ = password; |
80 captcha_ = captcha; | 80 captcha_ = captcha; |
81 } | 81 } |
82 | 82 |
83 virtual void OnUserChoseDatatypes(bool sync_everything, | 83 virtual void OnUserChoseDatatypes(bool sync_everything, |
84 const syncable::ModelTypeSet& chosen_types) { | 84 syncable::ModelEnumSet chosen_types) { |
85 user_chose_data_types_ = true; | 85 user_chose_data_types_ = true; |
86 chosen_data_types_ = chosen_types; | 86 chosen_data_types_ = chosen_types; |
87 } | 87 } |
88 | 88 |
89 virtual void OnUserCancelledDialog() { | 89 virtual void OnUserCancelledDialog() { |
90 user_cancelled_dialog_ = true; | 90 user_cancelled_dialog_ = true; |
91 } | 91 } |
92 | 92 |
93 virtual void SetPassphrase(const std::string& passphrase, | 93 virtual void SetPassphrase(const std::string& passphrase, |
94 bool is_explicit) { | 94 bool is_explicit) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 encrypt_everything_ = encrypt_everything; | 134 encrypt_everything_ = encrypt_everything; |
135 } | 135 } |
136 | 136 |
137 void ResetTestStats() { | 137 void ResetTestStats() { |
138 username_.clear(); | 138 username_.clear(); |
139 password_.clear(); | 139 password_.clear(); |
140 captcha_.clear(); | 140 captcha_.clear(); |
141 user_cancelled_dialog_ = false; | 141 user_cancelled_dialog_ = false; |
142 user_chose_data_types_ = false; | 142 user_chose_data_types_ = false; |
143 keep_everything_synced_ = false; | 143 keep_everything_synced_ = false; |
144 chosen_data_types_.clear(); | 144 chosen_data_types_.Clear(); |
145 } | 145 } |
146 | 146 |
147 // Use this to have the service act as if it were running under CrOS. | 147 // Use this to have the service act as if it were running under CrOS. |
148 void set_cros_mode() { | 148 void set_cros_mode() { |
149 cros_user_ = kTestUser; | 149 cros_user_ = kTestUser; |
150 } | 150 } |
151 | 151 |
152 virtual void ShowSyncSetup(const std::string& sub_page) { | 152 virtual void ShowSyncSetup(const std::string& sub_page) { |
153 // Do Nothing. | 153 // Do Nothing. |
154 } | 154 } |
155 | 155 |
156 void ClearObservers() { | 156 void ClearObservers() { |
157 observers_.Clear(); | 157 observers_.Clear(); |
158 } | 158 } |
159 | 159 |
160 SyncSetupWizard* GetWizard() { | 160 SyncSetupWizard* GetWizard() { |
161 return &wizard_; | 161 return &wizard_; |
162 } | 162 } |
163 | 163 |
164 std::string username_; | 164 std::string username_; |
165 std::string password_; | 165 std::string password_; |
166 std::string captcha_; | 166 std::string captcha_; |
167 bool user_cancelled_dialog_; | 167 bool user_cancelled_dialog_; |
168 bool user_chose_data_types_; | 168 bool user_chose_data_types_; |
169 bool keep_everything_synced_; | 169 bool keep_everything_synced_; |
170 bool is_using_secondary_passphrase_; | 170 bool is_using_secondary_passphrase_; |
171 bool encrypt_everything_; | 171 bool encrypt_everything_; |
172 syncable::ModelTypeSet chosen_data_types_; | 172 syncable::ModelEnumSet chosen_data_types_; |
173 std::string passphrase_; | 173 std::string passphrase_; |
174 | 174 |
175 private: | 175 private: |
176 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); | 176 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); |
177 }; | 177 }; |
178 | 178 |
179 class TestingProfileWithSyncService : public TestingProfile { | 179 class TestingProfileWithSyncService : public TestingProfile { |
180 public: | 180 public: |
181 TestingProfileWithSyncService() { | 181 TestingProfileWithSyncService() { |
182 sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this)); | 182 sync_service_.reset(new ProfileSyncServiceForWizardTest(&factory_, this)); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 "\"encryptAllData\":false}"; | 335 "\"encryptAllData\":false}"; |
336 data_type_choices_value.Append(new StringValue(data_type_choices)); | 336 data_type_choices_value.Append(new StringValue(data_type_choices)); |
337 | 337 |
338 // Simulate the user choosing data types; bookmarks, prefs, typed URLS, and | 338 // Simulate the user choosing data types; bookmarks, prefs, typed URLS, and |
339 // apps are on, the rest are off. | 339 // apps are on, the rest are off. |
340 handler_.HandleConfigure(&data_type_choices_value); | 340 handler_.HandleConfigure(&data_type_choices_value); |
341 // Since we don't need a passphrase, wizard should have transitioned to | 341 // Since we don't need a passphrase, wizard should have transitioned to |
342 // DONE state and closed the UI. | 342 // DONE state and closed the UI. |
343 EXPECT_FALSE(wizard_->IsVisible()); | 343 EXPECT_FALSE(wizard_->IsVisible()); |
344 EXPECT_FALSE(service_->keep_everything_synced_); | 344 EXPECT_FALSE(service_->keep_everything_synced_); |
345 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::BOOKMARKS)); | 345 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::BOOKMARKS)); |
346 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::PREFERENCES)); | 346 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::PREFERENCES)); |
347 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::THEMES)); | 347 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::THEMES)); |
348 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::PASSWORDS)); | 348 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::PASSWORDS)); |
349 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::AUTOFILL)); | 349 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::AUTOFILL)); |
350 EXPECT_EQ(0U, service_->chosen_data_types_.count(syncable::EXTENSIONS)); | 350 EXPECT_FALSE(service_->chosen_data_types_.Has(syncable::EXTENSIONS)); |
351 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::TYPED_URLS)); | 351 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::TYPED_URLS)); |
352 EXPECT_EQ(1U, service_->chosen_data_types_.count(syncable::APPS)); | 352 EXPECT_TRUE(service_->chosen_data_types_.Has(syncable::APPS)); |
353 EXPECT_EQ(0U, service_->chosen_data_types_.count( | 353 EXPECT_FALSE(service_->chosen_data_types_.Has( |
354 syncable::APP_NOTIFICATIONS)); | 354 syncable::APP_NOTIFICATIONS)); |
355 } | 355 } |
356 | 356 |
357 TEST_F(SyncSetupWizardTest, ShowErrorUIForPasswordTest) { | 357 TEST_F(SyncSetupWizardTest, ShowErrorUIForPasswordTest) { |
358 service_->ClearObservers(); | 358 service_->ClearObservers(); |
359 CompleteSetup(); | 359 CompleteSetup(); |
360 | 360 |
361 // Simulate an auth error and make sure the start and end state are set | 361 // Simulate an auth error and make sure the start and end state are set |
362 // right. | 362 // right. |
363 service_->set_last_auth_error( | 363 service_->set_last_auth_error( |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 614 |
615 service_->set_last_auth_error( | 615 service_->set_last_auth_error( |
616 AuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | 616 AuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
617 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR); | 617 wizard_->Step(SyncSetupWizard::NONFATAL_ERROR); |
618 AttachSyncSetupHandler(); | 618 AttachSyncSetupHandler(); |
619 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); | 619 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, flow_->current_state_); |
620 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); | 620 EXPECT_EQ(SyncSetupWizard::DONE, flow_->end_state_); |
621 CloseSetupUI(); | 621 CloseSetupUI(); |
622 EXPECT_FALSE(wizard_->IsVisible()); | 622 EXPECT_FALSE(wizard_->IsVisible()); |
623 } | 623 } |
OLD | NEW |