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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler_unittest.cc

Issue 12502017: signin: pull basic SigninManager functionality into new SigninManagerBase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: deal with new enterprise_platform_keys_private_api Created 7 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_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/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/signin/fake_auth_status_provider.h" 16 #include "chrome/browser/signin/fake_auth_status_provider.h"
17 #include "chrome/browser/signin/fake_signin_manager.h" 17 #include "chrome/browser/signin/fake_signin_manager.h"
18 #include "chrome/browser/signin/signin_manager.h"
18 #include "chrome/browser/signin/signin_manager_factory.h" 19 #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_service_factory.h"
20 #include "chrome/browser/sync/profile_sync_service_mock.h" 21 #include "chrome/browser/sync/profile_sync_service_mock.h"
21 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 22 #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/browser/ui/webui/signin/login_ui_service_factory.h"
23 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 24 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 using SyncSetupHandler::have_signin_tracker; 313 using SyncSetupHandler::have_signin_tracker;
313 314
314 private: 315 private:
315 virtual void DisplayGaiaLoginInNewTabOrWindow() OVERRIDE {} 316 virtual void DisplayGaiaLoginInNewTabOrWindow() OVERRIDE {}
316 317
317 // Weak pointer to parent profile. 318 // Weak pointer to parent profile.
318 Profile* profile_; 319 Profile* profile_;
319 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); 320 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler);
320 }; 321 };
321 322
322 class SigninManagerMock : public FakeSigninManager { 323 class SigninManagerBaseMock : public FakeSigninManagerBase {
323 public: 324 public:
324 explicit SigninManagerMock(Profile* profile) : FakeSigninManager(profile) {} 325 explicit SigninManagerBaseMock(Profile* profile)
326 : FakeSigninManagerBase(profile) {}
325 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); 327 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username));
326 }; 328 };
327 329
328 static ProfileKeyedService* BuildSigninManagerMock(Profile* profile) { 330 static ProfileKeyedService* BuildSigninManagerBaseMock(Profile* profile) {
329 return new SigninManagerMock(profile); 331 return new SigninManagerBaseMock(profile);
330 } 332 }
331 333
332 // The boolean parameter indicates whether the test is run with ClientOAuth 334 // The boolean parameter indicates whether the test is run with ClientOAuth
333 // or not. The test parameter is a bool: whether or not to test with/ 335 // or not. The test parameter is a bool: whether or not to test with/
334 // /ClientLogin enabled or not. 336 // /ClientLogin enabled or not.
335 class SyncSetupHandlerTest : public testing::TestWithParam<bool> { 337 class SyncSetupHandlerTest : public testing::TestWithParam<bool> {
336 public: 338 public:
337 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {} 339 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
338 virtual void SetUp() OVERRIDE { 340 virtual void SetUp() OVERRIDE {
339 bool use_client_login_flow = GetParam(); 341 bool use_client_login_flow = GetParam();
(...skipping 15 matching lines...) Expand all
355 profile_.get(), 357 profile_.get(),
356 ProfileSyncServiceMock::BuildMockProfileSyncService)); 358 ProfileSyncServiceMock::BuildMockProfileSyncService));
357 mock_pss_->Initialize(); 359 mock_pss_->Initialize();
358 360
359 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( 361 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault(
360 Return(syncer::IMPLICIT_PASSPHRASE)); 362 Return(syncer::IMPLICIT_PASSPHRASE));
361 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( 363 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault(
362 Return(base::Time())); 364 Return(base::Time()));
363 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( 365 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
364 Return(base::Time())); 366 Return(base::Time()));
365 mock_signin_ = static_cast<SigninManagerMock*>( 367 mock_signin_ = static_cast<SigninManagerBase*>(
366 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 368 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
367 profile_.get(), BuildSigninManagerMock)); 369 profile_.get(), BuildSigninManagerBaseMock));
368 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get())); 370 handler_.reset(new TestingSyncSetupHandler(&web_ui_, profile_.get()));
369 } 371 }
370 372
371 // Setup the expectations for calls made when displaying the config page. 373 // Setup the expectations for calls made when displaying the config page.
372 void SetDefaultExpectationsForConfigPage() { 374 void SetDefaultExpectationsForConfigPage() {
373 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()). 375 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()).
374 WillRepeatedly(Return(GetAllTypes())); 376 WillRepeatedly(Return(GetAllTypes()));
375 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). 377 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
376 WillRepeatedly(Return(GetAllTypes())); 378 WillRepeatedly(Return(GetAllTypes()));
377 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). 379 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()).
(...skipping 30 matching lines...) Expand all
408 std::string page; 410 std::string page;
409 ASSERT_TRUE(data.arg1->GetAsString(&page)); 411 ASSERT_TRUE(data.arg1->GetAsString(&page));
410 EXPECT_EQ(page, "done"); 412 EXPECT_EQ(page, "done");
411 } 413 }
412 414
413 scoped_ptr<Profile> profile_; 415 scoped_ptr<Profile> profile_;
414 ProfileSyncServiceMock* mock_pss_; 416 ProfileSyncServiceMock* mock_pss_;
415 GoogleServiceAuthError error_; 417 GoogleServiceAuthError error_;
416 // MessageLoop instance is required to work with OneShotTimer. 418 // MessageLoop instance is required to work with OneShotTimer.
417 MessageLoop message_loop_; 419 MessageLoop message_loop_;
418 SigninManagerMock* mock_signin_; 420 SigninManagerBase* mock_signin_;
419 TestWebUI web_ui_; 421 TestWebUI web_ui_;
420 scoped_ptr<TestingSyncSetupHandler> handler_; 422 scoped_ptr<TestingSyncSetupHandler> handler_;
421 }; 423 };
422 424
423 TEST_P(SyncSetupHandlerTest, Basic) { 425 TEST_P(SyncSetupHandlerTest, Basic) {
424 } 426 }
425 427
426 TEST_P(SyncSetupHandlerTest, DisplayBasicLogin) { 428 TEST_P(SyncSetupHandlerTest, DisplayBasicLogin) {
427 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 429 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
428 .WillRepeatedly(Return(false)); 430 .WillRepeatedly(Return(false));
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 EXPECT_EQ(page, "spinner"); 658 EXPECT_EQ(page, "spinner");
657 GoogleServiceAuthError error( 659 GoogleServiceAuthError error(
658 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 660 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
659 handler_->SigninFailed(error); 661 handler_->SigninFailed(error);
660 // On failure, the dialog will be closed. 662 // On failure, the dialog will be closed.
661 EXPECT_EQ(NULL, 663 EXPECT_EQ(NULL,
662 LoginUIServiceFactory::GetForProfile( 664 LoginUIServiceFactory::GetForProfile(
663 profile_.get())->current_login_ui()); 665 profile_.get())->current_login_ui());
664 } 666 }
665 667
666 TEST_P(SyncSetupHandlerTest, HandleGaiaAuthFailure) { 668 #if !defined(OS_CHROMEOS)
669
670 namespace {
671 class SigninManagerMock : public FakeSigninManager {
672 public:
673 explicit SigninManagerMock(Profile* profile) : FakeSigninManager(profile) {
674 }
675
676 virtual void StartSignIn(const std::string& username,
677 const std::string& password,
678 const std::string& login_token,
679 const std::string& login_captcha) OVERRIDE {
680 SetAuthenticatedUsername(username);
681 }
682
683 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username));
684 };
685 }
686
687 static ProfileKeyedService* BuildSigninManagerMock(Profile* profile) {
688 return new SigninManagerMock(profile);
689 }
690
691 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest {
692 public:
693 SyncSetupHandlerNonCrosTest() {}
694 virtual void SetUp() OVERRIDE {
695 SyncSetupHandlerTest::SetUp();
696 mock_signin_ = static_cast<SigninManagerMock*>(
697 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
698 profile_.get(), BuildSigninManagerMock));
699 }
700 };
701
702 TEST_P(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) {
667 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 703 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
668 .WillRepeatedly(Return(false)); 704 .WillRepeatedly(Return(false));
669 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) 705 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable())
670 .WillRepeatedly(Return(false)); 706 .WillRepeatedly(Return(false));
671 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 707 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
672 .WillRepeatedly(Return(false)); 708 .WillRepeatedly(Return(false));
673 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 709 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
674 .WillRepeatedly(Return(false)); 710 .WillRepeatedly(Return(false));
675 // Open the web UI. 711 // Open the web UI.
676 handler_->OpenSyncSetup(false); 712 handler_->OpenSyncSetup(false);
(...skipping 22 matching lines...) Expand all
699 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, 735 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS,
700 kTestUser, 736 kTestUser,
701 true, 737 true,
702 std::string()); 738 std::string());
703 } else { 739 } else {
704 ASSERT_FALSE(handler_->is_configuring_sync()); 740 ASSERT_FALSE(handler_->is_configuring_sync());
705 ASSERT_TRUE(handler_->have_signin_tracker()); 741 ASSERT_TRUE(handler_->have_signin_tracker());
706 } 742 }
707 } 743 }
708 744
709 TEST_P(SyncSetupHandlerTest, HandleCaptcha) { 745 TEST_P(SyncSetupHandlerNonCrosTest, HandleCaptcha) {
710 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 746 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
711 .WillRepeatedly(Return(false)); 747 .WillRepeatedly(Return(false));
712 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) 748 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable())
713 .WillRepeatedly(Return(false)); 749 .WillRepeatedly(Return(false));
714 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 750 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
715 .WillRepeatedly(Return(false)); 751 .WillRepeatedly(Return(false));
716 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 752 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
717 .WillRepeatedly(Return(false)); 753 .WillRepeatedly(Return(false));
718 // Open the web UI. 754 // Open the web UI.
719 handler_->OpenSyncSetup(false); 755 handler_->OpenSyncSetup(false);
(...skipping 23 matching lines...) Expand all
743 kTestUser, 779 kTestUser,
744 true, 780 true,
745 kTestCaptchaImageUrl); 781 kTestCaptchaImageUrl);
746 } else { 782 } else {
747 ASSERT_FALSE(handler_->is_configuring_sync()); 783 ASSERT_FALSE(handler_->is_configuring_sync());
748 ASSERT_TRUE(handler_->have_signin_tracker()); 784 ASSERT_TRUE(handler_->have_signin_tracker());
749 } 785 }
750 } 786 }
751 787
752 // TODO(kochi): We need equivalent tests for ChromeOS. 788 // TODO(kochi): We need equivalent tests for ChromeOS.
753 TEST_P(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { 789 TEST_P(SyncSetupHandlerNonCrosTest, UnrecoverableErrorInitializingSync) {
754 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 790 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
755 .WillRepeatedly(Return(false)); 791 .WillRepeatedly(Return(false));
756 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) 792 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable())
757 .WillRepeatedly(Return(false)); 793 .WillRepeatedly(Return(false));
758 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 794 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
759 .WillRepeatedly(Return(false)); 795 .WillRepeatedly(Return(false));
760 // Open the web UI. 796 // Open the web UI.
761 handler_->OpenSyncSetup(false); 797 handler_->OpenSyncSetup(false);
762 798
763 if (!SyncPromoUI::UseWebBasedSigninFlow()) { 799 if (!SyncPromoUI::UseWebBasedSigninFlow()) {
(...skipping 28 matching lines...) Expand all
792 GoogleServiceAuthError::NONE, 828 GoogleServiceAuthError::NONE,
793 kTestUser, 829 kTestUser,
794 true, 830 true,
795 std::string()); 831 std::string());
796 } else { 832 } else {
797 ASSERT_FALSE(handler_->is_configuring_sync()); 833 ASSERT_FALSE(handler_->is_configuring_sync());
798 ASSERT_TRUE(handler_->have_signin_tracker()); 834 ASSERT_TRUE(handler_->have_signin_tracker());
799 } 835 }
800 } 836 }
801 837
802 TEST_P(SyncSetupHandlerTest, GaiaErrorInitializingSync) { 838 TEST_P(SyncSetupHandlerNonCrosTest, GaiaErrorInitializingSync) {
803 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 839 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
804 .WillRepeatedly(Return(false)); 840 .WillRepeatedly(Return(false));
805 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) 841 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable())
806 .WillRepeatedly(Return(false)); 842 .WillRepeatedly(Return(false));
807 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 843 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
808 .WillRepeatedly(Return(false)); 844 .WillRepeatedly(Return(false));
809 // Open the web UI. 845 // Open the web UI.
810 handler_->OpenSyncSetup(false); 846 handler_->OpenSyncSetup(false);
811 847
812 if (!SyncPromoUI::UseWebBasedSigninFlow()) { 848 if (!SyncPromoUI::UseWebBasedSigninFlow()) {
(...skipping 29 matching lines...) Expand all
842 GoogleServiceAuthError::SERVICE_UNAVAILABLE, 878 GoogleServiceAuthError::SERVICE_UNAVAILABLE,
843 kTestUser, 879 kTestUser,
844 true, 880 true,
845 std::string()); 881 std::string());
846 } else { 882 } else {
847 ASSERT_FALSE(handler_->is_configuring_sync()); 883 ASSERT_FALSE(handler_->is_configuring_sync());
848 ASSERT_TRUE(handler_->have_signin_tracker()); 884 ASSERT_TRUE(handler_->have_signin_tracker());
849 } 885 }
850 } 886 }
851 887
888 // Tests that trying to log in with an invalid username results in an error
889 // displayed to the user.
890 TEST_P(SyncSetupHandlerNonCrosTest, SubmitAuthWithInvalidUsername) {
891 SigninManagerMock* mock_signin =
892 static_cast<SigninManagerMock*>(mock_signin_);
893 EXPECT_CALL(*mock_signin, IsAllowedUsername(_)).
894 WillRepeatedly(Return(false));
895
896 // Generate a blob of json that matches what would be submitted by the login
897 // javascript code.
898 DictionaryValue args;
899 args.SetString("user", "user@not_allowed.com");
900 args.SetString("pass", "password");
901 args.SetString("captcha", std::string());
902 args.SetString("otp", std::string());
903 args.SetString("accessCode", std::string());
904 std::string json;
905 base::JSONWriter::Write(&args, &json);
906 ListValue list_args;
907 list_args.Append(new StringValue(json));
908
909 // Mimic a login attempt from the UI.
910 handler_->HandleSubmitAuth(&list_args);
911
912 // Should result in the login page being displayed again.
913 ASSERT_EQ(1U, web_ui_.call_data().size());
914 const TestWebUI::CallData& data = web_ui_.call_data()[0];
915 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
916 std::string page;
917 ASSERT_TRUE(data.arg1->GetAsString(&page));
918 EXPECT_EQ(page, "login");
919
920 // Also make sure that the appropriate error message is being passed.
921 DictionaryValue* dictionary;
922 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
923 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED);
924 CheckShowSyncSetupArgs(dictionary,
925 err,
926 false,
927 GoogleServiceAuthError::NONE,
928 std::string(),
929 true,
930 std::string());
931 handler_->CloseSyncSetup();
932 EXPECT_EQ(NULL,
933 LoginUIServiceFactory::GetForProfile(
934 profile_.get())->current_login_ui());
935 }
936
937 #endif // #if !defined(OS_CHROMEOS)
938
852 TEST_P(SyncSetupHandlerTest, TestSyncEverything) { 939 TEST_P(SyncSetupHandlerTest, TestSyncEverything) {
853 std::string args = GetConfiguration( 940 std::string args = GetConfiguration(
854 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 941 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
855 ListValue list_args; 942 ListValue list_args;
856 list_args.Append(new StringValue(args)); 943 list_args.Append(new StringValue(args));
857 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 944 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
858 .WillRepeatedly(Return(false)); 945 .WillRepeatedly(Return(false));
859 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 946 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
860 .WillRepeatedly(Return(false)); 947 .WillRepeatedly(Return(false));
861 SetupInitializedProfileSyncService(); 948 SetupInitializedProfileSyncService();
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 // This should display the sync setup dialog (not login). 1333 // This should display the sync setup dialog (not login).
1247 handler_->OpenSyncSetup(false); 1334 handler_->OpenSyncSetup(false);
1248 1335
1249 ExpectConfig(); 1336 ExpectConfig();
1250 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 1337 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1251 DictionaryValue* dictionary; 1338 DictionaryValue* dictionary;
1252 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 1339 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1253 CheckBool(dictionary, "encryptAllData", true); 1340 CheckBool(dictionary, "encryptAllData", true);
1254 } 1341 }
1255 1342
1256 // Tests that trying to log in with an invalid username results in an error
1257 // displayed to the user.
1258 TEST_P(SyncSetupHandlerTest, SubmitAuthWithInvalidUsername) {
1259 EXPECT_CALL(*mock_signin_, IsAllowedUsername(_)).
1260 WillRepeatedly(Return(false));
1261
1262 // Generate a blob of json that matches what would be submitted by the login
1263 // javascript code.
1264 DictionaryValue args;
1265 args.SetString("user", "user@not_allowed.com");
1266 args.SetString("pass", "password");
1267 args.SetString("captcha", std::string());
1268 args.SetString("otp", std::string());
1269 args.SetString("accessCode", std::string());
1270 std::string json;
1271 base::JSONWriter::Write(&args, &json);
1272 ListValue list_args;
1273 list_args.Append(new StringValue(json));
1274
1275 // Mimic a login attempt from the UI.
1276 handler_->HandleSubmitAuth(&list_args);
1277
1278 // Should result in the login page being displayed again.
1279 ASSERT_EQ(1U, web_ui_.call_data().size());
1280 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1281 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
1282 std::string page;
1283 ASSERT_TRUE(data.arg1->GetAsString(&page));
1284 EXPECT_EQ(page, "login");
1285
1286 // Also make sure that the appropriate error message is being passed.
1287 DictionaryValue* dictionary;
1288 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1289 std::string err = l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED);
1290 CheckShowSyncSetupArgs(dictionary,
1291 err,
1292 false,
1293 GoogleServiceAuthError::NONE,
1294 std::string(),
1295 true,
1296 std::string());
1297 handler_->CloseSyncSetup();
1298 EXPECT_EQ(NULL,
1299 LoginUIServiceFactory::GetForProfile(
1300 profile_.get())->current_login_ui());
1301 }
1302
1303 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, 1343 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam,
1304 SyncSetupHandlerTest, 1344 SyncSetupHandlerTest,
1305 Values(true, false)); 1345 Values(true, false));
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698