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

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: Rebase Created 3 years, 9 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 interceptor_.reset(); 116 interceptor_.reset();
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(
127 std::string* output_auth_code) { 127 ArcRobotAuthCodeFetcher* fetcher,
128 arc::ArcAuthInfoFetcher::Status* output_fetch_status,
129 std::string* output_auth_code) {
128 base::RunLoop run_loop; 130 base::RunLoop run_loop;
129 fetcher->Fetch(base::Bind( 131 fetcher->Fetch(base::Bind(
130 [](std::string* output_auth_code, base::RunLoop* run_loop, 132 [](arc::ArcAuthInfoFetcher::Status* output_fetch_status,
133 std::string* output_auth_code, base::RunLoop* run_loop,
134 arc::ArcAuthInfoFetcher::Status fetch_status,
131 const std::string& auth_code) { 135 const std::string& auth_code) {
136 *output_fetch_status = fetch_status;
132 *output_auth_code = auth_code; 137 *output_auth_code = auth_code;
133 run_loop->Quit(); 138 run_loop->Quit();
134 }, 139 },
135 output_auth_code, &run_loop)); 140 output_fetch_status, output_auth_code, &run_loop));
136 // Because the Fetch() operation needs to interact with other threads, 141 // Because the Fetch() operation needs to interact with other threads,
137 // RunUntilIdle() won't work here. Instead, use Run() and Quit() explicitly 142 // RunUntilIdle() won't work here. Instead, use Run() and Quit() explicitly
138 // in the callback. 143 // in the callback.
139 run_loop.Run(); 144 run_loop.Run();
140 } 145 }
141 146
142 private: 147 private:
143 std::unique_ptr<policy::TestRequestInterceptor> interceptor_; 148 std::unique_ptr<policy::TestRequestInterceptor> interceptor_;
144 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 149 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
145 150
146 DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthCodeFetcherBrowserTest); 151 DISALLOW_COPY_AND_ASSIGN(ArcRobotAuthCodeFetcherBrowserTest);
147 }; 152 };
148 153
149 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, 154 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest,
150 RequestAccountInfoSuccess) { 155 RequestAccountInfoSuccess) {
151 interceptor()->PushJobCallback(base::Bind(&ResponseJob)); 156 interceptor()->PushJobCallback(base::Bind(&ResponseJob));
152 157
153 std::string auth_code; 158 std::string auth_code;
159 arc::ArcAuthInfoFetcher::Status fetch_status =
160 arc::ArcAuthInfoFetcher::Status::FAILURE;
161
154 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>(); 162 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>();
155 FetchAuthCode(robot_fetcher.get(), &auth_code); 163 FetchAuthCode(robot_fetcher.get(), &fetch_status, &auth_code);
164
165 EXPECT_EQ(arc::ArcAuthInfoFetcher::Status::SUCCESS, fetch_status);
156 EXPECT_EQ(kFakeAuthCode, auth_code); 166 EXPECT_EQ(kFakeAuthCode, auth_code);
157 } 167 }
158 168
159 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest, 169 IN_PROC_BROWSER_TEST_F(ArcRobotAuthCodeFetcherBrowserTest,
160 RequestAccountInfoError) { 170 RequestAccountInfoError) {
161 interceptor()->PushJobCallback( 171 interceptor()->PushJobCallback(
162 policy::TestRequestInterceptor::BadRequestJob()); 172 policy::TestRequestInterceptor::BadRequestJob());
163 173
164 // We expect auth_code is empty in this case. So initialize with non-empty 174 // We expect auth_code is empty in this case. So initialize with non-empty
165 // value. 175 // value.
166 std::string auth_code = "NOT-YET-FETCHED"; 176 std::string auth_code = "NOT-YET-FETCHED";
177 arc::ArcAuthInfoFetcher::Status fetch_status =
178 arc::ArcAuthInfoFetcher::Status::SUCCESS;
179
167 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>(); 180 auto robot_fetcher = base::MakeUnique<ArcRobotAuthCodeFetcher>();
168 FetchAuthCode(robot_fetcher.get(), &auth_code); 181 FetchAuthCode(robot_fetcher.get(), &fetch_status, &auth_code);
169 182
183 EXPECT_EQ(arc::ArcAuthInfoFetcher::Status::FAILURE, fetch_status);
170 // Use EXPECT_EQ for better logging in case of failure. 184 // Use EXPECT_EQ for better logging in case of failure.
171 EXPECT_EQ(std::string(), auth_code); 185 EXPECT_EQ(std::string(), auth_code);
172 } 186 }
173 187
174 } // namespace arc 188 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698