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/strings/utf_string_conversions.h" | 6 #include "base/strings/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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
13 #include "chrome/browser/profiles/profile_io_data.h" | 13 #include "chrome/browser/profiles/profile_io_data.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/signin/fake_signin_manager.h" | 15 #include "chrome/browser/signin/fake_signin_manager.h" |
16 #include "chrome/browser/signin/signin_manager.h" | 16 #include "chrome/browser/signin/signin_manager.h" |
17 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
18 #include "chrome/browser/signin/signin_names_io_thread.h" | 18 #include "chrome/browser/signin/signin_names_io_thread.h" |
19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/browser/sync/profile_sync_service_mock.h" | 20 #include "chrome/browser/sync/profile_sync_service_mock.h" |
21 #include "chrome/browser/sync/test_profile_sync_service.h" | 21 #include "chrome/browser/sync/test_profile_sync_service.h" |
22 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 22 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
24 #include "chrome/test/base/testing_browser_process.h" | 25 #include "chrome/test/base/testing_browser_process.h" |
25 #include "chrome/test/base/testing_pref_service_syncable.h" | 26 #include "chrome/test/base/testing_pref_service_syncable.h" |
26 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
27 #include "chrome/test/base/testing_profile_manager.h" | 28 #include "chrome/test/base/testing_profile_manager.h" |
28 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/password_form.h" | 31 #include "content/public/common/password_form.h" |
31 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
32 #include "content/public/test/mock_render_process_host.h" | 33 #include "content/public/test/mock_render_process_host.h" |
33 #include "content/public/test/test_renderer_host.h" | |
34 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
35 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
38 | 38 |
39 using ::testing::_; | 39 using ::testing::_; |
40 using ::testing::AtLeast; | 40 using ::testing::AtLeast; |
41 using ::testing::Return; | 41 using ::testing::Return; |
42 | 42 |
43 namespace { | 43 namespace { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bool first_setup_in_progress_; | 188 bool first_setup_in_progress_; |
189 }; | 189 }; |
190 | 190 |
191 static BrowserContextKeyedService* BuildSigninManagerMock( | 191 static BrowserContextKeyedService* BuildSigninManagerMock( |
192 content::BrowserContext* profile) { | 192 content::BrowserContext* profile) { |
193 return new SigninManagerMock(static_cast<Profile*>(profile)); | 193 return new SigninManagerMock(static_cast<Profile*>(profile)); |
194 } | 194 } |
195 | 195 |
196 } // namespace | 196 } // namespace |
197 | 197 |
198 class OneClickSigninHelperTest : public content::RenderViewHostTestHarness { | 198 class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { |
199 public: | 199 public: |
200 OneClickSigninHelperTest(); | 200 OneClickSigninHelperTest(); |
201 | 201 |
202 virtual void SetUp() OVERRIDE; | 202 virtual void SetUp() OVERRIDE; |
203 virtual void TearDown() OVERRIDE; | 203 virtual void TearDown() OVERRIDE; |
204 | 204 |
205 // Creates the sign-in manager for tests. If |use_incognito| is true then | 205 // Creates the sign-in manager for tests. If |use_incognito| is true then |
206 // a WebContents for an incognito profile is created. If |username| is | 206 // a WebContents for an incognito profile is created. If |username| is |
207 // is not empty, the profile of the mock WebContents will be connected to | 207 // is not empty, the profile of the mock WebContents will be connected to |
208 // the given account. | 208 // the given account. |
209 void CreateSigninManager(bool use_incognito, const std::string& username); | 209 void CreateSigninManager(bool use_incognito, const std::string& username); |
210 | 210 |
211 // Set the ID of the signin process that the test will assume to be the | 211 // Set the ID of the signin process that the test will assume to be the |
212 // only process allowed to sign the user in to Chrome. | 212 // only process allowed to sign the user in to Chrome. |
213 void SetTrustedSigninProcessID(int id); | 213 void SetTrustedSigninProcessID(int id); |
214 | 214 |
215 void AddEmailToOneClickRejectedList(const std::string& email); | 215 void AddEmailToOneClickRejectedList(const std::string& email); |
216 void EnableOneClick(bool enable); | 216 void EnableOneClick(bool enable); |
217 void AllowSigninCookies(bool enable); | 217 void AllowSigninCookies(bool enable); |
218 void SetAllowedUsernamePattern(const std::string& pattern); | 218 void SetAllowedUsernamePattern(const std::string& pattern); |
219 ProfileSyncServiceMock* CreateProfileSyncServiceMock(); | 219 ProfileSyncServiceMock* CreateProfileSyncServiceMock(); |
220 void SubmitGAIAPassword(OneClickSigninHelper* helper); | 220 void SubmitGAIAPassword(OneClickSigninHelper* helper); |
221 OneClickSigninHelper* SetupHelperForSignin(); | 221 OneClickSigninHelper* SetupHelperForSignin(); |
222 | 222 |
223 SigninManagerMock* signin_manager_; | 223 SigninManagerMock* signin_manager_; |
224 | 224 |
225 protected: | 225 protected: |
226 TestingProfile* profile_; | |
227 GoogleServiceAuthError no_error_; | 226 GoogleServiceAuthError no_error_; |
228 | 227 |
229 private: | 228 private: |
230 // The ID of the signin process the test will assume to be trusted. | 229 // The ID of the signin process the test will assume to be trusted. |
231 // By default, set to the test RenderProcessHost's process ID, but | 230 // By default, set to the test RenderProcessHost's process ID, but |
232 // overridden by SetTrustedSigninProcessID. | 231 // overridden by SetTrustedSigninProcessID. |
233 int trusted_signin_process_id_; | 232 int trusted_signin_process_id_; |
234 | 233 |
235 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); | 234 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); |
236 }; | 235 }; |
237 | 236 |
238 OneClickSigninHelperTest::OneClickSigninHelperTest() | 237 OneClickSigninHelperTest::OneClickSigninHelperTest() |
239 : profile_(NULL), | 238 : no_error_(GoogleServiceAuthError::NONE), |
240 no_error_(GoogleServiceAuthError::NONE), | |
241 trusted_signin_process_id_(-1) { | 239 trusted_signin_process_id_(-1) { |
242 } | 240 } |
243 | 241 |
244 void OneClickSigninHelperTest::SetUp() { | 242 void OneClickSigninHelperTest::SetUp() { |
245 SyncPromoUI::ForceWebBasedSigninFlowForTesting(true); | 243 SyncPromoUI::ForceWebBasedSigninFlowForTesting(true); |
246 profile_ = new TestingProfile(); | |
247 browser_context_.reset(profile_); | |
248 content::RenderViewHostTestHarness::SetUp(); | 244 content::RenderViewHostTestHarness::SetUp(); |
249 SetTrustedSigninProcessID(process()->GetID()); | 245 SetTrustedSigninProcessID(process()->GetID()); |
250 } | 246 } |
251 | 247 |
252 void OneClickSigninHelperTest::TearDown() { | 248 void OneClickSigninHelperTest::TearDown() { |
253 SyncPromoUI::ForceWebBasedSigninFlowForTesting(false); | 249 SyncPromoUI::ForceWebBasedSigninFlowForTesting(false); |
254 content::RenderViewHostTestHarness::TearDown(); | 250 content::RenderViewHostTestHarness::TearDown(); |
255 } | 251 } |
256 | 252 |
257 void OneClickSigninHelperTest::SetTrustedSigninProcessID(int id) { | 253 void OneClickSigninHelperTest::SetTrustedSigninProcessID(int id) { |
258 trusted_signin_process_id_ = id; | 254 trusted_signin_process_id_ = id; |
259 } | 255 } |
260 | 256 |
261 void OneClickSigninHelperTest::CreateSigninManager( | 257 void OneClickSigninHelperTest::CreateSigninManager( |
262 bool use_incognito, | 258 bool use_incognito, |
263 const std::string& username) { | 259 const std::string& username) { |
264 profile_->set_incognito(use_incognito); | 260 profile()->set_incognito(use_incognito); |
265 signin_manager_ = static_cast<SigninManagerMock*>( | 261 signin_manager_ = static_cast<SigninManagerMock*>( |
266 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 262 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
267 profile_, BuildSigninManagerMock)); | 263 profile(), BuildSigninManagerMock)); |
268 if (signin_manager_) | 264 if (signin_manager_) |
269 signin_manager_->SetSigninProcess(trusted_signin_process_id_); | 265 signin_manager_->SetSigninProcess(trusted_signin_process_id_); |
270 | 266 |
271 if (!username.empty()) { | 267 if (!username.empty()) { |
272 ASSERT_TRUE(signin_manager_); | 268 ASSERT_TRUE(signin_manager_); |
273 signin_manager_->SetAuthenticatedUsername(username); | 269 signin_manager_->SetAuthenticatedUsername(username); |
274 } | 270 } |
275 } | 271 } |
276 | 272 |
277 void OneClickSigninHelperTest::EnableOneClick(bool enable) { | 273 void OneClickSigninHelperTest::EnableOneClick(bool enable) { |
278 PrefService* pref_service = Profile::FromBrowserContext( | 274 PrefService* pref_service = profile()->GetPrefs(); |
279 browser_context_.get())->GetPrefs(); | |
280 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); | 275 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); |
281 } | 276 } |
282 | 277 |
283 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList( | 278 void OneClickSigninHelperTest::AddEmailToOneClickRejectedList( |
284 const std::string& email) { | 279 const std::string& email) { |
285 PrefService* pref_service = Profile::FromBrowserContext( | 280 PrefService* pref_service = profile()->GetPrefs(); |
286 browser_context_.get())->GetPrefs(); | |
287 ListPrefUpdate updater(pref_service, | 281 ListPrefUpdate updater(pref_service, |
288 prefs::kReverseAutologinRejectedEmailList); | 282 prefs::kReverseAutologinRejectedEmailList); |
289 updater->AppendIfNotPresent(new base::StringValue(email)); | 283 updater->AppendIfNotPresent(new base::StringValue(email)); |
290 } | 284 } |
291 | 285 |
292 void OneClickSigninHelperTest::AllowSigninCookies(bool enable) { | 286 void OneClickSigninHelperTest::AllowSigninCookies(bool enable) { |
293 CookieSettings* cookie_settings = CookieSettings::Factory::GetForProfile( | 287 CookieSettings* cookie_settings = |
294 Profile::FromBrowserContext(browser_context_.get())).get(); | 288 CookieSettings::Factory::GetForProfile(profile()).get(); |
295 cookie_settings->SetDefaultCookieSetting(enable ? CONTENT_SETTING_ALLOW | 289 cookie_settings->SetDefaultCookieSetting(enable ? CONTENT_SETTING_ALLOW |
296 : CONTENT_SETTING_BLOCK); | 290 : CONTENT_SETTING_BLOCK); |
297 } | 291 } |
298 | 292 |
299 void OneClickSigninHelperTest::SetAllowedUsernamePattern( | 293 void OneClickSigninHelperTest::SetAllowedUsernamePattern( |
300 const std::string& pattern) { | 294 const std::string& pattern) { |
301 PrefService* local_state = g_browser_process->local_state(); | 295 PrefService* local_state = g_browser_process->local_state(); |
302 local_state->SetString(prefs::kGoogleServicesUsernamePattern, pattern); | 296 local_state->SetString(prefs::kGoogleServicesUsernamePattern, pattern); |
303 } | 297 } |
304 | 298 |
305 ProfileSyncServiceMock* | 299 ProfileSyncServiceMock* |
306 OneClickSigninHelperTest::CreateProfileSyncServiceMock() { | 300 OneClickSigninHelperTest::CreateProfileSyncServiceMock() { |
307 ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( | 301 ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( |
308 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 302 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
309 profile_, | 303 profile(), |
310 ProfileSyncServiceMock::BuildMockProfileSyncService)); | 304 ProfileSyncServiceMock::BuildMockProfileSyncService)); |
311 EXPECT_CALL(*sync_service, SetSetupInProgress(true)); | 305 EXPECT_CALL(*sync_service, SetSetupInProgress(true)); |
312 EXPECT_CALL(*sync_service, AddObserver(_)).Times(AtLeast(1)); | 306 EXPECT_CALL(*sync_service, AddObserver(_)).Times(AtLeast(1)); |
313 EXPECT_CALL(*sync_service, FirstSetupInProgress()).WillRepeatedly( | 307 EXPECT_CALL(*sync_service, FirstSetupInProgress()).WillRepeatedly( |
314 Return(false)); | 308 Return(false)); |
315 EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(true)); | 309 EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(true)); |
316 EXPECT_CALL(*sync_service, RemoveObserver(_)).Times(AtLeast(1)); | 310 EXPECT_CALL(*sync_service, RemoveObserver(_)).Times(AtLeast(1)); |
317 EXPECT_CALL(*sync_service, GetAuthError()). | 311 EXPECT_CALL(*sync_service, GetAuthError()). |
318 WillRepeatedly(::testing::ReturnRef(no_error_)); | 312 WillRepeatedly(::testing::ReturnRef(no_error_)); |
319 EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(false)); | 313 EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(false)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 valid_gaia_url_("https://accounts.google.com/") { | 348 valid_gaia_url_("https://accounts.google.com/") { |
355 } | 349 } |
356 | 350 |
357 void OneClickSigninHelperIOTest::SetUp() { | 351 void OneClickSigninHelperIOTest::SetUp() { |
358 OneClickSigninHelperTest::SetUp(); | 352 OneClickSigninHelperTest::SetUp(); |
359 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 353 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
360 } | 354 } |
361 | 355 |
362 TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData( | 356 TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData( |
363 bool is_incognito) { | 357 bool is_incognito) { |
364 PrefService* pref_service = profile_->GetPrefs(); | 358 PrefService* pref_service = profile()->GetPrefs(); |
365 PrefService* local_state = g_browser_process->local_state(); | 359 PrefService* local_state = g_browser_process->local_state(); |
366 CookieSettings* cookie_settings = | 360 CookieSettings* cookie_settings = |
367 CookieSettings::Factory::GetForProfile(profile_).get(); | 361 CookieSettings::Factory::GetForProfile(profile()).get(); |
368 TestProfileIOData* io_data = new TestProfileIOData( | 362 TestProfileIOData* io_data = new TestProfileIOData( |
369 is_incognito, pref_service, local_state, cookie_settings); | 363 is_incognito, pref_service, local_state, cookie_settings); |
370 io_data->set_reverse_autologin_pending_email("user@gmail.com"); | 364 io_data->set_reverse_autologin_pending_email("user@gmail.com"); |
371 return io_data; | 365 return io_data; |
372 } | 366 } |
373 | 367 |
374 TEST_F(OneClickSigninHelperTest, CanOfferNoContents) { | 368 TEST_F(OneClickSigninHelperTest, CanOfferNoContents) { |
375 std::string error_message; | 369 std::string error_message; |
376 EXPECT_FALSE(OneClickSigninHelper::CanOffer( | 370 EXPECT_FALSE(OneClickSigninHelper::CanOffer( |
377 NULL, OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, | 371 NULL, OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 593 |
600 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). | 594 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). |
601 WillRepeatedly(Return(true)); | 595 WillRepeatedly(Return(true)); |
602 | 596 |
603 EnableOneClick(true); | 597 EnableOneClick(true); |
604 EXPECT_TRUE(OneClickSigninHelper::CanOffer( | 598 EXPECT_TRUE(OneClickSigninHelper::CanOffer( |
605 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, | 599 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, |
606 "user@gmail.com", NULL)); | 600 "user@gmail.com", NULL)); |
607 | 601 |
608 // Simulate a policy disabling signin by writing kSigninAllowed directly. | 602 // Simulate a policy disabling signin by writing kSigninAllowed directly. |
609 profile_->GetTestingPrefService()->SetManagedPref( | 603 profile()->GetTestingPrefService()->SetManagedPref( |
610 prefs::kSigninAllowed, base::Value::CreateBooleanValue(false)); | 604 prefs::kSigninAllowed, base::Value::CreateBooleanValue(false)); |
611 | 605 |
612 EXPECT_FALSE(OneClickSigninHelper::CanOffer( | 606 EXPECT_FALSE(OneClickSigninHelper::CanOffer( |
613 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, | 607 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, |
614 "user@gmail.com", NULL)); | 608 "user@gmail.com", NULL)); |
615 | 609 |
616 // Reset the preference value to true. | 610 // Reset the preference value to true. |
617 profile_->GetTestingPrefService()->SetManagedPref( | 611 profile()->GetTestingPrefService()->SetManagedPref( |
618 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); | 612 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); |
619 | 613 |
620 // Simulate a policy disabling sync by writing kSyncManaged directly. | 614 // Simulate a policy disabling sync by writing kSyncManaged directly. |
621 profile_->GetTestingPrefService()->SetManagedPref( | 615 profile()->GetTestingPrefService()->SetManagedPref( |
622 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); | 616 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); |
623 | 617 |
624 // Should still offer even if sync is disabled by policy. | 618 // Should still offer even if sync is disabled by policy. |
625 EXPECT_TRUE(OneClickSigninHelper::CanOffer( | 619 EXPECT_TRUE(OneClickSigninHelper::CanOffer( |
626 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, | 620 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, |
627 "user@gmail.com", NULL)); | 621 "user@gmail.com", NULL)); |
628 } | 622 } |
629 | 623 |
630 // Should not crash if a helper instance is not associated with an incognito | 624 // Should not crash if a helper instance is not associated with an incognito |
631 // web contents. | 625 // web contents. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 | 746 |
753 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabled) { | 747 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabled) { |
754 EnableOneClick(false); | 748 EnableOneClick(false); |
755 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 749 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
756 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, | 750 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, |
757 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 751 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
758 valid_gaia_url_, std::string(), &request_, io_data.get())); | 752 valid_gaia_url_, std::string(), &request_, io_data.get())); |
759 } | 753 } |
760 | 754 |
761 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadSignedIn) { | 755 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadSignedIn) { |
762 PrefService* pref_service = profile_->GetPrefs(); | 756 PrefService* pref_service = profile()->GetPrefs(); |
763 pref_service->SetString(prefs::kGoogleServicesUsername, "user@gmail.com"); | 757 pref_service->SetString(prefs::kGoogleServicesUsername, "user@gmail.com"); |
764 | 758 |
765 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 759 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
766 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, | 760 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, |
767 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 761 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
768 valid_gaia_url_, std::string(), &request_, io_data.get())); | 762 valid_gaia_url_, std::string(), &request_, io_data.get())); |
769 } | 763 } |
770 | 764 |
771 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadEmailNotAllowed) { | 765 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadEmailNotAllowed) { |
772 SetAllowedUsernamePattern("*@example.com"); | 766 SetAllowedUsernamePattern("*@example.com"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 } | 800 } |
807 | 801 |
808 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabledByPolicy) { | 802 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadDisabledByPolicy) { |
809 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 803 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
810 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 804 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
811 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 805 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
812 valid_gaia_url_, std::string(), &request_, io_data.get())); | 806 valid_gaia_url_, std::string(), &request_, io_data.get())); |
813 | 807 |
814 // Simulate a policy disabling signin by writing kSigninAllowed directly. | 808 // Simulate a policy disabling signin by writing kSigninAllowed directly. |
815 // We should not offer to sign in the browser. | 809 // We should not offer to sign in the browser. |
816 profile_->GetTestingPrefService()->SetManagedPref( | 810 profile()->GetTestingPrefService()->SetManagedPref( |
817 prefs::kSigninAllowed, base::Value::CreateBooleanValue(false)); | 811 prefs::kSigninAllowed, base::Value::CreateBooleanValue(false)); |
818 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, | 812 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, |
819 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 813 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
820 valid_gaia_url_, std::string(), &request_, io_data.get())); | 814 valid_gaia_url_, std::string(), &request_, io_data.get())); |
821 | 815 |
822 // Reset the preference. | 816 // Reset the preference. |
823 profile_->GetTestingPrefService()->SetManagedPref( | 817 profile()->GetTestingPrefService()->SetManagedPref( |
824 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); | 818 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); |
825 | 819 |
826 // Simulate a policy disabling sync by writing kSyncManaged directly. | 820 // Simulate a policy disabling sync by writing kSyncManaged directly. |
827 // We should still offer to sign in the browser. | 821 // We should still offer to sign in the browser. |
828 profile_->GetTestingPrefService()->SetManagedPref( | 822 profile()->GetTestingPrefService()->SetManagedPref( |
829 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); | 823 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); |
830 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 824 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
831 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 825 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
832 valid_gaia_url_, std::string(), &request_, io_data.get())); | 826 valid_gaia_url_, std::string(), &request_, io_data.get())); |
833 } | 827 } |
OLD | NEW |