OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "components/browser_sync/profile_sync_service_mock.h" | 10 #include "components/browser_sync/profile_sync_service_mock.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "ios/chrome/browser/signin/fake_signin_manager_builder.h" | 29 #include "ios/chrome/browser/signin/fake_signin_manager_builder.h" |
30 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" | 30 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" |
31 #include "ios/chrome/browser/signin/signin_client_factory.h" | 31 #include "ios/chrome/browser/signin/signin_client_factory.h" |
32 #include "ios/chrome/browser/signin/signin_client_impl.h" | 32 #include "ios/chrome/browser/signin/signin_client_impl.h" |
33 #include "ios/chrome/browser/signin/signin_error_controller_factory.h" | 33 #include "ios/chrome/browser/signin/signin_error_controller_factory.h" |
34 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 34 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
35 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 35 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
36 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h" | 36 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h" |
37 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 37 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
38 #include "ios/chrome/browser/sync/sync_setup_service_mock.h" | 38 #include "ios/chrome/browser/sync/sync_setup_service_mock.h" |
39 #include "ios/chrome/test/testing_application_context.h" | 39 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager
.h" |
40 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 40 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
41 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 41 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
42 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" | 42 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
43 #include "ios/web/public/test/test_web_thread_bundle.h" | 43 #include "ios/web/public/test/test_web_thread_bundle.h" |
44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
45 #include "testing/gtest_mac.h" | 45 #include "testing/gtest_mac.h" |
46 #include "testing/platform_test.h" | 46 #include "testing/platform_test.h" |
47 #import "third_party/ocmock/OCMock/OCMock.h" | 47 #import "third_party/ocmock/OCMock/OCMock.h" |
48 | 48 |
49 using testing::_; | 49 using testing::_; |
(...skipping 27 matching lines...) Expand all Loading... |
77 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state), | 77 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state), |
78 browser_state->GetPrefs()); | 78 browser_state->GetPrefs()); |
79 } | 79 } |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 class AuthenticationServiceTest : public PlatformTest, | 83 class AuthenticationServiceTest : public PlatformTest, |
84 public OAuth2TokenService::Observer { | 84 public OAuth2TokenService::Observer { |
85 protected: | 85 protected: |
86 AuthenticationServiceTest() | 86 AuthenticationServiceTest() |
87 : browser_state_manager_(base::FilePath()), | 87 : scoped_browser_state_manager_( |
| 88 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())), |
88 refresh_token_available_count_(0) {} | 89 refresh_token_available_count_(0) {} |
89 | 90 |
90 void SetUp() override { | 91 void SetUp() override { |
91 PlatformTest::SetUp(); | 92 PlatformTest::SetUp(); |
92 | 93 |
93 TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager( | |
94 &browser_state_manager_); | |
95 | |
96 identity_service_ = | 94 identity_service_ = |
97 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); | 95 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); |
98 identity_service_->AddIdentities(@[ @"foo", @"foo2" ]); | 96 identity_service_->AddIdentities(@[ @"foo", @"foo2" ]); |
99 identity_ = | 97 identity_ = |
100 [identity_service_->GetAllIdentitiesSortedForDisplay() objectAtIndex:0]; | 98 [identity_service_->GetAllIdentitiesSortedForDisplay() objectAtIndex:0]; |
101 identity2_ = | 99 identity2_ = |
102 [identity_service_->GetAllIdentitiesSortedForDisplay() objectAtIndex:1]; | 100 [identity_service_->GetAllIdentitiesSortedForDisplay() objectAtIndex:1]; |
103 | 101 |
104 TestChromeBrowserState::Builder builder; | 102 TestChromeBrowserState::Builder builder; |
105 builder.SetPrefService(CreatePrefService()); | 103 builder.SetPrefService(CreatePrefService()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 RegisterBrowserStatePrefs(registry.get()); | 135 RegisterBrowserStatePrefs(registry.get()); |
138 return prefs; | 136 return prefs; |
139 } | 137 } |
140 | 138 |
141 void TearDown() override { | 139 void TearDown() override { |
142 OAuth2TokenServiceFactory::GetForBrowserState(browser_state_.get()) | 140 OAuth2TokenServiceFactory::GetForBrowserState(browser_state_.get()) |
143 ->RemoveObserver(this); | 141 ->RemoveObserver(this); |
144 authentication_service_->Shutdown(); | 142 authentication_service_->Shutdown(); |
145 authentication_service_.reset(); | 143 authentication_service_.reset(); |
146 browser_state_.reset(); | 144 browser_state_.reset(); |
147 TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager( | |
148 nullptr); | |
149 PlatformTest::TearDown(); | 145 PlatformTest::TearDown(); |
150 } | 146 } |
151 | 147 |
152 void SetExpectationsForSignIn() { | 148 void SetExpectationsForSignIn() { |
153 EXPECT_CALL(*profile_sync_service_mock_, RequestStart()); | 149 EXPECT_CALL(*profile_sync_service_mock_, RequestStart()); |
154 EXPECT_CALL(*sync_setup_service_mock_, PrepareForFirstSyncSetup()); | 150 EXPECT_CALL(*sync_setup_service_mock_, PrepareForFirstSyncSetup()); |
155 } | 151 } |
156 | 152 |
157 void CreateAuthenticationService() { | 153 void CreateAuthenticationService() { |
158 if (authentication_service_.get()) { | 154 if (authentication_service_.get()) { |
159 authentication_service_->Shutdown(); | 155 authentication_service_->Shutdown(); |
160 } | 156 } |
161 authentication_service_.reset(new AuthenticationService( | 157 authentication_service_ = base::MakeUnique<AuthenticationService>( |
162 browser_state_.get(), | 158 browser_state_.get(), |
163 OAuth2TokenServiceFactory::GetForBrowserState(browser_state_.get()), | 159 OAuth2TokenServiceFactory::GetForBrowserState(browser_state_.get()), |
164 SyncSetupServiceFactory::GetForBrowserState(browser_state_.get()))); | 160 SyncSetupServiceFactory::GetForBrowserState(browser_state_.get())); |
165 authentication_service_->Initialize(); | 161 authentication_service_->Initialize(); |
166 } | 162 } |
167 | 163 |
168 void StoreAccountsInPrefs() { | 164 void StoreAccountsInPrefs() { |
169 authentication_service_->StoreAccountsInPrefs(); | 165 authentication_service_->StoreAccountsInPrefs(); |
170 } | 166 } |
171 | 167 |
172 void MigrateAccountsStoredInPrefsIfNeeded() { | 168 void MigrateAccountsStoredInPrefsIfNeeded() { |
173 authentication_service_->MigrateAccountsStoredInPrefsIfNeeded(); | 169 authentication_service_->MigrateAccountsStoredInPrefsIfNeeded(); |
174 } | 170 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 bool HasCachedMDMInfo(ChromeIdentity* identity) { | 203 bool HasCachedMDMInfo(ChromeIdentity* identity) { |
208 return authentication_service_->cached_mdm_infos_.count( | 204 return authentication_service_->cached_mdm_infos_.count( |
209 base::SysNSStringToUTF8([identity gaiaID])) > 0; | 205 base::SysNSStringToUTF8([identity gaiaID])) > 0; |
210 } | 206 } |
211 | 207 |
212 void OnRefreshTokenAvailable(const std::string& account_id) override { | 208 void OnRefreshTokenAvailable(const std::string& account_id) override { |
213 refresh_token_available_count_++; | 209 refresh_token_available_count_++; |
214 } | 210 } |
215 | 211 |
216 web::TestWebThreadBundle thread_bundle_; | 212 web::TestWebThreadBundle thread_bundle_; |
217 TestChromeBrowserStateManager browser_state_manager_; | 213 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; |
218 | |
219 std::unique_ptr<TestChromeBrowserState> browser_state_; | 214 std::unique_ptr<TestChromeBrowserState> browser_state_; |
220 ios::FakeChromeIdentityService* identity_service_; | 215 ios::FakeChromeIdentityService* identity_service_; |
221 browser_sync::ProfileSyncServiceMock* profile_sync_service_mock_; | 216 browser_sync::ProfileSyncServiceMock* profile_sync_service_mock_; |
222 SyncSetupServiceMock* sync_setup_service_mock_; | 217 SyncSetupServiceMock* sync_setup_service_mock_; |
223 SigninManager* signin_manager_; | 218 SigninManager* signin_manager_; |
224 std::unique_ptr<AuthenticationService> authentication_service_; | 219 std::unique_ptr<AuthenticationService> authentication_service_; |
225 ChromeIdentity* identity_; | 220 ChromeIdentity* identity_; |
226 ChromeIdentity* identity2_; | 221 ChromeIdentity* identity2_; |
227 int refresh_token_available_count_; | 222 int refresh_token_available_count_; |
228 }; | 223 }; |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 NSDictionary* user_info = [NSDictionary dictionary]; | 735 NSDictionary* user_info = [NSDictionary dictionary]; |
741 SetCachedMDMInfo(identity_, user_info); | 736 SetCachedMDMInfo(identity_, user_info); |
742 | 737 |
743 EXPECT_CALL(*identity_service_, | 738 EXPECT_CALL(*identity_service_, |
744 HandleMDMNotification(identity_, user_info, _)) | 739 HandleMDMNotification(identity_, user_info, _)) |
745 .WillOnce(Return(true)); | 740 .WillOnce(Return(true)); |
746 | 741 |
747 EXPECT_TRUE( | 742 EXPECT_TRUE( |
748 authentication_service_->ShowMDMErrorDialogForIdentity(identity_)); | 743 authentication_service_->ShowMDMErrorDialogForIdentity(identity_)); |
749 } | 744 } |
OLD | NEW |