| 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 void Init(arc::mojom::AuthHostPtr host_ptr) override {} | 71 void Init(arc::mojom::AuthHostPtr host_ptr) override {} |
| 72 void OnAccountInfoReady(arc::mojom::AccountInfoPtr account_info) override { | 72 void OnAccountInfoReady(arc::mojom::AccountInfoPtr account_info) override { |
| 73 ASSERT_FALSE(callback.is_null()); | 73 ASSERT_FALSE(callback.is_null()); |
| 74 callback.Run(account_info); | 74 callback.Run(account_info); |
| 75 } | 75 } |
| 76 base::Callback<void(const arc::mojom::AccountInfoPtr&)> callback; | 76 base::Callback<void(const arc::mojom::AccountInfoPtr&)> callback; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 class ArcRobotAuthBrowserTest : public InProcessBrowserTest { | 81 class ArcRobotAuthCodeFetcherBrowserTest : public InProcessBrowserTest { |
| 82 protected: | 82 protected: |
| 83 ArcRobotAuthBrowserTest() = default; | 83 ArcRobotAuthCodeFetcherBrowserTest() = default; |
| 84 | 84 |
| 85 // InProcessBrowserTest: | 85 // InProcessBrowserTest: |
| 86 ~ArcRobotAuthBrowserTest() override = default; | 86 ~ArcRobotAuthCodeFetcherBrowserTest() override = default; |
| 87 | 87 |
| 88 void SetUpCommandLine(base::CommandLine* command_line) override { | 88 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 89 InProcessBrowserTest::SetUpCommandLine(command_line); | 89 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 90 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, | 90 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, |
| 91 "http://localhost"); | 91 "http://localhost"); |
| 92 command_line->AppendSwitch(chromeos::switches::kEnableArc); | 92 command_line->AppendSwitch(chromeos::switches::kEnableArc); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void SetUpOnMainThread() override { | 95 void SetUpOnMainThread() override { |
| 96 interceptor_.reset(new policy::TestRequestInterceptor( | 96 interceptor_.reset(new policy::TestRequestInterceptor( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return static_cast<chromeos::FakeChromeUserManager*>( | 137 return static_cast<chromeos::FakeChromeUserManager*>( |
| 138 user_manager::UserManager::Get()); | 138 user_manager::UserManager::Get()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 std::unique_ptr<policy::TestRequestInterceptor> interceptor_; | 141 std::unique_ptr<policy::TestRequestInterceptor> interceptor_; |
| 142 FakeAuthInstance auth_instance_; | 142 FakeAuthInstance auth_instance_; |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 145 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 146 | 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthBrowserTest); | 147 DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthCodeFetcherBrowserTest); |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 IN_PROC_BROWSER_TEST_F(ArcRobotAuthBrowserTest, RequestAccountInfoSuccess) { | 150 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, |
| 151 RequestAccountInfoSuccess) { |
| 151 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); | 152 interceptor_->PushJobCallback(base::Bind(&ResponseJob)); |
| 152 | 153 |
| 153 auth_instance_.callback = | 154 auth_instance_.callback = |
| 154 base::Bind([](const mojom::AccountInfoPtr& account_info) { | 155 base::Bind([](const mojom::AccountInfoPtr& account_info) { |
| 155 EXPECT_EQ(kFakeAuthCode, account_info->auth_code.value()); | 156 EXPECT_EQ(kFakeAuthCode, account_info->auth_code.value()); |
| 156 EXPECT_EQ(mojom::ChromeAccountType::ROBOT_ACCOUNT, | 157 EXPECT_EQ(mojom::ChromeAccountType::ROBOT_ACCOUNT, |
| 157 account_info->account_type); | 158 account_info->account_type); |
| 158 EXPECT_FALSE(account_info->is_managed); | 159 EXPECT_FALSE(account_info->is_managed); |
| 159 }); | 160 }); |
| 160 | 161 |
| 161 ArcAuthService::GetForTest()->RequestAccountInfo(); | 162 ArcAuthService::GetForTest()->RequestAccountInfo(); |
| 162 base::RunLoop().RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 IN_PROC_BROWSER_TEST_F(ArcRobotAuthBrowserTest, RequestAccountInfoError) { | 166 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, |
| 167 RequestAccountInfoError) { |
| 166 interceptor_->PushJobCallback( | 168 interceptor_->PushJobCallback( |
| 167 policy::TestRequestInterceptor::BadRequestJob()); | 169 policy::TestRequestInterceptor::BadRequestJob()); |
| 168 | 170 |
| 169 auth_instance_.callback = | 171 auth_instance_.callback = |
| 170 base::Bind([](const mojom::AccountInfoPtr&) { FAIL(); }); | 172 base::Bind([](const mojom::AccountInfoPtr&) { FAIL(); }); |
| 171 | 173 |
| 174 ArcSessionManager::Get()->StartArc(); |
| 172 ArcAuthService::GetForTest()->RequestAccountInfo(); | 175 ArcAuthService::GetForTest()->RequestAccountInfo(); |
| 173 // This MessageLoop will be stopped by AttemptUserExit(), that is called as | 176 // This MessageLoop will be stopped by AttemptUserExit(), that is called as |
| 174 // a result of error of auth code fetching. | 177 // a result of error of auth code fetching. |
| 175 base::RunLoop().Run(); | 178 base::RunLoop().Run(); |
| 176 } | 179 } |
| 177 | 180 |
| 178 } // namespace arc | 181 } // namespace arc |
| OLD | NEW |