Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / sync_setup_handler_unittest.cc
bloba0c5de40413dc5095bdd10b2d3969f505e3573cb
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/webui/options/sync_setup_handler.h"
7 #include <vector>
9 #include "base/command_line.h"
10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/stl_util.h"
14 #include "base/values.h"
15 #include "chrome/browser/signin/fake_signin_manager.h"
16 #include "chrome/browser/signin/signin_error_controller_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/sync/profile_sync_service_mock.h"
20 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
21 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/scoped_testing_local_state.h"
25 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "components/signin/core/browser/fake_auth_status_provider.h"
28 #include "components/signin/core/browser/signin_manager.h"
29 #include "components/sync_driver/sync_prefs.h"
30 #include "content/public/browser/web_ui.h"
31 #include "content/public/test/test_browser_thread.h"
32 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/layout.h"
36 using ::testing::_;
37 using ::testing::Mock;
38 using ::testing::Return;
39 using ::testing::ReturnRef;
40 using ::testing::Values;
42 typedef GoogleServiceAuthError AuthError;
44 namespace {
46 MATCHER_P(ModelTypeSetMatches, value, "") { return arg.Equals(value); }
48 const char kTestUser[] = "chrome.p13n.test@gmail.com";
50 // Returns a ModelTypeSet with all user selectable types set.
51 syncer::ModelTypeSet GetAllTypes() {
52 return syncer::UserSelectableTypes();
55 enum SyncAllDataConfig {
56 SYNC_ALL_DATA,
57 CHOOSE_WHAT_TO_SYNC,
58 SYNC_NOTHING
61 enum EncryptAllConfig {
62 ENCRYPT_ALL_DATA,
63 ENCRYPT_PASSWORDS
66 // Create a json-format string with the key/value pairs appropriate for a call
67 // to HandleConfigure(). If |extra_values| is non-null, then the values from
68 // the passed dictionary are added to the json.
69 std::string GetConfiguration(const base::DictionaryValue* extra_values,
70 SyncAllDataConfig sync_all,
71 syncer::ModelTypeSet types,
72 const std::string& passphrase,
73 EncryptAllConfig encrypt_all) {
74 base::DictionaryValue result;
75 if (extra_values)
76 result.MergeDictionary(extra_values);
77 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA);
78 result.SetBoolean("syncNothing", sync_all == SYNC_NOTHING);
79 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA);
80 result.SetBoolean("usePassphrase", !passphrase.empty());
81 if (!passphrase.empty())
82 result.SetString("passphrase", passphrase);
83 // Add all of our data types.
84 result.SetBoolean("appsSynced", types.Has(syncer::APPS));
85 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL));
86 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS));
87 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS));
88 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS));
89 result.SetBoolean("preferencesSynced", types.Has(syncer::PREFERENCES));
90 result.SetBoolean("tabsSynced", types.Has(syncer::PROXY_TABS));
91 result.SetBoolean("themesSynced", types.Has(syncer::THEMES));
92 result.SetBoolean("typedUrlsSynced", types.Has(syncer::TYPED_URLS));
93 result.SetBoolean("wifiCredentialsSynced",
94 types.Has(syncer::WIFI_CREDENTIALS));
95 std::string args;
96 base::JSONWriter::Write(result, &args);
97 return args;
100 // Checks whether the passed |dictionary| contains a |key| with the given
101 // |expected_value|. If |omit_if_false| is true, then the value should only
102 // be present if |expected_value| is true.
103 void CheckBool(const base::DictionaryValue* dictionary,
104 const std::string& key,
105 bool expected_value,
106 bool omit_if_false) {
107 if (omit_if_false && !expected_value) {
108 EXPECT_FALSE(dictionary->HasKey(key)) <<
109 "Did not expect to find value for " << key;
110 } else {
111 bool actual_value;
112 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) <<
113 "No value found for " << key;
114 EXPECT_EQ(expected_value, actual_value) <<
115 "Mismatch found for " << key;
119 void CheckBool(const base::DictionaryValue* dictionary,
120 const std::string& key,
121 bool expected_value) {
122 return CheckBool(dictionary, key, expected_value, false);
125 // Checks to make sure that the values stored in |dictionary| match the values
126 // expected by the showSyncSetupPage() JS function for a given set of data
127 // types.
128 void CheckConfigDataTypeArguments(base::DictionaryValue* dictionary,
129 SyncAllDataConfig config,
130 syncer::ModelTypeSet types) {
131 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA);
132 CheckBool(dictionary, "syncNothing", config == SYNC_NOTHING);
133 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS));
134 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL));
135 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS));
136 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS));
137 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS));
138 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES));
139 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS));
140 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES));
141 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS));
142 CheckBool(dictionary, "wifiCredentialsSynced",
143 types.Has(syncer::WIFI_CREDENTIALS));
147 } // namespace
149 // Test instance of WebUI that tracks the data passed to
150 // CallJavascriptFunction().
151 class TestWebUI : public content::WebUI {
152 public:
153 ~TestWebUI() override { ClearTrackedCalls(); }
155 void ClearTrackedCalls() {
156 // Manually free the arguments stored in CallData, since there's no good
157 // way to use a self-freeing reference like scoped_ptr in a std::vector.
158 for (std::vector<CallData>::iterator i = call_data_.begin();
159 i != call_data_.end();
160 ++i) {
161 delete i->arg1;
162 delete i->arg2;
164 call_data_.clear();
167 void CallJavascriptFunction(const std::string& function_name) override {
168 call_data_.push_back(CallData());
169 call_data_.back().function_name = function_name;
172 void CallJavascriptFunction(const std::string& function_name,
173 const base::Value& arg1) override {
174 call_data_.push_back(CallData());
175 call_data_.back().function_name = function_name;
176 call_data_.back().arg1 = arg1.DeepCopy();
179 void CallJavascriptFunction(const std::string& function_name,
180 const base::Value& arg1,
181 const base::Value& arg2) override {
182 call_data_.push_back(CallData());
183 call_data_.back().function_name = function_name;
184 call_data_.back().arg1 = arg1.DeepCopy();
185 call_data_.back().arg2 = arg2.DeepCopy();
188 content::WebContents* GetWebContents() const override { return NULL; }
189 content::WebUIController* GetController() const override { return NULL; }
190 void SetController(content::WebUIController* controller) override {}
191 float GetDeviceScaleFactor() const override { return 1.0f; }
192 const base::string16& GetOverriddenTitle() const override {
193 return temp_string_;
195 void OverrideTitle(const base::string16& title) override {}
196 ui::PageTransition GetLinkTransitionType() const override {
197 return ui::PAGE_TRANSITION_LINK;
199 void SetLinkTransitionType(ui::PageTransition type) override {}
200 int GetBindings() const override { return 0; }
201 void SetBindings(int bindings) override {}
202 void OverrideJavaScriptFrame(const std::string& frame_name) override {}
203 void AddMessageHandler(content::WebUIMessageHandler* handler) override {}
204 void RegisterMessageCallback(const std::string& message,
205 const MessageCallback& callback) override {}
206 void ProcessWebUIMessage(const GURL& source_url,
207 const std::string& message,
208 const base::ListValue& args) override {}
209 void CallJavascriptFunction(const std::string& function_name,
210 const base::Value& arg1,
211 const base::Value& arg2,
212 const base::Value& arg3) override {}
213 void CallJavascriptFunction(const std::string& function_name,
214 const base::Value& arg1,
215 const base::Value& arg2,
216 const base::Value& arg3,
217 const base::Value& arg4) override {}
218 void CallJavascriptFunction(
219 const std::string& function_name,
220 const std::vector<const base::Value*>& args) override {}
222 class CallData {
223 public:
224 CallData() : arg1(NULL), arg2(NULL) {}
225 std::string function_name;
226 base::Value* arg1;
227 base::Value* arg2;
229 const std::vector<CallData>& call_data() { return call_data_; }
231 private:
232 std::vector<CallData> call_data_;
233 base::string16 temp_string_;
236 class TestingSyncSetupHandler : public SyncSetupHandler {
237 public:
238 TestingSyncSetupHandler(content::WebUI* web_ui, Profile* profile)
239 : profile_(profile) {
240 set_web_ui(web_ui);
242 ~TestingSyncSetupHandler() override { set_web_ui(NULL); }
244 void FocusUI() override {}
246 Profile* GetProfile() const override { return profile_; }
248 using SyncSetupHandler::is_configuring_sync;
250 private:
251 #if !defined(OS_CHROMEOS)
252 void DisplayGaiaLoginInNewTabOrWindow() override {}
253 #endif
255 // Weak pointer to parent profile.
256 Profile* profile_;
257 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler);
260 // The boolean parameter indicates whether the test is run with ClientOAuth
261 // or not. The test parameter is a bool: whether or not to test with/
262 // /ClientLogin enabled or not.
263 class SyncSetupHandlerTest : public testing::Test {
264 public:
265 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
266 void SetUp() override {
267 error_ = GoogleServiceAuthError::AuthErrorNone();
269 TestingProfile::Builder builder;
270 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
271 FakeSigninManagerBase::Build);
272 profile_ = builder.Build();
274 // Sign in the user.
275 mock_signin_ = static_cast<SigninManagerBase*>(
276 SigninManagerFactory::GetForProfile(profile_.get()));
277 std::string username = GetTestUser();
278 if (!username.empty())
279 mock_signin_->SetAuthenticatedAccountInfo(username, username);
281 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
282 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
283 profile_.get(),
284 ProfileSyncServiceMock::BuildMockProfileSyncService));
285 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
286 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault(
287 Return(syncer::IMPLICIT_PASSPHRASE));
288 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault(
289 Return(base::Time()));
290 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
291 Return(base::Time()));
292 ON_CALL(*mock_pss_, GetRegisteredDataTypes())
293 .WillByDefault(Return(syncer::ModelTypeSet()));
295 mock_pss_->Initialize();
297 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get()));
300 // Setup the expectations for calls made when displaying the config page.
301 void SetDefaultExpectationsForConfigPage() {
302 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).
303 WillRepeatedly(Return(true));
304 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()).
305 WillRepeatedly(Return(GetAllTypes()));
306 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
307 WillRepeatedly(Return(GetAllTypes()));
308 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()).
309 WillRepeatedly(Return(GetAllTypes()));
310 EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed()).
311 WillRepeatedly(Return(true));
312 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()).
313 WillRepeatedly(Return(false));
316 void SetupInitializedProfileSyncService() {
317 // An initialized ProfileSyncService will have already completed sync setup
318 // and will have an initialized sync backend.
319 ASSERT_TRUE(mock_signin_->IsInitialized());
320 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(true));
323 void ExpectConfig() {
324 ASSERT_EQ(1U, web_ui_.call_data().size());
325 const TestWebUI::CallData& data = web_ui_.call_data()[0];
326 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
327 std::string page;
328 ASSERT_TRUE(data.arg1->GetAsString(&page));
329 EXPECT_EQ(page, "configure");
332 void ExpectDone() {
333 ASSERT_EQ(1U, web_ui_.call_data().size());
334 const TestWebUI::CallData& data = web_ui_.call_data()[0];
335 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
336 std::string page;
337 ASSERT_TRUE(data.arg1->GetAsString(&page));
338 EXPECT_EQ(page, "done");
341 void ExpectSpinnerAndClose() {
342 // We expect a call to SyncSetupOverlay.showSyncSetupPage.
343 EXPECT_EQ(1U, web_ui_.call_data().size());
344 const TestWebUI::CallData& data = web_ui_.call_data()[0];
345 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
347 std::string page;
348 ASSERT_TRUE(data.arg1->GetAsString(&page));
349 EXPECT_EQ(page, "spinner");
350 // Cancelling the spinner dialog will cause CloseSyncSetup().
351 handler_->CloseSyncSetup();
352 EXPECT_EQ(NULL,
353 LoginUIServiceFactory::GetForProfile(
354 profile_.get())->current_login_ui());
357 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock
358 // so this helper routine dispatches an OnStateChanged() notification to the
359 // SyncStartupTracker.
360 void NotifySyncListeners() {
361 if (handler_->sync_startup_tracker_)
362 handler_->sync_startup_tracker_->OnStateChanged();
365 virtual std::string GetTestUser() {
366 return std::string(kTestUser);
369 content::TestBrowserThreadBundle thread_bundle_;
370 scoped_ptr<Profile> profile_;
371 ProfileSyncServiceMock* mock_pss_;
372 GoogleServiceAuthError error_;
373 SigninManagerBase* mock_signin_;
374 TestWebUI web_ui_;
375 scoped_ptr<TestingSyncSetupHandler> handler_;
378 class SyncSetupHandlerFirstSigninTest : public SyncSetupHandlerTest {
379 std::string GetTestUser() override { return std::string(); }
382 TEST_F(SyncSetupHandlerTest, Basic) {
385 #if !defined(OS_CHROMEOS)
386 TEST_F(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin) {
387 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
388 .WillRepeatedly(Return(false));
389 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
390 .WillRepeatedly(Return(false));
391 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
392 .WillRepeatedly(Return(false));
393 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
394 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
395 manager->SignOut(signin_metrics::SIGNOUT_TEST);
396 handler_->HandleStartSignin(NULL);
398 // Sync setup hands off control to the gaia login tab.
399 EXPECT_EQ(NULL,
400 LoginUIServiceFactory::GetForProfile(
401 profile_.get())->current_login_ui());
403 ASSERT_FALSE(handler_->is_configuring_sync());
405 handler_->CloseSyncSetup();
406 EXPECT_EQ(NULL,
407 LoginUIServiceFactory::GetForProfile(
408 profile_.get())->current_login_ui());
411 TEST_F(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn) {
412 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
413 .WillRepeatedly(Return(false));
414 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
415 .WillRepeatedly(Return(false));
416 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
417 .WillRepeatedly(Return(false));
418 handler_->HandleShowSetupUI(NULL);
420 // We expect a call to SyncSetupOverlay.showSyncSetupPage.
421 ASSERT_EQ(1U, web_ui_.call_data().size());
422 const TestWebUI::CallData& data = web_ui_.call_data()[0];
423 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
425 ASSERT_FALSE(handler_->is_configuring_sync());
426 EXPECT_EQ(NULL,
427 LoginUIServiceFactory::GetForProfile(
428 profile_.get())->current_login_ui());
430 #endif // !defined(OS_CHROMEOS)
432 // Verifies that the sync setup is terminated correctly when the
433 // sync is disabled.
434 TEST_F(SyncSetupHandlerTest, HandleSetupUIWhenSyncDisabled) {
435 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
436 handler_->HandleShowSetupUI(NULL);
438 // Sync setup is closed when sync is disabled.
439 EXPECT_EQ(NULL,
440 LoginUIServiceFactory::GetForProfile(
441 profile_.get())->current_login_ui());
442 ASSERT_FALSE(handler_->is_configuring_sync());
445 // Verifies that the handler correctly handles a cancellation when
446 // it is displaying the spinner to the user.
447 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
448 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
449 .WillRepeatedly(Return(true));
450 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
451 .WillRepeatedly(Return(true));
452 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
453 .WillRepeatedly(Return(false));
454 error_ = GoogleServiceAuthError::AuthErrorNone();
455 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
457 // We're simulating a user setting up sync, which would cause the backend to
458 // kick off initialization, but not download user data types. The sync
459 // backend will try to download control data types (e.g encryption info), but
460 // that won't finish for this test as we're simulating cancelling while the
461 // spinner is showing.
462 handler_->HandleShowSetupUI(NULL);
464 EXPECT_EQ(handler_.get(),
465 LoginUIServiceFactory::GetForProfile(
466 profile_.get())->current_login_ui());
468 ExpectSpinnerAndClose();
471 // Verifies that the handler correctly transitions from showing the spinner
472 // to showing a configuration page when sync setup completes successfully.
473 TEST_F(SyncSetupHandlerTest,
474 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
475 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
476 .WillRepeatedly(Return(true));
477 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
478 .WillRepeatedly(Return(true));
479 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
480 .WillRepeatedly(Return(false));
481 error_ = GoogleServiceAuthError::AuthErrorNone();
482 // Sync backend is stopped initially, and will start up.
483 EXPECT_CALL(*mock_pss_, backend_initialized())
484 .WillRepeatedly(Return(false));
485 SetDefaultExpectationsForConfigPage();
487 handler_->OpenSyncSetup();
489 // We expect a call to SyncSetupOverlay.showSyncSetupPage.
490 EXPECT_EQ(1U, web_ui_.call_data().size());
492 const TestWebUI::CallData& data0 = web_ui_.call_data()[0];
493 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data0.function_name);
494 std::string page;
495 ASSERT_TRUE(data0.arg1->GetAsString(&page));
496 EXPECT_EQ(page, "spinner");
498 Mock::VerifyAndClearExpectations(mock_pss_);
499 // Now, act as if the ProfileSyncService has started up.
500 SetDefaultExpectationsForConfigPage();
501 EXPECT_CALL(*mock_pss_, backend_initialized())
502 .WillRepeatedly(Return(true));
503 error_ = GoogleServiceAuthError::AuthErrorNone();
504 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
505 NotifySyncListeners();
507 // We expect a second call to SyncSetupOverlay.showSyncSetupPage.
508 EXPECT_EQ(2U, web_ui_.call_data().size());
509 const TestWebUI::CallData& data1 = web_ui_.call_data().back();
510 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data1.function_name);
511 ASSERT_TRUE(data1.arg1->GetAsString(&page));
512 EXPECT_EQ(page, "configure");
513 base::DictionaryValue* dictionary;
514 ASSERT_TRUE(data1.arg2->GetAsDictionary(&dictionary));
515 CheckBool(dictionary, "passphraseFailed", false);
516 CheckBool(dictionary, "syncAllDataTypes", true);
517 CheckBool(dictionary, "encryptAllDataAllowed", true);
518 CheckBool(dictionary, "encryptAllData", false);
519 CheckBool(dictionary, "usePassphrase", false);
522 // Verifies the case where the user cancels after the sync backend has
523 // initialized (meaning it already transitioned from the spinner to a proper
524 // configuration page, tested by
525 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user
526 // before the user has continued on.
527 TEST_F(SyncSetupHandlerTest,
528 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) {
529 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
530 .WillRepeatedly(Return(true));
531 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
532 .WillRepeatedly(Return(true));
533 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
534 .WillRepeatedly(Return(false));
535 error_ = GoogleServiceAuthError::AuthErrorNone();
536 EXPECT_CALL(*mock_pss_, backend_initialized())
537 .WillOnce(Return(false))
538 .WillRepeatedly(Return(true));
539 SetDefaultExpectationsForConfigPage();
540 handler_->OpenSyncSetup();
542 // It's important to tell sync the user cancelled the setup flow before we
543 // tell it we're through with the setup progress.
544 testing::InSequence seq;
545 EXPECT_CALL(*mock_pss_, DisableForUser());
546 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
548 handler_->CloseSyncSetup();
549 EXPECT_EQ(NULL,
550 LoginUIServiceFactory::GetForProfile(
551 profile_.get())->current_login_ui());
554 TEST_F(SyncSetupHandlerTest,
555 DisplayConfigureWithBackendDisabledAndSigninFailed) {
556 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
557 .WillRepeatedly(Return(true));
558 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
559 .WillRepeatedly(Return(true));
560 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
561 .WillRepeatedly(Return(false));
562 error_ = GoogleServiceAuthError::AuthErrorNone();
563 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
565 handler_->OpenSyncSetup();
566 const TestWebUI::CallData& data = web_ui_.call_data()[0];
567 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
568 std::string page;
569 ASSERT_TRUE(data.arg1->GetAsString(&page));
570 EXPECT_EQ(page, "spinner");
571 Mock::VerifyAndClearExpectations(mock_pss_);
572 error_ = GoogleServiceAuthError(
573 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
574 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
575 NotifySyncListeners();
577 // On failure, the dialog will be closed.
578 EXPECT_EQ(NULL,
579 LoginUIServiceFactory::GetForProfile(
580 profile_.get())->current_login_ui());
583 #if !defined(OS_CHROMEOS)
585 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest {
586 public:
587 SyncSetupHandlerNonCrosTest() {}
590 TEST_F(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) {
591 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
592 .WillRepeatedly(Return(false));
593 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
594 .WillRepeatedly(Return(false));
595 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
596 .WillRepeatedly(Return(false));
597 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
598 .WillRepeatedly(Return(false));
599 // Open the web UI.
600 handler_->OpenSyncSetup();
602 ASSERT_FALSE(handler_->is_configuring_sync());
605 // TODO(kochi): We need equivalent tests for ChromeOS.
606 TEST_F(SyncSetupHandlerNonCrosTest, UnrecoverableErrorInitializingSync) {
607 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
608 .WillRepeatedly(Return(false));
609 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
610 .WillRepeatedly(Return(false));
611 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
612 .WillRepeatedly(Return(false));
613 // Open the web UI.
614 handler_->OpenSyncSetup();
616 ASSERT_FALSE(handler_->is_configuring_sync());
619 TEST_F(SyncSetupHandlerNonCrosTest, GaiaErrorInitializingSync) {
620 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
621 .WillRepeatedly(Return(false));
622 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
623 .WillRepeatedly(Return(false));
624 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
625 .WillRepeatedly(Return(false));
626 // Open the web UI.
627 handler_->OpenSyncSetup();
629 ASSERT_FALSE(handler_->is_configuring_sync());
632 #endif // #if !defined(OS_CHROMEOS)
634 TEST_F(SyncSetupHandlerTest, TestSyncEverything) {
635 std::string args = GetConfiguration(
636 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
637 base::ListValue list_args;
638 list_args.Append(new base::StringValue(args));
639 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
640 .WillRepeatedly(Return(false));
641 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
642 .WillRepeatedly(Return(false));
643 SetupInitializedProfileSyncService();
644 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
645 handler_->HandleConfigure(&list_args);
647 // Ensure that we navigated to the "done" state since we don't need a
648 // passphrase.
649 ExpectDone();
652 TEST_F(SyncSetupHandlerTest, TestSyncNothing) {
653 std::string args = GetConfiguration(
654 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
655 base::ListValue list_args;
656 list_args.Append(new base::StringValue(args));
657 EXPECT_CALL(*mock_pss_, DisableForUser());
658 SetupInitializedProfileSyncService();
659 handler_->HandleConfigure(&list_args);
661 // We expect a call to SyncSetupOverlay.showSyncSetupPage.
662 ASSERT_EQ(1U, web_ui_.call_data().size());
663 const TestWebUI::CallData& data = web_ui_.call_data()[0];
664 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
667 TEST_F(SyncSetupHandlerTest, TurnOnEncryptAll) {
668 std::string args = GetConfiguration(
669 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
670 base::ListValue list_args;
671 list_args.Append(new base::StringValue(args));
672 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
673 .WillRepeatedly(Return(false));
674 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
675 .WillRepeatedly(Return(false));
676 EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed())
677 .WillRepeatedly(Return(true));
678 SetupInitializedProfileSyncService();
679 EXPECT_CALL(*mock_pss_, EnableEncryptEverything());
680 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
681 handler_->HandleConfigure(&list_args);
683 // Ensure that we navigated to the "done" state since we don't need a
684 // passphrase.
685 ExpectDone();
688 TEST_F(SyncSetupHandlerTest, TestPassphraseStillRequired) {
689 std::string args = GetConfiguration(
690 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
691 base::ListValue list_args;
692 list_args.Append(new base::StringValue(args));
693 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
694 .WillRepeatedly(Return(true));
695 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
696 .WillRepeatedly(Return(true));
697 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
698 .WillRepeatedly(Return(false));
699 SetupInitializedProfileSyncService();
700 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
701 SetDefaultExpectationsForConfigPage();
703 // We should navigate back to the configure page since we need a passphrase.
704 handler_->HandleConfigure(&list_args);
706 ExpectConfig();
709 TEST_F(SyncSetupHandlerTest, SuccessfullySetPassphrase) {
710 base::DictionaryValue dict;
711 dict.SetBoolean("isGooglePassphrase", true);
712 std::string args = GetConfiguration(&dict,
713 SYNC_ALL_DATA,
714 GetAllTypes(),
715 "gaiaPassphrase",
716 ENCRYPT_PASSWORDS);
717 base::ListValue list_args;
718 list_args.Append(new base::StringValue(args));
719 // Act as if an encryption passphrase is required the first time, then never
720 // again after that.
721 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true));
722 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
723 .WillRepeatedly(Return(false));
724 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
725 .WillRepeatedly(Return(false));
726 SetupInitializedProfileSyncService();
727 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
728 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")).
729 WillOnce(Return(true));
731 handler_->HandleConfigure(&list_args);
732 // We should navigate to "done" page since we finished configuring.
733 ExpectDone();
736 TEST_F(SyncSetupHandlerTest, SelectCustomEncryption) {
737 base::DictionaryValue dict;
738 dict.SetBoolean("isGooglePassphrase", false);
739 std::string args = GetConfiguration(&dict,
740 SYNC_ALL_DATA,
741 GetAllTypes(),
742 "custom_passphrase",
743 ENCRYPT_PASSWORDS);
744 base::ListValue list_args;
745 list_args.Append(new base::StringValue(args));
746 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
747 .WillRepeatedly(Return(false));
748 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
749 .WillRepeatedly(Return(false));
750 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
751 .WillRepeatedly(Return(false));
752 SetupInitializedProfileSyncService();
753 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
754 EXPECT_CALL(*mock_pss_,
755 SetEncryptionPassphrase("custom_passphrase",
756 ProfileSyncService::EXPLICIT));
758 handler_->HandleConfigure(&list_args);
759 // We should navigate to "done" page since we finished configuring.
760 ExpectDone();
763 TEST_F(SyncSetupHandlerTest, UnsuccessfullySetPassphrase) {
764 base::DictionaryValue dict;
765 dict.SetBoolean("isGooglePassphrase", true);
766 std::string args = GetConfiguration(&dict,
767 SYNC_ALL_DATA,
768 GetAllTypes(),
769 "invalid_passphrase",
770 ENCRYPT_PASSWORDS);
771 base::ListValue list_args;
772 list_args.Append(new base::StringValue(args));
773 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
774 .WillRepeatedly(Return(true));
775 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
776 .WillRepeatedly(Return(true));
777 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
778 .WillRepeatedly(Return(false));
779 SetupInitializedProfileSyncService();
780 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
781 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("invalid_passphrase")).
782 WillOnce(Return(false));
784 SetDefaultExpectationsForConfigPage();
785 // We should navigate back to the configure page since we need a passphrase.
786 handler_->HandleConfigure(&list_args);
788 ExpectConfig();
790 // Make sure we display an error message to the user due to the failed
791 // passphrase.
792 const TestWebUI::CallData& data = web_ui_.call_data()[0];
793 base::DictionaryValue* dictionary;
794 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
795 CheckBool(dictionary, "passphraseFailed", true);
798 // Walks through each user selectable type, and tries to sync just that single
799 // data type.
800 TEST_F(SyncSetupHandlerTest, TestSyncIndividualTypes) {
801 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
802 syncer::ModelTypeSet::Iterator it;
803 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
804 syncer::ModelTypeSet type_to_set;
805 type_to_set.Put(it.Get());
806 std::string args = GetConfiguration(NULL,
807 CHOOSE_WHAT_TO_SYNC,
808 type_to_set,
809 std::string(),
810 ENCRYPT_PASSWORDS);
811 base::ListValue list_args;
812 list_args.Append(new base::StringValue(args));
813 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
814 .WillRepeatedly(Return(false));
815 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
816 .WillRepeatedly(Return(false));
817 SetupInitializedProfileSyncService();
818 EXPECT_CALL(*mock_pss_,
819 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set)));
820 handler_->HandleConfigure(&list_args);
822 ExpectDone();
823 Mock::VerifyAndClearExpectations(mock_pss_);
824 web_ui_.ClearTrackedCalls();
828 TEST_F(SyncSetupHandlerTest, TestSyncAllManually) {
829 std::string args = GetConfiguration(NULL,
830 CHOOSE_WHAT_TO_SYNC,
831 GetAllTypes(),
832 std::string(),
833 ENCRYPT_PASSWORDS);
834 base::ListValue list_args;
835 list_args.Append(new base::StringValue(args));
836 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
837 .WillRepeatedly(Return(false));
838 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
839 .WillRepeatedly(Return(false));
840 SetupInitializedProfileSyncService();
841 EXPECT_CALL(*mock_pss_,
842 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes())));
843 handler_->HandleConfigure(&list_args);
845 ExpectDone();
848 TEST_F(SyncSetupHandlerTest, ShowSyncSetup) {
849 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
850 .WillRepeatedly(Return(false));
851 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
852 .WillRepeatedly(Return(false));
853 SetupInitializedProfileSyncService();
854 // This should display the sync setup dialog (not login).
855 SetDefaultExpectationsForConfigPage();
856 handler_->OpenSyncSetup();
858 ExpectConfig();
861 // We do not display signin on chromeos in the case of auth error.
862 TEST_F(SyncSetupHandlerTest, ShowSigninOnAuthError) {
863 // Initialize the system to a signed in state, but with an auth error.
864 error_ = GoogleServiceAuthError(
865 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
867 SetupInitializedProfileSyncService();
868 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
869 FakeAuthStatusProvider provider(
870 SigninErrorControllerFactory::GetForProfile(profile_.get()));
871 provider.SetAuthError(kTestUser, error_);
872 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
873 .WillRepeatedly(Return(true));
874 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
875 .WillRepeatedly(Return(true));
876 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
877 .WillRepeatedly(Return(false));
878 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
879 .WillRepeatedly(Return(false));
880 EXPECT_CALL(*mock_pss_, backend_initialized()).WillRepeatedly(Return(false));
882 #if defined(OS_CHROMEOS)
883 // On ChromeOS, auth errors are ignored - instead we just try to start the
884 // sync backend (which will fail due to the auth error). This should only
885 // happen if the user manually navigates to chrome://settings/syncSetup -
886 // clicking on the button in the UI will sign the user out rather than
887 // displaying a spinner. Should be no visible UI on ChromeOS in this case.
888 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(
889 profile_.get())->current_login_ui());
890 #else
892 // On ChromeOS, this should display the spinner while we try to startup the
893 // sync backend, and on desktop this displays the login dialog.
894 handler_->OpenSyncSetup();
896 // Sync setup is closed when re-auth is in progress.
897 EXPECT_EQ(NULL,
898 LoginUIServiceFactory::GetForProfile(
899 profile_.get())->current_login_ui());
901 ASSERT_FALSE(handler_->is_configuring_sync());
902 #endif
905 TEST_F(SyncSetupHandlerTest, ShowSetupSyncEverything) {
906 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
907 .WillRepeatedly(Return(false));
908 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
909 .WillRepeatedly(Return(false));
910 SetupInitializedProfileSyncService();
911 SetDefaultExpectationsForConfigPage();
912 // This should display the sync setup dialog (not login).
913 handler_->OpenSyncSetup();
915 ExpectConfig();
916 const TestWebUI::CallData& data = web_ui_.call_data()[0];
917 base::DictionaryValue* dictionary;
918 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
919 CheckBool(dictionary, "syncAllDataTypes", true);
920 CheckBool(dictionary, "appsRegistered", true);
921 CheckBool(dictionary, "autofillRegistered", true);
922 CheckBool(dictionary, "bookmarksRegistered", true);
923 CheckBool(dictionary, "extensionsRegistered", true);
924 CheckBool(dictionary, "passwordsRegistered", true);
925 CheckBool(dictionary, "preferencesRegistered", true);
926 CheckBool(dictionary, "wifiCredentialsRegistered", true);
927 CheckBool(dictionary, "tabsRegistered", true);
928 CheckBool(dictionary, "themesRegistered", true);
929 CheckBool(dictionary, "typedUrlsRegistered", true);
930 CheckBool(dictionary, "showPassphrase", false);
931 CheckBool(dictionary, "usePassphrase", false);
932 CheckBool(dictionary, "passphraseFailed", false);
933 CheckBool(dictionary, "encryptAllData", false);
934 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes());
937 TEST_F(SyncSetupHandlerTest, ShowSetupManuallySyncAll) {
938 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
939 .WillRepeatedly(Return(false));
940 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
941 .WillRepeatedly(Return(false));
942 SetupInitializedProfileSyncService();
943 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
944 sync_prefs.SetKeepEverythingSynced(false);
945 SetDefaultExpectationsForConfigPage();
946 // This should display the sync setup dialog (not login).
947 handler_->OpenSyncSetup();
949 ExpectConfig();
950 const TestWebUI::CallData& data = web_ui_.call_data()[0];
951 base::DictionaryValue* dictionary;
952 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
953 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes());
956 TEST_F(SyncSetupHandlerTest, ShowSetupSyncForAllTypesIndividually) {
957 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
958 syncer::ModelTypeSet::Iterator it;
959 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
960 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
961 .WillRepeatedly(Return(false));
962 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
963 .WillRepeatedly(Return(false));
964 SetupInitializedProfileSyncService();
965 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
966 sync_prefs.SetKeepEverythingSynced(false);
967 SetDefaultExpectationsForConfigPage();
968 syncer::ModelTypeSet types;
969 types.Put(it.Get());
970 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
971 WillRepeatedly(Return(types));
973 // This should display the sync setup dialog (not login).
974 handler_->OpenSyncSetup();
976 ExpectConfig();
977 // Close the config overlay.
978 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed(
979 handler_.get());
980 const TestWebUI::CallData& data = web_ui_.call_data()[0];
981 base::DictionaryValue* dictionary;
982 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
983 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types);
984 Mock::VerifyAndClearExpectations(mock_pss_);
985 // Clean up so we can loop back to display the dialog again.
986 web_ui_.ClearTrackedCalls();
990 TEST_F(SyncSetupHandlerTest, ShowSetupGaiaPassphraseRequired) {
991 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
992 .WillRepeatedly(Return(true));
993 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
994 .WillRepeatedly(Return(false));
995 SetupInitializedProfileSyncService();
996 SetDefaultExpectationsForConfigPage();
998 // This should display the sync setup dialog (not login).
999 handler_->OpenSyncSetup();
1001 ExpectConfig();
1002 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1003 base::DictionaryValue* dictionary;
1004 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1005 CheckBool(dictionary, "showPassphrase", true);
1006 CheckBool(dictionary, "usePassphrase", false);
1007 CheckBool(dictionary, "passphraseFailed", false);
1010 TEST_F(SyncSetupHandlerTest, ShowSetupCustomPassphraseRequired) {
1011 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
1012 .WillRepeatedly(Return(true));
1013 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
1014 .WillRepeatedly(Return(true));
1015 EXPECT_CALL(*mock_pss_, GetPassphraseType())
1016 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE));
1017 SetupInitializedProfileSyncService();
1018 SetDefaultExpectationsForConfigPage();
1020 // This should display the sync setup dialog (not login).
1021 handler_->OpenSyncSetup();
1023 ExpectConfig();
1024 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1025 base::DictionaryValue* dictionary;
1026 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1027 CheckBool(dictionary, "showPassphrase", true);
1028 CheckBool(dictionary, "usePassphrase", true);
1029 CheckBool(dictionary, "passphraseFailed", false);
1032 TEST_F(SyncSetupHandlerTest, ShowSetupEncryptAll) {
1033 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
1034 .WillRepeatedly(Return(false));
1035 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
1036 .WillRepeatedly(Return(false));
1037 SetupInitializedProfileSyncService();
1038 SetDefaultExpectationsForConfigPage();
1039 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()).
1040 WillRepeatedly(Return(true));
1042 // This should display the sync setup dialog (not login).
1043 handler_->OpenSyncSetup();
1045 ExpectConfig();
1046 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1047 base::DictionaryValue* dictionary;
1048 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1049 CheckBool(dictionary, "encryptAllData", true);
1052 TEST_F(SyncSetupHandlerTest, ShowSetupEncryptAllDisallowed) {
1053 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
1054 .WillRepeatedly(Return(false));
1055 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
1056 .WillRepeatedly(Return(false));
1057 SetupInitializedProfileSyncService();
1058 SetDefaultExpectationsForConfigPage();
1059 EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed()).
1060 WillRepeatedly(Return(false));
1062 // This should display the sync setup dialog (not login).
1063 handler_->OpenSyncSetup();
1065 ExpectConfig();
1066 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1067 base::DictionaryValue* dictionary;
1068 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1069 CheckBool(dictionary, "encryptAllData", false);
1070 CheckBool(dictionary, "encryptAllDataAllowed", false);
1073 TEST_F(SyncSetupHandlerTest, TurnOnEncryptAllDisallowed) {
1074 std::string args = GetConfiguration(
1075 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
1076 base::ListValue list_args;
1077 list_args.Append(new base::StringValue(args));
1078 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
1079 .WillRepeatedly(Return(false));
1080 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
1081 .WillRepeatedly(Return(false));
1082 SetupInitializedProfileSyncService();
1083 EXPECT_CALL(*mock_pss_, EncryptEverythingAllowed()).
1084 WillRepeatedly(Return(false));
1085 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
1086 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
1087 handler_->HandleConfigure(&list_args);
1089 // Ensure that we navigated to the "done" state since we don't need a
1090 // passphrase.
1091 ExpectDone();