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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698