Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Side by Side Diff: chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher_browsertest.cc

Issue 2705213002: Show different error message if ARC is disabled. (Closed)
Patch Set: Fix browsertests and add a new test for 904 Arc Disabled Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 118
119 chromeos::FakeChromeUserManager* GetFakeUserManager() const { 119 chromeos::FakeChromeUserManager* GetFakeUserManager() const {
120 return static_cast<chromeos::FakeChromeUserManager*>( 120 return static_cast<chromeos::FakeChromeUserManager*>(
121 user_manager::UserManager::Get()); 121 user_manager::UserManager::Get());
122 } 122 }
123 123
124 policy::TestRequestInterceptor* interceptor() { return interceptor_.get(); } 124 policy::TestRequestInterceptor* interceptor() { return interceptor_.get(); }
125 125
126 static void FetchAuthCode(ArcRobotAuthCodeFetcher* fetcher, 126 static void FetchAuthCode(ArcRobotAuthCodeFetcher* fetcher,
127 arc::ArcAuthInfoFetchStatus* output_fetch_status,
127 std::string* output_auth_code) { 128 std::string* output_auth_code) {
128 base::RunLoop run_loop; 129 base::RunLoop run_loop;
129 fetcher->Fetch(base::Bind( 130 fetcher->Fetch(base::Bind(
130 [](std::string* output_auth_code, base::RunLoop* run_loop, 131 [](arc::ArcAuthInfoFetchStatus* output_fetch_status,
132 std::string* output_auth_code, base::RunLoop* run_loop,
133 arc::ArcAuthInfoFetchStatus fetch_status,
131 const std::string& auth_code) { 134 const std::string& auth_code) {
135 *output_fetch_status = fetch_status;
132 *output_auth_code = auth_code; 136 *output_auth_code = auth_code;
133 run_loop->Quit(); 137 run_loop->Quit();
134 }, 138 },
135 output_auth_code, &run_loop)); 139 output_fetch_status, output_auth_code, &run_loop));
136 // Because the Fetch() operation needs to interact with other threads, 140 // Because the Fetch() operation needs to interact with other threads,
137 // RunUntilIdle() won't work here. Instead, use Run() and Quit() explicitly 141 // RunUntilIdle() won't work here. Instead, use Run() and Quit() explicitly
138 // in the callback. 142 // in the callback.
139 run_loop.Run(); 143 run_loop.Run();
140 } 144 }
141 145
142 private: 146 private:
143 std::unique_ptr<policy::TestRequestInterceptor> interceptor_; 147 std::unique_ptr<policy::TestRequestInterceptor> interceptor_;
144 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 148 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
145 149
146 DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthCodeFetcherBrowserTest); 150 DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthCodeFetcherBrowserTest);
147 }; 151 };
148 152
149 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, 153 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest,
150 RequestAccountInfoSuccess) { 154 RequestAccountInfoSuccess) {
151 interceptor()->PushJobCallback(base::Bind(&ResponseJob)); 155 interceptor()->PushJobCallback(base::Bind(&ResponseJob));
152 156
153 std::string auth_code; 157 std::string auth_code;
158 arc::ArcAuthInfoFetchStatus fetch_status = arc::ArcAuthInfoFetchStatus::SIZE;
159
154 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>(); 160 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>();
155 FetchAuthCode(robot_fetcher.get(), &auth_code); 161 FetchAuthCode(robot_fetcher.get(), &fetch_status, &auth_code);
162
163 EXPECT_EQ(arc::ArcAuthInfoFetchStatus::SUCCESS, fetch_status);
156 EXPECT_EQ(kFakeAuthCode, auth_code); 164 EXPECT_EQ(kFakeAuthCode, auth_code);
157 } 165 }
158 166
159 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, 167 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest,
160 RequestAccountInfoError) { 168 RequestAccountInfoError) {
161 interceptor()->PushJobCallback( 169 interceptor()->PushJobCallback(
162 policy::TestRequestInterceptor::BadRequestJob()); 170 policy::TestRequestInterceptor::BadRequestJob());
163 171
164 // We expect auth_code is empty in this case. So initialize with non-empty 172 // We expect auth_code is empty in this case. So initialize with non-empty
165 // value. 173 // value.
166 std::string auth_code = "NOT-YET-FETCHED"; 174 std::string auth_code = "NOT-YET-FETCHED";
175 arc::ArcAuthInfoFetchStatus fetch_status = arc::ArcAuthInfoFetchStatus::SIZE;
176
167 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>(); 177 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>();
168 FetchAuthCode(robot_fetcher.get(), &auth_code); 178 FetchAuthCode(robot_fetcher.get(), &fetch_status, &auth_code);
169 179
180 EXPECT_EQ(arc::ArcAuthInfoFetchStatus::FAILURE, fetch_status);
170 // Use EXPECT_EQ for better logging in case of failure. 181 // Use EXPECT_EQ for better logging in case of failure.
171 EXPECT_EQ(std::string(), auth_code); 182 EXPECT_EQ(std::string(), auth_code);
172 } 183 }
173 184
174 } // namespace arc 185 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698