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

Unified Diff: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc

Issue 7810002: Move infobar handling to a tab helper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
index 3109341892f0a64dd122da90081325ba7c6655df..f84da774dc415d26728d80d18ab4e57eec0f123a 100644
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
+#include "chrome/browser/infobars/infobar_tab_helper.h"
#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
#include "chrome/browser/tab_contents/infobar.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
@@ -211,14 +212,14 @@ void GeolocationPermissionContextTests::TearDown() {
TEST_F(GeolocationPermissionContextTests, SinglePermission) {
GURL requesting_frame("http://www.example.com/geolocation");
NavigateAndCommit(requesting_frame);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
Peter Kasting 2011/08/31 18:47:32 Nit: Can you factor out infobar_tab_helper() temps
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
infobar_0->Cancel();
- contents_wrapper()->RemoveInfoBar(infobar_0);
+ contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_0);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
infobar_0->InfoBarClosed();
@@ -242,16 +243,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
// Request permission for two frames.
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame_0);
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
// Ensure only one infobar is created.
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
string16 text_0 = infobar_0->GetMessageText();
@@ -260,16 +261,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(bridge_id(), true);
- contents_wrapper()->RemoveInfoBar(infobar_0);
+ contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_0);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
closed_delegate_tracker_.Clear();
infobar_0->InfoBarClosed();
// Now we should have a new infobar for the second frame.
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_1 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* infobar_1 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_1);
string16 text_1 = infobar_1->GetMessageText();
EXPECT_NE(text_0, text_1);
@@ -278,11 +279,11 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
infobar_1->Cancel();
CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
CheckPermissionMessageSent(bridge_id() + 1, false);
- contents_wrapper()->RemoveInfoBar(infobar_1);
+ contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
infobar_1->InfoBarClosed();
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
profile()->GetHostContentSettingsMap()->GetContentSetting(
@@ -318,16 +319,16 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
// Request permission for two frames.
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame_0);
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
string16 text_0 = infobar_0->GetMessageText();
@@ -339,10 +340,10 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
closed_delegate_tracker_.Clear();
infobar_0->InfoBarClosed();
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_1 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* infobar_1 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_1);
string16 text_1 = infobar_1->GetMessageText();
EXPECT_NE(text_0, text_1);
@@ -351,11 +352,11 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
infobar_1->Accept();
CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(bridge_id() + 1, true);
- contents_wrapper()->RemoveInfoBar(infobar_1);
+ contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
infobar_1->InfoBarClosed();
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ASK,
profile()->GetHostContentSettingsMap()->GetContentSetting(
@@ -376,10 +377,10 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) {
GURL invalid_embedder;
GURL requesting_frame("about:blank");
NavigateAndCommit(invalid_embedder);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
CheckPermissionMessageSent(bridge_id(), false);
}
@@ -390,34 +391,34 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
AddNewTab(url_b);
AddNewTab(url_a);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), url_a);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b);
- EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a);
- ASSERT_EQ(1U, extra_tabs_[1]->infobar_count());
+ ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->infobar_count());
- ConfirmInfoBarDelegate* removed_infobar =
- extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]->
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
// Accept the first tab.
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
infobar_0->Accept();
CheckPermissionMessageSent(bridge_id(), true);
- contents_wrapper()->RemoveInfoBar(infobar_0);
+ contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_0);
EXPECT_EQ(2U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
infobar_0->InfoBarClosed();
// Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0U, extra_tabs_[1]->infobar_count());
+ EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count());
CheckPermissionMessageSentForTab(1, bridge_id(), true);
EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
closed_delegate_tracker_.Clear();
@@ -425,11 +426,11 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
removed_infobar->InfoBarClosed();
// But the other tab should still have the info bar...
- ASSERT_EQ(1U, extra_tabs_[0]->infobar_count());
- ConfirmInfoBarDelegate* infobar_1 =
- extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
infobar_1->Cancel();
- extra_tabs_[0]->RemoveInfoBar(infobar_1);
+ extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
infobar_1->InfoBarClosed();
@@ -443,34 +444,34 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
NavigateAndCommit(url_a);
AddNewTab(url_a);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), url_a);
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a);
- EXPECT_EQ(1U, extra_tabs_[0]->infobar_count());
+ EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
geolocation_permission_context_->RequestGeolocationPermission(
process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b);
- ASSERT_EQ(1U, extra_tabs_[0]->infobar_count());
+ ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
- ConfirmInfoBarDelegate* removed_infobar =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* removed_infobar = contents_wrapper()->
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
// Accept the second tab.
- ConfirmInfoBarDelegate* infobar_0 =
- extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
infobar_0->Accept();
CheckPermissionMessageSentForTab(0, bridge_id(), true);
- extra_tabs_[0]->RemoveInfoBar(infobar_0);
+ extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0);
EXPECT_EQ(2U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
infobar_0->InfoBarClosed();
// Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
CheckPermissionMessageSent(bridge_id(), true);
EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
closed_delegate_tracker_.Clear();
@@ -478,15 +479,15 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
removed_infobar->InfoBarClosed();
// And we should have the queued infobar displayed now.
- ASSERT_EQ(1U, extra_tabs_[0]->infobar_count());
+ ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
// Accept the second infobar.
- ConfirmInfoBarDelegate* infobar_1 =
- extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_1);
infobar_1->Accept();
CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
- extra_tabs_[0]->RemoveInfoBar(infobar_1);
+ extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
EXPECT_EQ(1U, closed_delegate_tracker_.size());
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
infobar_1->InfoBarClosed();
@@ -514,16 +515,16 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
std::string()));
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, contents_wrapper()->infobar_count());
+ EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count());
// Request permission for two frames.
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id(), requesting_frame_0);
geolocation_permission_context_->RequestGeolocationPermission(
process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
// Ensure only one infobar is created.
- ASSERT_EQ(1U, contents_wrapper()->infobar_count());
- ConfirmInfoBarDelegate* infobar_0 =
- contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
+ ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()->
+ GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(infobar_0);
// Delete the tab contents.

Powered by Google App Engine
This is Rietveld 408576698