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/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" |
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_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/browser/signin/signin_names_io_thread.h" | 18 #include "chrome/browser/signin/signin_names_io_thread.h" |
18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
19 #include "chrome/browser/sync/profile_sync_service_mock.h" | 20 #include "chrome/browser/sync/profile_sync_service_mock.h" |
20 #include "chrome/browser/sync/test_profile_sync_service.h" | 21 #include "chrome/browser/sync/test_profile_sync_service.h" |
21 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 22 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chrome/test/base/testing_pref_service_syncable.h" | 25 #include "chrome/test/base/testing_pref_service_syncable.h" |
25 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
(...skipping 20 matching lines...) Expand all Loading... |
46 // points. Implicit URLs are those to sign for some Google service, like gmail | 47 // points. Implicit URLs are those to sign for some Google service, like gmail |
47 // or drive. In former case, with a valid URL, we don't want to offer the | 48 // or drive. In former case, with a valid URL, we don't want to offer the |
48 // interstitial. In all other cases we do. | 49 // interstitial. In all other cases we do. |
49 | 50 |
50 const char kImplicitURLString[] = | 51 const char kImplicitURLString[] = |
51 "https://accounts.google.com/ServiceLogin" | 52 "https://accounts.google.com/ServiceLogin" |
52 "?service=foo&continue=http://foo.google.com"; | 53 "?service=foo&continue=http://foo.google.com"; |
53 | 54 |
54 class SigninManagerMock : public FakeSigninManager { | 55 class SigninManagerMock : public FakeSigninManager { |
55 public: | 56 public: |
56 explicit SigninManagerMock(Profile* profile) | 57 explicit SigninManagerMock(Profile* profile) : FakeSigninManager(profile) { |
57 : FakeSigninManager(profile) {} | 58 } |
58 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); | 59 MOCK_CONST_METHOD1(IsAllowedUsername, bool(const std::string& username)); |
59 }; | 60 }; |
60 | 61 |
61 class TestProfileIOData : public ProfileIOData { | 62 class TestProfileIOData : public ProfileIOData { |
62 public: | 63 public: |
63 TestProfileIOData(bool is_incognito, PrefService* pref_service, | 64 TestProfileIOData(bool is_incognito, PrefService* pref_service, |
64 PrefService* local_state, CookieSettings* cookie_settings) | 65 PrefService* local_state, CookieSettings* cookie_settings) |
65 : ProfileIOData(is_incognito) { | 66 : ProfileIOData(is_incognito) { |
66 // Initialize the IO members required for these tests, but keep them on | 67 // Initialize the IO members required for these tests, but keep them on |
67 // this thread since we don't use a background thread here. | 68 // this thread since we don't use a background thread here. |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 261 |
261 void OneClickSigninHelperTest::CreateSigninManager( | 262 void OneClickSigninHelperTest::CreateSigninManager( |
262 bool use_incognito, | 263 bool use_incognito, |
263 const std::string& username) { | 264 const std::string& username) { |
264 profile_->set_incognito(use_incognito); | 265 profile_->set_incognito(use_incognito); |
265 signin_manager_ = static_cast<SigninManagerMock*>( | 266 signin_manager_ = static_cast<SigninManagerMock*>( |
266 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 267 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
267 profile_, BuildSigninManagerMock)); | 268 profile_, BuildSigninManagerMock)); |
268 if (signin_manager_) | 269 if (signin_manager_) |
269 signin_manager_->SetSigninProcess(trusted_signin_process_id_); | 270 signin_manager_->SetSigninProcess(trusted_signin_process_id_); |
| 271 |
270 if (!username.empty()) { | 272 if (!username.empty()) { |
271 ASSERT_TRUE(signin_manager_); | 273 ASSERT_TRUE(signin_manager_); |
272 signin_manager_->StartSignIn(username, std::string(), std::string(), | 274 signin_manager_->SetAuthenticatedUsername(username); |
273 std::string()); | |
274 } | 275 } |
275 } | 276 } |
276 | 277 |
277 OneClickSigninHelper* OneClickSigninHelperTest::SetupHelperForSignin() { | 278 OneClickSigninHelper* OneClickSigninHelperTest::SetupHelperForSignin() { |
278 CreateSigninManager(false, ""); | 279 CreateSigninManager(false, ""); |
279 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). | 280 EXPECT_CALL(*signin_manager_, IsAllowedUsername(_)). |
280 WillRepeatedly(Return(true)); | 281 WillRepeatedly(Return(true)); |
281 | 282 |
282 CreateProfileSyncServiceMock(); | 283 CreateProfileSyncServiceMock(); |
283 | 284 |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); | 892 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); |
892 | 893 |
893 // Simulate a policy disabling sync by writing kSyncManaged directly. | 894 // Simulate a policy disabling sync by writing kSyncManaged directly. |
894 // We should still offer to sign in the browser. | 895 // We should still offer to sign in the browser. |
895 profile_->GetTestingPrefService()->SetManagedPref( | 896 profile_->GetTestingPrefService()->SetManagedPref( |
896 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); | 897 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); |
897 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 898 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
898 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 899 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
899 valid_gaia_url_, std::string(), &request_, io_data.get())); | 900 valid_gaia_url_, std::string(), &request_, io_data.get())); |
900 } | 901 } |
OLD | NEW |