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

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

Issue 787033004: Update geolocation permission tests for the permission bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Browser tests done Created 6 years 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/geolocation_permission_context_unittest.cc
diff --git a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
index 282a808928adc7823d816b2a8a4ac551b22c6589..8f6c704373a4770644df679de367d0b312bf7eb8 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -9,6 +9,7 @@
#include <utility>
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/containers/hash_tables.h"
#include "base/id_map.h"
#include "base/memory/scoped_vector.h"
@@ -19,6 +20,10 @@
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_request.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_view.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
@@ -48,6 +53,30 @@
using content::MockRenderProcessHost;
+class MockPermissionBubbleView : public PermissionBubbleView {
+ public:
+ MockPermissionBubbleView() {}
+ virtual ~MockPermissionBubbleView() {}
+
+ virtual void SetDelegate(Delegate* delegate) override {
+ }
+ virtual void Show(
+ const std::vector<PermissionBubbleRequest*>& requests,
+ const std::vector<bool>& accept_state,
+ bool customization_mode) override {
+ }
+
+ virtual bool CanAcceptRequestUpdate() override {
+ return true;
+ }
+
+ virtual void Hide() override {
+ }
+
+ virtual bool IsVisible() override {
+ return false;
+ }
+};
// ClosedInfoBarTracker -------------------------------------------------------
@@ -119,8 +148,8 @@ class GeolocationPermissionContextTests
void RequestGeolocationPermission(content::WebContents* web_contents,
const PermissionRequestID& id,
- const GURL& requesting_frame);
-
+ const GURL& requesting_frame,
+ bool user_gesture);
void PermissionResponse(const PermissionRequestID& id,
bool allowed);
void CheckPermissionMessageSent(int bridge_id, bool allowed);
@@ -131,10 +160,18 @@ class GeolocationPermissionContextTests
void AddNewTab(const GURL& url);
void CheckTabContentsState(const GURL& requesting_frame,
ContentSetting expected_content_setting);
+ base::string16 GetFirstRequestText(PermissionBubbleManager* mgr);
+ int GetBubblesQueueSize(PermissionBubbleManager* mgr);
+ void AcceptBubble(PermissionBubbleManager* mgr);
+ void DenyBubble(PermissionBubbleManager* mgr);
+ void CloseBubble(PermissionBubbleManager* mgr);
+ void BubbleManagerDocumentLoadCompleted();
+ void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents);
// owned by the browser context
GeolocationPermissionContext* geolocation_permission_context_;
ClosedInfoBarTracker closed_infobar_tracker_;
+ MockPermissionBubbleView bubble_view_;
ScopedVector<content::WebContents> extra_tabs_;
// A map between renderer child id and a pair represending the bridge id and
@@ -164,12 +201,13 @@ PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab(
void GeolocationPermissionContextTests::RequestGeolocationPermission(
content::WebContents* web_contents,
const PermissionRequestID& id,
- const GURL& requesting_frame) {
+ const GURL& requesting_frame,
+ bool user_gesture) {
geolocation_permission_context_->RequestPermission(
- web_contents, id, requesting_frame, false,
+ web_contents, id, requesting_frame, user_gesture,
base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
base::Unretained(this), id));
- content::RunAllBlockingPoolTasksUntilIdle();
+ content::RunAllBlockingPoolTasksUntilIdle();
}
void GeolocationPermissionContextTests::PermissionResponse(
@@ -216,6 +254,9 @@ void GeolocationPermissionContextTests::AddNewTab(const GURL& url) {
extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS);
#endif
InfoBarService::CreateForWebContents(new_tab);
+ PermissionBubbleManager::CreateForWebContents(new_tab);
+ PermissionBubbleManager::FromWebContents(new_tab)->SetView(
+ &bubble_view_);
extra_tabs_.push_back(new_tab);
}
@@ -250,6 +291,9 @@ void GeolocationPermissionContextTests::SetUp() {
#endif
geolocation_permission_context_ =
GeolocationPermissionContextFactory::GetForProfile(profile());
+ PermissionBubbleManager::CreateForWebContents(web_contents());
+ PermissionBubbleManager::FromWebContents(web_contents())->SetView(
+ &bubble_view_);
}
void GeolocationPermissionContextTests::TearDown() {
@@ -257,13 +301,82 @@ void GeolocationPermissionContextTests::TearDown() {
ChromeRenderViewHostTestHarness::TearDown();
}
+base::string16 GeolocationPermissionContextTests::GetFirstRequestText(
+ PermissionBubbleManager* mgr) {
Michael van Ouwerkerk 2014/12/17 17:20:19 s/mgr/manager/ - http://google-styleguide.googleco
felt 2014/12/18 22:09:10 Done.
+ return mgr->requests_.front()->GetMessageText();
+}
+
+int GeolocationPermissionContextTests::GetBubblesQueueSize(
+ PermissionBubbleManager* mgr) {
+ return static_cast<int>(mgr->requests_.size());
+}
+
+void GeolocationPermissionContextTests::AcceptBubble(
+ PermissionBubbleManager* mgr) {
+ mgr->Accept();
+}
+
+void GeolocationPermissionContextTests::DenyBubble(
+ PermissionBubbleManager* mgr) {
+ mgr->Deny();
+}
+
+void GeolocationPermissionContextTests::CloseBubble(
+ PermissionBubbleManager* mgr) {
+ mgr->Closing();
+}
+
+void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() {
+ PermissionBubbleManager::FromWebContents(web_contents())->
+ DocumentOnLoadCompletedInMainFrame();
+}
+
+void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
+ content::WebContents* web_contents) {
+ PermissionBubbleManager::FromWebContents(web_contents)->
+ DocumentOnLoadCompletedInMainFrame();
+}
+
+// Needed to parameterize the tests for both infobars & permission bubbles.
+class GeolocationPermissionContextParamTests :
+ public GeolocationPermissionContextTests,
+ public ::testing::WithParamInterface<bool> {
+ protected:
+ GeolocationPermissionContextParamTests() {}
+ ~GeolocationPermissionContextParamTests() override {}
+
+ bool BubbleEnabled() {
+ return GetParam();
+ }
+
+ void SetUp() override {
+ GeolocationPermissionContextTests::SetUp();
+#if !defined(OS_ANDROID)
+ if (BubbleEnabled()) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePermissionsBubbles);
+ EXPECT_TRUE(PermissionBubbleManager::Enabled());
+ } else {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kDisablePermissionsBubbles);
+ EXPECT_FALSE(PermissionBubbleManager::Enabled());
+ }
+#endif
+ }
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextParamTests);
+};
+
// Tests ----------------------------------------------------------------------
-TEST_F(GeolocationPermissionContextTests, SinglePermission) {
+TEST_P(GeolocationPermissionContextParamTests, SinglePermissionInfobar) {
+ if (BubbleEnabled()) return;
+
GURL requesting_frame("http://www.example.com/geolocation");
NavigateAndCommit(requesting_frame);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
ConfirmInfoBarDelegate* infobar_delegate =
@@ -275,53 +388,22 @@ TEST_F(GeolocationPermissionContextTests, SinglePermission) {
EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
}
-#if defined(OS_ANDROID)
-TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
- GURL requesting_frame("http://www.example.com/geolocation");
- NavigateAndCommit(requesting_frame);
- MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- EXPECT_EQ(1U, infobar_service()->infobar_count());
- ConfirmInfoBarDelegate* infobar_delegate_0 =
- infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_0);
- base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
- ConfirmInfoBarDelegate::BUTTON_OK);
-
- Reload();
- MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
-}
+TEST_P(GeolocationPermissionContextParamTests, SinglePermissionBubble) {
+ if (!BubbleEnabled()) return;
-TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
GURL requesting_frame("http://www.example.com/geolocation");
NavigateAndCommit(requesting_frame);
- MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- EXPECT_EQ(1U, infobar_service()->infobar_count());
- ConfirmInfoBarDelegate* infobar_delegate =
- infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate);
- infobar_delegate->Accept();
- CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
- CheckPermissionMessageSent(0, true);
-}
+ BubbleManagerDocumentLoadCompleted();
-TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
- GURL requesting_frame("http://www.example.com/geolocation");
- NavigateAndCommit(requesting_frame);
- MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
}
-#endif
-TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
+TEST_P(GeolocationPermissionContextParamTests, QueuedPermission) {
GURL requesting_frame_0("http://www.example.com/geolocation");
GURL requesting_frame_1("http://www.example-2.com/geolocation");
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -333,48 +415,84 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
requesting_frame_1, requesting_frame_0,
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ infobars::InfoBar* infobar_0;
+ infobars::InfoBar* infobar_1;
+ ConfirmInfoBarDelegate* infobar_delegate_0;
+ ConfirmInfoBarDelegate* infobar_delegate_1;
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ // Check that no permission requests have happened yet.
+ if (BubbleEnabled())
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+ else
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, BubbleEnabled());
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, BubbleEnabled());
+
// Ensure only one infobar is created.
- ASSERT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_0 =
- infobar_0->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_0);
- base::string16 text_0 = infobar_delegate_0->GetMessageText();
+ base::string16 text_0;
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ text_0 = GetFirstRequestText(mgr);
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobar_0 = infobar_service()->infobar_at(0);
+ infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_0);
+ text_0 = infobar_delegate_0->GetMessageText();
+ }
// Accept the first frame.
- infobar_delegate_0->Accept();
+ if (BubbleEnabled())
+ AcceptBubble(mgr);
+ else
+ infobar_delegate_0->Accept();
CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
+ if (!BubbleEnabled()) {
+ infobar_service()->RemoveInfoBar(infobar_0);
+ EXPECT_EQ(1U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
+ closed_infobar_tracker_.Clear();
+ }
- infobar_service()->RemoveInfoBar(infobar_0);
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
- closed_infobar_tracker_.Clear();
- // Now we should have a new infobar for the second frame.
- ASSERT_EQ(1U, infobar_service()->infobar_count());
+ // Now we should have a new request for the second frame.
+ base::string16 text_1;
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ text_1 = GetFirstRequestText(mgr);
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobar_1 = infobar_service()->infobar_at(0);
+ infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_1);
+ text_1 = infobar_delegate_1->GetMessageText();
+ }
- infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_1 =
- infobar_1->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_1);
- base::string16 text_1 = infobar_delegate_1->GetMessageText();
+ // Check that the messages differ.
EXPECT_NE(text_0, text_1);
// Cancel (block) this frame.
- infobar_delegate_1->Cancel();
+ if (BubbleEnabled())
+ DenyBubble(mgr);
+ else
+ infobar_delegate_1->Cancel();
CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
CheckPermissionMessageSent(1, false);
- infobar_service()->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ if (!BubbleEnabled()) {
+ infobar_service()->RemoveInfoBar(infobar_1);
+ EXPECT_EQ(1U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ }
+
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
profile()->GetHostContentSettingsMap()->GetContentSetting(
@@ -387,50 +505,92 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
}
-TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
+TEST_P(GeolocationPermissionContextParamTests, HashIsIgnored) {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ infobars::InfoBar* infobar;
+ ConfirmInfoBarDelegate* infobar_delegate;
+
GURL url_a("http://www.example.com/geolocation#a");
GURL url_b("http://www.example.com/geolocation#b");
- // Navigate to the first url and check permission is requested.
+ // Navigate to the first url.
NavigateAndCommit(url_a);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
- ASSERT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate =
- infobar->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate);
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ // Check permission is requested.
+ if (BubbleEnabled()) {
Michael van Ouwerkerk 2014/12/17 17:20:19 These kinds of branches make the code harder to re
felt 2014/12/18 22:09:09 OK, I added a few helper methods. I think the code
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true);
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ } else {
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a, false);
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobar = infobar_service()->infobar_at(0);
+ infobar_delegate =
+ infobar->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate);
+ }
// Change the hash, we'll still be on the same page.
NavigateAndCommit(url_b);
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
// Accept.
- infobar_delegate->Accept();
+ if (BubbleEnabled())
+ AcceptBubble(mgr);
+ else
+ infobar_delegate->Accept();
CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
// Cleanup.
- infobar_service()->RemoveInfoBar(infobar);
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
+ if (!BubbleEnabled()) {
+ infobar_service()->RemoveInfoBar(infobar);
+ EXPECT_EQ(1U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
+ }
}
-TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
+TEST_P(GeolocationPermissionContextParamTests, PermissionForFileScheme) {
+ // TODO(felt): The bubble is rejecting file:// permission requests.
+ // Fix and enable this test.
+ if (BubbleEnabled()) return;
+
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ infobars::InfoBar* infobar;
+ ConfirmInfoBarDelegate* infobar_delegate;
+
GURL requesting_frame("file://example/geolocation.html");
NavigateAndCommit(requesting_frame);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- EXPECT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate =
- infobar->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate);
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ // Check permission is requested.
+ if (BubbleEnabled()) {
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ } else {
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, false);
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobar = infobar_service()->infobar_at(0);
+ infobar_delegate = infobar->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate);
+ }
+
// Accept the frame.
- infobar_delegate->Accept();
+ if (BubbleEnabled())
+ AcceptBubble(mgr);
+ else
+ infobar_delegate->Accept();
CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
- infobar_service()->RemoveInfoBar(infobar);
// Make sure the setting is not stored.
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -441,179 +601,286 @@ TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
std::string()));
}
-TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
- GURL requesting_frame_0("http://www.example.com/geolocation");
- GURL requesting_frame_1("http://www.example-2.com/geolocation");
+TEST_P(GeolocationPermissionContextParamTests,
+ CancelGeolocationPermissionRequest) {
+ GURL frame_0("http://www.example.com/geolocation");
+ GURL frame_1("http://www.example-2.com/geolocation");
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
EXPECT_EQ(CONTENT_SETTING_ASK,
profile()->GetHostContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0,
+ frame_0, frame_0,
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
EXPECT_EQ(CONTENT_SETTING_ASK,
profile()->GetHostContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0,
+ frame_1, frame_0,
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
- NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ NavigateAndCommit(frame_0);
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ if (BubbleEnabled())
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+ else
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), frame_0, BubbleEnabled());
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
- ASSERT_EQ(1U, infobar_service()->infobar_count());
-
- infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_0 =
- infobar_0->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_0);
- base::string16 text_0 = infobar_delegate_0->GetMessageText();
-
- // Simulate the frame going away, ensure the infobar for this frame
- // is removed and the next pending infobar is created.
- geolocation_permission_context_->CancelPermissionRequest(web_contents(),
- RequestID(0));
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
- closed_infobar_tracker_.Clear();
- ASSERT_EQ(1U, infobar_service()->infobar_count());
+ web_contents(), RequestID(1), frame_1, BubbleEnabled());
+ if (BubbleEnabled())
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ else
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+
+ // Get the first permission request text.
+ base::string16 text_0;
+ infobars::InfoBar* infobar_0;
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ text_0 = GetFirstRequestText(mgr);
+ } else {
+ infobar_0 = infobar_service()->infobar_at(0);
+ ConfirmInfoBarDelegate* infobar_delegate_0 =
+ infobar_0->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_0);
+ text_0 = infobar_delegate_0->GetMessageText();
+ }
+ ASSERT_NE(base::string16(), text_0);
+
+ // Simulate frame 0 going away; the request should be removed.
+ if (BubbleEnabled()) {
+ CloseBubble(mgr);
+ } else {
+ geolocation_permission_context_->CancelPermissionRequest(web_contents(),
+ RequestID(0));
+ EXPECT_EQ(1U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
+ closed_infobar_tracker_.Clear();
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ }
- infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_1 =
- infobar_1->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_1);
- base::string16 text_1 = infobar_delegate_1->GetMessageText();
+ // Check that the next pending request is created correctly.
+ base::string16 text_1;
+ infobars::InfoBar* infobar_1;
+ ConfirmInfoBarDelegate* infobar_delegate_1;
+ if (BubbleEnabled()) {
+ base::string16 text_1 = GetFirstRequestText(mgr);
+ } else {
+ infobar_1 = infobar_service()->infobar_at(0);
+ infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_1);
+ text_1 = infobar_delegate_1->GetMessageText();
+ }
EXPECT_NE(text_0, text_1);
- // Allow this frame.
- infobar_delegate_1->Accept();
- CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
+ // Allow this frame and check that it worked.
+ if (BubbleEnabled()) {
+ AcceptBubble(mgr);
+ } else {
+ infobar_delegate_1->Accept();
+ infobar_service()->RemoveInfoBar(infobar_1);
+ EXPECT_EQ(1U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ }
+ CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(1, true);
- infobar_service()->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+
// Ensure the persisted permissions are ok.
EXPECT_EQ(CONTENT_SETTING_ASK,
profile()->GetHostContentSettingsMap()->GetContentSetting(
- requesting_frame_0, requesting_frame_0,
+ frame_0, frame_0,
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
profile()->GetHostContentSettingsMap()->GetContentSetting(
- requesting_frame_1, requesting_frame_0,
+ frame_1, frame_0,
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
}
-TEST_F(GeolocationPermissionContextTests, InvalidURL) {
+TEST_P(GeolocationPermissionContextParamTests, InvalidURL) {
+ // Navigate to the first url.
GURL invalid_embedder("about:blank");
GURL requesting_frame;
NavigateAndCommit(invalid_embedder);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ // Nothing should be displayed.
+ if (BubbleEnabled()) {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+ } else {
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, false);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ }
CheckPermissionMessageSent(0, false);
}
-TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
+TEST_P(GeolocationPermissionContextParamTests, SameOriginMultipleTabs) {
GURL url_a("http://www.example.com/geolocation");
GURL url_b("http://www.example-2.com/geolocation");
- NavigateAndCommit(url_a);
- AddNewTab(url_b);
- AddNewTab(url_a);
-
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
- ASSERT_EQ(1U, infobar_service()->infobar_count());
-
- RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b);
- EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
+ NavigateAndCommit(url_a); // Tab A0
+ AddNewTab(url_b); // Tab B (extra_tabs_[0])
+ AddNewTab(url_a); // Tab A1 (extra_tabs_[1])
+ if (BubbleEnabled()) {
+ BubbleManagerDocumentLoadCompleted();
+ BubbleManagerDocumentLoadCompleted(extra_tabs_[0]);
+ BubbleManagerDocumentLoadCompleted(extra_tabs_[1]);
+ }
+ PermissionBubbleManager* mgr_a0 =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ PermissionBubbleManager* mgr_b =
+ PermissionBubbleManager::FromWebContents(extra_tabs_[0]);
+ PermissionBubbleManager* mgr_a1 =
+ PermissionBubbleManager::FromWebContents(extra_tabs_[1]);
+
+ // Request permission in all three tabs.
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), url_a, BubbleEnabled());
+ RequestGeolocationPermission(
+ extra_tabs_[0], RequestIDForTab(0, 0), url_b, BubbleEnabled());
+ RequestGeolocationPermission(
+ extra_tabs_[1], RequestIDForTab(1, 0), url_a, BubbleEnabled());
+ infobars::InfoBar* infobar_a1;
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_a0));
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_b));
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1));
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
+ ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
+ }
- RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a);
- ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
+ // Accept the permission in tab A0.
+ if (BubbleEnabled()) {
+ AcceptBubble(mgr_a0);
+ } else {
+ infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0);
+ infobar_a1 = infobar_service_for_tab(1)->infobar_at(0); // Save for later.
+ ConfirmInfoBarDelegate* infobar_delegate_a0 =
+ infobar_a0->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_a0);
+ infobar_delegate_a0->Accept();
+ infobar_service()->RemoveInfoBar(infobar_a0);
+ EXPECT_EQ(2U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0));
+ }
+ CheckPermissionMessageSent(0, true);
- infobars::InfoBar* removed_infobar =
- infobar_service_for_tab(1)->infobar_at(0);
+ // Because they're the same origin, this will cause tab A1's infobar to
+ // disappear. It does not cause the bubble to disappear: crbug.com/443013.
+ // TODO(felt): Update this test when the bubble's behavior is changed.
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1));
+ } else {
+ CheckPermissionMessageSentForTab(1, 0, true);
+ ASSERT_EQ(0U, infobar_service_for_tab(1)->infobar_count());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1));
+ closed_infobar_tracker_.Clear();
+ }
- // Accept the first tab.
- infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_0 =
- infobar_0->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_0);
- infobar_delegate_0->Accept();
- CheckPermissionMessageSent(0, true);
- infobar_service()->RemoveInfoBar(infobar_0);
- EXPECT_EQ(2U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
- // Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count());
- CheckPermissionMessageSentForTab(1, 0, true);
- EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar));
- closed_infobar_tracker_.Clear();
-
- // But the other tab should still have the info bar...
- ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
- infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_1 =
- infobar_1->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_1);
- infobar_delegate_1->Cancel();
- infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
+ // Either way, tab B should still have a pending permission request.
+ if (BubbleEnabled())
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_b));
+ else
+ ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
}
-TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
+TEST_P(GeolocationPermissionContextParamTests, QueuedOriginMultipleTabs) {
GURL url_a("http://www.example.com/geolocation");
GURL url_b("http://www.example-2.com/geolocation");
- NavigateAndCommit(url_a);
- AddNewTab(url_a);
-
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
- ASSERT_EQ(1U, infobar_service()->infobar_count());
-
- RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a);
- EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
+ NavigateAndCommit(url_a); // Tab A0.
+ AddNewTab(url_a); // Tab A1.
+ if (BubbleEnabled()) {
+ BubbleManagerDocumentLoadCompleted();
+ BubbleManagerDocumentLoadCompleted(extra_tabs_[0]);
+ }
+ PermissionBubbleManager* mgr_a0 =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ PermissionBubbleManager* mgr_a1 =
+ PermissionBubbleManager::FromWebContents(extra_tabs_[0]);
+ infobars::InfoBar* infobar_a0;
+
+ // Request permission in both tabs; the extra tab will have two permission
+ // requests from two origins.
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), url_a, BubbleEnabled());
+ RequestGeolocationPermission(
+ extra_tabs_[0], RequestIDForTab(0, 0), url_a, BubbleEnabled());
+ RequestGeolocationPermission(
+ extra_tabs_[0], RequestIDForTab(0, 1), url_b, BubbleEnabled());
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_a0));
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1));
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
+ infobar_a0 = infobar_service()->infobar_at(0); // Save for later.
+ }
- RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b);
- ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
+ // Accept the first request in tab A1.
+ if (BubbleEnabled()) {
+ AcceptBubble(mgr_a1);
+ } else {
+ infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0);
+ ConfirmInfoBarDelegate* infobar_delegate_a1 =
+ infobar_a1->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_a1);
+ infobar_delegate_a1->Accept();
+ infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1);
+ EXPECT_EQ(2U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1));
+ }
+ CheckPermissionMessageSentForTab(0, 0, true);
- infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0);
+ // Because they're the same origin, this will cause tab A0's infobar to
+ // disappear. It does not cause the bubble to disappear: crbug.com/443013.
+ // TODO(felt): Update this test when the bubble's behavior is changed.
+ if (BubbleEnabled()) {
+ EXPECT_EQ(1, GetBubblesQueueSize(mgr_a0));
+ } else {
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ CheckPermissionMessageSent(0, true);
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0));
+ closed_infobar_tracker_.Clear();
+ }
- // Accept the second tab.
- infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_0 =
- infobar_0->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_0);
- infobar_delegate_0->Accept();
- CheckPermissionMessageSentForTab(0, 0, true);
- infobar_service_for_tab(0)->RemoveInfoBar(infobar_0);
- EXPECT_EQ(2U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
- // Now the infobar for the tab with the same origin should have gone.
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- CheckPermissionMessageSent(0, true);
- EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar));
- closed_infobar_tracker_.Clear();
-
- // And we should have the queued infobar displayed now.
- ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
-
- // Accept the second infobar.
- infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_1 =
- infobar_1->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate_1);
- infobar_delegate_1->Accept();
+ // The second request should now be visible in tab A1.
+ if (BubbleEnabled())
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1));
+ else
+ ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
+
+ // Accept the second request and check that it's gone.
+ if (BubbleEnabled()) {
+ AcceptBubble(mgr_a1);
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr_a1));
+ } else {
+ infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
+ ConfirmInfoBarDelegate* infobar_delegate_1 =
+ infobar_1->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_1);
+ infobar_delegate_1->Accept();
+ infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
+ EXPECT_EQ(1U, closed_infobar_tracker_.size());
+ EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
+ }
CheckPermissionMessageSentForTab(0, 1, true);
- infobar_service_for_tab(0)->RemoveInfoBar(infobar_1);
- EXPECT_EQ(1U, closed_infobar_tracker_.size());
- EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
}
-TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
+TEST_P(GeolocationPermissionContextParamTests, TabDestroyed) {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
GURL requesting_frame_0("http://www.example.com/geolocation");
GURL requesting_frame_1("http://www.example-2.com/geolocation");
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -627,28 +894,43 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ if (BubbleEnabled())
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+ else
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, false);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
- // Ensure only one infobar is created.
- ASSERT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
-
- // Delete the tab contents.
- DeleteContents();
-
- // During contents destruction, the infobar will have been closed, and the
- // pending request should have been cleared without an infobar being created.
- ASSERT_EQ(1U, closed_infobar_tracker_.size());
- ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
+ web_contents(), RequestID(1), requesting_frame_1, false);
+
+ // Ensure only one infobar/bubble is created.
+ if (BubbleEnabled())
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ else
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+
+ // Delete the tab contents and check that the infobar/bubble was removed.
+ if (BubbleEnabled()) {
+ DeleteContents();
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+ } else {
+ infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
+ DeleteContents();
+ ASSERT_EQ(1U, closed_infobar_tracker_.size());
+ ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
+ }
}
-TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
+TEST_P(GeolocationPermissionContextParamTests, LastUsageAudited) {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
GURL requesting_frame("http://www.example.com/geolocation");
NavigateAndCommit(requesting_frame);
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
base::SimpleTestClock* test_clock = new base::SimpleTestClock;
test_clock->SetNow(base::Time::UnixEpoch() +
@@ -663,14 +945,23 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
0);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
- ASSERT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate =
- infobar->delegate()->AsConfirmInfoBarDelegate();
- ASSERT_TRUE(infobar_delegate);
- infobar_delegate->Accept();
+ if (BubbleEnabled())
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+ else
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, false);
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ AcceptBubble(mgr);
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
+ ConfirmInfoBarDelegate* infobar_delegate =
+ infobar->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate);
+ infobar_delegate->Accept();
+ }
CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
@@ -681,7 +972,8 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
10);
test_clock->Advance(base::TimeDelta::FromSeconds(3));
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, false);
// Permission has been used three seconds later.
EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
@@ -690,7 +982,9 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
13);
}
-TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
+TEST_P(GeolocationPermissionContextParamTests, LastUsageAuditedMultipleFrames) {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
base::SimpleTestClock* test_clock = new base::SimpleTestClock;
test_clock->SetNow(base::Time::UnixEpoch() +
base::TimeDelta::FromSeconds(10));
@@ -712,25 +1006,39 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
0);
NavigateAndCommit(requesting_frame_0);
- EXPECT_EQ(0U, infobar_service()->infobar_count());
+ if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
+
+ if (BubbleEnabled())
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+ else
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, false);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
-
- // Ensure only one infobar is created.
- ASSERT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_0 =
- infobar_0->delegate()->AsConfirmInfoBarDelegate();
+ web_contents(), RequestID(1), requesting_frame_1, false);
+
+ // Ensure only one request is created.
+ infobars::InfoBar* infobar_0;
+ ConfirmInfoBarDelegate* infobar_delegate_0;
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobar_0 = infobar_service()->infobar_at(0);
+ infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate();
+ }
// Accept the first frame.
- infobar_delegate_0->Accept();
+ if (BubbleEnabled()) {
+ AcceptBubble(mgr);
+ } else {
+ infobar_delegate_0->Accept();
+ infobar_service()->RemoveInfoBar(infobar_0);
+ }
CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
- infobar_service()->RemoveInfoBar(infobar_0);
// Verify that accepting the first didn't accept because it's embedder
// in the other.
@@ -743,18 +1051,27 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
0);
- ASSERT_EQ(1U, infobar_service()->infobar_count());
- infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
- ConfirmInfoBarDelegate* infobar_delegate_1 =
- infobar_1->delegate()->AsConfirmInfoBarDelegate();
+ infobars::InfoBar* infobar_1;
+ ConfirmInfoBarDelegate* infobar_delegate_1;
+ if (BubbleEnabled()) {
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ } else {
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobar_1 = infobar_service()->infobar_at(0);
+ infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate();
+ }
test_clock->Advance(base::TimeDelta::FromSeconds(1));
// Allow the second frame.
- infobar_delegate_1->Accept();
+ if (BubbleEnabled()) {
+ AcceptBubble(mgr);
+ } else {
+ infobar_delegate_1->Accept();
+ infobar_service()->RemoveInfoBar(infobar_1);
+ }
CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(1, true);
- infobar_service()->RemoveInfoBar(infobar_1);
// Verify that the times are different.
EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
@@ -768,7 +1085,7 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
test_clock->Advance(base::TimeDelta::FromSeconds(2));
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, false);
// Verify that requesting permission in one frame doesn't update other where
// it is the embedder.
@@ -781,3 +1098,63 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
11);
}
+
+INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles,
+ GeolocationPermissionContextParamTests,
+ ::testing::Values(false, true));
+
+// Infobar-only tests ----------------------------------------------------------
+// Android doesn't support permission bubbles.
+
+#if defined(OS_ANDROID)
+TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
+ EXPECT_FALSE(PermissionBubbleManager::Enabled());
+ GURL requesting_frame("http://www.example.com/geolocation");
+ NavigateAndCommit(requesting_frame);
+ MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ EXPECT_EQ(1U, infobar_service()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_delegate_0 =
+ infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate_0);
+ base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
+ ConfirmInfoBarDelegate::BUTTON_OK);
+
+ Reload();
+ MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+}
+
+TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
+ EXPECT_FALSE(PermissionBubbleManager::Enabled());
+ GURL requesting_frame("http://www.example.com/geolocation");
+ NavigateAndCommit(requesting_frame);
+ MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ EXPECT_EQ(1U, infobar_service()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_delegate =
+ infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate);
+ infobar_delegate->Accept();
+ CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(0, true);
+}
+
+TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
+ EXPECT_FALSE(PermissionBubbleManager::Enabled());
+ GURL requesting_frame("http://www.example.com/geolocation");
+ NavigateAndCommit(requesting_frame);
+ MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698