Chromium Code Reviews| Index: chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher_browsertest.cc |
| diff --git a/chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher_browsertest.cc b/chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher_browsertest.cc |
| index 1ec0c7c61a144630005e2e78d8a70ac262335b1f..974c03a233fd269da658526b40df68fb9f94f3bf 100644 |
| --- a/chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher_browsertest.cc |
| +++ b/chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher_browsertest.cc |
| @@ -12,15 +12,13 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| +#include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h" |
| #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chromeos/chromeos_switches.h" |
| -#include "components/arc/arc_bridge_service.h" |
| -#include "components/arc/arc_service_manager.h" |
| -#include "components/arc/common/auth.mojom.h" |
| #include "components/policy/core/common/cloud/device_management_service.h" |
| #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" |
| #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
| @@ -66,16 +64,6 @@ net::URLRequestJob* ResponseJob(net::URLRequest* request, |
| response_data, true); |
| } |
| -class FakeAuthInstance : public arc::mojom::AuthInstance { |
| - public: |
| - void Init(arc::mojom::AuthHostPtr host_ptr) override {} |
| - void OnAccountInfoReady(arc::mojom::AccountInfoPtr account_info) override { |
| - ASSERT_FALSE(callback.is_null()); |
| - callback.Run(account_info); |
| - } |
| - base::Callback<void(const arc::mojom::AccountInfoPtr&)> callback; |
| -}; |
| - |
| } // namespace |
| class ArcRobotAuthCodeFetcherBrowserTest : public InProcessBrowserTest { |
| @@ -93,12 +81,13 @@ class ArcRobotAuthCodeFetcherBrowserTest : public InProcessBrowserTest { |
| } |
| void SetUpOnMainThread() override { |
| - interceptor_.reset(new policy::TestRequestInterceptor( |
| + interceptor_ = base::MakeUnique<policy::TestRequestInterceptor>( |
| "localhost", content::BrowserThread::GetTaskRunnerForThread( |
| - content::BrowserThread::IO))); |
| + content::BrowserThread::IO)); |
| - user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( |
| - new chromeos::FakeChromeUserManager)); |
| + user_manager_enabler_ = |
| + base::MakeUnique<chromeos::ScopedUserManagerEnabler>( |
| + new chromeos::FakeChromeUserManager()); |
| const AccountId account_id(AccountId::FromUserEmail(kFakeUserName)); |
| GetFakeUserManager()->AddArcKioskAppUser(account_id); |
| @@ -118,14 +107,9 @@ class ArcRobotAuthCodeFetcherBrowserTest : public InProcessBrowserTest { |
| cloud_policy_manager->core()->client()); |
| cloud_policy_client->SetDMToken("fake-dm-token"); |
| cloud_policy_client->client_id_ = "client-id"; |
| - |
| - ArcBridgeService::Get()->auth()->SetInstance(&auth_instance_); |
| } |
| void TearDownOnMainThread() override { |
| - ArcBridgeService::Get()->auth()->SetInstance(nullptr); |
| - ArcSessionManager::Get()->Shutdown(); |
| - ArcServiceManager::Get()->Shutdown(); |
| user_manager_enabler_.reset(); |
| // Verify that all the expected requests were handled. |
| @@ -138,10 +122,10 @@ class ArcRobotAuthCodeFetcherBrowserTest : public InProcessBrowserTest { |
| user_manager::UserManager::Get()); |
| } |
| - std::unique_ptr<policy::TestRequestInterceptor> interceptor_; |
| - FakeAuthInstance auth_instance_; |
| + policy::TestRequestInterceptor* interceptor() { return interceptor_.get(); } |
| private: |
| + std::unique_ptr<policy::TestRequestInterceptor> interceptor_; |
| std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthCodeFetcherBrowserTest); |
| @@ -149,33 +133,24 @@ class ArcRobotAuthCodeFetcherBrowserTest : public InProcessBrowserTest { |
| IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, |
| RequestAccountInfoSuccess) { |
| - interceptor_->PushJobCallback(base::Bind(&ResponseJob)); |
| - |
| - auth_instance_.callback = |
| - base::Bind([](const mojom::AccountInfoPtr& account_info) { |
| - EXPECT_EQ(kFakeAuthCode, account_info->auth_code.value()); |
| - EXPECT_EQ(mojom::ChromeAccountType::ROBOT_ACCOUNT, |
| - account_info->account_type); |
| - EXPECT_FALSE(account_info->is_managed); |
| - }); |
| + interceptor()->PushJobCallback(base::Bind(&ResponseJob)); |
| - ArcAuthService::GetForTest()->RequestAccountInfo(); |
| + auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>(); |
| + robot_fetcher->Fetch(base::Bind([](const std::string& auth_code) { |
| + EXPECT_EQ(kFakeAuthCode, auth_code); |
|
Luis Héctor Chávez
2016/12/06 19:08:56
nit: maybe have a std::string outside the closure
hidehiko
2016/12/08 14:29:33
Done.
|
| + })); |
| base::RunLoop().RunUntilIdle(); |
| } |
| IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, |
| RequestAccountInfoError) { |
| - interceptor_->PushJobCallback( |
| + interceptor()->PushJobCallback( |
| policy::TestRequestInterceptor::BadRequestJob()); |
| - auth_instance_.callback = |
| - base::Bind([](const mojom::AccountInfoPtr&) { FAIL(); }); |
| - |
| - ArcSessionManager::Get()->StartArc(); |
| - ArcAuthService::GetForTest()->RequestAccountInfo(); |
| - // This MessageLoop will be stopped by AttemptUserExit(), that is called as |
| - // a result of error of auth code fetching. |
|
Luis Héctor Chávez
2016/12/06 19:08:56
Great! Having this Run() was kind of annoying :D
|
| - base::RunLoop().Run(); |
| + auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>(); |
| + robot_fetcher->Fetch(base::Bind( |
| + [](const std::string& auth_code) { EXPECT_TRUE(auth_code.empty()); })); |
|
Luis Héctor Chávez
2016/12/06 19:08:56
maybe do something similar here, but also pass a b
hidehiko
2016/12/08 14:29:33
Did similar stuff. Instead of passing bool, initia
|
| + base::RunLoop().RunUntilIdle(); |
| } |
| } // namespace arc |