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

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

Issue 160363002: OneClickSigninHelper::CanOffer checks IsEnableWebBasedSignin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h"
5 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
6 #include "base/prefs/scoped_user_pref_update.h" 7 #include "base/prefs/scoped_user_pref_update.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/content_settings/cookie_settings.h" 11 #include "chrome/browser/content_settings/cookie_settings.h"
11 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 12 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_info_cache.h" 14 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_io_data.h" 15 #include "chrome/browser/profiles/profile_io_data.h"
15 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 17 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
17 #include "chrome/browser/signin/fake_signin_manager.h" 18 #include "chrome/browser/signin/fake_signin_manager.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service.h"
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20 #include "chrome/browser/signin/signin_manager.h" 21 #include "chrome/browser/signin/signin_manager.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 22 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/signin_names_io_thread.h" 23 #include "chrome/browser/signin/signin_names_io_thread.h"
23 #include "chrome/browser/signin/signin_promo.h" 24 #include "chrome/browser/signin/signin_promo.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 25 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/sync/profile_sync_service_mock.h" 26 #include "chrome/browser/sync/profile_sync_service_mock.h"
26 #include "chrome/browser/sync/test_profile_sync_service.h" 27 #include "chrome/browser/sync/test_profile_sync_service.h"
27 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 28 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
28 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 29 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
29 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 30 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
31 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 33 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
32 #include "chrome/test/base/testing_browser_process.h" 34 #include "chrome/test/base/testing_browser_process.h"
33 #include "chrome/test/base/testing_pref_service_syncable.h" 35 #include "chrome/test/base/testing_pref_service_syncable.h"
34 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
35 #include "chrome/test/base/testing_profile_manager.h" 37 #include "chrome/test/base/testing_profile_manager.h"
36 #include "components/autofill/core/common/password_form.h" 38 #include "components/autofill/core/common/password_form.h"
37 #include "content/public/browser/browser_context.h" 39 #include "content/public/browser/browser_context.h"
38 #include "content/public/browser/navigation_details.h" 40 #include "content/public/browser/navigation_details.h"
39 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 first_setup_in_progress_(false) {} 188 first_setup_in_progress_(false) {}
187 189
188 bool first_setup_in_progress_; 190 bool first_setup_in_progress_;
189 }; 191 };
190 192
191 } // namespace 193 } // namespace
192 194
193 class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { 195 class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness {
194 public: 196 public:
195 OneClickSigninHelperTest(); 197 OneClickSigninHelperTest();
198 virtual ~OneClickSigninHelperTest();
196 199
197 virtual void SetUp() OVERRIDE; 200 virtual void SetUp() OVERRIDE;
198 virtual void TearDown() OVERRIDE; 201 virtual void TearDown() OVERRIDE;
199 202
200 // Creates the sign-in manager for tests. If |username| is 203 // Creates the sign-in manager for tests. If |username| is
201 // is not empty, the profile of the mock WebContents will be connected to 204 // is not empty, the profile of the mock WebContents will be connected to
202 // the given account. 205 // the given account.
203 void CreateSigninManager(const std::string& username); 206 void CreateSigninManager(const std::string& username);
204 207
205 // Set the ID of the signin process that the test will assume to be the 208 // Set the ID of the signin process that the test will assume to be the
206 // only process allowed to sign the user in to Chrome. 209 // only process allowed to sign the user in to Chrome.
207 void SetTrustedSigninProcessID(int id); 210 void SetTrustedSigninProcessID(int id);
208 211
209 void AddEmailToOneClickRejectedList(const std::string& email); 212 void AddEmailToOneClickRejectedList(const std::string& email);
210 void EnableOneClick(bool enable); 213 void EnableOneClick(bool enable);
211 void AllowSigninCookies(bool enable); 214 void AllowSigninCookies(bool enable);
212 void SetAllowedUsernamePattern(const std::string& pattern); 215 void SetAllowedUsernamePattern(const std::string& pattern);
213 ProfileSyncServiceMock* CreateProfileSyncServiceMock(); 216 ProfileSyncServiceMock* CreateProfileSyncServiceMock();
214 void SubmitGAIAPassword(OneClickSigninHelper* helper); 217 void SubmitGAIAPassword(OneClickSigninHelper* helper);
215 218
216 SigninManagerMock* signin_manager_; 219 SigninManagerMock* signin_manager_;
217 FakeProfileOAuth2TokenService* fake_oauth2_token_service_; 220 FakeProfileOAuth2TokenService* fake_oauth2_token_service_;
218 221
219 protected: 222 protected:
223 enum SetupArgument { ENABLE_WEB_BASED_SIGNIN, DISABLE_WEB_BASED_SIGNIN };
224
225 // A helper method to SetUp(void).
226 void SetUp(SetupArgument arg);
227
220 GoogleServiceAuthError no_error_; 228 GoogleServiceAuthError no_error_;
221 229
222 private: 230 private:
223 // ChromeRenderViewHostTestHarness overrides: 231 // ChromeRenderViewHostTestHarness overrides:
224 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE; 232 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE;
225 233
226 // The ID of the signin process the test will assume to be trusted. 234 // The ID of the signin process the test will assume to be trusted.
227 // By default, set to the test RenderProcessHost's process ID, but 235 // By default, set to the test RenderProcessHost's process ID, but
228 // overridden by SetTrustedSigninProcessID. 236 // overridden by SetTrustedSigninProcessID.
229 int trusted_signin_process_id_; 237 int trusted_signin_process_id_;
230 238
231 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); 239 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest);
232 }; 240 };
233 241
234 OneClickSigninHelperTest::OneClickSigninHelperTest() 242 OneClickSigninHelperTest::OneClickSigninHelperTest()
235 : signin_manager_(NULL), 243 : signin_manager_(NULL),
236 fake_oauth2_token_service_(NULL), 244 fake_oauth2_token_service_(NULL),
237 no_error_(GoogleServiceAuthError::NONE), 245 no_error_(GoogleServiceAuthError::NONE),
238 trusted_signin_process_id_(-1) { 246 trusted_signin_process_id_(-1) {
239 } 247 }
240 248
249 OneClickSigninHelperTest::~OneClickSigninHelperTest() {}
250
241 void OneClickSigninHelperTest::SetUp() { 251 void OneClickSigninHelperTest::SetUp() {
252 SetUp(ENABLE_WEB_BASED_SIGNIN);
253 }
254
255 void OneClickSigninHelperTest::SetUp(SetupArgument arg) {
256 if (arg == ENABLE_WEB_BASED_SIGNIN) {
257 CommandLine::ForCurrentProcess()->AppendSwitch(
258 switches::kEnableWebBasedSignin);
259 }
242 signin::ForceWebBasedSigninFlowForTesting(true); 260 signin::ForceWebBasedSigninFlowForTesting(true);
243 content::RenderViewHostTestHarness::SetUp(); 261 content::RenderViewHostTestHarness::SetUp();
244 SetTrustedSigninProcessID(process()->GetID()); 262 SetTrustedSigninProcessID(process()->GetID());
245 } 263 }
246 264
247 void OneClickSigninHelperTest::TearDown() { 265 void OneClickSigninHelperTest::TearDown() {
248 signin::ForceWebBasedSigninFlowForTesting(false); 266 signin::ForceWebBasedSigninFlowForTesting(false);
249 content::RenderViewHostTestHarness::TearDown(); 267 content::RenderViewHostTestHarness::TearDown();
250 } 268 }
251 269
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 fake_oauth2_token_service_ = 345 fake_oauth2_token_service_ =
328 static_cast<FakeProfileOAuth2TokenService*>( 346 static_cast<FakeProfileOAuth2TokenService*>(
329 ProfileOAuth2TokenServiceFactory::GetForProfile(profile.get())); 347 ProfileOAuth2TokenServiceFactory::GetForProfile(profile.get()));
330 348
331 return profile.release(); 349 return profile.release();
332 } 350 }
333 351
334 class OneClickSigninHelperIOTest : public OneClickSigninHelperTest { 352 class OneClickSigninHelperIOTest : public OneClickSigninHelperTest {
335 public: 353 public:
336 OneClickSigninHelperIOTest(); 354 OneClickSigninHelperIOTest();
355 virtual ~OneClickSigninHelperIOTest();
337 356
338 virtual void SetUp() OVERRIDE; 357 virtual void SetUp() OVERRIDE;
339 358
340 TestProfileIOData* CreateTestProfileIOData(bool is_incognito); 359 TestProfileIOData* CreateTestProfileIOData(bool is_incognito);
341 360
342 protected: 361 protected:
343 TestingProfileManager testing_profile_manager_; 362 TestingProfileManager testing_profile_manager_;
344 TestURLRequest request_; 363 TestURLRequest request_;
345 const GURL valid_gaia_url_; 364 const GURL valid_gaia_url_;
346 365
347 private: 366 private:
348 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest); 367 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest);
349 }; 368 };
350 369
351 OneClickSigninHelperIOTest::OneClickSigninHelperIOTest() 370 OneClickSigninHelperIOTest::OneClickSigninHelperIOTest()
352 : testing_profile_manager_( 371 : testing_profile_manager_(
353 TestingBrowserProcess::GetGlobal()), 372 TestingBrowserProcess::GetGlobal()),
354 valid_gaia_url_("https://accounts.google.com/") { 373 valid_gaia_url_("https://accounts.google.com/") {
355 } 374 }
356 375
376 OneClickSigninHelperIOTest::~OneClickSigninHelperIOTest() {}
377
357 void OneClickSigninHelperIOTest::SetUp() { 378 void OneClickSigninHelperIOTest::SetUp() {
358 OneClickSigninHelperTest::SetUp(); 379 OneClickSigninHelperTest::SetUp();
359 ASSERT_TRUE(testing_profile_manager_.SetUp()); 380 ASSERT_TRUE(testing_profile_manager_.SetUp());
360 } 381 }
361 382
362 TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData( 383 TestProfileIOData* OneClickSigninHelperIOTest::CreateTestProfileIOData(
363 bool is_incognito) { 384 bool is_incognito) {
364 PrefService* pref_service = profile()->GetPrefs(); 385 PrefService* pref_service = profile()->GetPrefs();
365 PrefService* local_state = g_browser_process->local_state(); 386 PrefService* local_state = g_browser_process->local_state();
366 CookieSettings* cookie_settings = 387 CookieSettings* cookie_settings =
(...skipping 11 matching lines...) Expand all
378 }; 399 };
379 400
380 content::BrowserContext* 401 content::BrowserContext*
381 OneClickSigninHelperIncognitoTest::CreateBrowserContext() { 402 OneClickSigninHelperIncognitoTest::CreateBrowserContext() {
382 // Builds an incognito profile to run this test. 403 // Builds an incognito profile to run this test.
383 TestingProfile::Builder builder; 404 TestingProfile::Builder builder;
384 builder.SetIncognito(); 405 builder.SetIncognito();
385 return builder.Build().release(); 406 return builder.Build().release();
386 } 407 }
387 408
409 class OneClickSigninHelperDisableWebBasedSigninTest
410 : public OneClickSigninHelperTest {
411 public:
412 // No additional data members => no need to declare a virtual destructor.
413 virtual void SetUp() OVERRIDE;
414 };
415
416 void OneClickSigninHelperDisableWebBasedSigninTest::SetUp() {
417 OneClickSigninHelperTest::SetUp(DISABLE_WEB_BASED_SIGNIN);
418 }
Roger Tawa OOO till Jul 10th 2014/02/12 15:36:50 Please use testing::TestWithParam and TEST_P macro
vabr (Chromium) 2014/02/12 18:42:15 Modifications to the unit-test dropped.
419
388 TEST_F(OneClickSigninHelperTest, CanOfferNoContents) { 420 TEST_F(OneClickSigninHelperTest, CanOfferNoContents) {
389 std::string error_message; 421 std::string error_message;
390 EXPECT_FALSE(OneClickSigninHelper::CanOffer( 422 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
391 NULL, OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, 423 NULL, OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY,
392 "user@gmail.com", &error_message)); 424 "user@gmail.com", &error_message));
393 EXPECT_EQ("", error_message); 425 EXPECT_EQ("", error_message);
394 EXPECT_FALSE(OneClickSigninHelper::CanOffer( 426 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
395 NULL, OneClickSigninHelper::CAN_OFFER_FOR_ALL, 427 NULL, OneClickSigninHelper::CAN_OFFER_FOR_ALL,
396 "user@gmail.com", &error_message)); 428 "user@gmail.com", &error_message));
397 EXPECT_EQ("", error_message); 429 EXPECT_EQ("", error_message);
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); 870 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true));
839 871
840 // Simulate a policy disabling sync by writing kSyncManaged directly. 872 // Simulate a policy disabling sync by writing kSyncManaged directly.
841 // We should still offer to sign in the browser. 873 // We should still offer to sign in the browser.
842 profile()->GetTestingPrefService()->SetManagedPref( 874 profile()->GetTestingPrefService()->SetManagedPref(
843 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); 875 prefs::kSyncManaged, base::Value::CreateBooleanValue(true));
844 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, 876 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER,
845 OneClickSigninHelper::CanOfferOnIOThreadImpl( 877 OneClickSigninHelper::CanOfferOnIOThreadImpl(
846 valid_gaia_url_, &request_, io_data.get())); 878 valid_gaia_url_, &request_, io_data.get()));
847 } 879 }
880
881 TEST_F(OneClickSigninHelperDisableWebBasedSigninTest, CanOffer) {
882 CreateSigninManager(std::string());
883
884 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)).
885 WillRepeatedly(Return(true));
Roger Tawa OOO till Jul 10th 2014/02/12 15:36:50 Indent 2 less.
vabr (Chromium) 2014/02/12 18:42:15 Modifications to the unit-test dropped.
886
887 // Whithout the "enable-web-based-signin" flag, CanOffer should always return
888 // false, independently of the OneClick setting.
889 for (int i = 0; i < 2; ++i) {
890 bool enable_one_click = !i;
891 EnableOneClick(enable_one_click);
892 SCOPED_TRACE(testing::Message()
893 << "enable_one_click = " << enable_one_click);
894 std::string error_message;
895
896 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
897 web_contents(),
898 OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY,
899 "user@gmail.com",
900 &error_message));
901 EXPECT_EQ("", error_message);
902 EXPECT_FALSE(
903 OneClickSigninHelper::CanOffer(web_contents(),
904 OneClickSigninHelper::CAN_OFFER_FOR_ALL,
905 "user@gmail.com",
906 &error_message));
907 EXPECT_EQ("", error_message);
908 EXPECT_FALSE(OneClickSigninHelper::CanOffer(
909 web_contents(),
910 OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY,
911 std::string(),
912 &error_message));
913 EXPECT_EQ("", error_message);
914 }
915 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698