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