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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 278 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
279 done.Wait(); | 279 done.Wait(); |
280 db_thread_.Stop(); | 280 db_thread_.Stop(); |
281 } | 281 } |
282 | 282 |
283 // Tests ---------------------------------------------------------------------- | 283 // Tests ---------------------------------------------------------------------- |
284 | 284 |
285 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 285 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
286 GURL requesting_frame("http://www.example.com/geolocation"); | 286 GURL requesting_frame("http://www.example.com/geolocation"); |
287 NavigateAndCommit(requesting_frame); | 287 NavigateAndCommit(requesting_frame); |
288 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 288 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
289 RequestGeolocationPermission(RequestID(0), requesting_frame); | 289 RequestGeolocationPermission(RequestID(0), requesting_frame); |
290 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 290 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
291 ConfirmInfoBarDelegate* infobar_0 = | 291 ConfirmInfoBarDelegate* infobar_0 = |
292 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 292 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
293 infobar_0->Cancel(); | 293 infobar_0->Cancel(); |
294 infobar_service()->RemoveInfoBar(infobar_0); | 294 infobar_service()->RemoveInfoBar(infobar_0); |
295 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 295 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
296 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 296 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
297 delete infobar_0; | 297 delete infobar_0; |
298 } | 298 } |
299 | 299 |
300 #if defined(OS_ANDROID) | 300 #if defined(OS_ANDROID) |
301 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 301 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
302 GURL requesting_frame("http://www.example.com/geolocation"); | 302 GURL requesting_frame("http://www.example.com/geolocation"); |
303 NavigateAndCommit(requesting_frame); | 303 NavigateAndCommit(requesting_frame); |
304 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 304 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
305 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 305 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
306 RequestGeolocationPermission(RequestID(0), requesting_frame); | 306 RequestGeolocationPermission(RequestID(0), requesting_frame); |
307 EXPECT_EQ(1U, infobar_service()->GetInfoBarCount()); | 307 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
308 ConfirmInfoBarDelegate* infobar_0 = | 308 ConfirmInfoBarDelegate* infobar_0 = |
309 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 309 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
310 ASSERT_TRUE(infobar_0); | 310 ASSERT_TRUE(infobar_0); |
311 string16 text_0 = infobar_0->GetButtonLabel( | 311 string16 text_0 = infobar_0->GetButtonLabel( |
312 ConfirmInfoBarDelegate::BUTTON_OK); | 312 ConfirmInfoBarDelegate::BUTTON_OK); |
313 | 313 |
314 NavigateAndCommit(requesting_frame); | 314 NavigateAndCommit(requesting_frame); |
315 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 315 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
316 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 316 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
317 RequestGeolocationPermission(RequestID(0), requesting_frame); | 317 RequestGeolocationPermission(RequestID(0), requesting_frame); |
318 EXPECT_EQ(1U, infobar_service()->GetInfoBarCount()); | 318 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
319 ConfirmInfoBarDelegate* infobar_1 = | 319 ConfirmInfoBarDelegate* infobar_1 = |
320 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 320 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
321 ASSERT_TRUE(infobar_1); | 321 ASSERT_TRUE(infobar_1); |
322 string16 text_1 = infobar_1->GetButtonLabel( | 322 string16 text_1 = infobar_1->GetButtonLabel( |
323 ConfirmInfoBarDelegate::BUTTON_OK); | 323 ConfirmInfoBarDelegate::BUTTON_OK); |
324 EXPECT_NE(text_0, text_1); | 324 EXPECT_NE(text_0, text_1); |
325 | 325 |
326 NavigateAndCommit(requesting_frame); | 326 NavigateAndCommit(requesting_frame); |
327 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); | 327 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); |
328 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 328 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
329 RequestGeolocationPermission(RequestID(0), requesting_frame); | 329 RequestGeolocationPermission(RequestID(0), requesting_frame); |
330 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 330 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
331 } | 331 } |
332 | 332 |
333 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 333 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
334 GURL requesting_frame("http://www.example.com/geolocation"); | 334 GURL requesting_frame("http://www.example.com/geolocation"); |
335 NavigateAndCommit(requesting_frame); | 335 NavigateAndCommit(requesting_frame); |
336 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 336 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
337 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 337 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
338 RequestGeolocationPermission(RequestID(0), requesting_frame); | 338 RequestGeolocationPermission(RequestID(0), requesting_frame); |
339 EXPECT_EQ(1U, infobar_service()->GetInfoBarCount()); | 339 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
340 ConfirmInfoBarDelegate* infobar_0 = | 340 ConfirmInfoBarDelegate* infobar_0 = |
341 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 341 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
342 ASSERT_TRUE(infobar_0); | 342 ASSERT_TRUE(infobar_0); |
343 infobar_0->Accept(); | 343 infobar_0->Accept(); |
344 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 344 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
345 CheckPermissionMessageSent(0, true); | 345 CheckPermissionMessageSent(0, true); |
346 } | 346 } |
347 | 347 |
348 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 348 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { |
349 GURL requesting_frame("http://www.example.com/geolocation"); | 349 GURL requesting_frame("http://www.example.com/geolocation"); |
350 NavigateAndCommit(requesting_frame); | 350 NavigateAndCommit(requesting_frame); |
351 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 351 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
352 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 352 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
353 RequestGeolocationPermission(RequestID(0), requesting_frame); | 353 RequestGeolocationPermission(RequestID(0), requesting_frame); |
354 EXPECT_EQ(1U, infobar_service()->GetInfoBarCount()); | 354 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
355 ConfirmInfoBarDelegate* infobar_0 = | 355 ConfirmInfoBarDelegate* infobar_0 = |
356 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 356 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
357 ASSERT_TRUE(infobar_0); | 357 ASSERT_TRUE(infobar_0); |
358 infobar_0->Accept(); | 358 infobar_0->Accept(); |
359 EXPECT_TRUE( | 359 EXPECT_TRUE( |
360 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); | 360 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); |
361 } | 361 } |
362 #endif | 362 #endif |
363 | 363 |
364 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 364 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
365 GURL requesting_frame_0("http://www.example.com/geolocation"); | 365 GURL requesting_frame_0("http://www.example.com/geolocation"); |
366 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 366 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
367 EXPECT_EQ(CONTENT_SETTING_ASK, | 367 EXPECT_EQ(CONTENT_SETTING_ASK, |
368 profile()->GetHostContentSettingsMap()->GetContentSetting( | 368 profile()->GetHostContentSettingsMap()->GetContentSetting( |
369 requesting_frame_0, | 369 requesting_frame_0, |
370 requesting_frame_0, | 370 requesting_frame_0, |
371 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 371 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
372 std::string())); | 372 std::string())); |
373 EXPECT_EQ(CONTENT_SETTING_ASK, | 373 EXPECT_EQ(CONTENT_SETTING_ASK, |
374 profile()->GetHostContentSettingsMap()->GetContentSetting( | 374 profile()->GetHostContentSettingsMap()->GetContentSetting( |
375 requesting_frame_1, | 375 requesting_frame_1, |
376 requesting_frame_0, | 376 requesting_frame_0, |
377 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 377 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
378 std::string())); | 378 std::string())); |
379 | 379 |
380 | 380 |
381 NavigateAndCommit(requesting_frame_0); | 381 NavigateAndCommit(requesting_frame_0); |
382 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 382 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
383 // Request permission for two frames. | 383 // Request permission for two frames. |
384 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 384 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
385 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 385 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
386 // Ensure only one infobar is created. | 386 // Ensure only one infobar is created. |
387 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 387 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
388 ConfirmInfoBarDelegate* infobar_0 = | 388 ConfirmInfoBarDelegate* infobar_0 = |
389 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 389 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
390 ASSERT_TRUE(infobar_0); | 390 ASSERT_TRUE(infobar_0); |
391 string16 text_0 = infobar_0->GetMessageText(); | 391 string16 text_0 = infobar_0->GetMessageText(); |
392 | 392 |
393 // Accept the first frame. | 393 // Accept the first frame. |
394 infobar_0->Accept(); | 394 infobar_0->Accept(); |
395 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 395 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
396 CheckPermissionMessageSent(0, true); | 396 CheckPermissionMessageSent(0, true); |
397 | 397 |
398 infobar_service()->RemoveInfoBar(infobar_0); | 398 infobar_service()->RemoveInfoBar(infobar_0); |
399 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 399 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
400 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 400 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
401 closed_delegate_tracker_.Clear(); | 401 closed_delegate_tracker_.Clear(); |
402 delete infobar_0; | 402 delete infobar_0; |
403 // Now we should have a new infobar for the second frame. | 403 // Now we should have a new infobar for the second frame. |
404 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 404 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
405 | 405 |
406 ConfirmInfoBarDelegate* infobar_1 = | 406 ConfirmInfoBarDelegate* infobar_1 = |
407 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 407 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
408 ASSERT_TRUE(infobar_1); | 408 ASSERT_TRUE(infobar_1); |
409 string16 text_1 = infobar_1->GetMessageText(); | 409 string16 text_1 = infobar_1->GetMessageText(); |
410 EXPECT_NE(text_0, text_1); | 410 EXPECT_NE(text_0, text_1); |
411 | 411 |
412 // Cancel (block) this frame. | 412 // Cancel (block) this frame. |
413 infobar_1->Cancel(); | 413 infobar_1->Cancel(); |
414 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 414 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
415 CheckPermissionMessageSent(1, false); | 415 CheckPermissionMessageSent(1, false); |
416 infobar_service()->RemoveInfoBar(infobar_1); | 416 infobar_service()->RemoveInfoBar(infobar_1); |
417 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 417 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
418 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 418 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
419 delete infobar_1; | 419 delete infobar_1; |
420 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 420 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
421 // Ensure the persisted permissions are ok. | 421 // Ensure the persisted permissions are ok. |
422 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 422 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
423 profile()->GetHostContentSettingsMap()->GetContentSetting( | 423 profile()->GetHostContentSettingsMap()->GetContentSetting( |
424 requesting_frame_0, | 424 requesting_frame_0, |
425 requesting_frame_0, | 425 requesting_frame_0, |
426 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 426 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
427 std::string())); | 427 std::string())); |
428 | 428 |
429 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 429 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
430 profile()->GetHostContentSettingsMap()->GetContentSetting( | 430 profile()->GetHostContentSettingsMap()->GetContentSetting( |
431 requesting_frame_1, | 431 requesting_frame_1, |
432 requesting_frame_0, | 432 requesting_frame_0, |
433 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 433 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
434 std::string())); | 434 std::string())); |
435 } | 435 } |
436 | 436 |
437 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 437 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { |
438 GURL requesting_frame("file://example/geolocation.html"); | 438 GURL requesting_frame("file://example/geolocation.html"); |
439 NavigateAndCommit(requesting_frame); | 439 NavigateAndCommit(requesting_frame); |
440 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 440 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
441 RequestGeolocationPermission(RequestID(0), requesting_frame); | 441 RequestGeolocationPermission(RequestID(0), requesting_frame); |
442 EXPECT_EQ(1U, infobar_service()->GetInfoBarCount()); | 442 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
443 ConfirmInfoBarDelegate* infobar = | 443 ConfirmInfoBarDelegate* infobar = |
444 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 444 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
445 ASSERT_TRUE(infobar); | 445 ASSERT_TRUE(infobar); |
446 // Accept the frame | 446 // Accept the frame |
447 infobar->Accept(); | 447 infobar->Accept(); |
448 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 448 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
449 CheckPermissionMessageSent(0, true); | 449 CheckPermissionMessageSent(0, true); |
450 infobar_service()->RemoveInfoBar(infobar); | 450 infobar_service()->RemoveInfoBar(infobar); |
451 delete infobar; | 451 delete infobar; |
452 | 452 |
453 // Make sure the setting is not stored. | 453 // Make sure the setting is not stored. |
454 EXPECT_EQ(CONTENT_SETTING_ASK, | 454 EXPECT_EQ(CONTENT_SETTING_ASK, |
(...skipping 16 matching lines...) Expand all Loading... |
471 | 471 |
472 EXPECT_EQ(CONTENT_SETTING_ASK, | 472 EXPECT_EQ(CONTENT_SETTING_ASK, |
473 profile()->GetHostContentSettingsMap()->GetContentSetting( | 473 profile()->GetHostContentSettingsMap()->GetContentSetting( |
474 requesting_frame_1, | 474 requesting_frame_1, |
475 requesting_frame_0, | 475 requesting_frame_0, |
476 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 476 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
477 std::string())); | 477 std::string())); |
478 | 478 |
479 | 479 |
480 NavigateAndCommit(requesting_frame_0); | 480 NavigateAndCommit(requesting_frame_0); |
481 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 481 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
482 // Request permission for two frames. | 482 // Request permission for two frames. |
483 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 483 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
484 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 484 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
485 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 485 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
486 | 486 |
487 ConfirmInfoBarDelegate* infobar_0 = | 487 ConfirmInfoBarDelegate* infobar_0 = |
488 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 488 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
489 ASSERT_TRUE(infobar_0); | 489 ASSERT_TRUE(infobar_0); |
490 string16 text_0 = infobar_0->GetMessageText(); | 490 string16 text_0 = infobar_0->GetMessageText(); |
491 | 491 |
492 // Simulate the frame going away, ensure the infobar for this frame | 492 // Simulate the frame going away, ensure the infobar for this frame |
493 // is removed and the next pending infobar is created. | 493 // is removed and the next pending infobar is created. |
494 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); | 494 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); |
495 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 495 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
496 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 496 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
497 closed_delegate_tracker_.Clear(); | 497 closed_delegate_tracker_.Clear(); |
498 delete infobar_0; | 498 delete infobar_0; |
499 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 499 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
500 | 500 |
501 ConfirmInfoBarDelegate* infobar_1 = | 501 ConfirmInfoBarDelegate* infobar_1 = |
502 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 502 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
503 ASSERT_TRUE(infobar_1); | 503 ASSERT_TRUE(infobar_1); |
504 string16 text_1 = infobar_1->GetMessageText(); | 504 string16 text_1 = infobar_1->GetMessageText(); |
505 EXPECT_NE(text_0, text_1); | 505 EXPECT_NE(text_0, text_1); |
506 | 506 |
507 // Allow this frame. | 507 // Allow this frame. |
508 infobar_1->Accept(); | 508 infobar_1->Accept(); |
509 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 509 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
510 CheckPermissionMessageSent(1, true); | 510 CheckPermissionMessageSent(1, true); |
511 infobar_service()->RemoveInfoBar(infobar_1); | 511 infobar_service()->RemoveInfoBar(infobar_1); |
512 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 512 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
513 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 513 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
514 delete infobar_1; | 514 delete infobar_1; |
515 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 515 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
516 // Ensure the persisted permissions are ok. | 516 // Ensure the persisted permissions are ok. |
517 EXPECT_EQ(CONTENT_SETTING_ASK, | 517 EXPECT_EQ(CONTENT_SETTING_ASK, |
518 profile()->GetHostContentSettingsMap()->GetContentSetting( | 518 profile()->GetHostContentSettingsMap()->GetContentSetting( |
519 requesting_frame_0, | 519 requesting_frame_0, |
520 requesting_frame_0, | 520 requesting_frame_0, |
521 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 521 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
522 std::string())); | 522 std::string())); |
523 | 523 |
524 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 524 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
525 profile()->GetHostContentSettingsMap()->GetContentSetting( | 525 profile()->GetHostContentSettingsMap()->GetContentSetting( |
526 requesting_frame_1, | 526 requesting_frame_1, |
527 requesting_frame_0, | 527 requesting_frame_0, |
528 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 528 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
529 std::string())); | 529 std::string())); |
530 } | 530 } |
531 | 531 |
532 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 532 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
533 GURL invalid_embedder("about:blank"); | 533 GURL invalid_embedder("about:blank"); |
534 GURL requesting_frame; | 534 GURL requesting_frame; |
535 NavigateAndCommit(invalid_embedder); | 535 NavigateAndCommit(invalid_embedder); |
536 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 536 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
537 RequestGeolocationPermission(RequestID(0), requesting_frame); | 537 RequestGeolocationPermission(RequestID(0), requesting_frame); |
538 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 538 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
539 CheckPermissionMessageSent(0, false); | 539 CheckPermissionMessageSent(0, false); |
540 } | 540 } |
541 | 541 |
542 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 542 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
543 GURL url_a("http://www.example.com/geolocation"); | 543 GURL url_a("http://www.example.com/geolocation"); |
544 GURL url_b("http://www.example-2.com/geolocation"); | 544 GURL url_b("http://www.example-2.com/geolocation"); |
545 NavigateAndCommit(url_a); | 545 NavigateAndCommit(url_a); |
546 AddNewTab(url_b); | 546 AddNewTab(url_b); |
547 AddNewTab(url_a); | 547 AddNewTab(url_a); |
548 | 548 |
549 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 549 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
550 RequestGeolocationPermission(RequestID(0), url_a); | 550 RequestGeolocationPermission(RequestID(0), url_a); |
551 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 551 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
552 | 552 |
553 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); | 553 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
554 EXPECT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); | 554 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
555 | 555 |
556 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); | 556 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
557 ASSERT_EQ(1U, infobar_service_for_tab(1)->GetInfoBarCount()); | 557 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
558 | 558 |
559 ConfirmInfoBarDelegate* removed_infobar = infobar_service_for_tab(1)-> | 559 ConfirmInfoBarDelegate* removed_infobar = |
560 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 560 infobar_service_for_tab(1)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
561 | 561 |
562 // Accept the first tab. | 562 // Accept the first tab. |
563 ConfirmInfoBarDelegate* infobar_0 = | 563 ConfirmInfoBarDelegate* infobar_0 = |
564 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 564 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
565 ASSERT_TRUE(infobar_0); | 565 ASSERT_TRUE(infobar_0); |
566 infobar_0->Accept(); | 566 infobar_0->Accept(); |
567 CheckPermissionMessageSent(0, true); | 567 CheckPermissionMessageSent(0, true); |
568 infobar_service()->RemoveInfoBar(infobar_0); | 568 infobar_service()->RemoveInfoBar(infobar_0); |
569 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 569 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
570 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 570 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
571 delete infobar_0; | 571 delete infobar_0; |
572 // Now the infobar for the tab with the same origin should have gone. | 572 // Now the infobar for the tab with the same origin should have gone. |
573 EXPECT_EQ(0U, infobar_service_for_tab(1)->GetInfoBarCount()); | 573 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); |
574 CheckPermissionMessageSentForTab(1, 0, true); | 574 CheckPermissionMessageSentForTab(1, 0, true); |
575 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 575 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
576 closed_delegate_tracker_.Clear(); | 576 closed_delegate_tracker_.Clear(); |
577 // Destroy the infobar that has just been removed. | 577 // Destroy the infobar that has just been removed. |
578 delete removed_infobar; | 578 delete removed_infobar; |
579 | 579 |
580 // But the other tab should still have the info bar... | 580 // But the other tab should still have the info bar... |
581 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); | 581 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
582 ConfirmInfoBarDelegate* infobar_1 = infobar_service_for_tab(0)-> | 582 ConfirmInfoBarDelegate* infobar_1 = |
583 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 583 infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
584 infobar_1->Cancel(); | 584 infobar_1->Cancel(); |
585 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 585 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
586 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 586 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
587 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 587 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
588 delete infobar_1; | 588 delete infobar_1; |
589 } | 589 } |
590 | 590 |
591 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 591 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
592 GURL url_a("http://www.example.com/geolocation"); | 592 GURL url_a("http://www.example.com/geolocation"); |
593 GURL url_b("http://www.example-2.com/geolocation"); | 593 GURL url_b("http://www.example-2.com/geolocation"); |
594 NavigateAndCommit(url_a); | 594 NavigateAndCommit(url_a); |
595 AddNewTab(url_a); | 595 AddNewTab(url_a); |
596 | 596 |
597 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 597 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
598 RequestGeolocationPermission(RequestID(0), url_a); | 598 RequestGeolocationPermission(RequestID(0), url_a); |
599 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 599 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
600 | 600 |
601 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); | 601 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
602 EXPECT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); | 602 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
603 | 603 |
604 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); | 604 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
605 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); | 605 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
606 | 606 |
607 ConfirmInfoBarDelegate* removed_infobar = | 607 ConfirmInfoBarDelegate* removed_infobar = |
608 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 608 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
609 | 609 |
610 // Accept the second tab. | 610 // Accept the second tab. |
611 ConfirmInfoBarDelegate* infobar_0 = infobar_service_for_tab(0)-> | 611 ConfirmInfoBarDelegate* infobar_0 = |
612 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 612 infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
613 ASSERT_TRUE(infobar_0); | 613 ASSERT_TRUE(infobar_0); |
614 infobar_0->Accept(); | 614 infobar_0->Accept(); |
615 CheckPermissionMessageSentForTab(0, 0, true); | 615 CheckPermissionMessageSentForTab(0, 0, true); |
616 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 616 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); |
617 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 617 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
618 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 618 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
619 delete infobar_0; | 619 delete infobar_0; |
620 // Now the infobar for the tab with the same origin should have gone. | 620 // Now the infobar for the tab with the same origin should have gone. |
621 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 621 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
622 CheckPermissionMessageSent(0, true); | 622 CheckPermissionMessageSent(0, true); |
623 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 623 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
624 closed_delegate_tracker_.Clear(); | 624 closed_delegate_tracker_.Clear(); |
625 // Destroy the infobar that has just been removed. | 625 // Destroy the infobar that has just been removed. |
626 delete removed_infobar; | 626 delete removed_infobar; |
627 | 627 |
628 // And we should have the queued infobar displayed now. | 628 // And we should have the queued infobar displayed now. |
629 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); | 629 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
630 | 630 |
631 // Accept the second infobar. | 631 // Accept the second infobar. |
632 ConfirmInfoBarDelegate* infobar_1 = infobar_service_for_tab(0)-> | 632 ConfirmInfoBarDelegate* infobar_1 = |
633 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 633 infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
634 ASSERT_TRUE(infobar_1); | 634 ASSERT_TRUE(infobar_1); |
635 infobar_1->Accept(); | 635 infobar_1->Accept(); |
636 CheckPermissionMessageSentForTab(0, 1, true); | 636 CheckPermissionMessageSentForTab(0, 1, true); |
637 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 637 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
638 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 638 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
639 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 639 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
640 delete infobar_1; | 640 delete infobar_1; |
641 } | 641 } |
642 | 642 |
643 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 643 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
644 GURL requesting_frame_0("http://www.example.com/geolocation"); | 644 GURL requesting_frame_0("http://www.example.com/geolocation"); |
645 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 645 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
646 EXPECT_EQ( | 646 EXPECT_EQ( |
647 CONTENT_SETTING_ASK, | 647 CONTENT_SETTING_ASK, |
648 profile()->GetHostContentSettingsMap()->GetContentSetting( | 648 profile()->GetHostContentSettingsMap()->GetContentSetting( |
649 requesting_frame_0, | 649 requesting_frame_0, |
650 requesting_frame_0, | 650 requesting_frame_0, |
651 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 651 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
652 std::string())); | 652 std::string())); |
653 | 653 |
654 EXPECT_EQ( | 654 EXPECT_EQ( |
655 CONTENT_SETTING_ASK, | 655 CONTENT_SETTING_ASK, |
656 profile()->GetHostContentSettingsMap()->GetContentSetting( | 656 profile()->GetHostContentSettingsMap()->GetContentSetting( |
657 requesting_frame_1, | 657 requesting_frame_1, |
658 requesting_frame_0, | 658 requesting_frame_0, |
659 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 659 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
660 std::string())); | 660 std::string())); |
661 | 661 |
662 NavigateAndCommit(requesting_frame_0); | 662 NavigateAndCommit(requesting_frame_0); |
663 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 663 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
664 // Request permission for two frames. | 664 // Request permission for two frames. |
665 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 665 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
666 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 666 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
667 // Ensure only one infobar is created. | 667 // Ensure only one infobar is created. |
668 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 668 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
669 ConfirmInfoBarDelegate* infobar_0 = | 669 ConfirmInfoBarDelegate* infobar_0 = |
670 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 670 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
671 ASSERT_TRUE(infobar_0); | 671 ASSERT_TRUE(infobar_0); |
672 | 672 |
673 // Delete the tab contents. | 673 // Delete the tab contents. |
674 DeleteContents(); | 674 DeleteContents(); |
675 delete infobar_0; | 675 delete infobar_0; |
676 | 676 |
677 // During contents destruction, the infobar will have been closed, and the | 677 // During contents destruction, the infobar will have been closed, and the |
678 // pending request should have been cleared without an infobar being created. | 678 // pending request should have been cleared without an infobar being created. |
679 ASSERT_EQ(1U, closed_delegate_tracker_.size()); | 679 ASSERT_EQ(1U, closed_delegate_tracker_.size()); |
680 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 680 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
681 } | 681 } |
682 | 682 |
683 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 683 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
684 GURL requesting_frame_0("http://www.example.com/geolocation"); | 684 GURL requesting_frame_0("http://www.example.com/geolocation"); |
685 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 685 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
686 NavigateAndCommit(requesting_frame_0); | 686 NavigateAndCommit(requesting_frame_0); |
687 NavigateAndCommit(requesting_frame_1); | 687 NavigateAndCommit(requesting_frame_1); |
688 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 688 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
689 // Go back: navigate to a pending entry before requesting geolocation | 689 // Go back: navigate to a pending entry before requesting geolocation |
690 // permission. | 690 // permission. |
691 web_contents()->GetController().GoBack(); | 691 web_contents()->GetController().GoBack(); |
692 // Request permission for the committed frame (not the pending one). | 692 // Request permission for the committed frame (not the pending one). |
693 RequestGeolocationPermission(RequestID(0), requesting_frame_1); | 693 RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
694 // Ensure the infobar is created. | 694 // Ensure the infobar is created. |
695 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); | 695 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
696 InfoBarDelegate* infobar_0 = infobar_service()->GetInfoBarDelegateAt(0); | 696 InfoBarDelegate* infobar_0 = infobar_service()->infobar_at(0); |
697 ASSERT_TRUE(infobar_0); | 697 ASSERT_TRUE(infobar_0); |
698 // Ensure the infobar wouldn't expire for a navigation to the committed entry. | 698 // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
699 content::LoadCommittedDetails details; | 699 content::LoadCommittedDetails details; |
700 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 700 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
701 EXPECT_FALSE(infobar_0->ShouldExpire(details)); | 701 EXPECT_FALSE(infobar_0->ShouldExpire(details)); |
702 // Ensure the infobar will expire when we commit the pending navigation. | 702 // Ensure the infobar will expire when we commit the pending navigation. |
703 details.entry = web_contents()->GetController().GetActiveEntry(); | 703 details.entry = web_contents()->GetController().GetActiveEntry(); |
704 EXPECT_TRUE(infobar_0->ShouldExpire(details)); | 704 EXPECT_TRUE(infobar_0->ShouldExpire(details)); |
705 | 705 |
706 // Delete the tab contents. | 706 // Delete the tab contents. |
707 DeleteContents(); | 707 DeleteContents(); |
708 delete infobar_0; | 708 delete infobar_0; |
709 } | 709 } |
OLD | NEW |