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

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

Issue 12374007: signin: force web signin flow initiated visits to accounts.google.com to their own process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review nit 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 224
225 virtual void SetUp() OVERRIDE; 225 virtual void SetUp() OVERRIDE;
226 virtual void TearDown() OVERRIDE; 226 virtual void TearDown() OVERRIDE;
227 227
228 // Creates the sign-in manager for tests. If |use_incognito| is true then 228 // Creates the sign-in manager for tests. If |use_incognito| is true then
229 // a WebContents for an incognito profile is created. If |username| is 229 // a WebContents for an incognito profile is created. If |username| is
230 // is not empty, the profile of the mock WebContents will be connected to 230 // is not empty, the profile of the mock WebContents will be connected to
231 // the given account. 231 // the given account.
232 void CreateSigninManager(bool use_incognito, const std::string& username); 232 void CreateSigninManager(bool use_incognito, const std::string& username);
233 233
234 // Set the ID of the signin process that the test will assume to be the
235 // only process allowed to sign the user in to Chrome.
236 void SetTrustedSigninProcessID(int id);
237
234 void AddEmailToOneClickRejectedList(const std::string& email); 238 void AddEmailToOneClickRejectedList(const std::string& email);
235 void EnableOneClick(bool enable); 239 void EnableOneClick(bool enable);
236 void AllowSigninCookies(bool enable); 240 void AllowSigninCookies(bool enable);
237 void SetAllowedUsernamePattern(const std::string& pattern); 241 void SetAllowedUsernamePattern(const std::string& pattern);
238 242
239 SigninManagerMock* signin_manager_; 243 SigninManagerMock* signin_manager_;
240 244
241 protected: 245 protected:
242 TestingProfile* profile_; 246 TestingProfile* profile_;
243 247
244 private: 248 private:
245 // Members to fake that we are on the UI thread. 249 // Members to fake that we are on the UI thread.
246 content::TestBrowserThread ui_thread_; 250 content::TestBrowserThread ui_thread_;
247 251
252 // The ID of the signin process the test will assume to be trusted.
253 // By default, set to the test RenderProcessHost's process ID, but
254 // overridden by SetTrustedSigninProcessID.
255 int trusted_signin_process_id_;
256
248 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); 257 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest);
249 }; 258 };
250 259
251 OneClickSigninHelperTest::OneClickSigninHelperTest() 260 OneClickSigninHelperTest::OneClickSigninHelperTest()
252 : profile_(NULL), 261 : profile_(NULL),
253 ui_thread_(content::BrowserThread::UI, &message_loop_) { 262 ui_thread_(content::BrowserThread::UI, &message_loop_),
263 trusted_signin_process_id_(-1) {
254 } 264 }
255 265
256 void OneClickSigninHelperTest::SetUp() { 266 void OneClickSigninHelperTest::SetUp() {
257 SyncPromoUI::ForceWebBasedSigninFlowForTesting(true); 267 SyncPromoUI::ForceWebBasedSigninFlowForTesting(true);
258 profile_ = new TestingProfile(); 268 profile_ = new TestingProfile();
259 browser_context_.reset(profile_); 269 browser_context_.reset(profile_);
260 content::RenderViewHostTestHarness::SetUp(); 270 content::RenderViewHostTestHarness::SetUp();
271 SetTrustedSigninProcessID(process()->GetID());
261 } 272 }
262 273
263 void OneClickSigninHelperTest::TearDown() { 274 void OneClickSigninHelperTest::TearDown() {
264 SyncPromoUI::ForceWebBasedSigninFlowForTesting(false); 275 SyncPromoUI::ForceWebBasedSigninFlowForTesting(false);
265 content::RenderViewHostTestHarness::TearDown(); 276 content::RenderViewHostTestHarness::TearDown();
266 } 277 }
267 278
279 void OneClickSigninHelperTest::SetTrustedSigninProcessID(int id) {
280 trusted_signin_process_id_ = id;
281 }
282
268 void OneClickSigninHelperTest::CreateSigninManager( 283 void OneClickSigninHelperTest::CreateSigninManager(
269 bool use_incognito, 284 bool use_incognito,
270 const std::string& username) { 285 const std::string& username) {
271 profile_->set_incognito(use_incognito); 286 profile_->set_incognito(use_incognito);
272 signin_manager_ = static_cast<SigninManagerMock*>( 287 signin_manager_ = static_cast<SigninManagerMock*>(
273 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 288 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
274 profile_, BuildSigninManagerMock)); 289 profile_, BuildSigninManagerMock));
275 290 if (signin_manager_)
291 signin_manager_->SetSigninProcess(trusted_signin_process_id_);
276 if (!username.empty()) { 292 if (!username.empty()) {
293 ASSERT_TRUE(signin_manager_);
277 signin_manager_->StartSignIn(username, std::string(), std::string(), 294 signin_manager_->StartSignIn(username, std::string(), std::string(),
278 std::string()); 295 std::string());
279 } 296 }
280 } 297 }
281 298
282 void OneClickSigninHelperTest::EnableOneClick(bool enable) { 299 void OneClickSigninHelperTest::EnableOneClick(bool enable) {
283 PrefService* pref_service = Profile::FromBrowserContext( 300 PrefService* pref_service = Profile::FromBrowserContext(
284 browser_context_.get())->GetPrefs(); 301 browser_context_.get())->GetPrefs();
285 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); 302 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable);
286 } 303 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 EXPECT_FALSE(OneClickSigninHelper::CanOffer( 581 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
565 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, 582 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL,
566 "user@gmail.com", &error_message)); 583 "user@gmail.com", &error_message));
567 EXPECT_EQ("", error_message); 584 EXPECT_EQ("", error_message);
568 EXPECT_FALSE(OneClickSigninHelper::CanOffer( 585 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
569 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, 586 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY,
570 "", &error_message)); 587 "", &error_message));
571 EXPECT_EQ("", error_message); 588 EXPECT_EQ("", error_message);
572 } 589 }
573 590
591 TEST_F(OneClickSigninHelperTest, CanOfferUntrustedProcess) {
592 content::MockRenderProcessHost trusted(browser_context_.get());
593 ASSERT_NE(trusted.GetID(), process()->GetID());
594 // Make sure the RenderProcessHost used by the test is untrusted.
595 SetTrustedSigninProcessID(trusted.GetID());
596 CreateSigninManager(false, "");
597
598 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)).
599 WillRepeatedly(Return(true));
600
601 EnableOneClick(true);
602 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
603 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL,
604 "user@gmail.com", NULL));
605 }
606
574 TEST_F(OneClickSigninHelperTest, CanOfferDisabledByPolicy) { 607 TEST_F(OneClickSigninHelperTest, CanOfferDisabledByPolicy) {
575 CreateSigninManager(false, ""); 608 CreateSigninManager(false, "");
576 609
577 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). 610 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)).
578 WillRepeatedly(Return(true)); 611 WillRepeatedly(Return(true));
579 612
580 EnableOneClick(true); 613 EnableOneClick(true);
581 EXPECT_TRUE(OneClickSigninHelper::CanOffer( 614 EXPECT_TRUE(OneClickSigninHelper::CanOffer(
582 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, 615 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL,
583 "user@gmail.com", NULL)); 616 "user@gmail.com", NULL));
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 valid_gaia_url_, "", &request_, io_data.get())); 819 valid_gaia_url_, "", &request_, io_data.get()));
787 820
788 // Simulate a policy disabling sync by writing kSyncManaged directly. 821 // Simulate a policy disabling sync by writing kSyncManaged directly.
789 // We should still offer to sign in the browser. 822 // We should still offer to sign in the browser.
790 profile_->GetTestingPrefService()->SetManagedPref( 823 profile_->GetTestingPrefService()->SetManagedPref(
791 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); 824 prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
792 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, 825 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
793 OneClickSigninHelper::CanOfferOnIOThreadImpl( 826 OneClickSigninHelper::CanOfferOnIOThreadImpl(
794 valid_gaia_url_, "", &request_, io_data.get())); 827 valid_gaia_url_, "", &request_, io_data.get()));
795 } 828 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698