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

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 NavigateAndCommit(requesting_frame); 287 NavigateAndCommit(requesting_frame);
288 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 288 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
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()->GetInfoBarCount());
291 ConfirmInfoBarDelegate* infobar_0 = 291 ConfirmInfoBarDelegate* infobar_0 =
292 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 292 infobar_service()->GetInfoBarDelegateAt(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 infobar_0->InfoBarClosed(); 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()->GetInfoBarCount());
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()->GetInfoBarCount());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 infobar_0->InfoBarClosed(); 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()->GetInfoBarCount());
405 405
406 ConfirmInfoBarDelegate* infobar_1 = 406 ConfirmInfoBarDelegate* infobar_1 =
407 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 407 infobar_service()->GetInfoBarDelegateAt(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 infobar_1->InfoBarClosed(); 419 delete infobar_1;
420 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 420 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
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,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 463 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
464 ASSERT_TRUE(infobar_0); 464 ASSERT_TRUE(infobar_0);
465 string16 text_0 = infobar_0->GetMessageText(); 465 string16 text_0 = infobar_0->GetMessageText();
466 466
467 // Simulate the frame going away, ensure the infobar for this frame 467 // Simulate the frame going away, ensure the infobar for this frame
468 // is removed and the next pending infobar is created. 468 // is removed and the next pending infobar is created.
469 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); 469 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0);
470 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 470 EXPECT_EQ(1U, closed_delegate_tracker_.size());
471 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 471 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
472 closed_delegate_tracker_.Clear(); 472 closed_delegate_tracker_.Clear();
473 infobar_0->InfoBarClosed(); 473 delete infobar_0;
474 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); 474 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount());
475 475
476 ConfirmInfoBarDelegate* infobar_1 = 476 ConfirmInfoBarDelegate* infobar_1 =
477 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 477 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
478 ASSERT_TRUE(infobar_1); 478 ASSERT_TRUE(infobar_1);
479 string16 text_1 = infobar_1->GetMessageText(); 479 string16 text_1 = infobar_1->GetMessageText();
480 EXPECT_NE(text_0, text_1); 480 EXPECT_NE(text_0, text_1);
481 481
482 // Allow this frame. 482 // Allow this frame.
483 infobar_1->Accept(); 483 infobar_1->Accept();
484 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 484 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
485 CheckPermissionMessageSent(1, true); 485 CheckPermissionMessageSent(1, true);
486 infobar_service()->RemoveInfoBar(infobar_1); 486 infobar_service()->RemoveInfoBar(infobar_1);
487 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 487 EXPECT_EQ(1U, closed_delegate_tracker_.size());
488 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 488 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
489 infobar_1->InfoBarClosed(); 489 delete infobar_1;
490 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 490 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
491 // Ensure the persisted permissions are ok. 491 // Ensure the persisted permissions are ok.
492 EXPECT_EQ(CONTENT_SETTING_ASK, 492 EXPECT_EQ(CONTENT_SETTING_ASK,
493 profile()->GetHostContentSettingsMap()->GetContentSetting( 493 profile()->GetHostContentSettingsMap()->GetContentSetting(
494 requesting_frame_0, 494 requesting_frame_0,
495 requesting_frame_0, 495 requesting_frame_0,
496 CONTENT_SETTINGS_TYPE_GEOLOCATION, 496 CONTENT_SETTINGS_TYPE_GEOLOCATION,
497 std::string())); 497 std::string()));
498 498
499 EXPECT_EQ(CONTENT_SETTING_ALLOW, 499 EXPECT_EQ(CONTENT_SETTING_ALLOW,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 536
537 // Accept the first tab. 537 // Accept the first tab.
538 ConfirmInfoBarDelegate* infobar_0 = 538 ConfirmInfoBarDelegate* infobar_0 =
539 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 539 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
540 ASSERT_TRUE(infobar_0); 540 ASSERT_TRUE(infobar_0);
541 infobar_0->Accept(); 541 infobar_0->Accept();
542 CheckPermissionMessageSent(0, true); 542 CheckPermissionMessageSent(0, true);
543 infobar_service()->RemoveInfoBar(infobar_0); 543 infobar_service()->RemoveInfoBar(infobar_0);
544 EXPECT_EQ(2U, closed_delegate_tracker_.size()); 544 EXPECT_EQ(2U, closed_delegate_tracker_.size());
545 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 545 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
546 infobar_0->InfoBarClosed(); 546 delete infobar_0;
547 // Now the infobar for the tab with the same origin should have gone. 547 // Now the infobar for the tab with the same origin should have gone.
548 EXPECT_EQ(0U, infobar_service_for_tab(1)->GetInfoBarCount()); 548 EXPECT_EQ(0U, infobar_service_for_tab(1)->GetInfoBarCount());
549 CheckPermissionMessageSentForTab(1, 0, true); 549 CheckPermissionMessageSentForTab(1, 0, true);
550 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); 550 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
551 closed_delegate_tracker_.Clear(); 551 closed_delegate_tracker_.Clear();
552 // Destroy the infobar that has just been removed. 552 // Destroy the infobar that has just been removed.
553 removed_infobar->InfoBarClosed(); 553 delete removed_infobar;
554 554
555 // But the other tab should still have the info bar... 555 // But the other tab should still have the info bar...
556 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); 556 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount());
557 ConfirmInfoBarDelegate* infobar_1 = infobar_service_for_tab(0)-> 557 ConfirmInfoBarDelegate* infobar_1 = infobar_service_for_tab(0)->
558 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 558 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
559 infobar_1->Cancel(); 559 infobar_1->Cancel();
560 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); 560 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
561 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 561 EXPECT_EQ(1U, closed_delegate_tracker_.size());
562 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 562 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
563 infobar_1->InfoBarClosed(); 563 delete infobar_1;
564 } 564 }
565 565
566 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 566 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
567 GURL url_a("http://www.example.com/geolocation"); 567 GURL url_a("http://www.example.com/geolocation");
568 GURL url_b("http://www.example-2.com/geolocation"); 568 GURL url_b("http://www.example-2.com/geolocation");
569 NavigateAndCommit(url_a); 569 NavigateAndCommit(url_a);
570 AddNewTab(url_a); 570 AddNewTab(url_a);
571 571
572 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 572 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
573 RequestGeolocationPermission(RequestID(0), url_a); 573 RequestGeolocationPermission(RequestID(0), url_a);
(...skipping 10 matching lines...) Expand all
584 584
585 // Accept the second tab. 585 // Accept the second tab.
586 ConfirmInfoBarDelegate* infobar_0 = infobar_service_for_tab(0)-> 586 ConfirmInfoBarDelegate* infobar_0 = infobar_service_for_tab(0)->
587 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 587 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
588 ASSERT_TRUE(infobar_0); 588 ASSERT_TRUE(infobar_0);
589 infobar_0->Accept(); 589 infobar_0->Accept();
590 CheckPermissionMessageSentForTab(0, 0, true); 590 CheckPermissionMessageSentForTab(0, 0, true);
591 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); 591 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0);
592 EXPECT_EQ(2U, closed_delegate_tracker_.size()); 592 EXPECT_EQ(2U, closed_delegate_tracker_.size());
593 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 593 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
594 infobar_0->InfoBarClosed(); 594 delete infobar_0;
595 // Now the infobar for the tab with the same origin should have gone. 595 // Now the infobar for the tab with the same origin should have gone.
596 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); 596 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount());
597 CheckPermissionMessageSent(0, true); 597 CheckPermissionMessageSent(0, true);
598 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); 598 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
599 closed_delegate_tracker_.Clear(); 599 closed_delegate_tracker_.Clear();
600 // Destroy the infobar that has just been removed. 600 // Destroy the infobar that has just been removed.
601 removed_infobar->InfoBarClosed(); 601 delete removed_infobar;
602 602
603 // And we should have the queued infobar displayed now. 603 // And we should have the queued infobar displayed now.
604 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount()); 604 ASSERT_EQ(1U, infobar_service_for_tab(0)->GetInfoBarCount());
605 605
606 // Accept the second infobar. 606 // Accept the second infobar.
607 ConfirmInfoBarDelegate* infobar_1 = infobar_service_for_tab(0)-> 607 ConfirmInfoBarDelegate* infobar_1 = infobar_service_for_tab(0)->
608 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 608 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
609 ASSERT_TRUE(infobar_1); 609 ASSERT_TRUE(infobar_1);
610 infobar_1->Accept(); 610 infobar_1->Accept();
611 CheckPermissionMessageSentForTab(0, 1, true); 611 CheckPermissionMessageSentForTab(0, 1, true);
612 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); 612 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
613 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 613 EXPECT_EQ(1U, closed_delegate_tracker_.size());
614 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 614 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
615 infobar_1->InfoBarClosed(); 615 delete infobar_1;
616 } 616 }
617 617
618 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 618 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
619 GURL requesting_frame_0("http://www.example.com/geolocation"); 619 GURL requesting_frame_0("http://www.example.com/geolocation");
620 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 620 GURL requesting_frame_1("http://www.example-2.com/geolocation");
621 EXPECT_EQ( 621 EXPECT_EQ(
622 CONTENT_SETTING_ASK, 622 CONTENT_SETTING_ASK,
623 profile()->GetHostContentSettingsMap()->GetContentSetting( 623 profile()->GetHostContentSettingsMap()->GetContentSetting(
624 requesting_frame_0, 624 requesting_frame_0,
625 requesting_frame_0, 625 requesting_frame_0,
(...skipping 14 matching lines...) Expand all
640 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 640 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
641 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 641 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
642 // Ensure only one infobar is created. 642 // Ensure only one infobar is created.
643 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount()); 643 ASSERT_EQ(1U, infobar_service()->GetInfoBarCount());
644 ConfirmInfoBarDelegate* infobar_0 = 644 ConfirmInfoBarDelegate* infobar_0 =
645 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 645 infobar_service()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
646 ASSERT_TRUE(infobar_0); 646 ASSERT_TRUE(infobar_0);
647 647
648 // Delete the tab contents. 648 // Delete the tab contents.
649 DeleteContents(); 649 DeleteContents();
650 infobar_0->InfoBarClosed(); 650 delete infobar_0;
651 651
652 // During contents destruction, the infobar will have been closed, and the 652 // During contents destruction, the infobar will have been closed, and the
653 // pending request should have been cleared without an infobar being created. 653 // pending request should have been cleared without an infobar being created.
654 ASSERT_EQ(1U, closed_delegate_tracker_.size()); 654 ASSERT_EQ(1U, closed_delegate_tracker_.size());
655 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 655 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
656 } 656 }
657 657
658 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { 658 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
659 GURL requesting_frame_0("http://www.example.com/geolocation"); 659 GURL requesting_frame_0("http://www.example.com/geolocation");
660 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 660 GURL requesting_frame_1("http://www.example-2.com/geolocation");
(...skipping 12 matching lines...) Expand all
673 // Ensure the infobar wouldn't expire for a navigation to the committed entry. 673 // Ensure the infobar wouldn't expire for a navigation to the committed entry.
674 content::LoadCommittedDetails details; 674 content::LoadCommittedDetails details;
675 details.entry = web_contents()->GetController().GetLastCommittedEntry(); 675 details.entry = web_contents()->GetController().GetLastCommittedEntry();
676 EXPECT_FALSE(infobar_0->ShouldExpire(details)); 676 EXPECT_FALSE(infobar_0->ShouldExpire(details));
677 // Ensure the infobar will expire when we commit the pending navigation. 677 // Ensure the infobar will expire when we commit the pending navigation.
678 details.entry = web_contents()->GetController().GetActiveEntry(); 678 details.entry = web_contents()->GetController().GetActiveEntry();
679 EXPECT_TRUE(infobar_0->ShouldExpire(details)); 679 EXPECT_TRUE(infobar_0->ShouldExpire(details));
680 680
681 // Delete the tab contents. 681 // Delete the tab contents.
682 DeleteContents(); 682 DeleteContents();
683 infobar_0->InfoBarClosed(); 683 delete infobar_0;
684 } 684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698