| OLD | NEW |
| 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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/content_settings/cookie_settings.h" | 8 #include "chrome/browser/content_settings/cookie_settings.h" |
| 9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 profile_, BuildSigninManagerMock)); | 269 profile_, BuildSigninManagerMock)); |
| 270 if (signin_manager_) | 270 if (signin_manager_) |
| 271 signin_manager_->SetSigninProcess(trusted_signin_process_id_); | 271 signin_manager_->SetSigninProcess(trusted_signin_process_id_); |
| 272 | 272 |
| 273 if (!username.empty()) { | 273 if (!username.empty()) { |
| 274 ASSERT_TRUE(signin_manager_); | 274 ASSERT_TRUE(signin_manager_); |
| 275 signin_manager_->SetAuthenticatedUsername(username); | 275 signin_manager_->SetAuthenticatedUsername(username); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 OneClickSigninHelper* OneClickSigninHelperTest::SetupHelperForSignin() { | |
| 280 CreateSigninManager(false, ""); | |
| 281 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). | |
| 282 WillRepeatedly(Return(true)); | |
| 283 | |
| 284 CreateProfileSyncServiceMock(); | |
| 285 | |
| 286 content::WebContents* contents = web_contents(); | |
| 287 | |
| 288 OneClickSigninHelper::CreateForWebContents(contents); | |
| 289 OneClickSigninHelper* helper = | |
| 290 OneClickSigninHelper::FromWebContents(contents); | |
| 291 | |
| 292 GURL continueUrl( | |
| 293 "https://www.google.com/intl/en-US/chrome/blank.html?source=1"); | |
| 294 OneClickSigninHelper::ShowInfoBarUIThread( | |
| 295 "session_index", "user@gmail.com", | |
| 296 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, | |
| 297 SyncPromoUI::SOURCE_NTP_LINK, | |
| 298 continueUrl, process()->GetID(), rvh()->GetRoutingID()); | |
| 299 | |
| 300 SubmitGAIAPassword(helper); | |
| 301 | |
| 302 NavigateAndCommit(continueUrl); | |
| 303 helper->DidStopLoading(rvh()); | |
| 304 helper->OnStateChanged(); | |
| 305 return helper; | |
| 306 } | |
| 307 | |
| 308 void OneClickSigninHelperTest::EnableOneClick(bool enable) { | 279 void OneClickSigninHelperTest::EnableOneClick(bool enable) { |
| 309 PrefService* pref_service = Profile::FromBrowserContext( | 280 PrefService* pref_service = Profile::FromBrowserContext( |
| 310 browser_context_.get())->GetPrefs(); | 281 browser_context_.get())->GetPrefs(); |
| 311 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); | 282 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); |
| 312 } | 283 } |
| 313 | 284 |
| 314 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList( | 285 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList( |
| 315 const std::string& email) { | 286 const std::string& email) { |
| 316 PrefService* pref_service = Profile::FromBrowserContext( | 287 PrefService* pref_service = Profile::FromBrowserContext( |
| 317 browser_context_.get())->GetPrefs(); | 288 browser_context_.get())->GetPrefs(); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 OneClickSigninHelper::FromWebContents(web_contents()); | 645 OneClickSigninHelper::FromWebContents(web_contents()); |
| 675 EXPECT_EQ(NULL, helper); | 646 EXPECT_EQ(NULL, helper); |
| 676 | 647 |
| 677 OneClickSigninHelper::ShowInfoBarUIThread( | 648 OneClickSigninHelper::ShowInfoBarUIThread( |
| 678 "session_index", "email", OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED, | 649 "session_index", "email", OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED, |
| 679 SyncPromoUI::SOURCE_UNKNOWN, GURL(), process()->GetID(), | 650 SyncPromoUI::SOURCE_UNKNOWN, GURL(), process()->GetID(), |
| 680 rvh()->GetRoutingID()); | 651 rvh()->GetRoutingID()); |
| 681 } | 652 } |
| 682 | 653 |
| 683 // If Chrome signin is triggered from a webstore install, and user chooses to | 654 // If Chrome signin is triggered from a webstore install, and user chooses to |
| 684 // config sync, then Chrome should redirect immidiately to sync settings page, | 655 // config sync, then Chrome should redirect immediately to sync settings page, |
| 685 // and upon successful setup, redirect back to webstore. | 656 // and upon successful setup, redirect back to webstore. |
| 686 TEST_F(OneClickSigninHelperTest, SigninFromWebstoreWithConfigSyncfirst) { | 657 TEST_F(OneClickSigninHelperTest, SigninFromWebstoreWithConfigSyncfirst) { |
| 687 CreateSigninManager(false, std::string()); | 658 CreateSigninManager(false, std::string()); |
| 688 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)) | 659 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)) |
| 689 .WillRepeatedly(Return(true)); | 660 .WillRepeatedly(Return(true)); |
| 690 | 661 |
| 691 CreateProfileSyncServiceMock(); | 662 CreateProfileSyncServiceMock(); |
| 692 | 663 |
| 693 content::WebContents* contents = web_contents(); | 664 content::WebContents* contents = web_contents(); |
| 694 | 665 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 706 SubmitGAIAPassword(helper); | 677 SubmitGAIAPassword(helper); |
| 707 | 678 |
| 708 NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); | 679 NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); |
| 709 helper->DidStopLoading(rvh()); | 680 helper->DidStopLoading(rvh()); |
| 710 | 681 |
| 711 helper->OnStateChanged(); | 682 helper->OnStateChanged(); |
| 712 EXPECT_EQ(GURL(continueUrl), contents->GetURL()); | 683 EXPECT_EQ(GURL(continueUrl), contents->GetURL()); |
| 713 EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); | 684 EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); |
| 714 } | 685 } |
| 715 | 686 |
| 716 TEST_F(OneClickSigninHelperTest, ShowSigninBubbleAfterSigninComplete) { | |
| 717 OneClickSigninHelper* helper = SetupHelperForSignin(); | |
| 718 PrefService* pref_service = profile_->GetPrefs(); | |
| 719 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); | |
| 720 helper->SigninSuccess(); | |
| 721 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), true); | |
| 722 } | |
| 723 | |
| 724 TEST_F(OneClickSigninHelperTest, SigninCancelled) { | |
| 725 OneClickSigninHelper* helper = SetupHelperForSignin(); | |
| 726 | |
| 727 PrefService* pref_service = profile_->GetPrefs(); | |
| 728 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); | |
| 729 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); | |
| 730 helper->SigninFailed(error); | |
| 731 // Should not show the NTP bubble on user cancellation. | |
| 732 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); | |
| 733 } | |
| 734 | |
| 735 TEST_F(OneClickSigninHelperTest, SigninFailed) { | |
| 736 OneClickSigninHelper* helper = SetupHelperForSignin(); | |
| 737 | |
| 738 PrefService* pref_service = profile_->GetPrefs(); | |
| 739 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); | |
| 740 GoogleServiceAuthError error( | |
| 741 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | |
| 742 helper->SigninFailed(error); | |
| 743 // Should show the NTP bubble with an error. | |
| 744 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), true); | |
| 745 } | |
| 746 | |
| 747 // I/O thread tests | 687 // I/O thread tests |
| 748 | 688 |
| 749 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { | 689 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { |
| 750 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 690 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
| 751 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 691 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
| 752 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 692 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
| 753 valid_gaia_url_, std::string(), &request_, io_data.get())); | 693 valid_gaia_url_, std::string(), &request_, io_data.get())); |
| 754 } | 694 } |
| 755 | 695 |
| 756 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { | 696 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); | 833 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); |
| 894 | 834 |
| 895 // Simulate a policy disabling sync by writing kSyncManaged directly. | 835 // Simulate a policy disabling sync by writing kSyncManaged directly. |
| 896 // We should still offer to sign in the browser. | 836 // We should still offer to sign in the browser. |
| 897 profile_->GetTestingPrefService()->SetManagedPref( | 837 profile_->GetTestingPrefService()->SetManagedPref( |
| 898 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); | 838 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); |
| 899 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 839 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
| 900 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 840 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
| 901 valid_gaia_url_, std::string(), &request_, io_data.get())); | 841 valid_gaia_url_, std::string(), &request_, io_data.get())); |
| 902 } | 842 } |
| OLD | NEW |