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

Side by Side Diff: chrome/browser/ui/webui/settings/people_handler_unittest.cc

Issue 1503333003: Settings People Rewrite: Make Sync/Sign-in naming consistent to People. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ui/webui/settings/sync_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/signin/fake_signin_manager_builder.h" 15 #include "chrome/browser/signin/fake_signin_manager_builder.h"
(...skipping 21 matching lines...) Expand all
37 using ::testing::_; 37 using ::testing::_;
38 using ::testing::Mock; 38 using ::testing::Mock;
39 using ::testing::Return; 39 using ::testing::Return;
40 using ::testing::ReturnRef; 40 using ::testing::ReturnRef;
41 using ::testing::Values; 41 using ::testing::Values;
42 42
43 typedef GoogleServiceAuthError AuthError; 43 typedef GoogleServiceAuthError AuthError;
44 44
45 namespace { 45 namespace {
46 46
47 MATCHER_P(ModelTypeSetMatches, value, "") { return arg.Equals(value); } 47 MATCHER_P(ModelTypeSetMatches, value, "") {
48 return arg.Equals(value);
49 }
48 50
49 const char kTestUser[] = "chrome.p13n.test@gmail.com"; 51 const char kTestUser[] = "chrome.p13n.test@gmail.com";
50 52
51 // Returns a ModelTypeSet with all user selectable types set. 53 // Returns a ModelTypeSet with all user selectable types set.
52 syncer::ModelTypeSet GetAllTypes() { 54 syncer::ModelTypeSet GetAllTypes() {
53 return syncer::UserSelectableTypes(); 55 return syncer::UserSelectableTypes();
54 } 56 }
55 57
56 enum SyncAllDataConfig { 58 enum SyncAllDataConfig { SYNC_ALL_DATA, CHOOSE_WHAT_TO_SYNC, SYNC_NOTHING };
57 SYNC_ALL_DATA,
58 CHOOSE_WHAT_TO_SYNC,
59 SYNC_NOTHING
60 };
61 59
62 enum EncryptAllConfig { 60 enum EncryptAllConfig { ENCRYPT_ALL_DATA, ENCRYPT_PASSWORDS };
63 ENCRYPT_ALL_DATA,
64 ENCRYPT_PASSWORDS
65 };
66 61
67 // Create a json-format string with the key/value pairs appropriate for a call 62 // Create a json-format string with the key/value pairs appropriate for a call
68 // to HandleConfigure(). If |extra_values| is non-null, then the values from 63 // to HandleConfigure(). If |extra_values| is non-null, then the values from
69 // the passed dictionary are added to the json. 64 // the passed dictionary are added to the json.
70 std::string GetConfiguration(const base::DictionaryValue* extra_values, 65 std::string GetConfiguration(const base::DictionaryValue* extra_values,
71 SyncAllDataConfig sync_all, 66 SyncAllDataConfig sync_all,
72 syncer::ModelTypeSet types, 67 syncer::ModelTypeSet types,
73 const std::string& passphrase, 68 const std::string& passphrase,
74 EncryptAllConfig encrypt_all) { 69 EncryptAllConfig encrypt_all) {
75 base::DictionaryValue result; 70 base::DictionaryValue result;
(...skipping 23 matching lines...) Expand all
99 } 94 }
100 95
101 // Checks whether the passed |dictionary| contains a |key| with the given 96 // Checks whether the passed |dictionary| contains a |key| with the given
102 // |expected_value|. If |omit_if_false| is true, then the value should only 97 // |expected_value|. If |omit_if_false| is true, then the value should only
103 // be present if |expected_value| is true. 98 // be present if |expected_value| is true.
104 void CheckBool(const base::DictionaryValue* dictionary, 99 void CheckBool(const base::DictionaryValue* dictionary,
105 const std::string& key, 100 const std::string& key,
106 bool expected_value, 101 bool expected_value,
107 bool omit_if_false) { 102 bool omit_if_false) {
108 if (omit_if_false && !expected_value) { 103 if (omit_if_false && !expected_value) {
109 EXPECT_FALSE(dictionary->HasKey(key)) << 104 EXPECT_FALSE(dictionary->HasKey(key)) << "Did not expect to find value for "
110 "Did not expect to find value for " << key; 105 << key;
111 } else { 106 } else {
112 bool actual_value; 107 bool actual_value;
113 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << 108 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value))
114 "No value found for " << key; 109 << "No value found for " << key;
115 EXPECT_EQ(expected_value, actual_value) << 110 EXPECT_EQ(expected_value, actual_value) << "Mismatch found for " << key;
116 "Mismatch found for " << key;
117 } 111 }
118 } 112 }
119 113
120 void CheckBool(const base::DictionaryValue* dictionary, 114 void CheckBool(const base::DictionaryValue* dictionary,
121 const std::string& key, 115 const std::string& key,
122 bool expected_value) { 116 bool expected_value) {
123 return CheckBool(dictionary, key, expected_value, false); 117 return CheckBool(dictionary, key, expected_value, false);
124 } 118 }
125 119
126 // Checks to make sure that the values stored in |dictionary| match the values 120 // Checks to make sure that the values stored in |dictionary| match the values
(...skipping 14 matching lines...) Expand all
141 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); 135 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES));
142 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); 136 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS));
143 CheckBool(dictionary, "wifiCredentialsSynced", 137 CheckBool(dictionary, "wifiCredentialsSynced",
144 types.Has(syncer::WIFI_CREDENTIALS)); 138 types.Has(syncer::WIFI_CREDENTIALS));
145 } 139 }
146 140
147 } // namespace 141 } // namespace
148 142
149 namespace settings { 143 namespace settings {
150 144
151 class TestingSyncHandler : public SyncHandler { 145 class TestingPeopleHandler : public PeopleHandler {
152 public: 146 public:
153 TestingSyncHandler(content::WebUI* web_ui, Profile* profile) 147 TestingPeopleHandler(content::WebUI* web_ui, Profile* profile)
154 : SyncHandler(profile) { 148 : PeopleHandler(profile) {
155 set_web_ui(web_ui); 149 set_web_ui(web_ui);
156 } 150 }
157 ~TestingSyncHandler() override { 151 ~TestingPeopleHandler() override {
158 // TODO(tommycli): SyncHandler needs this call to destruct properly in the 152 // TODO(tommycli): PeopleHandler needs this call to destruct properly in the
159 // unit testing context. See the destructor to SyncHandler. This is hacky. 153 // unit testing context. See the destructor to PeopleHandler. This is hacky.
160 set_web_ui(nullptr); 154 set_web_ui(nullptr);
161 } 155 }
162 156
163 void FocusUI() override {} 157 void FocusUI() override {}
164 158
165 using SyncHandler::is_configuring_sync; 159 using PeopleHandler::is_configuring_sync;
166 160
167 private: 161 private:
168 #if !defined(OS_CHROMEOS) 162 #if !defined(OS_CHROMEOS)
169 void DisplayGaiaLoginInNewTabOrWindow( 163 void DisplayGaiaLoginInNewTabOrWindow(
170 signin_metrics::AccessPoint access_point) override {} 164 signin_metrics::AccessPoint access_point) override {}
171 #endif 165 #endif
172 166
173 DISALLOW_COPY_AND_ASSIGN(TestingSyncHandler); 167 DISALLOW_COPY_AND_ASSIGN(TestingPeopleHandler);
174 }; 168 };
175 169
176 // The boolean parameter indicates whether the test is run with ClientOAuth 170 // The boolean parameter indicates whether the test is run with ClientOAuth
177 // or not. The test parameter is a bool: whether or not to test with/ 171 // or not. The test parameter is a bool: whether or not to test with/
178 // /ClientLogin enabled or not. 172 // /ClientLogin enabled or not.
179 class SyncHandlerTest : public testing::Test { 173 class PeopleHandlerTest : public testing::Test {
180 public: 174 public:
181 SyncHandlerTest() : error_(GoogleServiceAuthError::NONE) {} 175 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
182 void SetUp() override { 176 void SetUp() override {
183 error_ = GoogleServiceAuthError::AuthErrorNone(); 177 error_ = GoogleServiceAuthError::AuthErrorNone();
184 178
185 TestingProfile::Builder builder; 179 TestingProfile::Builder builder;
186 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), 180 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
187 BuildFakeSigninManagerBase); 181 BuildFakeSigninManagerBase);
188 profile_ = builder.Build(); 182 profile_ = builder.Build();
189 183
190 // Sign in the user. 184 // Sign in the user.
191 mock_signin_ = static_cast<SigninManagerBase*>( 185 mock_signin_ = static_cast<SigninManagerBase*>(
192 SigninManagerFactory::GetForProfile(profile_.get())); 186 SigninManagerFactory::GetForProfile(profile_.get()));
193 std::string username = GetTestUser(); 187 std::string username = GetTestUser();
194 if (!username.empty()) 188 if (!username.empty())
195 mock_signin_->SetAuthenticatedAccountInfo(username, username); 189 mock_signin_->SetAuthenticatedAccountInfo(username, username);
196 190
197 mock_pss_ = static_cast<ProfileSyncServiceMock*>( 191 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
198 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 192 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
199 profile_.get(), 193 profile_.get(),
200 ProfileSyncServiceMock::BuildMockProfileSyncService)); 194 ProfileSyncServiceMock::BuildMockProfileSyncService));
201 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 195 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
202 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( 196 ON_CALL(*mock_pss_, GetPassphraseType())
203 Return(syncer::IMPLICIT_PASSPHRASE)); 197 .WillByDefault(Return(syncer::IMPLICIT_PASSPHRASE));
204 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( 198 ON_CALL(*mock_pss_, GetPassphraseTime())
205 Return(base::Time())); 199 .WillByDefault(Return(base::Time()));
206 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( 200 ON_CALL(*mock_pss_, GetExplicitPassphraseTime())
207 Return(base::Time())); 201 .WillByDefault(Return(base::Time()));
208 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) 202 ON_CALL(*mock_pss_, GetRegisteredDataTypes())
209 .WillByDefault(Return(syncer::ModelTypeSet())); 203 .WillByDefault(Return(syncer::ModelTypeSet()));
210 204
211 mock_pss_->Initialize(); 205 mock_pss_->Initialize();
212 206
213 handler_.reset(new TestingSyncHandler(&web_ui_, profile_.get())); 207 handler_.reset(new TestingPeopleHandler(&web_ui_, profile_.get()));
214 } 208 }
215 209
216 // Setup the expectations for calls made when displaying the config page. 210 // Setup the expectations for calls made when displaying the config page.
217 void SetDefaultExpectationsForConfigPage() { 211 void SetDefaultExpectationsForConfigPage() {
218 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 212 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
219 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()) 213 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes())
220 .WillRepeatedly(Return(GetAllTypes())); 214 .WillRepeatedly(Return(GetAllTypes()));
221 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) 215 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes())
222 .WillRepeatedly(Return(GetAllTypes())); 216 .WillRepeatedly(Return(GetAllTypes()));
223 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) 217 EXPECT_CALL(*mock_pss_, GetActiveDataTypes())
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 268 }
275 269
276 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock 270 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock
277 // so this helper routine dispatches an OnStateChanged() notification to the 271 // so this helper routine dispatches an OnStateChanged() notification to the
278 // SyncStartupTracker. 272 // SyncStartupTracker.
279 void NotifySyncListeners() { 273 void NotifySyncListeners() {
280 if (handler_->sync_startup_tracker_) 274 if (handler_->sync_startup_tracker_)
281 handler_->sync_startup_tracker_->OnStateChanged(); 275 handler_->sync_startup_tracker_->OnStateChanged();
282 } 276 }
283 277
284 virtual std::string GetTestUser() { 278 virtual std::string GetTestUser() { return std::string(kTestUser); }
285 return std::string(kTestUser);
286 }
287 279
288 content::TestBrowserThreadBundle thread_bundle_; 280 content::TestBrowserThreadBundle thread_bundle_;
289 scoped_ptr<Profile> profile_; 281 scoped_ptr<Profile> profile_;
290 ProfileSyncServiceMock* mock_pss_; 282 ProfileSyncServiceMock* mock_pss_;
291 GoogleServiceAuthError error_; 283 GoogleServiceAuthError error_;
292 SigninManagerBase* mock_signin_; 284 SigninManagerBase* mock_signin_;
293 content::TestWebUI web_ui_; 285 content::TestWebUI web_ui_;
294 scoped_ptr<TestingSyncHandler> handler_; 286 scoped_ptr<TestingPeopleHandler> handler_;
295 }; 287 };
296 288
297 class SyncHandlerFirstSigninTest : public SyncHandlerTest { 289 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest {
298 std::string GetTestUser() override { return std::string(); } 290 std::string GetTestUser() override { return std::string(); }
299 }; 291 };
300 292
301 TEST_F(SyncHandlerTest, Basic) { 293 TEST_F(PeopleHandlerTest, Basic) {}
302 }
303 294
304 #if !defined(OS_CHROMEOS) 295 #if !defined(OS_CHROMEOS)
305 TEST_F(SyncHandlerFirstSigninTest, DisplayBasicLogin) { 296 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) {
306 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 297 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
307 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 298 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
308 .WillRepeatedly(Return(false)); 299 .WillRepeatedly(Return(false));
309 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 300 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
310 .WillRepeatedly(Return(false)); 301 .WillRepeatedly(Return(false));
311 // Ensure that the user is not signed in before calling |HandleStartSignin()|. 302 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
312 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); 303 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
313 manager->SignOut(signin_metrics::SIGNOUT_TEST); 304 manager->SignOut(signin_metrics::SIGNOUT_TEST);
314 handler_->HandleStartSignin(NULL); 305 handler_->HandleStartSignin(NULL);
315 306
316 // Sync setup hands off control to the gaia login tab. 307 // Sync setup hands off control to the gaia login tab.
317 EXPECT_EQ(NULL, 308 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
318 LoginUIServiceFactory::GetForProfile( 309 ->current_login_ui());
dschuyler 2015/12/10 17:55:16 nit: (well, this is a collection of nits): Please
tommycli 2015/12/10 19:34:35 Wrapping with " ->" is pretty common in the Chrom
319 profile_.get())->current_login_ui());
320 310
321 ASSERT_FALSE(handler_->is_configuring_sync()); 311 ASSERT_FALSE(handler_->is_configuring_sync());
322 312
323 handler_->CloseSyncSetup(); 313 handler_->CloseSyncSetup();
324 EXPECT_EQ(NULL, 314 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
325 LoginUIServiceFactory::GetForProfile( 315 ->current_login_ui());
326 profile_.get())->current_login_ui());
327 } 316 }
328 317
329 TEST_F(SyncHandlerTest, ShowSyncSetupWhenNotSignedIn) { 318 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) {
330 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 319 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
331 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 320 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
332 .WillRepeatedly(Return(false)); 321 .WillRepeatedly(Return(false));
333 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 322 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
334 .WillRepeatedly(Return(false)); 323 .WillRepeatedly(Return(false));
335 handler_->HandleShowSetupUI(NULL); 324 handler_->HandleShowSetupUI(NULL);
336 325
337 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 326 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
338 ASSERT_EQ(1U, web_ui_.call_data().size()); 327 ASSERT_EQ(1U, web_ui_.call_data().size());
339 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 328 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
340 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 329 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
341 330
342 ASSERT_FALSE(handler_->is_configuring_sync()); 331 ASSERT_FALSE(handler_->is_configuring_sync());
343 EXPECT_EQ(NULL, 332 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
344 LoginUIServiceFactory::GetForProfile( 333 ->current_login_ui());
345 profile_.get())->current_login_ui());
346 } 334 }
347 #endif // !defined(OS_CHROMEOS) 335 #endif // !defined(OS_CHROMEOS)
348 336
349 // Verifies that the sync setup is terminated correctly when the 337 // Verifies that the sync setup is terminated correctly when the
350 // sync is disabled. 338 // sync is disabled.
351 TEST_F(SyncHandlerTest, HandleSetupUIWhenSyncDisabled) { 339 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) {
352 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true)); 340 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
353 handler_->HandleShowSetupUI(NULL); 341 handler_->HandleShowSetupUI(NULL);
354 342
355 // Sync setup is closed when sync is disabled. 343 // Sync setup is closed when sync is disabled.
356 EXPECT_EQ(NULL, 344 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
357 LoginUIServiceFactory::GetForProfile( 345 ->current_login_ui());
358 profile_.get())->current_login_ui());
359 ASSERT_FALSE(handler_->is_configuring_sync()); 346 ASSERT_FALSE(handler_->is_configuring_sync());
360 } 347 }
361 348
362 // Verifies that the handler correctly handles a cancellation when 349 // Verifies that the handler correctly handles a cancellation when
363 // it is displaying the spinner to the user. 350 // it is displaying the spinner to the user.
364 TEST_F(SyncHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 351 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
365 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 352 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
366 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 353 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
367 .WillRepeatedly(Return(true)); 354 .WillRepeatedly(Return(true));
368 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 355 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
369 .WillRepeatedly(Return(false)); 356 .WillRepeatedly(Return(false));
370 error_ = GoogleServiceAuthError::AuthErrorNone(); 357 error_ = GoogleServiceAuthError::AuthErrorNone();
371 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 358 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
372 359
373 // We're simulating a user setting up sync, which would cause the backend to 360 // We're simulating a user setting up sync, which would cause the backend to
374 // kick off initialization, but not download user data types. The sync 361 // kick off initialization, but not download user data types. The sync
375 // backend will try to download control data types (e.g encryption info), but 362 // backend will try to download control data types (e.g encryption info), but
376 // that won't finish for this test as we're simulating cancelling while the 363 // that won't finish for this test as we're simulating cancelling while the
377 // spinner is showing. 364 // spinner is showing.
378 handler_->HandleShowSetupUI(NULL); 365 handler_->HandleShowSetupUI(NULL);
379 366
380 EXPECT_EQ(handler_.get(), 367 EXPECT_EQ(handler_.get(), LoginUIServiceFactory::GetForProfile(profile_.get())
381 LoginUIServiceFactory::GetForProfile( 368 ->current_login_ui());
382 profile_.get())->current_login_ui());
383 369
384 ExpectSpinnerAndClose(); 370 ExpectSpinnerAndClose();
385 } 371 }
386 372
387 // Verifies that the handler correctly transitions from showing the spinner 373 // Verifies that the handler correctly transitions from showing the spinner
388 // to showing a configuration page when sync setup completes successfully. 374 // to showing a configuration page when sync setup completes successfully.
389 TEST_F(SyncHandlerTest, 375 TEST_F(PeopleHandlerTest,
390 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 376 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
391 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 377 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
392 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 378 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
393 .WillRepeatedly(Return(true)); 379 .WillRepeatedly(Return(true));
394 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 380 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
395 .WillRepeatedly(Return(false)); 381 .WillRepeatedly(Return(false));
396 error_ = GoogleServiceAuthError::AuthErrorNone(); 382 error_ = GoogleServiceAuthError::AuthErrorNone();
397 // Sync backend is stopped initially, and will start up. 383 // Sync backend is stopped initially, and will start up.
398 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 384 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
399 SetDefaultExpectationsForConfigPage(); 385 SetDefaultExpectationsForConfigPage();
(...skipping 30 matching lines...) Expand all
430 CheckBool(dictionary, "encryptAllDataAllowed", true); 416 CheckBool(dictionary, "encryptAllDataAllowed", true);
431 CheckBool(dictionary, "encryptAllData", false); 417 CheckBool(dictionary, "encryptAllData", false);
432 CheckBool(dictionary, "usePassphrase", false); 418 CheckBool(dictionary, "usePassphrase", false);
433 } 419 }
434 420
435 // Verifies the case where the user cancels after the sync backend has 421 // Verifies the case where the user cancels after the sync backend has
436 // initialized (meaning it already transitioned from the spinner to a proper 422 // initialized (meaning it already transitioned from the spinner to a proper
437 // configuration page, tested by 423 // configuration page, tested by
438 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user 424 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user
439 // before the user has continued on. 425 // before the user has continued on.
440 TEST_F(SyncHandlerTest, 426 TEST_F(PeopleHandlerTest,
441 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { 427 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) {
442 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 428 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
443 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 429 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
444 .WillRepeatedly(Return(true)); 430 .WillRepeatedly(Return(true));
445 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 431 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
446 .WillRepeatedly(Return(false)); 432 .WillRepeatedly(Return(false));
447 error_ = GoogleServiceAuthError::AuthErrorNone(); 433 error_ = GoogleServiceAuthError::AuthErrorNone();
448 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 434 EXPECT_CALL(*mock_pss_, IsBackendInitialized())
449 .WillOnce(Return(false)) 435 .WillOnce(Return(false))
450 .WillRepeatedly(Return(true)); 436 .WillRepeatedly(Return(true));
451 SetDefaultExpectationsForConfigPage(); 437 SetDefaultExpectationsForConfigPage();
452 handler_->OpenSyncSetup(nullptr); 438 handler_->OpenSyncSetup(nullptr);
453 439
454 // It's important to tell sync the user cancelled the setup flow before we 440 // It's important to tell sync the user cancelled the setup flow before we
455 // tell it we're through with the setup progress. 441 // tell it we're through with the setup progress.
456 testing::InSequence seq; 442 testing::InSequence seq;
457 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 443 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
458 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); 444 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
459 445
460 handler_->CloseSyncSetup(); 446 handler_->CloseSyncSetup();
461 EXPECT_EQ(NULL, 447 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
462 LoginUIServiceFactory::GetForProfile( 448 ->current_login_ui());
463 profile_.get())->current_login_ui());
464 } 449 }
465 450
466 TEST_F(SyncHandlerTest, 451 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndSigninFailed) {
467 DisplayConfigureWithBackendDisabledAndSigninFailed) {
468 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 452 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
469 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 453 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
470 .WillRepeatedly(Return(true)); 454 .WillRepeatedly(Return(true));
471 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 455 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
472 .WillRepeatedly(Return(false)); 456 .WillRepeatedly(Return(false));
473 error_ = GoogleServiceAuthError::AuthErrorNone(); 457 error_ = GoogleServiceAuthError::AuthErrorNone();
474 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 458 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
475 459
476 handler_->OpenSyncSetup(nullptr); 460 handler_->OpenSyncSetup(nullptr);
477 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 461 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
478 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 462 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
479 std::string page; 463 std::string page;
480 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 464 ASSERT_TRUE(data.arg1()->GetAsString(&page));
481 EXPECT_EQ(page, "spinner"); 465 EXPECT_EQ(page, "spinner");
482 Mock::VerifyAndClearExpectations(mock_pss_); 466 Mock::VerifyAndClearExpectations(mock_pss_);
483 error_ = GoogleServiceAuthError( 467 error_ =
484 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 468 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
485 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 469 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
486 NotifySyncListeners(); 470 NotifySyncListeners();
487 471
488 // On failure, the dialog will be closed. 472 // On failure, the dialog will be closed.
489 EXPECT_EQ(NULL, 473 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
490 LoginUIServiceFactory::GetForProfile( 474 ->current_login_ui());
491 profile_.get())->current_login_ui());
492 } 475 }
493 476
494 #if !defined(OS_CHROMEOS) 477 #if !defined(OS_CHROMEOS)
495 478
496 class SyncHandlerNonCrosTest : public SyncHandlerTest { 479 class PeopleHandlerNonCrosTest : public PeopleHandlerTest {
497 public: 480 public:
498 SyncHandlerNonCrosTest() {} 481 PeopleHandlerNonCrosTest() {}
499 }; 482 };
500 483
501 TEST_F(SyncHandlerNonCrosTest, HandleGaiaAuthFailure) { 484 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) {
502 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 485 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
503 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 486 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
504 .WillRepeatedly(Return(false)); 487 .WillRepeatedly(Return(false));
505 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 488 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
506 .WillRepeatedly(Return(false)); 489 .WillRepeatedly(Return(false));
507 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 490 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
508 .WillRepeatedly(Return(false)); 491 .WillRepeatedly(Return(false));
509 // Open the web UI. 492 // Open the web UI.
510 handler_->OpenSyncSetup(nullptr); 493 handler_->OpenSyncSetup(nullptr);
511 494
512 ASSERT_FALSE(handler_->is_configuring_sync()); 495 ASSERT_FALSE(handler_->is_configuring_sync());
513 } 496 }
514 497
515 // TODO(kochi): We need equivalent tests for ChromeOS. 498 // TODO(kochi): We need equivalent tests for ChromeOS.
516 TEST_F(SyncHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { 499 TEST_F(PeopleHandlerNonCrosTest, UnrecoverableErrorInitializingSync) {
517 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 500 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
518 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 501 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
519 .WillRepeatedly(Return(false)); 502 .WillRepeatedly(Return(false));
520 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 503 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
521 .WillRepeatedly(Return(false)); 504 .WillRepeatedly(Return(false));
522 // Open the web UI. 505 // Open the web UI.
523 handler_->OpenSyncSetup(nullptr); 506 handler_->OpenSyncSetup(nullptr);
524 507
525 ASSERT_FALSE(handler_->is_configuring_sync()); 508 ASSERT_FALSE(handler_->is_configuring_sync());
526 } 509 }
527 510
528 TEST_F(SyncHandlerNonCrosTest, GaiaErrorInitializingSync) { 511 TEST_F(PeopleHandlerNonCrosTest, GaiaErrorInitializingSync) {
529 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 512 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
530 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 513 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
531 .WillRepeatedly(Return(false)); 514 .WillRepeatedly(Return(false));
532 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 515 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
533 .WillRepeatedly(Return(false)); 516 .WillRepeatedly(Return(false));
534 // Open the web UI. 517 // Open the web UI.
535 handler_->OpenSyncSetup(nullptr); 518 handler_->OpenSyncSetup(nullptr);
536 519
537 ASSERT_FALSE(handler_->is_configuring_sync()); 520 ASSERT_FALSE(handler_->is_configuring_sync());
538 } 521 }
539 522
540 #endif // #if !defined(OS_CHROMEOS) 523 #endif // #if !defined(OS_CHROMEOS)
541 524
542 TEST_F(SyncHandlerTest, TestSyncEverything) { 525 TEST_F(PeopleHandlerTest, TestSyncEverything) {
543 std::string args = GetConfiguration( 526 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(),
544 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 527 std::string(), ENCRYPT_PASSWORDS);
545 base::ListValue list_args; 528 base::ListValue list_args;
546 list_args.Append(new base::StringValue(args)); 529 list_args.Append(new base::StringValue(args));
547 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 530 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
548 .WillRepeatedly(Return(false)); 531 .WillRepeatedly(Return(false));
549 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 532 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
550 .WillRepeatedly(Return(false));
551 SetupInitializedProfileSyncService(); 533 SetupInitializedProfileSyncService();
552 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 534 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
553 handler_->HandleConfigure(&list_args); 535 handler_->HandleConfigure(&list_args);
554 536
555 // Ensure that we navigated to the "done" state since we don't need a 537 // Ensure that we navigated to the "done" state since we don't need a
556 // passphrase. 538 // passphrase.
557 ExpectDone(); 539 ExpectDone();
558 } 540 }
559 541
560 TEST_F(SyncHandlerTest, TestSyncNothing) { 542 TEST_F(PeopleHandlerTest, TestSyncNothing) {
561 std::string args = GetConfiguration( 543 std::string args = GetConfiguration(NULL, SYNC_NOTHING, GetAllTypes(),
562 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 544 std::string(), ENCRYPT_PASSWORDS);
563 base::ListValue list_args; 545 base::ListValue list_args;
564 list_args.Append(new base::StringValue(args)); 546 list_args.Append(new base::StringValue(args));
565 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 547 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
566 SetupInitializedProfileSyncService(); 548 SetupInitializedProfileSyncService();
567 handler_->HandleConfigure(&list_args); 549 handler_->HandleConfigure(&list_args);
568 550
569 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 551 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
570 ASSERT_EQ(1U, web_ui_.call_data().size()); 552 ASSERT_EQ(1U, web_ui_.call_data().size());
571 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 553 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
572 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 554 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
573 } 555 }
574 556
575 TEST_F(SyncHandlerTest, TurnOnEncryptAll) { 557 TEST_F(PeopleHandlerTest, TurnOnEncryptAll) {
576 std::string args = GetConfiguration( 558 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(),
577 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); 559 std::string(), ENCRYPT_ALL_DATA);
578 base::ListValue list_args; 560 base::ListValue list_args;
579 list_args.Append(new base::StringValue(args)); 561 list_args.Append(new base::StringValue(args));
580 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 562 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
581 .WillRepeatedly(Return(false)); 563 .WillRepeatedly(Return(false));
582 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 564 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
583 .WillRepeatedly(Return(false));
584 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 565 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
585 .WillRepeatedly(Return(true)); 566 .WillRepeatedly(Return(true));
586 SetupInitializedProfileSyncService(); 567 SetupInitializedProfileSyncService();
587 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()); 568 EXPECT_CALL(*mock_pss_, EnableEncryptEverything());
588 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 569 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
589 handler_->HandleConfigure(&list_args); 570 handler_->HandleConfigure(&list_args);
590 571
591 // Ensure that we navigated to the "done" state since we don't need a 572 // Ensure that we navigated to the "done" state since we don't need a
592 // passphrase. 573 // passphrase.
593 ExpectDone(); 574 ExpectDone();
594 } 575 }
595 576
596 TEST_F(SyncHandlerTest, TestPassphraseStillRequired) { 577 TEST_F(PeopleHandlerTest, TestPassphraseStillRequired) {
597 std::string args = GetConfiguration( 578 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(),
598 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 579 std::string(), ENCRYPT_PASSWORDS);
599 base::ListValue list_args; 580 base::ListValue list_args;
600 list_args.Append(new base::StringValue(args)); 581 list_args.Append(new base::StringValue(args));
601 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 582 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
602 .WillRepeatedly(Return(true)); 583 .WillRepeatedly(Return(true));
603 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 584 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true));
604 .WillRepeatedly(Return(true));
605 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 585 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
606 .WillRepeatedly(Return(false)); 586 .WillRepeatedly(Return(false));
607 SetupInitializedProfileSyncService(); 587 SetupInitializedProfileSyncService();
608 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 588 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
609 SetDefaultExpectationsForConfigPage(); 589 SetDefaultExpectationsForConfigPage();
610 590
611 // We should navigate back to the configure page since we need a passphrase. 591 // We should navigate back to the configure page since we need a passphrase.
612 handler_->HandleConfigure(&list_args); 592 handler_->HandleConfigure(&list_args);
613 593
614 ExpectConfig(); 594 ExpectConfig();
615 } 595 }
616 596
617 TEST_F(SyncHandlerTest, SuccessfullySetPassphrase) { 597 TEST_F(PeopleHandlerTest, SuccessfullySetPassphrase) {
618 base::DictionaryValue dict; 598 base::DictionaryValue dict;
619 dict.SetBoolean("isGooglePassphrase", true); 599 dict.SetBoolean("isGooglePassphrase", true);
620 std::string args = GetConfiguration(&dict, 600 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(),
621 SYNC_ALL_DATA, 601 "gaiaPassphrase", ENCRYPT_PASSWORDS);
622 GetAllTypes(),
623 "gaiaPassphrase",
624 ENCRYPT_PASSWORDS);
625 base::ListValue list_args; 602 base::ListValue list_args;
626 list_args.Append(new base::StringValue(args)); 603 list_args.Append(new base::StringValue(args));
627 // Act as if an encryption passphrase is required the first time, then never 604 // Act as if an encryption passphrase is required the first time, then never
628 // again after that. 605 // again after that.
629 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); 606 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true));
630 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 607 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
631 .WillRepeatedly(Return(false)); 608 .WillRepeatedly(Return(false));
632 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 609 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
633 .WillRepeatedly(Return(false)); 610 .WillRepeatedly(Return(false));
634 SetupInitializedProfileSyncService(); 611 SetupInitializedProfileSyncService();
635 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 612 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
636 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")). 613 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase"))
637 WillOnce(Return(true)); 614 .WillOnce(Return(true));
638 615
639 handler_->HandleConfigure(&list_args); 616 handler_->HandleConfigure(&list_args);
640 // We should navigate to "done" page since we finished configuring. 617 // We should navigate to "done" page since we finished configuring.
641 ExpectDone(); 618 ExpectDone();
642 } 619 }
643 620
644 TEST_F(SyncHandlerTest, SelectCustomEncryption) { 621 TEST_F(PeopleHandlerTest, SelectCustomEncryption) {
645 base::DictionaryValue dict; 622 base::DictionaryValue dict;
646 dict.SetBoolean("isGooglePassphrase", false); 623 dict.SetBoolean("isGooglePassphrase", false);
647 std::string args = GetConfiguration(&dict, 624 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(),
648 SYNC_ALL_DATA, 625 "custom_passphrase", ENCRYPT_PASSWORDS);
649 GetAllTypes(),
650 "custom_passphrase",
651 ENCRYPT_PASSWORDS);
652 base::ListValue list_args; 626 base::ListValue list_args;
653 list_args.Append(new base::StringValue(args)); 627 list_args.Append(new base::StringValue(args));
654 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 628 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
655 .WillRepeatedly(Return(false)); 629 .WillRepeatedly(Return(false));
656 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 630 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
657 .WillRepeatedly(Return(false));
658 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 631 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
659 .WillRepeatedly(Return(false)); 632 .WillRepeatedly(Return(false));
660 SetupInitializedProfileSyncService(); 633 SetupInitializedProfileSyncService();
661 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 634 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
662 EXPECT_CALL(*mock_pss_, 635 EXPECT_CALL(*mock_pss_,
663 SetEncryptionPassphrase("custom_passphrase", 636 SetEncryptionPassphrase("custom_passphrase",
664 ProfileSyncService::EXPLICIT)); 637 ProfileSyncService::EXPLICIT));
665 638
666 handler_->HandleConfigure(&list_args); 639 handler_->HandleConfigure(&list_args);
667 // We should navigate to "done" page since we finished configuring. 640 // We should navigate to "done" page since we finished configuring.
668 ExpectDone(); 641 ExpectDone();
669 } 642 }
670 643
671 TEST_F(SyncHandlerTest, UnsuccessfullySetPassphrase) { 644 TEST_F(PeopleHandlerTest, UnsuccessfullySetPassphrase) {
672 base::DictionaryValue dict; 645 base::DictionaryValue dict;
673 dict.SetBoolean("isGooglePassphrase", true); 646 dict.SetBoolean("isGooglePassphrase", true);
674 std::string args = GetConfiguration(&dict, 647 std::string args = GetConfiguration(&dict, SYNC_ALL_DATA, GetAllTypes(),
675 SYNC_ALL_DATA, 648 "invalid_passphrase", ENCRYPT_PASSWORDS);
676 GetAllTypes(),
677 "invalid_passphrase",
678 ENCRYPT_PASSWORDS);
679 base::ListValue list_args; 649 base::ListValue list_args;
680 list_args.Append(new base::StringValue(args)); 650 list_args.Append(new base::StringValue(args));
681 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 651 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
682 .WillRepeatedly(Return(true)); 652 .WillRepeatedly(Return(true));
683 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 653 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true));
684 .WillRepeatedly(Return(true));
685 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 654 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
686 .WillRepeatedly(Return(false)); 655 .WillRepeatedly(Return(false));
687 SetupInitializedProfileSyncService(); 656 SetupInitializedProfileSyncService();
688 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 657 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
689 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")). 658 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase"))
690 WillOnce(Return(false)); 659 .WillOnce(Return(false));
691 660
692 SetDefaultExpectationsForConfigPage(); 661 SetDefaultExpectationsForConfigPage();
693 // We should navigate back to the configure page since we need a passphrase. 662 // We should navigate back to the configure page since we need a passphrase.
694 handler_->HandleConfigure(&list_args); 663 handler_->HandleConfigure(&list_args);
695 664
696 ExpectConfig(); 665 ExpectConfig();
697 666
698 // Make sure we display an error message to the user due to the failed 667 // Make sure we display an error message to the user due to the failed
699 // passphrase. 668 // passphrase.
700 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 669 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
701 const base::DictionaryValue* dictionary = nullptr; 670 const base::DictionaryValue* dictionary = nullptr;
702 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 671 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
703 CheckBool(dictionary, "passphraseFailed", true); 672 CheckBool(dictionary, "passphraseFailed", true);
704 } 673 }
705 674
706 // Walks through each user selectable type, and tries to sync just that single 675 // Walks through each user selectable type, and tries to sync just that single
707 // data type. 676 // data type.
708 TEST_F(SyncHandlerTest, TestSyncIndividualTypes) { 677 TEST_F(PeopleHandlerTest, TestSyncIndividualTypes) {
709 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); 678 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
710 syncer::ModelTypeSet::Iterator it; 679 syncer::ModelTypeSet::Iterator it;
711 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { 680 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
712 syncer::ModelTypeSet type_to_set; 681 syncer::ModelTypeSet type_to_set;
713 type_to_set.Put(it.Get()); 682 type_to_set.Put(it.Get());
714 std::string args = GetConfiguration(NULL, 683 std::string args = GetConfiguration(NULL, CHOOSE_WHAT_TO_SYNC, type_to_set,
715 CHOOSE_WHAT_TO_SYNC, 684 std::string(), ENCRYPT_PASSWORDS);
716 type_to_set,
717 std::string(),
718 ENCRYPT_PASSWORDS);
719 base::ListValue list_args; 685 base::ListValue list_args;
720 list_args.Append(new base::StringValue(args)); 686 list_args.Append(new base::StringValue(args));
721 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 687 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
722 .WillRepeatedly(Return(false)); 688 .WillRepeatedly(Return(false));
723 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 689 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
724 .WillRepeatedly(Return(false)); 690 .WillRepeatedly(Return(false));
725 SetupInitializedProfileSyncService(); 691 SetupInitializedProfileSyncService();
726 EXPECT_CALL(*mock_pss_, 692 EXPECT_CALL(*mock_pss_,
727 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); 693 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set)));
728 handler_->HandleConfigure(&list_args); 694 handler_->HandleConfigure(&list_args);
729 695
730 ExpectDone(); 696 ExpectDone();
731 Mock::VerifyAndClearExpectations(mock_pss_); 697 Mock::VerifyAndClearExpectations(mock_pss_);
732 web_ui_.ClearTrackedCalls(); 698 web_ui_.ClearTrackedCalls();
733 } 699 }
734 } 700 }
735 701
736 TEST_F(SyncHandlerTest, TestSyncAllManually) { 702 TEST_F(PeopleHandlerTest, TestSyncAllManually) {
737 std::string args = GetConfiguration(NULL, 703 std::string args = GetConfiguration(NULL, CHOOSE_WHAT_TO_SYNC, GetAllTypes(),
738 CHOOSE_WHAT_TO_SYNC, 704 std::string(), ENCRYPT_PASSWORDS);
739 GetAllTypes(),
740 std::string(),
741 ENCRYPT_PASSWORDS);
742 base::ListValue list_args; 705 base::ListValue list_args;
743 list_args.Append(new base::StringValue(args)); 706 list_args.Append(new base::StringValue(args));
744 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 707 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
745 .WillRepeatedly(Return(false)); 708 .WillRepeatedly(Return(false));
746 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 709 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
747 .WillRepeatedly(Return(false));
748 SetupInitializedProfileSyncService(); 710 SetupInitializedProfileSyncService();
749 EXPECT_CALL(*mock_pss_, 711 EXPECT_CALL(*mock_pss_,
750 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); 712 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes())));
751 handler_->HandleConfigure(&list_args); 713 handler_->HandleConfigure(&list_args);
752 714
753 ExpectDone(); 715 ExpectDone();
754 } 716 }
755 717
756 TEST_F(SyncHandlerTest, ShowSyncSetup) { 718 TEST_F(PeopleHandlerTest, ShowSyncSetup) {
757 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 719 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
758 .WillRepeatedly(Return(false));
759 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 720 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
760 .WillRepeatedly(Return(false)); 721 .WillRepeatedly(Return(false));
761 SetupInitializedProfileSyncService(); 722 SetupInitializedProfileSyncService();
762 // This should display the sync setup dialog (not login). 723 // This should display the sync setup dialog (not login).
763 SetDefaultExpectationsForConfigPage(); 724 SetDefaultExpectationsForConfigPage();
764 handler_->OpenSyncSetup(nullptr); 725 handler_->OpenSyncSetup(nullptr);
765 726
766 ExpectConfig(); 727 ExpectConfig();
767 } 728 }
768 729
769 // We do not display signin on chromeos in the case of auth error. 730 // We do not display signin on chromeos in the case of auth error.
770 TEST_F(SyncHandlerTest, ShowSigninOnAuthError) { 731 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) {
771 // Initialize the system to a signed in state, but with an auth error. 732 // Initialize the system to a signed in state, but with an auth error.
772 error_ = GoogleServiceAuthError( 733 error_ =
773 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 734 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
774 735
775 SetupInitializedProfileSyncService(); 736 SetupInitializedProfileSyncService();
776 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 737 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
777 FakeAuthStatusProvider provider( 738 FakeAuthStatusProvider provider(
778 SigninErrorControllerFactory::GetForProfile(profile_.get())); 739 SigninErrorControllerFactory::GetForProfile(profile_.get()));
779 provider.SetAuthError(kTestUser, error_); 740 provider.SetAuthError(kTestUser, error_);
780 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 741 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
781 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 742 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
782 .WillRepeatedly(Return(true)); 743 .WillRepeatedly(Return(true));
783 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 744 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
784 .WillRepeatedly(Return(false));
785 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 745 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
786 .WillRepeatedly(Return(false)); 746 .WillRepeatedly(Return(false));
787 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 747 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
788 748
789 #if defined(OS_CHROMEOS) 749 #if defined(OS_CHROMEOS)
790 // On ChromeOS, auth errors are ignored - instead we just try to start the 750 // On ChromeOS, auth errors are ignored - instead we just try to start the
791 // sync backend (which will fail due to the auth error). This should only 751 // sync backend (which will fail due to the auth error). This should only
792 // happen if the user manually navigates to chrome://settings/syncSetup - 752 // happen if the user manually navigates to chrome://settings/syncSetup -
793 // clicking on the button in the UI will sign the user out rather than 753 // clicking on the button in the UI will sign the user out rather than
794 // displaying a spinner. Should be no visible UI on ChromeOS in this case. 754 // displaying a spinner. Should be no visible UI on ChromeOS in this case.
795 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( 755 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
796 profile_.get())->current_login_ui()); 756 ->current_login_ui());
797 #else 757 #else
798 758
799 // On ChromeOS, this should display the spinner while we try to startup the 759 // On ChromeOS, this should display the spinner while we try to startup the
800 // sync backend, and on desktop this displays the login dialog. 760 // sync backend, and on desktop this displays the login dialog.
801 handler_->OpenSyncSetup(nullptr); 761 handler_->OpenSyncSetup(nullptr);
802 762
803 // Sync setup is closed when re-auth is in progress. 763 // Sync setup is closed when re-auth is in progress.
804 EXPECT_EQ(NULL, 764 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(profile_.get())
805 LoginUIServiceFactory::GetForProfile( 765 ->current_login_ui());
806 profile_.get())->current_login_ui());
807 766
808 ASSERT_FALSE(handler_->is_configuring_sync()); 767 ASSERT_FALSE(handler_->is_configuring_sync());
809 #endif 768 #endif
810 } 769 }
811 770
812 TEST_F(SyncHandlerTest, ShowSetupSyncEverything) { 771 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) {
813 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 772 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
814 .WillRepeatedly(Return(false));
815 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 773 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
816 .WillRepeatedly(Return(false)); 774 .WillRepeatedly(Return(false));
817 SetupInitializedProfileSyncService(); 775 SetupInitializedProfileSyncService();
818 SetDefaultExpectationsForConfigPage(); 776 SetDefaultExpectationsForConfigPage();
819 // This should display the sync setup dialog (not login). 777 // This should display the sync setup dialog (not login).
820 handler_->OpenSyncSetup(nullptr); 778 handler_->OpenSyncSetup(nullptr);
821 779
822 ExpectConfig(); 780 ExpectConfig();
823 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 781 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
824 const base::DictionaryValue* dictionary = nullptr; 782 const base::DictionaryValue* dictionary = nullptr;
825 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 783 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
826 CheckBool(dictionary, "syncAllDataTypes", true); 784 CheckBool(dictionary, "syncAllDataTypes", true);
827 CheckBool(dictionary, "appsRegistered", true); 785 CheckBool(dictionary, "appsRegistered", true);
828 CheckBool(dictionary, "autofillRegistered", true); 786 CheckBool(dictionary, "autofillRegistered", true);
829 CheckBool(dictionary, "bookmarksRegistered", true); 787 CheckBool(dictionary, "bookmarksRegistered", true);
830 CheckBool(dictionary, "extensionsRegistered", true); 788 CheckBool(dictionary, "extensionsRegistered", true);
831 CheckBool(dictionary, "passwordsRegistered", true); 789 CheckBool(dictionary, "passwordsRegistered", true);
832 CheckBool(dictionary, "preferencesRegistered", true); 790 CheckBool(dictionary, "preferencesRegistered", true);
833 CheckBool(dictionary, "wifiCredentialsRegistered", true); 791 CheckBool(dictionary, "wifiCredentialsRegistered", true);
834 CheckBool(dictionary, "tabsRegistered", true); 792 CheckBool(dictionary, "tabsRegistered", true);
835 CheckBool(dictionary, "themesRegistered", true); 793 CheckBool(dictionary, "themesRegistered", true);
836 CheckBool(dictionary, "typedUrlsRegistered", true); 794 CheckBool(dictionary, "typedUrlsRegistered", true);
837 CheckBool(dictionary, "showPassphrase", false); 795 CheckBool(dictionary, "showPassphrase", false);
838 CheckBool(dictionary, "usePassphrase", false); 796 CheckBool(dictionary, "usePassphrase", false);
839 CheckBool(dictionary, "passphraseFailed", false); 797 CheckBool(dictionary, "passphraseFailed", false);
840 CheckBool(dictionary, "encryptAllData", false); 798 CheckBool(dictionary, "encryptAllData", false);
841 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); 799 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes());
842 } 800 }
843 801
844 TEST_F(SyncHandlerTest, ShowSetupManuallySyncAll) { 802 TEST_F(PeopleHandlerTest, ShowSetupManuallySyncAll) {
845 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 803 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
846 .WillRepeatedly(Return(false));
847 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 804 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
848 .WillRepeatedly(Return(false)); 805 .WillRepeatedly(Return(false));
849 SetupInitializedProfileSyncService(); 806 SetupInitializedProfileSyncService();
850 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); 807 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
851 sync_prefs.SetKeepEverythingSynced(false); 808 sync_prefs.SetKeepEverythingSynced(false);
852 SetDefaultExpectationsForConfigPage(); 809 SetDefaultExpectationsForConfigPage();
853 // This should display the sync setup dialog (not login). 810 // This should display the sync setup dialog (not login).
854 handler_->OpenSyncSetup(nullptr); 811 handler_->OpenSyncSetup(nullptr);
855 812
856 ExpectConfig(); 813 ExpectConfig();
857 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 814 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
858 const base::DictionaryValue* dictionary = nullptr; 815 const base::DictionaryValue* dictionary = nullptr;
859 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 816 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
860 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); 817 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes());
861 } 818 }
862 819
863 TEST_F(SyncHandlerTest, ShowSetupSyncForAllTypesIndividually) { 820 TEST_F(PeopleHandlerTest, ShowSetupSyncForAllTypesIndividually) {
864 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); 821 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
865 syncer::ModelTypeSet::Iterator it; 822 syncer::ModelTypeSet::Iterator it;
866 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { 823 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
867 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 824 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
868 .WillRepeatedly(Return(false)); 825 .WillRepeatedly(Return(false));
869 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 826 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
870 .WillRepeatedly(Return(false)); 827 .WillRepeatedly(Return(false));
871 SetupInitializedProfileSyncService(); 828 SetupInitializedProfileSyncService();
872 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); 829 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
873 sync_prefs.SetKeepEverythingSynced(false); 830 sync_prefs.SetKeepEverythingSynced(false);
874 SetDefaultExpectationsForConfigPage(); 831 SetDefaultExpectationsForConfigPage();
875 syncer::ModelTypeSet types; 832 syncer::ModelTypeSet types;
876 types.Put(it.Get()); 833 types.Put(it.Get());
877 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). 834 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes())
878 WillRepeatedly(Return(types)); 835 .WillRepeatedly(Return(types));
879 836
880 // This should display the sync setup dialog (not login). 837 // This should display the sync setup dialog (not login).
881 handler_->OpenSyncSetup(nullptr); 838 handler_->OpenSyncSetup(nullptr);
882 839
883 ExpectConfig(); 840 ExpectConfig();
884 // Close the config overlay. 841 // Close the config overlay.
885 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed( 842 LoginUIServiceFactory::GetForProfile(profile_.get())
886 handler_.get()); 843 ->LoginUIClosed(handler_.get());
887 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 844 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
888 const base::DictionaryValue* dictionary = nullptr; 845 const base::DictionaryValue* dictionary = nullptr;
889 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 846 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
890 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); 847 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types);
891 Mock::VerifyAndClearExpectations(mock_pss_); 848 Mock::VerifyAndClearExpectations(mock_pss_);
892 // Clean up so we can loop back to display the dialog again. 849 // Clean up so we can loop back to display the dialog again.
893 web_ui_.ClearTrackedCalls(); 850 web_ui_.ClearTrackedCalls();
894 } 851 }
895 } 852 }
896 853
897 TEST_F(SyncHandlerTest, ShowSetupGaiaPassphraseRequired) { 854 TEST_F(PeopleHandlerTest, ShowSetupGaiaPassphraseRequired) {
898 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 855 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true));
899 .WillRepeatedly(Return(true));
900 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 856 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
901 .WillRepeatedly(Return(false)); 857 .WillRepeatedly(Return(false));
902 SetupInitializedProfileSyncService(); 858 SetupInitializedProfileSyncService();
903 SetDefaultExpectationsForConfigPage(); 859 SetDefaultExpectationsForConfigPage();
904 860
905 // This should display the sync setup dialog (not login). 861 // This should display the sync setup dialog (not login).
906 handler_->OpenSyncSetup(nullptr); 862 handler_->OpenSyncSetup(nullptr);
907 863
908 ExpectConfig(); 864 ExpectConfig();
909 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 865 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
910 const base::DictionaryValue* dictionary = nullptr; 866 const base::DictionaryValue* dictionary = nullptr;
911 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 867 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
912 CheckBool(dictionary, "showPassphrase", true); 868 CheckBool(dictionary, "showPassphrase", true);
913 CheckBool(dictionary, "usePassphrase", false); 869 CheckBool(dictionary, "usePassphrase", false);
914 CheckBool(dictionary, "passphraseFailed", false); 870 CheckBool(dictionary, "passphraseFailed", false);
915 } 871 }
916 872
917 TEST_F(SyncHandlerTest, ShowSetupCustomPassphraseRequired) { 873 TEST_F(PeopleHandlerTest, ShowSetupCustomPassphraseRequired) {
918 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 874 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(true));
919 .WillRepeatedly(Return(true));
920 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 875 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
921 .WillRepeatedly(Return(true)); 876 .WillRepeatedly(Return(true));
922 EXPECT_CALL(*mock_pss_, GetPassphraseType()) 877 EXPECT_CALL(*mock_pss_, GetPassphraseType())
923 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE)); 878 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE));
924 SetupInitializedProfileSyncService(); 879 SetupInitializedProfileSyncService();
925 SetDefaultExpectationsForConfigPage(); 880 SetDefaultExpectationsForConfigPage();
926 881
927 // This should display the sync setup dialog (not login). 882 // This should display the sync setup dialog (not login).
928 handler_->OpenSyncSetup(nullptr); 883 handler_->OpenSyncSetup(nullptr);
929 884
930 ExpectConfig(); 885 ExpectConfig();
931 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 886 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
932 const base::DictionaryValue* dictionary = nullptr; 887 const base::DictionaryValue* dictionary = nullptr;
933 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 888 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
934 CheckBool(dictionary, "showPassphrase", true); 889 CheckBool(dictionary, "showPassphrase", true);
935 CheckBool(dictionary, "usePassphrase", true); 890 CheckBool(dictionary, "usePassphrase", true);
936 CheckBool(dictionary, "passphraseFailed", false); 891 CheckBool(dictionary, "passphraseFailed", false);
937 } 892 }
938 893
939 TEST_F(SyncHandlerTest, ShowSetupEncryptAll) { 894 TEST_F(PeopleHandlerTest, ShowSetupEncryptAll) {
940 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 895 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
941 .WillRepeatedly(Return(false));
942 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 896 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
943 .WillRepeatedly(Return(false)); 897 .WillRepeatedly(Return(false));
944 SetupInitializedProfileSyncService(); 898 SetupInitializedProfileSyncService();
945 SetDefaultExpectationsForConfigPage(); 899 SetDefaultExpectationsForConfigPage();
946 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) 900 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled())
947 .WillRepeatedly(Return(true)); 901 .WillRepeatedly(Return(true));
948 902
949 // This should display the sync setup dialog (not login). 903 // This should display the sync setup dialog (not login).
950 handler_->OpenSyncSetup(nullptr); 904 handler_->OpenSyncSetup(nullptr);
951 905
952 ExpectConfig(); 906 ExpectConfig();
953 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 907 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
954 const base::DictionaryValue* dictionary = nullptr; 908 const base::DictionaryValue* dictionary = nullptr;
955 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 909 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
956 CheckBool(dictionary, "encryptAllData", true); 910 CheckBool(dictionary, "encryptAllData", true);
957 } 911 }
958 912
959 TEST_F(SyncHandlerTest, ShowSetupEncryptAllDisallowed) { 913 TEST_F(PeopleHandlerTest, ShowSetupEncryptAllDisallowed) {
960 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 914 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
961 .WillRepeatedly(Return(false));
962 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 915 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
963 .WillRepeatedly(Return(false)); 916 .WillRepeatedly(Return(false));
964 SetupInitializedProfileSyncService(); 917 SetupInitializedProfileSyncService();
965 SetDefaultExpectationsForConfigPage(); 918 SetDefaultExpectationsForConfigPage();
966 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 919 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
967 .WillRepeatedly(Return(false)); 920 .WillRepeatedly(Return(false));
968 921
969 // This should display the sync setup dialog (not login). 922 // This should display the sync setup dialog (not login).
970 handler_->OpenSyncSetup(nullptr); 923 handler_->OpenSyncSetup(nullptr);
971 924
972 ExpectConfig(); 925 ExpectConfig();
973 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 926 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
974 const base::DictionaryValue* dictionary = nullptr; 927 const base::DictionaryValue* dictionary = nullptr;
975 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 928 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
976 CheckBool(dictionary, "encryptAllData", false); 929 CheckBool(dictionary, "encryptAllData", false);
977 CheckBool(dictionary, "encryptAllDataAllowed", false); 930 CheckBool(dictionary, "encryptAllDataAllowed", false);
978 } 931 }
979 932
980 TEST_F(SyncHandlerTest, TurnOnEncryptAllDisallowed) { 933 TEST_F(PeopleHandlerTest, TurnOnEncryptAllDisallowed) {
981 std::string args = GetConfiguration( 934 std::string args = GetConfiguration(NULL, SYNC_ALL_DATA, GetAllTypes(),
982 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); 935 std::string(), ENCRYPT_ALL_DATA);
983 base::ListValue list_args; 936 base::ListValue list_args;
984 list_args.Append(new base::StringValue(args)); 937 list_args.Append(new base::StringValue(args));
985 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 938 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
986 .WillRepeatedly(Return(false)); 939 .WillRepeatedly(Return(false));
987 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 940 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillRepeatedly(Return(false));
988 .WillRepeatedly(Return(false));
989 SetupInitializedProfileSyncService(); 941 SetupInitializedProfileSyncService();
990 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 942 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
991 .WillRepeatedly(Return(false)); 943 .WillRepeatedly(Return(false));
992 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 944 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
993 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 945 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
994 handler_->HandleConfigure(&list_args); 946 handler_->HandleConfigure(&list_args);
995 947
996 // Ensure that we navigated to the "done" state since we don't need a 948 // Ensure that we navigated to the "done" state since we don't need a
997 // passphrase. 949 // passphrase.
998 ExpectDone(); 950 ExpectDone();
999 } 951 }
1000 952
1001 } // namespace settings 953 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698