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