| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 16 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 20 #include "chrome/browser/policy/cloud/test_request_interceptor.h" | 20 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
| 21 #include "chrome/browser/policy/profile_policy_connector.h" | 21 #include "chrome/browser/policy/profile_policy_connector.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 22 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 23 #include "chrome/browser/policy/test/local_policy_test_server.h" | 23 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 constexpr char kRefreshToken[] = "fake-refresh-token"; | 56 constexpr char kRefreshToken[] = "fake-refresh-token"; |
| 57 // Set managed auth token for Android managed accounts. | 57 // Set managed auth token for Android managed accounts. |
| 58 constexpr char kManagedAuthToken[] = "managed-auth-token"; | 58 constexpr char kManagedAuthToken[] = "managed-auth-token"; |
| 59 // Set unmanaged auth token for other Android unmanaged accounts. | 59 // Set unmanaged auth token for other Android unmanaged accounts. |
| 60 constexpr char kUnmanagedAuthToken[] = "unmanaged-auth-token"; | 60 constexpr char kUnmanagedAuthToken[] = "unmanaged-auth-token"; |
| 61 constexpr char kWellKnownConsumerName[] = "test@gmail.com"; | 61 constexpr char kWellKnownConsumerName[] = "test@gmail.com"; |
| 62 constexpr char kFakeUserName[] = "test@example.com"; | 62 constexpr char kFakeUserName[] = "test@example.com"; |
| 63 constexpr char kFakeAuthCode[] = "fake-auth-code"; | |
| 64 | |
| 65 // JobCallback for the interceptor. | |
| 66 net::URLRequestJob* ResponseJob(net::URLRequest* request, | |
| 67 net::NetworkDelegate* network_delegate) { | |
| 68 const net::UploadDataStream* upload = request->get_upload(); | |
| 69 if (!upload || !upload->GetElementReaders() || | |
| 70 upload->GetElementReaders()->size() != 1 || | |
| 71 !(*upload->GetElementReaders())[0]->AsBytesReader()) | |
| 72 return nullptr; | |
| 73 | |
| 74 const net::UploadBytesElementReader* bytes_reader = | |
| 75 (*upload->GetElementReaders())[0]->AsBytesReader(); | |
| 76 | |
| 77 enterprise_management::DeviceManagementRequest parsed_request; | |
| 78 EXPECT_TRUE(parsed_request.ParseFromArray(bytes_reader->bytes(), | |
| 79 bytes_reader->length())); | |
| 80 // Check if auth code is requested. | |
| 81 EXPECT_TRUE(parsed_request.has_service_api_access_request()); | |
| 82 | |
| 83 enterprise_management::DeviceManagementResponse response; | |
| 84 response.mutable_service_api_access_response()->set_auth_code(kFakeAuthCode); | |
| 85 | |
| 86 std::string response_data; | |
| 87 EXPECT_TRUE(response.SerializeToString(&response_data)); | |
| 88 | |
| 89 return new net::URLRequestTestJob(request, network_delegate, | |
| 90 net::URLRequestTestJob::test_headers(), | |
| 91 response_data, true); | |
| 92 } | |
| 93 | |
| 94 class FakeAuthInstance : public arc::mojom::AuthInstance { | |
| 95 public: | |
| 96 void Init(arc::mojom::AuthHostPtr host_ptr) override {} | |
| 97 void OnAccountInfoReady(arc::mojom::AccountInfoPtr account_info) override { | |
| 98 ASSERT_FALSE(callback.is_null()); | |
| 99 callback.Run(account_info); | |
| 100 } | |
| 101 base::Callback<void(const arc::mojom::AccountInfoPtr&)> callback; | |
| 102 }; | |
| 103 | 63 |
| 104 } // namespace | 64 } // namespace |
| 105 | 65 |
| 106 namespace arc { | 66 namespace arc { |
| 107 | 67 |
| 108 // Observer of ARC bridge shutdown. | 68 // Observer of ARC bridge shutdown. |
| 109 class ArcAuthServiceShutdownObserver : public ArcAuthService::Observer { | 69 class ArcSessionManagerShutdownObserver : public ArcSessionManager::Observer { |
| 110 public: | 70 public: |
| 111 ArcAuthServiceShutdownObserver() { ArcAuthService::Get()->AddObserver(this); } | 71 ArcSessionManagerShutdownObserver() { |
| 72 ArcSessionManager::Get()->AddObserver(this); |
| 73 } |
| 112 | 74 |
| 113 ~ArcAuthServiceShutdownObserver() override { | 75 ~ArcSessionManagerShutdownObserver() override { |
| 114 ArcAuthService::Get()->RemoveObserver(this); | 76 ArcSessionManager::Get()->RemoveObserver(this); |
| 115 } | 77 } |
| 116 | 78 |
| 117 void Wait() { | 79 void Wait() { |
| 118 run_loop_.reset(new base::RunLoop); | 80 run_loop_.reset(new base::RunLoop); |
| 119 run_loop_->Run(); | 81 run_loop_->Run(); |
| 120 run_loop_.reset(); | 82 run_loop_.reset(); |
| 121 } | 83 } |
| 122 | 84 |
| 123 // ArcAuthService::Observer: | 85 // ArcSessionManager::Observer: |
| 124 void OnShutdownBridge() override { | 86 void OnShutdownBridge() override { |
| 125 if (!run_loop_) | 87 if (!run_loop_) |
| 126 return; | 88 return; |
| 127 run_loop_->Quit(); | 89 run_loop_->Quit(); |
| 128 } | 90 } |
| 129 | 91 |
| 130 private: | 92 private: |
| 131 std::unique_ptr<base::RunLoop> run_loop_; | 93 std::unique_ptr<base::RunLoop> run_loop_; |
| 132 | 94 |
| 133 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceShutdownObserver); | 95 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); |
| 134 }; | 96 }; |
| 135 | 97 |
| 136 class ArcAuthServiceTest : public InProcessBrowserTest { | 98 class ArcSessionManagerTest : public InProcessBrowserTest { |
| 137 protected: | 99 protected: |
| 138 ArcAuthServiceTest() {} | 100 ArcSessionManagerTest() {} |
| 139 | 101 |
| 140 // InProcessBrowserTest: | 102 // InProcessBrowserTest: |
| 141 ~ArcAuthServiceTest() override {} | 103 ~ArcSessionManagerTest() override {} |
| 142 | 104 |
| 143 void SetUpInProcessBrowserTestFixture() override { | 105 void SetUpInProcessBrowserTestFixture() override { |
| 144 // Start test device management server. | 106 // Start test device management server. |
| 145 test_server_.reset(new policy::LocalPolicyTestServer()); | 107 test_server_.reset(new policy::LocalPolicyTestServer()); |
| 146 ASSERT_TRUE(test_server_->Start()); | 108 ASSERT_TRUE(test_server_->Start()); |
| 147 | 109 |
| 148 // Specify device management server URL. | 110 // Specify device management server URL. |
| 149 std::string url = test_server_->GetServiceURL().spec(); | 111 std::string url = test_server_->GetServiceURL().spec(); |
| 150 base::CommandLine* const command_line = | 112 base::CommandLine* const command_line = |
| 151 base::CommandLine::ForCurrentProcess(); | 113 base::CommandLine::ForCurrentProcess(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 164 // Mock out ARC bridge. | 126 // Mock out ARC bridge. |
| 165 // Here inject FakeArcSession so blocking task runner is not needed. | 127 // Here inject FakeArcSession so blocking task runner is not needed. |
| 166 auto service = base::MakeUnique<ArcBridgeServiceImpl>(nullptr); | 128 auto service = base::MakeUnique<ArcBridgeServiceImpl>(nullptr); |
| 167 service->SetArcSessionFactoryForTesting(base::Bind(FakeArcSession::Create)); | 129 service->SetArcSessionFactoryForTesting(base::Bind(FakeArcSession::Create)); |
| 168 ArcServiceManager::SetArcBridgeServiceForTesting(std::move(service)); | 130 ArcServiceManager::SetArcBridgeServiceForTesting(std::move(service)); |
| 169 } | 131 } |
| 170 | 132 |
| 171 void SetUpOnMainThread() override { | 133 void SetUpOnMainThread() override { |
| 172 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( | 134 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( |
| 173 new chromeos::FakeChromeUserManager)); | 135 new chromeos::FakeChromeUserManager)); |
| 174 // Init ArcAuthService for testing. | 136 // Init ArcSessionManager for testing. |
| 175 ArcAuthService::DisableUIForTesting(); | 137 ArcSessionManager::DisableUIForTesting(); |
| 176 ArcAuthService::EnableCheckAndroidManagementForTesting(); | 138 ArcSessionManager::EnableCheckAndroidManagementForTesting(); |
| 177 | 139 |
| 178 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 140 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 179 | 141 |
| 180 // Create test profile. | 142 // Create test profile. |
| 181 TestingProfile::Builder profile_builder; | 143 TestingProfile::Builder profile_builder; |
| 182 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); | 144 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); |
| 183 profile_builder.SetProfileName(kFakeUserName); | 145 profile_builder.SetProfileName(kFakeUserName); |
| 184 profile_builder.AddTestingFactory( | 146 profile_builder.AddTestingFactory( |
| 185 ProfileOAuth2TokenServiceFactory::GetInstance(), | 147 ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 186 BuildFakeProfileOAuth2TokenService); | 148 BuildFakeProfileOAuth2TokenService); |
| 187 profile_ = profile_builder.Build(); | 149 profile_ = profile_builder.Build(); |
| 188 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( | 150 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( |
| 189 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); | 151 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); |
| 190 token_service_->UpdateCredentials("", kRefreshToken); | 152 token_service_->UpdateCredentials("", kRefreshToken); |
| 191 | 153 |
| 192 profile()->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); | 154 profile()->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); |
| 193 | 155 |
| 194 const AccountId account_id( | 156 const AccountId account_id( |
| 195 AccountId::FromUserEmailGaiaId(kFakeUserName, "1234567890")); | 157 AccountId::FromUserEmailGaiaId(kFakeUserName, "1234567890")); |
| 196 GetFakeUserManager()->AddUser(account_id); | 158 GetFakeUserManager()->AddUser(account_id); |
| 197 GetFakeUserManager()->LoginUser(account_id); | 159 GetFakeUserManager()->LoginUser(account_id); |
| 198 | 160 |
| 199 // Set up ARC for test profile. | 161 // Set up ARC for test profile. |
| 200 std::unique_ptr<BooleanPrefMember> arc_enabled_pref = | 162 std::unique_ptr<BooleanPrefMember> arc_enabled_pref = |
| 201 base::MakeUnique<BooleanPrefMember>(); | 163 base::MakeUnique<BooleanPrefMember>(); |
| 202 arc_enabled_pref->Init(prefs::kArcEnabled, profile()->GetPrefs()); | 164 arc_enabled_pref->Init(prefs::kArcEnabled, profile()->GetPrefs()); |
| 203 ArcServiceManager::Get()->OnPrimaryUserProfilePrepared( | 165 ArcServiceManager::Get()->OnPrimaryUserProfilePrepared( |
| 204 multi_user_util::GetAccountIdFromProfile(profile()), | 166 multi_user_util::GetAccountIdFromProfile(profile()), |
| 205 std::move(arc_enabled_pref)); | 167 std::move(arc_enabled_pref)); |
| 206 ArcAuthService::Get()->OnPrimaryUserProfilePrepared(profile()); | 168 ArcSessionManager::Get()->OnPrimaryUserProfilePrepared(profile()); |
| 207 } | 169 } |
| 208 | 170 |
| 209 void TearDownOnMainThread() override { | 171 void TearDownOnMainThread() override { |
| 210 ArcAuthService::Get()->Shutdown(); | 172 ArcSessionManager::Get()->Shutdown(); |
| 211 ArcServiceManager::Get()->Shutdown(); | 173 ArcServiceManager::Get()->Shutdown(); |
| 212 profile_.reset(); | 174 profile_.reset(); |
| 213 user_manager_enabler_.reset(); | 175 user_manager_enabler_.reset(); |
| 214 test_server_.reset(); | 176 test_server_.reset(); |
| 215 } | 177 } |
| 216 | 178 |
| 217 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 179 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 218 return static_cast<chromeos::FakeChromeUserManager*>( | 180 return static_cast<chromeos::FakeChromeUserManager*>( |
| 219 user_manager::UserManager::Get()); | 181 user_manager::UserManager::Get()); |
| 220 } | 182 } |
| 221 | 183 |
| 222 void set_profile_name(const std::string& username) { | 184 void set_profile_name(const std::string& username) { |
| 223 profile_->set_profile_name(username); | 185 profile_->set_profile_name(username); |
| 224 } | 186 } |
| 225 | 187 |
| 226 Profile* profile() { return profile_.get(); } | 188 Profile* profile() { return profile_.get(); } |
| 227 | 189 |
| 228 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 190 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 229 | 191 |
| 230 private: | 192 private: |
| 231 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; | 193 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; |
| 232 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 194 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 233 base::ScopedTempDir temp_dir_; | 195 base::ScopedTempDir temp_dir_; |
| 234 std::unique_ptr<TestingProfile> profile_; | 196 std::unique_ptr<TestingProfile> profile_; |
| 235 FakeProfileOAuth2TokenService* token_service_; | 197 FakeProfileOAuth2TokenService* token_service_; |
| 236 | 198 |
| 237 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); | 199 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 238 }; | 200 }; |
| 239 | 201 |
| 240 IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, ConsumerAccount) { | 202 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { |
| 241 PrefService* const prefs = profile()->GetPrefs(); | 203 PrefService* const prefs = profile()->GetPrefs(); |
| 242 prefs->SetBoolean(prefs::kArcEnabled, true); | 204 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 243 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, | 205 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, |
| 244 base::Time::Max()); | 206 base::Time::Max()); |
| 245 ASSERT_EQ(ArcAuthService::State::ACTIVE, ArcAuthService::Get()->state()); | 207 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 208 ArcSessionManager::Get()->state()); |
| 246 } | 209 } |
| 247 | 210 |
| 248 IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, WellKnownConsumerAccount) { | 211 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { |
| 249 set_profile_name(kWellKnownConsumerName); | 212 set_profile_name(kWellKnownConsumerName); |
| 250 PrefService* const prefs = profile()->GetPrefs(); | 213 PrefService* const prefs = profile()->GetPrefs(); |
| 251 | 214 |
| 252 prefs->SetBoolean(prefs::kArcEnabled, true); | 215 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 253 ASSERT_EQ(ArcAuthService::State::ACTIVE, ArcAuthService::Get()->state()); | 216 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 217 ArcSessionManager::Get()->state()); |
| 254 } | 218 } |
| 255 | 219 |
| 256 IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, ManagedChromeAccount) { | 220 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { |
| 257 policy::ProfilePolicyConnector* const connector = | 221 policy::ProfilePolicyConnector* const connector = |
| 258 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); | 222 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); |
| 259 connector->OverrideIsManagedForTesting(true); | 223 connector->OverrideIsManagedForTesting(true); |
| 260 | 224 |
| 261 PrefService* const pref = profile()->GetPrefs(); | 225 PrefService* const pref = profile()->GetPrefs(); |
| 262 | 226 |
| 263 pref->SetBoolean(prefs::kArcEnabled, true); | 227 pref->SetBoolean(prefs::kArcEnabled, true); |
| 264 ASSERT_EQ(ArcAuthService::State::ACTIVE, ArcAuthService::Get()->state()); | 228 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 229 ArcSessionManager::Get()->state()); |
| 265 } | 230 } |
| 266 | 231 |
| 267 IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, ManagedAndroidAccount) { | 232 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { |
| 268 PrefService* const prefs = profile()->GetPrefs(); | 233 PrefService* const prefs = profile()->GetPrefs(); |
| 269 | 234 |
| 270 prefs->SetBoolean(prefs::kArcEnabled, true); | 235 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 271 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 236 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 272 base::Time::Max()); | 237 base::Time::Max()); |
| 273 ArcAuthServiceShutdownObserver observer; | 238 ArcSessionManagerShutdownObserver observer; |
| 274 observer.Wait(); | 239 observer.Wait(); |
| 275 ASSERT_EQ(ArcAuthService::State::STOPPED, ArcAuthService::Get()->state()); | 240 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
| 276 } | 241 ArcSessionManager::Get()->state()); |
| 277 | |
| 278 class KioskArcAuthServiceTest : public InProcessBrowserTest { | |
| 279 protected: | |
| 280 KioskArcAuthServiceTest() = default; | |
| 281 | |
| 282 // InProcessBrowserTest: | |
| 283 ~KioskArcAuthServiceTest() override = default; | |
| 284 | |
| 285 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 286 InProcessBrowserTest::SetUpCommandLine(command_line); | |
| 287 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, | |
| 288 "http://localhost"); | |
| 289 command_line->AppendSwitch(chromeos::switches::kEnableArc); | |
| 290 } | |
| 291 | |
| 292 void SetUpOnMainThread() override { | |
| 293 interceptor_.reset(new policy::TestRequestInterceptor( | |
| 294 "localhost", content::BrowserThread::GetTaskRunnerForThread( | |
| 295 content::BrowserThread::IO))); | |
| 296 | |
| 297 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( | |
| 298 new chromeos::FakeChromeUserManager)); | |
| 299 | |
| 300 const AccountId account_id(AccountId::FromUserEmail(kFakeUserName)); | |
| 301 GetFakeUserManager()->AddArcKioskAppUser(account_id); | |
| 302 GetFakeUserManager()->LoginUser(account_id); | |
| 303 | |
| 304 policy::BrowserPolicyConnectorChromeOS* const connector = | |
| 305 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 306 policy::DeviceCloudPolicyManagerChromeOS* const cloud_policy_manager = | |
| 307 connector->GetDeviceCloudPolicyManager(); | |
| 308 | |
| 309 cloud_policy_manager->StartConnection( | |
| 310 base::MakeUnique<policy::MockCloudPolicyClient>(), | |
| 311 connector->GetInstallAttributes()); | |
| 312 | |
| 313 policy::MockCloudPolicyClient* const cloud_policy_client = | |
| 314 static_cast<policy::MockCloudPolicyClient*>( | |
| 315 cloud_policy_manager->core()->client()); | |
| 316 cloud_policy_client->SetDMToken("fake-dm-token"); | |
| 317 cloud_policy_client->client_id_ = "client-id"; | |
| 318 | |
| 319 ArcBridgeService::Get()->auth()->SetInstance(&auth_instance_); | |
| 320 } | |
| 321 | |
| 322 void TearDownOnMainThread() override { | |
| 323 ArcBridgeService::Get()->auth()->SetInstance(nullptr); | |
| 324 ArcAuthService::Get()->Shutdown(); | |
| 325 ArcServiceManager::Get()->Shutdown(); | |
| 326 user_manager_enabler_.reset(); | |
| 327 | |
| 328 // Verify that all the expected requests were handled. | |
| 329 EXPECT_EQ(0u, interceptor_->GetPendingSize()); | |
| 330 interceptor_.reset(); | |
| 331 } | |
| 332 | |
| 333 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | |
| 334 return static_cast<chromeos::FakeChromeUserManager*>( | |
| 335 user_manager::UserManager::Get()); | |
| 336 } | |
| 337 | |
| 338 std::unique_ptr<policy::TestRequestInterceptor> interceptor_; | |
| 339 FakeAuthInstance auth_instance_; | |
| 340 | |
| 341 private: | |
| 342 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | |
| 343 | |
| 344 DISALLOW_COPY_AND_ASSIGN(KioskArcAuthServiceTest); | |
| 345 }; | |
| 346 | |
| 347 IN_PROC_BROWSER_TEST_F(KioskArcAuthServiceTest, RequestAccountInfoSuccess) { | |
| 348 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); | |
| 349 | |
| 350 auth_instance_.callback = | |
| 351 base::Bind([](const mojom::AccountInfoPtr& account_info) { | |
| 352 EXPECT_EQ(kFakeAuthCode, account_info->auth_code.value()); | |
| 353 EXPECT_EQ(mojom::ChromeAccountType::ROBOT_ACCOUNT, | |
| 354 account_info->account_type); | |
| 355 EXPECT_FALSE(account_info->is_managed); | |
| 356 }); | |
| 357 | |
| 358 ArcAuthService::Get()->RequestAccountInfo(); | |
| 359 base::RunLoop().RunUntilIdle(); | |
| 360 } | |
| 361 | |
| 362 IN_PROC_BROWSER_TEST_F(KioskArcAuthServiceTest, RequestAccountInfoError) { | |
| 363 interceptor_->PushJobCallback( | |
| 364 policy::TestRequestInterceptor::BadRequestJob()); | |
| 365 | |
| 366 auth_instance_.callback = | |
| 367 base::Bind([](const mojom::AccountInfoPtr&) { FAIL(); }); | |
| 368 | |
| 369 ArcAuthService::Get()->RequestAccountInfo(); | |
| 370 // This MessageLoop will be stopped by AttemptUserExit(), that is called as | |
| 371 // a result of error of auth code fetching. | |
| 372 base::RunLoop().Run(); | |
| 373 } | 242 } |
| 374 | 243 |
| 375 } // namespace arc | 244 } // namespace arc |
| OLD | NEW |