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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Set the ID of the signin process that the test will assume to be the | 209 // Set the ID of the signin process that the test will assume to be the |
210 // only process allowed to sign the user in to Chrome. | 210 // only process allowed to sign the user in to Chrome. |
211 void SetTrustedSigninProcessID(int id); | 211 void SetTrustedSigninProcessID(int id); |
212 | 212 |
213 void AddEmailToOneClickRejectedList(const std::string& email); | 213 void AddEmailToOneClickRejectedList(const std::string& email); |
214 void EnableOneClick(bool enable); | 214 void EnableOneClick(bool enable); |
215 void AllowSigninCookies(bool enable); | 215 void AllowSigninCookies(bool enable); |
216 void SetAllowedUsernamePattern(const std::string& pattern); | 216 void SetAllowedUsernamePattern(const std::string& pattern); |
217 ProfileSyncServiceMock* CreateProfileSyncServiceMock(); | 217 ProfileSyncServiceMock* CreateProfileSyncServiceMock(); |
218 void SubmitGAIAPassword(OneClickSigninHelper* helper); | 218 void SubmitGAIAPassword(OneClickSigninHelper* helper); |
| 219 OneClickSigninHelper* SetupHelperForSignin(); |
219 | 220 |
220 SigninManagerMock* signin_manager_; | 221 SigninManagerMock* signin_manager_; |
221 | 222 |
222 protected: | 223 protected: |
223 TestingProfile* profile_; | 224 TestingProfile* profile_; |
224 | 225 |
225 private: | 226 private: |
226 // Members to fake that we are on the UI thread. | 227 // Members to fake that we are on the UI thread. |
227 content::TestBrowserThread ui_thread_; | 228 content::TestBrowserThread ui_thread_; |
228 | 229 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 profile_, BuildSigninManagerMock)); | 267 profile_, BuildSigninManagerMock)); |
267 if (signin_manager_) | 268 if (signin_manager_) |
268 signin_manager_->SetSigninProcess(trusted_signin_process_id_); | 269 signin_manager_->SetSigninProcess(trusted_signin_process_id_); |
269 if (!username.empty()) { | 270 if (!username.empty()) { |
270 ASSERT_TRUE(signin_manager_); | 271 ASSERT_TRUE(signin_manager_); |
271 signin_manager_->StartSignIn(username, std::string(), std::string(), | 272 signin_manager_->StartSignIn(username, std::string(), std::string(), |
272 std::string()); | 273 std::string()); |
273 } | 274 } |
274 } | 275 } |
275 | 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 |
276 void OneClickSigninHelperTest::EnableOneClick(bool enable) { | 306 void OneClickSigninHelperTest::EnableOneClick(bool enable) { |
277 PrefService* pref_service = Profile::FromBrowserContext( | 307 PrefService* pref_service = Profile::FromBrowserContext( |
278 browser_context_.get())->GetPrefs(); | 308 browser_context_.get())->GetPrefs(); |
279 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); | 309 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); |
280 } | 310 } |
281 | 311 |
282 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList( | 312 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList( |
283 const std::string& email) { | 313 const std::string& email) { |
284 PrefService* pref_service = Profile::FromBrowserContext( | 314 PrefService* pref_service = Profile::FromBrowserContext( |
285 browser_context_.get())->GetPrefs(); | 315 browser_context_.get())->GetPrefs(); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 721 |
692 NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); | 722 NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); |
693 helper->DidStopLoading(rvh()); | 723 helper->DidStopLoading(rvh()); |
694 | 724 |
695 helper->OnStateChanged(); | 725 helper->OnStateChanged(); |
696 EXPECT_EQ(GURL(continueUrl), contents->GetURL()); | 726 EXPECT_EQ(GURL(continueUrl), contents->GetURL()); |
697 EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); | 727 EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); |
698 } | 728 } |
699 | 729 |
700 TEST_F(OneClickSigninHelperTest, ShowSigninBubbleAfterSigninComplete) { | 730 TEST_F(OneClickSigninHelperTest, ShowSigninBubbleAfterSigninComplete) { |
701 CreateSigninManager(false, std::string()); | 731 OneClickSigninHelper* helper = SetupHelperForSignin(); |
702 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)) | |
703 .WillRepeatedly(Return(true)); | |
704 | |
705 CreateProfileSyncServiceMock(); | |
706 | |
707 content::WebContents* contents = web_contents(); | |
708 | |
709 OneClickSigninHelper::CreateForWebContents(contents); | |
710 OneClickSigninHelper* helper = | |
711 OneClickSigninHelper::FromWebContents(contents); | |
712 | |
713 GURL continueUrl( | |
714 "https://www.google.com/intl/en-US/chrome/blank.html?source=1"); | |
715 OneClickSigninHelper::ShowInfoBarUIThread( | |
716 "session_index", "user@gmail.com", | |
717 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, | |
718 SyncPromoUI::SOURCE_NTP_LINK, | |
719 continueUrl, process()->GetID(), rvh()->GetRoutingID()); | |
720 | |
721 SubmitGAIAPassword(helper); | |
722 | |
723 NavigateAndCommit(continueUrl); | |
724 helper->DidStopLoading(rvh()); | |
725 helper->OnStateChanged(); | |
726 | |
727 PrefService* pref_service = profile_->GetPrefs(); | 732 PrefService* pref_service = profile_->GetPrefs(); |
728 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); | 733 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); |
729 helper->SigninSuccess(); | 734 helper->SigninSuccess(); |
730 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), true); | 735 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), true); |
731 } | 736 } |
732 | 737 |
| 738 TEST_F(OneClickSigninHelperTest, SigninCancelled) { |
| 739 OneClickSigninHelper* helper = SetupHelperForSignin(); |
| 740 |
| 741 PrefService* pref_service = profile_->GetPrefs(); |
| 742 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); |
| 743 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
| 744 helper->SigninFailed(error); |
| 745 // Should not show the NTP bubble on user cancellation. |
| 746 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); |
| 747 } |
| 748 |
| 749 TEST_F(OneClickSigninHelperTest, SigninFailed) { |
| 750 OneClickSigninHelper* helper = SetupHelperForSignin(); |
| 751 |
| 752 PrefService* pref_service = profile_->GetPrefs(); |
| 753 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), false); |
| 754 GoogleServiceAuthError error( |
| 755 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 756 helper->SigninFailed(error); |
| 757 // Should show the NTP bubble with an error. |
| 758 EXPECT_EQ(pref_service->GetBoolean(prefs::kSyncPromoShowNTPBubble), true); |
| 759 } |
| 760 |
733 // I/O thread tests | 761 // I/O thread tests |
734 | 762 |
735 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { | 763 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { |
736 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 764 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
737 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 765 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
738 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 766 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
739 valid_gaia_url_, std::string(), &request_, io_data.get())); | 767 valid_gaia_url_, std::string(), &request_, io_data.get())); |
740 } | 768 } |
741 | 769 |
742 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { | 770 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); | 907 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); |
880 | 908 |
881 // Simulate a policy disabling sync by writing kSyncManaged directly. | 909 // Simulate a policy disabling sync by writing kSyncManaged directly. |
882 // We should still offer to sign in the browser. | 910 // We should still offer to sign in the browser. |
883 profile_->GetTestingPrefService()->SetManagedPref( | 911 profile_->GetTestingPrefService()->SetManagedPref( |
884 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); | 912 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); |
885 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 913 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
886 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 914 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
887 valid_gaia_url_, std::string(), &request_, io_data.get())); | 915 valid_gaia_url_, std::string(), &request_, io_data.get())); |
888 } | 916 } |
OLD | NEW |