Chromium Code Reviews| Index: chrome/browser/ui/sync/one_click_signin_helper_unittest.cc |
| diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc |
| index c61d8065496d26dcd26630d8c41a265cc8731273..17dca514c5940b2a6f09b1f7ff75241ba53dce71 100644 |
| --- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc |
| +++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include "base/prefs/pref_service.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/content_settings/cookie_settings.h" |
| #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| @@ -13,6 +14,8 @@ |
| #include "chrome/browser/profiles/profile_io_data.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/signin/fake_signin_manager.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| #include "chrome/browser/signin/signin_manager.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| #include "chrome/browser/signin/signin_names_io_thread.h" |
| @@ -21,6 +24,8 @@ |
| #include "chrome/browser/sync/profile_sync_service_mock.h" |
| #include "chrome/browser/sync/test_profile_sync_service.h" |
| #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| +#include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| +#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_browser_process.h" |
| @@ -62,6 +67,42 @@ class SigninManagerMock : public FakeSigninManager { |
| MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); |
| }; |
| +static BrowserContextKeyedService* BuildSigninManagerMock( |
| + content::BrowserContext* profile) { |
| + return new SigninManagerMock(static_cast<Profile*>(profile)); |
| +} |
| + |
| +class OAuth2TokenServiceMock : public ProfileOAuth2TokenService { |
|
Andrew T Wilson (Slow)
2013/08/19 15:23:06
Technically this isn't a Mock, it's a Fake. Again,
Roger Tawa OOO till Jul 10th
2013/08/29 19:28:41
Done.
|
| + public: |
| + // For testing: set the refresh token to be used. |
| + void set_refresh_token(const std::string& refresh_token) { |
| + refresh_token_ = refresh_token; |
| + } |
| + |
| + protected: |
| + virtual std::string GetRefreshToken() OVERRIDE { return refresh_token_; } |
| + |
| + private: |
| + // OAuth2TokenService implementation. |
| + virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE { |
| + return NULL; |
| + } |
| + |
| + std::string refresh_token_; |
| +}; |
| + |
| +static BrowserContextKeyedService* BuildOAuth2TokenServiceMock( |
| + content::BrowserContext* profile) { |
| + OAuth2TokenServiceMock* token_service = new OAuth2TokenServiceMock; |
| + token_service->Initialize(static_cast<Profile*>(profile)); |
| + return token_service; |
| +} |
| + |
| +class FakeLoginUI : public LoginUIService::LoginUI { |
| + virtual void FocusUI() OVERRIDE {} |
| + virtual void CloseUI() OVERRIDE {} |
| +}; |
| + |
| class TestProfileIOData : public ProfileIOData { |
| public: |
| TestProfileIOData(bool is_incognito, PrefService* pref_service, |
| @@ -191,11 +232,6 @@ class OneClickTestProfileSyncService : public TestProfileSyncService { |
| bool first_setup_in_progress_; |
| }; |
| -static BrowserContextKeyedService* BuildSigninManagerMock( |
| - content::BrowserContext* profile) { |
| - return new SigninManagerMock(static_cast<Profile*>(profile)); |
| -} |
| - |
| } // namespace |
| class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { |
| @@ -211,6 +247,10 @@ class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { |
| // the given account. |
| void CreateSigninManager(bool use_incognito, const std::string& username); |
| + // Creates the oauth2 token service, and provides a way to fire a dummy |
| + // fresh token available event. |
| + void CreateOAuth2TokenService(); |
| + |
| // Set the ID of the signin process that the test will assume to be the |
| // only process allowed to sign the user in to Chrome. |
| void SetTrustedSigninProcessID(int id); |
| @@ -224,6 +264,7 @@ class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { |
| OneClickSigninHelper* SetupHelperForSignin(); |
| SigninManagerMock* signin_manager_; |
| + OAuth2TokenServiceMock* token_service_; |
| protected: |
| GoogleServiceAuthError no_error_; |
| @@ -238,7 +279,9 @@ class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { |
| }; |
| OneClickSigninHelperTest::OneClickSigninHelperTest() |
| - : no_error_(GoogleServiceAuthError::NONE), |
| + : signin_manager_(NULL), |
| + token_service_(NULL), |
| + no_error_(GoogleServiceAuthError::NONE), |
| trusted_signin_process_id_(-1) { |
| } |
| @@ -273,6 +316,12 @@ void OneClickSigninHelperTest::CreateSigninManager( |
| } |
| } |
| +void OneClickSigninHelperTest::CreateOAuth2TokenService() { |
| + token_service_ = static_cast<OAuth2TokenServiceMock*>( |
| + ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| + profile(), BuildOAuth2TokenServiceMock)); |
| +} |
| + |
| void OneClickSigninHelperTest::EnableOneClick(bool enable) { |
| PrefService* pref_service = profile()->GetPrefs(); |
| pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); |
| @@ -642,6 +691,7 @@ TEST_F(OneClickSigninHelperTest, ShowInfoBarUIThreadIncognito) { |
| // config sync, then Chrome should redirect immediately to sync settings page, |
| // and upon successful setup, redirect back to webstore. |
| TEST_F(OneClickSigninHelperTest, SigninFromWebstoreWithConfigSyncfirst) { |
| + CreateOAuth2TokenService(); |
| CreateSigninManager(false, std::string()); |
| EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)) |
| .WillRepeatedly(Return(true)); |
| @@ -667,6 +717,17 @@ TEST_F(OneClickSigninHelperTest, SigninFromWebstoreWithConfigSyncfirst) { |
| NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); |
| helper->DidStopLoading(rvh()); |
| + token_service_->set_refresh_token("refresh_token"); |
| + FakeLoginUI fake_login_ui; |
| + LoginUIServiceFactory::GetForProfile(profile())->SetLoginUI(&fake_login_ui); |
| + GoogleServiceSigninSuccessDetails details("user@gmail.com", "password"); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| + content::Source<Profile>(profile()), |
| + content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| + LoginUIServiceFactory::GetForProfile(profile())-> |
| + LoginUIClosed(&fake_login_ui); |
| + |
| helper->OnStateChanged(); |
| EXPECT_EQ(GURL(continueUrl), contents->GetURL()); |
| EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); |