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