| 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/prefs/scoped_user_pref_update.h" | 6 #include "base/prefs/scoped_user_pref_update.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 virtual ~TestProfileIOData() { | 109 virtual ~TestProfileIOData() { |
| 110 signin_names()->ReleaseResourcesOnUIThread(); | 110 signin_names()->ReleaseResourcesOnUIThread(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // ProfileIOData overrides: | 113 // ProfileIOData overrides: |
| 114 virtual void InitializeInternal( | 114 virtual void InitializeInternal( |
| 115 ProfileParams* profile_params, | 115 ProfileParams* profile_params, |
| 116 content::ProtocolHandlerMap* protocol_handlers, | 116 content::ProtocolHandlerMap* protocol_handlers, |
| 117 content::URLRequestInterceptorScopedVector request_interceptors) | 117 content::URLRequestInterceptorScopedVector request_interceptors) |
| 118 const OVERRIDE { | 118 const override { |
| 119 NOTREACHED(); | 119 NOTREACHED(); |
| 120 } | 120 } |
| 121 virtual void InitializeExtensionsRequestContext( | 121 virtual void InitializeExtensionsRequestContext( |
| 122 ProfileParams* profile_params) const OVERRIDE { | 122 ProfileParams* profile_params) const override { |
| 123 NOTREACHED(); | 123 NOTREACHED(); |
| 124 } | 124 } |
| 125 virtual net::URLRequestContext* InitializeAppRequestContext( | 125 virtual net::URLRequestContext* InitializeAppRequestContext( |
| 126 net::URLRequestContext* main_context, | 126 net::URLRequestContext* main_context, |
| 127 const StoragePartitionDescriptor& details, | 127 const StoragePartitionDescriptor& details, |
| 128 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 128 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 129 protocol_handler_interceptor, | 129 protocol_handler_interceptor, |
| 130 content::ProtocolHandlerMap* protocol_handlers, | 130 content::ProtocolHandlerMap* protocol_handlers, |
| 131 content::URLRequestInterceptorScopedVector request_interceptors) | 131 content::URLRequestInterceptorScopedVector request_interceptors) |
| 132 const OVERRIDE { | 132 const override { |
| 133 NOTREACHED(); | 133 NOTREACHED(); |
| 134 return NULL; | 134 return NULL; |
| 135 } | 135 } |
| 136 virtual net::URLRequestContext* InitializeMediaRequestContext( | 136 virtual net::URLRequestContext* InitializeMediaRequestContext( |
| 137 net::URLRequestContext* original_context, | 137 net::URLRequestContext* original_context, |
| 138 const StoragePartitionDescriptor& details) const OVERRIDE { | 138 const StoragePartitionDescriptor& details) const override { |
| 139 NOTREACHED(); | 139 NOTREACHED(); |
| 140 return NULL; | 140 return NULL; |
| 141 } | 141 } |
| 142 virtual net::URLRequestContext* | 142 virtual net::URLRequestContext* |
| 143 AcquireMediaRequestContext() const OVERRIDE { | 143 AcquireMediaRequestContext() const override { |
| 144 NOTREACHED(); | 144 NOTREACHED(); |
| 145 return NULL; | 145 return NULL; |
| 146 } | 146 } |
| 147 virtual net::URLRequestContext* AcquireIsolatedAppRequestContext( | 147 virtual net::URLRequestContext* AcquireIsolatedAppRequestContext( |
| 148 net::URLRequestContext* main_context, | 148 net::URLRequestContext* main_context, |
| 149 const StoragePartitionDescriptor& partition_descriptor, | 149 const StoragePartitionDescriptor& partition_descriptor, |
| 150 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 150 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 151 protocol_handler_interceptor, | 151 protocol_handler_interceptor, |
| 152 content::ProtocolHandlerMap* protocol_handlers, | 152 content::ProtocolHandlerMap* protocol_handlers, |
| 153 content::URLRequestInterceptorScopedVector request_interceptors) | 153 content::URLRequestInterceptorScopedVector request_interceptors) |
| 154 const OVERRIDE { | 154 const override { |
| 155 NOTREACHED(); | 155 NOTREACHED(); |
| 156 return NULL; | 156 return NULL; |
| 157 } | 157 } |
| 158 virtual net::URLRequestContext* | 158 virtual net::URLRequestContext* |
| 159 AcquireIsolatedMediaRequestContext( | 159 AcquireIsolatedMediaRequestContext( |
| 160 net::URLRequestContext* app_context, | 160 net::URLRequestContext* app_context, |
| 161 const StoragePartitionDescriptor& partition_descriptor) | 161 const StoragePartitionDescriptor& partition_descriptor) |
| 162 const OVERRIDE { | 162 const override { |
| 163 NOTREACHED(); | 163 NOTREACHED(); |
| 164 return NULL; | 164 return NULL; |
| 165 } | 165 } |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 class TestURLRequest : public base::SupportsUserData { | 168 class TestURLRequest : public base::SupportsUserData { |
| 169 public: | 169 public: |
| 170 TestURLRequest() {} | 170 TestURLRequest() {} |
| 171 virtual ~TestURLRequest() {} | 171 virtual ~TestURLRequest() {} |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 class OneClickTestProfileSyncService : public TestProfileSyncService { | 174 class OneClickTestProfileSyncService : public TestProfileSyncService { |
| 175 public: | 175 public: |
| 176 virtual ~OneClickTestProfileSyncService() {} | 176 virtual ~OneClickTestProfileSyncService() {} |
| 177 | 177 |
| 178 // Helper routine to be used in conjunction with | 178 // Helper routine to be used in conjunction with |
| 179 // BrowserContextKeyedServiceFactory::SetTestingFactory(). | 179 // BrowserContextKeyedServiceFactory::SetTestingFactory(). |
| 180 static KeyedService* Build(content::BrowserContext* profile) { | 180 static KeyedService* Build(content::BrowserContext* profile) { |
| 181 return new OneClickTestProfileSyncService(static_cast<Profile*>(profile)); | 181 return new OneClickTestProfileSyncService(static_cast<Profile*>(profile)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 // Need to control this for certain tests. | 184 // Need to control this for certain tests. |
| 185 virtual bool FirstSetupInProgress() const OVERRIDE { | 185 virtual bool FirstSetupInProgress() const override { |
| 186 return first_setup_in_progress_; | 186 return first_setup_in_progress_; |
| 187 } | 187 } |
| 188 | 188 |
| 189 virtual bool sync_initialized() const OVERRIDE { return sync_initialized_; } | 189 virtual bool sync_initialized() const override { return sync_initialized_; } |
| 190 | 190 |
| 191 // Controls return value of FirstSetupInProgress. Because some bits | 191 // Controls return value of FirstSetupInProgress. Because some bits |
| 192 // of UI depend on that value, it's useful to control it separately | 192 // of UI depend on that value, it's useful to control it separately |
| 193 // from the internal work and components that are triggered (such as | 193 // from the internal work and components that are triggered (such as |
| 194 // ReconfigureDataTypeManager) to facilitate unit tests. | 194 // ReconfigureDataTypeManager) to facilitate unit tests. |
| 195 void set_first_setup_in_progress(bool in_progress) { | 195 void set_first_setup_in_progress(bool in_progress) { |
| 196 first_setup_in_progress_ = in_progress; | 196 first_setup_in_progress_ = in_progress; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void set_sync_initialized(bool initialized) { | 199 void set_sync_initialized(bool initialized) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 215 bool first_setup_in_progress_; | 215 bool first_setup_in_progress_; |
| 216 bool sync_initialized_; | 216 bool sync_initialized_; |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 } // namespace | 219 } // namespace |
| 220 | 220 |
| 221 class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { | 221 class OneClickSigninHelperTest : public ChromeRenderViewHostTestHarness { |
| 222 public: | 222 public: |
| 223 OneClickSigninHelperTest(); | 223 OneClickSigninHelperTest(); |
| 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 // Sets up the sign-in manager for tests. If |username| is | 228 // Sets up the sign-in manager for tests. If |username| is |
| 229 // is not empty, the profile of the mock WebContents will be connected to | 229 // is not empty, the profile of the mock WebContents will be connected to |
| 230 // the given account. | 230 // the given account. |
| 231 void SetUpSigninManager(const std::string& username); | 231 void SetUpSigninManager(const std::string& username); |
| 232 | 232 |
| 233 // Set the ID of the signin process that the test will assume to be the | 233 // Set the ID of the signin process that the test will assume to be the |
| 234 // only process allowed to sign the user in to Chrome. | 234 // only process allowed to sign the user in to Chrome. |
| 235 void SetTrustedSigninProcessID(int id); | 235 void SetTrustedSigninProcessID(int id); |
| 236 | 236 |
| 237 void AddEmailToOneClickRejectedList(const std::string& email); | 237 void AddEmailToOneClickRejectedList(const std::string& email); |
| 238 void EnableOneClick(bool enable); | 238 void EnableOneClick(bool enable); |
| 239 void AllowSigninCookies(bool enable); | 239 void AllowSigninCookies(bool enable); |
| 240 void SetAllowedUsernamePattern(const std::string& pattern); | 240 void SetAllowedUsernamePattern(const std::string& pattern); |
| 241 void SubmitGAIAPassword(OneClickSigninHelper* helper); | 241 void SubmitGAIAPassword(OneClickSigninHelper* helper); |
| 242 | 242 |
| 243 SigninManagerMock* signin_manager_; | 243 SigninManagerMock* signin_manager_; |
| 244 FakeProfileOAuth2TokenService* fake_oauth2_token_service_; | 244 FakeProfileOAuth2TokenService* fake_oauth2_token_service_; |
| 245 | 245 |
| 246 protected: | 246 protected: |
| 247 GoogleServiceAuthError no_error_; | 247 GoogleServiceAuthError no_error_; |
| 248 | 248 |
| 249 private: | 249 private: |
| 250 // ChromeRenderViewHostTestHarness overrides: | 250 // ChromeRenderViewHostTestHarness overrides: |
| 251 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE; | 251 virtual content::BrowserContext* CreateBrowserContext() override; |
| 252 | 252 |
| 253 // The ID of the signin process the test will assume to be trusted. | 253 // The ID of the signin process the test will assume to be trusted. |
| 254 // By default, set to the test RenderProcessHost's process ID, but | 254 // By default, set to the test RenderProcessHost's process ID, but |
| 255 // overridden by SetTrustedSigninProcessID. | 255 // overridden by SetTrustedSigninProcessID. |
| 256 int trusted_signin_process_id_; | 256 int trusted_signin_process_id_; |
| 257 | 257 |
| 258 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); | 258 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperTest); |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 OneClickSigninHelperTest::OneClickSigninHelperTest() | 261 OneClickSigninHelperTest::OneClickSigninHelperTest() |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 static_cast<FakeProfileOAuth2TokenService*>( | 341 static_cast<FakeProfileOAuth2TokenService*>( |
| 342 ProfileOAuth2TokenServiceFactory::GetForProfile(profile.get())); | 342 ProfileOAuth2TokenServiceFactory::GetForProfile(profile.get())); |
| 343 | 343 |
| 344 return profile.release(); | 344 return profile.release(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 class OneClickSigninHelperIOTest : public OneClickSigninHelperTest { | 347 class OneClickSigninHelperIOTest : public OneClickSigninHelperTest { |
| 348 public: | 348 public: |
| 349 OneClickSigninHelperIOTest(); | 349 OneClickSigninHelperIOTest(); |
| 350 | 350 |
| 351 virtual void SetUp() OVERRIDE; | 351 virtual void SetUp() override; |
| 352 | 352 |
| 353 TestProfileIOData* CreateTestProfileIOData(Profile::ProfileType profile_type); | 353 TestProfileIOData* CreateTestProfileIOData(Profile::ProfileType profile_type); |
| 354 | 354 |
| 355 protected: | 355 protected: |
| 356 TestingProfileManager testing_profile_manager_; | 356 TestingProfileManager testing_profile_manager_; |
| 357 TestURLRequest request_; | 357 TestURLRequest request_; |
| 358 const GURL valid_gaia_url_; | 358 const GURL valid_gaia_url_; |
| 359 | 359 |
| 360 private: | 360 private: |
| 361 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest); | 361 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 380 CookieSettings::Factory::GetForProfile(profile()).get(); | 380 CookieSettings::Factory::GetForProfile(profile()).get(); |
| 381 TestProfileIOData* io_data = new TestProfileIOData( | 381 TestProfileIOData* io_data = new TestProfileIOData( |
| 382 profile_type, pref_service, local_state, cookie_settings); | 382 profile_type, pref_service, local_state, cookie_settings); |
| 383 io_data->set_reverse_autologin_pending_email("user@gmail.com"); | 383 io_data->set_reverse_autologin_pending_email("user@gmail.com"); |
| 384 return io_data; | 384 return io_data; |
| 385 } | 385 } |
| 386 | 386 |
| 387 class OneClickSigninHelperIncognitoTest : public OneClickSigninHelperTest { | 387 class OneClickSigninHelperIncognitoTest : public OneClickSigninHelperTest { |
| 388 protected: | 388 protected: |
| 389 // content::RenderViewHostTestHarness. | 389 // content::RenderViewHostTestHarness. |
| 390 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE; | 390 virtual content::BrowserContext* CreateBrowserContext() override; |
| 391 }; | 391 }; |
| 392 | 392 |
| 393 content::BrowserContext* | 393 content::BrowserContext* |
| 394 OneClickSigninHelperIncognitoTest::CreateBrowserContext() { | 394 OneClickSigninHelperIncognitoTest::CreateBrowserContext() { |
| 395 // Simulate an incognito profile to run this test. RenderViewHostTestHarness | 395 // Simulate an incognito profile to run this test. RenderViewHostTestHarness |
| 396 // takes ownership of the return value, so it can't be a "proper" incognito | 396 // takes ownership of the return value, so it can't be a "proper" incognito |
| 397 // profile, since they are owned by their parent, non-incognito profile. | 397 // profile, since they are owned by their parent, non-incognito profile. |
| 398 scoped_ptr<TestingProfile> profile = TestingProfile::Builder().Build(); | 398 scoped_ptr<TestingProfile> profile = TestingProfile::Builder().Build(); |
| 399 profile->ForceIncognito(true); | 399 profile->ForceIncognito(true); |
| 400 return profile.release(); | 400 return profile.release(); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 | 855 |
| 856 MockStarterWrapper::MockStarterWrapper( | 856 MockStarterWrapper::MockStarterWrapper( |
| 857 const OneClickSigninHelper::StartSyncArgs& args, | 857 const OneClickSigninHelper::StartSyncArgs& args, |
| 858 OneClickSigninSyncStarter::StartSyncMode start_mode) | 858 OneClickSigninSyncStarter::StartSyncMode start_mode) |
| 859 : testing::StrictMock<OneClickSigninHelper::SyncStarterWrapper>( | 859 : testing::StrictMock<OneClickSigninHelper::SyncStarterWrapper>( |
| 860 args, start_mode) { | 860 args, start_mode) { |
| 861 } | 861 } |
| 862 | 862 |
| 863 class OneClickSyncStarterWrapperTest : public testing::Test { | 863 class OneClickSyncStarterWrapperTest : public testing::Test { |
| 864 public: | 864 public: |
| 865 virtual void SetUp() OVERRIDE { | 865 virtual void SetUp() override { |
| 866 TestingProfile::Builder builder; | 866 TestingProfile::Builder builder; |
| 867 profile_ = builder.Build(); | 867 profile_ = builder.Build(); |
| 868 } | 868 } |
| 869 | 869 |
| 870 virtual void TearDown() OVERRIDE { | 870 virtual void TearDown() override { |
| 871 // Let the SyncStarterWrapper delete itself. | 871 // Let the SyncStarterWrapper delete itself. |
| 872 base::RunLoop().RunUntilIdle(); | 872 base::RunLoop().RunUntilIdle(); |
| 873 } | 873 } |
| 874 | 874 |
| 875 void SetCookie(const std::string& value) { | 875 void SetCookie(const std::string& value) { |
| 876 // Set a valid LSID cookie in the test cookie store. | 876 // Set a valid LSID cookie in the test cookie store. |
| 877 scoped_refptr<net::CookieMonster> cookie_monster = | 877 scoped_refptr<net::CookieMonster> cookie_monster = |
| 878 profile()->GetCookieMonster(); | 878 profile()->GetCookieMonster(); |
| 879 net::CookieOptions options; | 879 net::CookieOptions options; |
| 880 options.set_include_httponly(); | 880 options.set_include_httponly(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 args.email = "foo@gmail.com"; | 979 args.email = "foo@gmail.com"; |
| 980 args.profile = profile(); | 980 args.profile = profile(); |
| 981 MockStarterWrapper* wrapper = new MockStarterWrapper( | 981 MockStarterWrapper* wrapper = new MockStarterWrapper( |
| 982 args, OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 982 args, OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 983 SetCookie("LSID=1234; domain=google.com; secure; httponly"); | 983 SetCookie("LSID=1234; domain=google.com; secure; httponly"); |
| 984 | 984 |
| 985 EXPECT_CALL(*wrapper, DisplayErrorBubble(_)); | 985 EXPECT_CALL(*wrapper, DisplayErrorBubble(_)); |
| 986 wrapper->Start(); | 986 wrapper->Start(); |
| 987 base::RunLoop().RunUntilIdle(); | 987 base::RunLoop().RunUntilIdle(); |
| 988 } | 988 } |
| OLD | NEW |