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

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

Issue 12088040: Add a SigninAllowed policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits and rebase to ToT. Created 7 years, 9 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 reverse_autologin_enabled()->Init(prefs::kReverseAutologinEnabled, 70 reverse_autologin_enabled()->Init(prefs::kReverseAutologinEnabled,
71 pref_service); 71 pref_service);
72 one_click_signin_rejected_email_list()->Init( 72 one_click_signin_rejected_email_list()->Init(
73 prefs::kReverseAutologinRejectedEmailList, pref_service); 73 prefs::kReverseAutologinRejectedEmailList, pref_service);
74 74
75 google_services_username_pattern()->Init( 75 google_services_username_pattern()->Init(
76 prefs::kGoogleServicesUsernamePattern, local_state); 76 prefs::kGoogleServicesUsernamePattern, local_state);
77 77
78 sync_disabled()->Init(prefs::kSyncManaged, pref_service); 78 sync_disabled()->Init(prefs::kSyncManaged, pref_service);
79 79
80 signin_allowed()->Init(prefs::kSigninAllowed, pref_service);
81
80 set_signin_names_for_testing(new SigninNamesOnIOThread()); 82 set_signin_names_for_testing(new SigninNamesOnIOThread());
81 SetCookieSettingsForTesting(cookie_settings); 83 SetCookieSettingsForTesting(cookie_settings);
82 } 84 }
83 85
84 virtual ~TestProfileIOData() { 86 virtual ~TestProfileIOData() {
85 signin_names()->ReleaseResourcesOnUIThread(); 87 signin_names()->ReleaseResourcesOnUIThread();
86 } 88 }
87 89
88 // ProfileIOData overrides: 90 // ProfileIOData overrides:
89 virtual void InitializeInternal( 91 virtual void InitializeInternal(
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 CreateSigninManager(false, ""); 577 CreateSigninManager(false, "");
576 578
577 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). 579 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)).
578 WillRepeatedly(Return(true)); 580 WillRepeatedly(Return(true));
579 581
580 EnableOneClick(true); 582 EnableOneClick(true);
581 EXPECT_TRUE(OneClickSigninHelper::CanOffer( 583 EXPECT_TRUE(OneClickSigninHelper::CanOffer(
582 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, 584 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL,
583 "user@gmail.com", NULL)); 585 "user@gmail.com", NULL));
584 586
587 // Simulate a policy disabling signin by writing kSigninAllowed directly.
588 profile_->GetTestingPrefService()->SetManagedPref(
589 prefs::kSigninAllowed, base::Value::CreateBooleanValue(false));
590
591 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
592 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL,
593 "user@gmail.com", NULL));
594
595 // Reset the preference value to true.
596 profile_->GetTestingPrefService()->SetManagedPref(
597 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true));
598
585 // Simulate a policy disabling sync by writing kSyncManaged directly. 599 // Simulate a policy disabling sync by writing kSyncManaged directly.
586 profile_->GetTestingPrefService()->SetManagedPref( 600 profile_->GetTestingPrefService()->SetManagedPref(
587 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); 601 prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
588 602
589 // Should still offer even if sync is disabled by policy. 603 // Should still offer even if sync is disabled by policy.
590 EXPECT_TRUE(OneClickSigninHelper::CanOffer( 604 EXPECT_TRUE(OneClickSigninHelper::CanOffer(
591 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, 605 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL,
592 "user@gmail.com", NULL)); 606 "user@gmail.com", NULL));
593 } 607 }
594 608
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 OneClickSigninHelper::CanOfferOnIOThreadImpl( 792 OneClickSigninHelper::CanOfferOnIOThreadImpl(
779 valid_gaia_url_, "", &request_, io_data.get())); 793 valid_gaia_url_, "", &request_, io_data.get()));
780 } 794 }
781 795
782 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabledByPolicy) { 796 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabledByPolicy) {
783 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); 797 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false));
784 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, 798 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
785 OneClickSigninHelper::CanOfferOnIOThreadImpl( 799 OneClickSigninHelper::CanOfferOnIOThreadImpl(
786 valid_gaia_url_, "", &request_, io_data.get())); 800 valid_gaia_url_, "", &request_, io_data.get()));
787 801
802 // Simulate a policy disabling signin by writing kSigninAllowed directly.
803 // We should not offer to sign in the browser.
804 profile_->GetTestingPrefService()->SetManagedPref(
805 prefs::kSigninAllowed, base::Value::CreateBooleanValue(false));
806 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER,
807 OneClickSigninHelper::CanOfferOnIOThreadImpl(
808 valid_gaia_url_, "", &request_, io_data.get()));
809
810 // Reset the preference.
811 profile_->GetTestingPrefService()->SetManagedPref(
812 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true));
813
788 // Simulate a policy disabling sync by writing kSyncManaged directly. 814 // Simulate a policy disabling sync by writing kSyncManaged directly.
789 // We should still offer to sign in the browser. 815 // We should still offer to sign in the browser.
790 profile_->GetTestingPrefService()->SetManagedPref( 816 profile_->GetTestingPrefService()->SetManagedPref(
791 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); 817 prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
792 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, 818 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
793 OneClickSigninHelper::CanOfferOnIOThreadImpl( 819 OneClickSigninHelper::CanOfferOnIOThreadImpl(
794 valid_gaia_url_, "", &request_, io_data.get())); 820 valid_gaia_url_, "", &request_, io_data.get()));
795 } 821 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | chrome/browser/ui/toolbar/wrench_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698