OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/api/identity/identity_api.h" | 8 #include "chrome/browser/extensions/api/identity/identity_api.h" |
9 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | 9 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 171 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
172 NoClientId) { | 172 NoClientId) { |
173 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 173 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
174 func->set_extension(CreateExtension(SCOPES)); | 174 func->set_extension(CreateExtension(SCOPES)); |
175 std::string error = utils::RunFunctionAndReturnError( | 175 std::string error = utils::RunFunctionAndReturnError( |
176 func.get(), "[{}]", browser()); | 176 func.get(), "[{}]", browser()); |
177 EXPECT_EQ(std::string(errors::kInvalidClientId), error); | 177 EXPECT_EQ(std::string(errors::kInvalidClientId), error); |
178 EXPECT_FALSE(func->login_ui_shown()); | 178 EXPECT_FALSE(func->login_ui_shown()); |
179 EXPECT_FALSE(func->install_ui_shown()); | 179 EXPECT_FALSE(func->install_ui_shown()); |
180 CloseShellWindowsAndWaitForAppToExit(); | |
181 } | 180 } |
182 | 181 |
183 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 182 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
184 NoScopes) { | 183 NoScopes) { |
185 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 184 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
186 func->set_extension(CreateExtension(CLIENT_ID)); | 185 func->set_extension(CreateExtension(CLIENT_ID)); |
187 std::string error = utils::RunFunctionAndReturnError( | 186 std::string error = utils::RunFunctionAndReturnError( |
188 func.get(), "[{}]", browser()); | 187 func.get(), "[{}]", browser()); |
189 EXPECT_EQ(std::string(errors::kInvalidScopes), error); | 188 EXPECT_EQ(std::string(errors::kInvalidScopes), error); |
190 EXPECT_FALSE(func->login_ui_shown()); | 189 EXPECT_FALSE(func->login_ui_shown()); |
191 EXPECT_FALSE(func->install_ui_shown()); | 190 EXPECT_FALSE(func->install_ui_shown()); |
192 CloseShellWindowsAndWaitForAppToExit(); | |
193 } | 191 } |
194 | 192 |
195 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 193 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
196 NonInteractiveNotSignedIn) { | 194 NonInteractiveNotSignedIn) { |
197 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 195 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
198 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 196 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
199 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 197 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
200 std::string error = utils::RunFunctionAndReturnError( | 198 std::string error = utils::RunFunctionAndReturnError( |
201 func.get(), "[{}]", browser()); | 199 func.get(), "[{}]", browser()); |
202 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 200 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
203 EXPECT_FALSE(func->login_ui_shown()); | 201 EXPECT_FALSE(func->login_ui_shown()); |
204 EXPECT_FALSE(func->install_ui_shown()); | 202 EXPECT_FALSE(func->install_ui_shown()); |
205 CloseShellWindowsAndWaitForAppToExit(); | |
206 } | 203 } |
207 | 204 |
208 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 205 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
209 NonInteractiveMintFailure) { | 206 NonInteractiveMintFailure) { |
210 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 207 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
211 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 208 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
212 EXPECT_CALL(*func.get(), HasLoginToken()) | 209 EXPECT_CALL(*func.get(), HasLoginToken()) |
213 .WillOnce(Return(true)) | 210 .WillOnce(Return(true)) |
214 .WillOnce(Return(true)); | 211 .WillOnce(Return(true)); |
215 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 212 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
216 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 213 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
217 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 214 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
218 std::string error = utils::RunFunctionAndReturnError( | 215 std::string error = utils::RunFunctionAndReturnError( |
219 func.get(), "[{}]", browser()); | 216 func.get(), "[{}]", browser()); |
220 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 217 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
221 EXPECT_FALSE(func->login_ui_shown()); | 218 EXPECT_FALSE(func->login_ui_shown()); |
222 EXPECT_FALSE(func->install_ui_shown()); | 219 EXPECT_FALSE(func->install_ui_shown()); |
223 CloseShellWindowsAndWaitForAppToExit(); | |
224 } | 220 } |
225 | 221 |
226 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 222 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
227 NonInteractiveSuccess) { | 223 NonInteractiveSuccess) { |
228 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 224 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
229 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 225 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
230 EXPECT_CALL(*func.get(), HasLoginToken()) | 226 EXPECT_CALL(*func.get(), HasLoginToken()) |
231 .WillOnce(Return(true)) | 227 .WillOnce(Return(true)) |
232 .WillOnce(Return(true)); | 228 .WillOnce(Return(true)); |
233 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 229 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
234 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 230 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
235 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 231 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
236 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 232 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
237 func.get(), "[{}]", browser())); | 233 func.get(), "[{}]", browser())); |
238 std::string access_token; | 234 std::string access_token; |
239 EXPECT_TRUE(value->GetAsString(&access_token)); | 235 EXPECT_TRUE(value->GetAsString(&access_token)); |
240 EXPECT_EQ(std::string(kAccessToken), access_token); | 236 EXPECT_EQ(std::string(kAccessToken), access_token); |
241 EXPECT_FALSE(func->login_ui_shown()); | 237 EXPECT_FALSE(func->login_ui_shown()); |
242 EXPECT_FALSE(func->install_ui_shown()); | 238 EXPECT_FALSE(func->install_ui_shown()); |
243 CloseShellWindowsAndWaitForAppToExit(); | |
244 } | 239 } |
245 | 240 |
246 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 241 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
247 InteractiveLoginCanceled) { | 242 InteractiveLoginCanceled) { |
248 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 243 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
249 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 244 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
250 EXPECT_CALL(*func.get(), HasLoginToken()).WillRepeatedly(Return(false)); | 245 EXPECT_CALL(*func.get(), HasLoginToken()).WillRepeatedly(Return(false)); |
251 std::string error = utils::RunFunctionAndReturnError( | 246 std::string error = utils::RunFunctionAndReturnError( |
252 func.get(), "[{\"interactive\": true}]", browser()); | 247 func.get(), "[{\"interactive\": true}]", browser()); |
253 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 248 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
254 EXPECT_TRUE(func->login_ui_shown()); | 249 EXPECT_TRUE(func->login_ui_shown()); |
255 EXPECT_FALSE(func->install_ui_shown()); | 250 EXPECT_FALSE(func->install_ui_shown()); |
256 CloseShellWindowsAndWaitForAppToExit(); | |
257 } | 251 } |
258 | 252 |
259 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 253 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
260 InteractiveLoginSuccessMintFailure) { | 254 InteractiveLoginSuccessMintFailure) { |
261 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 255 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
262 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 256 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
263 EXPECT_CALL(*func.get(), HasLoginToken()) | 257 EXPECT_CALL(*func.get(), HasLoginToken()) |
264 .WillOnce(Return(false)) | 258 .WillOnce(Return(false)) |
265 .WillOnce(Return(true)); | 259 .WillOnce(Return(true)); |
266 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 260 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
267 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 261 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
268 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 262 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
269 std::string error = utils::RunFunctionAndReturnError( | 263 std::string error = utils::RunFunctionAndReturnError( |
270 func.get(), "[{\"interactive\": true}]", browser()); | 264 func.get(), "[{\"interactive\": true}]", browser()); |
271 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 265 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
272 EXPECT_TRUE(func->login_ui_shown()); | 266 EXPECT_TRUE(func->login_ui_shown()); |
273 EXPECT_FALSE(func->install_ui_shown()); | 267 EXPECT_FALSE(func->install_ui_shown()); |
274 CloseShellWindowsAndWaitForAppToExit(); | |
275 } | 268 } |
276 | 269 |
277 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 270 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
278 InteractiveLoginSuccessMintSuccess) { | 271 InteractiveLoginSuccessMintSuccess) { |
279 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 272 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
280 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 273 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
281 EXPECT_CALL(*func.get(), HasLoginToken()) | 274 EXPECT_CALL(*func.get(), HasLoginToken()) |
282 .WillOnce(Return(false)) | 275 .WillOnce(Return(false)) |
283 .WillOnce(Return(true)); | 276 .WillOnce(Return(true)); |
284 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 277 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
285 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 278 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
286 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 279 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
287 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 280 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
288 func.get(), "[{\"interactive\": true}]", browser())); | 281 func.get(), "[{\"interactive\": true}]", browser())); |
289 std::string access_token; | 282 std::string access_token; |
290 EXPECT_TRUE(value->GetAsString(&access_token)); | 283 EXPECT_TRUE(value->GetAsString(&access_token)); |
291 EXPECT_EQ(std::string(kAccessToken), access_token); | 284 EXPECT_EQ(std::string(kAccessToken), access_token); |
292 EXPECT_TRUE(func->login_ui_shown()); | 285 EXPECT_TRUE(func->login_ui_shown()); |
293 EXPECT_FALSE(func->install_ui_shown()); | 286 EXPECT_FALSE(func->install_ui_shown()); |
294 CloseShellWindowsAndWaitForAppToExit(); | |
295 } | 287 } |
296 | 288 |
297 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 289 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
298 InteractiveLoginSuccessApprovalAborted) { | 290 InteractiveLoginSuccessApprovalAborted) { |
299 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 291 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
300 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 292 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
301 EXPECT_CALL(*func.get(), HasLoginToken()) | 293 EXPECT_CALL(*func.get(), HasLoginToken()) |
302 .WillOnce(Return(false)) | 294 .WillOnce(Return(false)) |
303 .WillOnce(Return(true)); | 295 .WillOnce(Return(true)); |
304 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 296 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
305 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 297 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
306 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 298 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
307 func->set_install_ui_result(false); | 299 func->set_install_ui_result(false); |
308 std::string error = utils::RunFunctionAndReturnError( | 300 std::string error = utils::RunFunctionAndReturnError( |
309 func.get(), "[{\"interactive\": true}]", browser()); | 301 func.get(), "[{\"interactive\": true}]", browser()); |
310 EXPECT_EQ(std::string(errors::kUserRejected), error); | 302 EXPECT_EQ(std::string(errors::kUserRejected), error); |
311 EXPECT_TRUE(func->login_ui_shown()); | 303 EXPECT_TRUE(func->login_ui_shown()); |
312 EXPECT_TRUE(func->install_ui_shown()); | 304 EXPECT_TRUE(func->install_ui_shown()); |
313 CloseShellWindowsAndWaitForAppToExit(); | |
314 } | 305 } |
315 | 306 |
316 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 307 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
317 InteractiveLoginSuccessApprovalDoneMintFailure) { | 308 InteractiveLoginSuccessApprovalDoneMintFailure) { |
318 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 309 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
319 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 310 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
320 EXPECT_CALL(*func.get(), HasLoginToken()) | 311 EXPECT_CALL(*func.get(), HasLoginToken()) |
321 .WillOnce(Return(false)) | 312 .WillOnce(Return(false)) |
322 .WillOnce(Return(true)) | 313 .WillOnce(Return(true)) |
323 .WillOnce(Return(true)); | 314 .WillOnce(Return(true)); |
324 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 315 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
325 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 316 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
326 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 317 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( |
327 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 318 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
328 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 319 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
329 .WillOnce(Return(flow1)) | 320 .WillOnce(Return(flow1)) |
330 .WillOnce(Return(flow2)); | 321 .WillOnce(Return(flow2)); |
331 | 322 |
332 func->set_install_ui_result(true); | 323 func->set_install_ui_result(true); |
333 std::string error = utils::RunFunctionAndReturnError( | 324 std::string error = utils::RunFunctionAndReturnError( |
334 func.get(), "[{\"interactive\": true}]", browser()); | 325 func.get(), "[{\"interactive\": true}]", browser()); |
335 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 326 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
336 EXPECT_TRUE(func->login_ui_shown()); | 327 EXPECT_TRUE(func->login_ui_shown()); |
337 EXPECT_TRUE(func->install_ui_shown()); | 328 EXPECT_TRUE(func->install_ui_shown()); |
338 CloseShellWindowsAndWaitForAppToExit(); | |
339 } | 329 } |
340 | 330 |
341 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 331 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
342 InteractiveLoginSuccessApprovalDoneMintSuccess) { | 332 InteractiveLoginSuccessApprovalDoneMintSuccess) { |
343 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 333 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
344 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 334 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
345 EXPECT_CALL(*func.get(), HasLoginToken()) | 335 EXPECT_CALL(*func.get(), HasLoginToken()) |
346 .WillOnce(Return(false)) | 336 .WillOnce(Return(false)) |
347 .WillOnce(Return(true)) | 337 .WillOnce(Return(true)) |
348 .WillOnce(Return(true)); | 338 .WillOnce(Return(true)); |
349 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 339 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
350 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 340 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
351 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 341 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( |
352 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 342 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
353 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 343 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
354 .WillOnce(Return(flow1)) | 344 .WillOnce(Return(flow1)) |
355 .WillOnce(Return(flow2)); | 345 .WillOnce(Return(flow2)); |
356 | 346 |
357 func->set_install_ui_result(true); | 347 func->set_install_ui_result(true); |
358 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 348 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
359 func.get(), "[{\"interactive\": true}]", browser())); | 349 func.get(), "[{\"interactive\": true}]", browser())); |
360 std::string access_token; | 350 std::string access_token; |
361 EXPECT_TRUE(value->GetAsString(&access_token)); | 351 EXPECT_TRUE(value->GetAsString(&access_token)); |
362 EXPECT_EQ(std::string(kAccessToken), access_token); | 352 EXPECT_EQ(std::string(kAccessToken), access_token); |
363 EXPECT_TRUE(func->login_ui_shown()); | 353 EXPECT_TRUE(func->login_ui_shown()); |
364 EXPECT_TRUE(func->install_ui_shown()); | 354 EXPECT_TRUE(func->install_ui_shown()); |
365 CloseShellWindowsAndWaitForAppToExit(); | |
366 } | 355 } |
367 | 356 |
368 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 357 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
369 InteractiveApprovalAborted) { | 358 InteractiveApprovalAborted) { |
370 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 359 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
371 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 360 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
372 EXPECT_CALL(*func.get(), HasLoginToken()) | 361 EXPECT_CALL(*func.get(), HasLoginToken()) |
373 .WillOnce(Return(true)) | 362 .WillOnce(Return(true)) |
374 .WillOnce(Return(true)); | 363 .WillOnce(Return(true)); |
375 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 364 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
376 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 365 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
377 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 366 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
378 func->set_install_ui_result(false); | 367 func->set_install_ui_result(false); |
379 std::string error = utils::RunFunctionAndReturnError( | 368 std::string error = utils::RunFunctionAndReturnError( |
380 func.get(), "[{\"interactive\": true}]", browser()); | 369 func.get(), "[{\"interactive\": true}]", browser()); |
381 EXPECT_EQ(std::string(errors::kUserRejected), error); | 370 EXPECT_EQ(std::string(errors::kUserRejected), error); |
382 EXPECT_FALSE(func->login_ui_shown()); | 371 EXPECT_FALSE(func->login_ui_shown()); |
383 EXPECT_TRUE(func->install_ui_shown()); | 372 EXPECT_TRUE(func->install_ui_shown()); |
384 CloseShellWindowsAndWaitForAppToExit(); | |
385 } | 373 } |
386 | 374 |
387 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 375 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
388 InteractiveApprovalDoneMintSuccess) { | 376 InteractiveApprovalDoneMintSuccess) { |
389 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 377 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
390 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 378 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
391 EXPECT_CALL(*func.get(), HasLoginToken()) | 379 EXPECT_CALL(*func.get(), HasLoginToken()) |
392 .WillOnce(Return(true)) | 380 .WillOnce(Return(true)) |
393 .WillOnce(Return(true)) | 381 .WillOnce(Return(true)) |
394 .WillOnce(Return(true)); | 382 .WillOnce(Return(true)); |
395 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 383 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
396 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 384 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
397 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 385 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( |
398 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 386 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
399 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 387 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
400 .WillOnce(Return(flow1)) | 388 .WillOnce(Return(flow1)) |
401 .WillOnce(Return(flow2)); | 389 .WillOnce(Return(flow2)); |
402 | 390 |
403 func->set_install_ui_result(true); | 391 func->set_install_ui_result(true); |
404 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 392 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
405 func.get(), "[{\"interactive\": true}]", browser())); | 393 func.get(), "[{\"interactive\": true}]", browser())); |
406 std::string access_token; | 394 std::string access_token; |
407 EXPECT_TRUE(value->GetAsString(&access_token)); | 395 EXPECT_TRUE(value->GetAsString(&access_token)); |
408 EXPECT_EQ(std::string(kAccessToken), access_token); | 396 EXPECT_EQ(std::string(kAccessToken), access_token); |
409 EXPECT_FALSE(func->login_ui_shown()); | 397 EXPECT_FALSE(func->login_ui_shown()); |
410 EXPECT_TRUE(func->install_ui_shown()); | 398 EXPECT_TRUE(func->install_ui_shown()); |
411 CloseShellWindowsAndWaitForAppToExit(); | |
412 } | 399 } |
413 | 400 |
414 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest { | 401 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest { |
415 protected: | 402 protected: |
416 void RunAndCheckBounds( | 403 void RunAndCheckBounds( |
417 const std::string& extra_params, | 404 const std::string& extra_params, |
418 int expected_x, | 405 int expected_x, |
419 int expected_y, | 406 int expected_y, |
420 int expected_width, | 407 int expected_width, |
421 int expected_height) { | 408 int expected_height) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 }; | 445 }; |
459 | 446 |
460 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { | 447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { |
461 RunAndCheckBounds("", 0, 0, 0, 0); | 448 RunAndCheckBounds("", 0, 0, 0, 0); |
462 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); | 449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); |
463 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); | 450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); |
464 RunAndCheckBounds( | 451 RunAndCheckBounds( |
465 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", | 452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", |
466 100, 200, 300, 400); | 453 100, 200, 300, 400); |
467 } | 454 } |
OLD | NEW |