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

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

Issue 341833004: [WebsiteSettings] Enable permission bubbles by default. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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/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 9ae3a305414dee56dd96abfacef9508e28c93f37..d9cdac3aea654df7fc0cde70c468dbf66bee82cd 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -21,6 +21,9 @@
#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/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
@@ -32,6 +35,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_renderer_host.h"
+#include "content/public/test/test_utils.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -47,6 +51,37 @@
using content::MockRenderProcessHost;
+class MockPermissionBubbleView : public PermissionBubbleView {
+ public:
+ MockPermissionBubbleView() : shown_(false) {}
+ 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 {
+LOG(INFO) << "Showing view... " << requests[0]->GetMessageText();
+ shown_ = true;
+ }
+
+ virtual bool CanAcceptRequestUpdate() OVERRIDE {
+ return true;
+ }
+
+ virtual void Hide() OVERRIDE {
+ shown_ = false;
+ }
+
+ virtual bool IsVisible() OVERRIDE {
+ return shown_;
+ }
+
+ private:
+ bool shown_;
+};
// ClosedInfoBarTracker -------------------------------------------------------
@@ -118,10 +153,12 @@ class GeolocationPermissionContextTests
void RequestGeolocationPermission(content::WebContents* web_contents,
const PermissionRequestID& id,
- const GURL& requesting_frame);
+ const GURL& requesting_frame,
+ bool user_gesture);
void RequestGeolocationPermission(content::WebContents* web_contents,
const PermissionRequestID& id,
const GURL& requesting_frame,
+ bool user_gesture,
base::Closure* cancel_callback);
void PermissionResponse(const PermissionRequestID& id,
bool allowed);
@@ -133,9 +170,15 @@ 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 BubbleManagerDocumentLoadCompleted();
scoped_refptr<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
@@ -165,17 +208,20 @@ PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab(
void GeolocationPermissionContextTests::RequestGeolocationPermission(
content::WebContents* web_contents,
const PermissionRequestID& id,
- const GURL& requesting_frame) {
- RequestGeolocationPermission(web_contents, id, requesting_frame, NULL);
+ const GURL& requesting_frame,
+ bool user_gesture) {
+ RequestGeolocationPermission(web_contents, id, requesting_frame,
+ user_gesture, NULL);
}
void GeolocationPermissionContextTests::RequestGeolocationPermission(
content::WebContents* web_contents,
const PermissionRequestID& id,
const GURL& requesting_frame,
+ bool user_gesture,
base::Closure* cancel_callback) {
geolocation_permission_context_->RequestGeolocationPermission(
- web_contents, id.bridge_id(), requesting_frame, false,
+ web_contents, id.bridge_id(), requesting_frame, user_gesture,
base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
base::Unretained(this), id),
cancel_callback);
@@ -238,13 +284,16 @@ void GeolocationPermissionContextTests::CheckTabContentsState(
TabSpecificContentSettings::FromWebContents(web_contents());
const ContentSettingsUsagesState::StateMap& state_map =
content_settings->geolocation_usages_state().state_map();
- EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
- EXPECT_EQ(0U, state_map.count(requesting_frame));
+ EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()))
+ << " for " << requesting_frame.spec();
+ EXPECT_EQ(0U, state_map.count(requesting_frame))
+ << " for " << requesting_frame.spec();
ContentSettingsUsagesState::StateMap::const_iterator settings =
state_map.find(requesting_frame.GetOrigin());
ASSERT_FALSE(settings == state_map.end())
<< "geolocation state not found " << requesting_frame;
- EXPECT_EQ(expected_content_setting, settings->second);
+ EXPECT_EQ(expected_content_setting, settings->second)
+ << " for " << requesting_frame.spec();
}
void GeolocationPermissionContextTests::SetUp() {
@@ -261,6 +310,10 @@ void GeolocationPermissionContextTests::SetUp() {
#endif
geolocation_permission_context_ =
GeolocationPermissionContextFactory::GetForProfile(profile());
+
+ PermissionBubbleManager::CreateForWebContents(web_contents());
+ PermissionBubbleManager::FromWebContents(web_contents())->SetView(
+ &bubble_view_);
}
void GeolocationPermissionContextTests::TearDown() {
@@ -268,13 +321,42 @@ void GeolocationPermissionContextTests::TearDown() {
ChromeRenderViewHostTestHarness::TearDown();
}
+base::string16 GeolocationPermissionContextTests::GetFirstRequestText(
+ PermissionBubbleManager* mgr) {
+ 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::BubbleManagerDocumentLoadCompleted() {
+ PermissionBubbleManager::FromWebContents(web_contents())->
+ DocumentOnLoadCompletedInMainFrame();
+}
+
// Tests ----------------------------------------------------------------------
-TEST_F(GeolocationPermissionContextTests, SinglePermission) {
+TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ 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 =
@@ -286,13 +368,29 @@ TEST_F(GeolocationPermissionContextTests, SinglePermission) {
EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
}
+TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ GURL requesting_frame("http://www.example.com/geolocation");
+ NavigateAndCommit(requesting_frame);
+ BubbleManagerDocumentLoadCompleted();
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+}
+
#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);
+ 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();
@@ -303,7 +401,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
Reload();
MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
}
@@ -312,7 +411,8 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
NavigateAndCommit(requesting_frame);
MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ 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();
@@ -327,12 +427,16 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
NavigateAndCommit(requesting_frame);
MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
}
#endif
-TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
+TEST_F(GeolocationPermissionContextTests, QueuedPermissionInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
GURL requesting_frame_0("http://www.example.com/geolocation");
GURL requesting_frame_1("http://www.example-2.com/geolocation");
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -348,9 +452,9 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
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, true);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, true);
// Ensure only one infobar is created.
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
@@ -398,14 +502,76 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
}
-TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
+TEST_F(GeolocationPermissionContextTests, QueuedPermissionBubble) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ GURL requesting_frame_0("http://www.example.com/geolocation");
+ GURL requesting_frame_1("http://www.example-2.com/geolocation");
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_0, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_1, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ NavigateAndCommit(requesting_frame_0);
+ BubbleManagerDocumentLoadCompleted();
+
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+
+ // Request permission for two frames.
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame_0, true);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(1), requesting_frame_1, true);
+ // Only main frame permission shown.
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ base::string16 text_0 = GetFirstRequestText(mgr);
+
+ // Accept the first frame.
+ AcceptBubble(mgr);
+ CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(0, true);
+
+ // Now we should have a new bubble for the second frame.
+ EXPECT_EQ(1, GetBubblesQueueSize(mgr));
+
+ base::string16 text_1 = GetFirstRequestText(mgr);
+ EXPECT_NE(text_0, text_1);
+
+ // Cancel (block) this frame.
+ DenyBubble(mgr);
+ CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
+ CheckPermissionMessageSent(1, false);
+
+ // Ensure the persisted permissions are ok.
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_0, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_1, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+}
+
+TEST_F(GeolocationPermissionContextTests, UrlFragmentIsIgnoredInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
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.
NavigateAndCommit(url_a);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true);
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
ConfirmInfoBarDelegate* infobar_delegate =
@@ -427,11 +593,45 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
}
-TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
+TEST_F(GeolocationPermissionContextTests, UrlFragmentIsIgnoredBubble) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ 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.
+ NavigateAndCommit(url_a);
+ BubbleManagerDocumentLoadCompleted();
+
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true);
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+
+ // Change the hash, we'll still be on the same page.
+ NavigateAndCommit(url_b);
+ BubbleManagerDocumentLoadCompleted();
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+
+ // Accept.
+ AcceptBubble(mgr);
+ CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
+ CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(0, true);
+}
+
+TEST_F(GeolocationPermissionContextTests, PermissionForFileSchemeInfobars) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
GURL requesting_frame("file://example/geolocation.html");
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);
EXPECT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
ConfirmInfoBarDelegate* infobar_delegate =
@@ -452,7 +652,40 @@ TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
std::string()));
}
-TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
+TEST_F(GeolocationPermissionContextTests, PermissionForFileSchemeBubbles) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ GURL requesting_frame("file://example/geolocation.html");
+ NavigateAndCommit(requesting_frame);
+ BubbleManagerDocumentLoadCompleted();
+
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+
+ // Accept the frame.
+ AcceptBubble(mgr);
+ CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(0, true);
+
+ // Make sure the setting is not stored.
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame,
+ requesting_frame,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string()));
+}
+
+TEST_F(GeolocationPermissionContextTests,
+ CancelGeolocationPermissionRequestInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
GURL requesting_frame_0("http://www.example.com/geolocation");
GURL requesting_frame_1("http://www.example-2.com/geolocation");
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -470,9 +703,9 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
// Request permission for two frames.
base::Closure cancel_callback;
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0, &cancel_callback);
+ web_contents(), RequestID(0), requesting_frame_0, true, &cancel_callback);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, true);
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
@@ -516,17 +749,80 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
}
+TEST_F(GeolocationPermissionContextTests,
+ CancelGeolocationPermissionRequestBubbles) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ GURL requesting_frame_0("http://www.example.com/geolocation");
+ GURL requesting_frame_1("http://www.example-2.com/geolocation");
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_0, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_1, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ NavigateAndCommit(requesting_frame_0);
+ BubbleManagerDocumentLoadCompleted();
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ // Request permission for two frames.
+ base::Closure cancel_callback;
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame_0, true, &cancel_callback);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(1), requesting_frame_1, true);
+
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_TRUE(mgr != NULL);
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+ base::string16 text_0 = GetFirstRequestText(mgr);
+ ASSERT_NE(base::string16(), text_0);
+
+ // Cancel the request. This will still leave the bubble showing, since
+ // the request is showing in the view. It will just be dummied.
+ cancel_callback.Run();
+ AcceptBubble(mgr); // Dummy accept
+ base::string16 text_1 = GetFirstRequestText(mgr);
+ EXPECT_NE(text_0, text_1);
+
+ // Allow this frame.
+ AcceptBubble(mgr);
+ CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(1, true);
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+
+ // Ensure the persisted permissions are ok.
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_0, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_1, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+}
+
TEST_F(GeolocationPermissionContextTests, InvalidURL) {
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);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
CheckPermissionMessageSent(0, false);
}
-TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
+TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabsInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
GURL url_a("http://www.example.com/geolocation");
GURL url_b("http://www.example-2.com/geolocation");
NavigateAndCommit(url_a);
@@ -534,13 +830,15 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
AddNewTab(url_a);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true);
ASSERT_EQ(1U, infobar_service()->infobar_count());
- RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b);
+ RequestGeolocationPermission(
+ extra_tabs_[0], RequestIDForTab(0, 0), url_b, true);
EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
- RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a);
+ RequestGeolocationPermission(
+ extra_tabs_[1], RequestIDForTab(1, 0), url_a, true);
ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
infobars::InfoBar* removed_infobar =
@@ -574,20 +872,25 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
}
-TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
+TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabsInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
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);
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true);
ASSERT_EQ(1U, infobar_service()->infobar_count());
- RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a);
+ RequestGeolocationPermission(
+ extra_tabs_[0], RequestIDForTab(0, 0), url_a, true);
EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
- RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b);
+ RequestGeolocationPermission(
+ extra_tabs_[0], RequestIDForTab(0, 1), url_b, true);
ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0);
@@ -623,7 +926,10 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
}
-TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
+TEST_F(GeolocationPermissionContextTests, TabDestroyedInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
GURL requesting_frame_0("http://www.example.com/geolocation");
GURL requesting_frame_1("http://www.example-2.com/geolocation");
EXPECT_EQ(CONTENT_SETTING_ASK,
@@ -640,9 +946,9 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
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, true);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, true);
// Ensure only one infobar is created.
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
@@ -656,7 +962,48 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
}
+TEST_F(GeolocationPermissionContextTests, TabDestroyedBubbles) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ GURL requesting_frame_0("http://www.example.com/geolocation");
+ GURL requesting_frame_1("http://www.example-2.com/geolocation");
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_0, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_frame_1, requesting_frame_0,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
+
+ NavigateAndCommit(requesting_frame_0);
+ BubbleManagerDocumentLoadCompleted();
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ ASSERT_TRUE(mgr != NULL);
+ ASSERT_EQ(0, GetBubblesQueueSize(mgr));
+
+ // Request permission for two frames.
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame_0, true);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(1), requesting_frame_1, true);
+ // Ensure only one bubble request is shown.
+ ASSERT_EQ(1, GetBubblesQueueSize(mgr));
+
+ // Delete the tab contents.
+ DeleteContents();
+
+ // During contents destruction, the bubble will have been closed, and the
+ // pending request should have been cleared without a bubble being shown.
+}
+
TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
GURL requesting_frame_0("http://www.example.com/geolocation");
GURL requesting_frame_1("http://www.example-2.com/geolocation");
NavigateAndCommit(requesting_frame_0);
@@ -667,7 +1014,7 @@ TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
web_contents()->GetController().GoBack();
// Request permission for the committed frame (not the pending one).
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_1);
+ web_contents(), RequestID(0), requesting_frame_1, true);
// Ensure the infobar is created.
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBarDelegate* infobar_delegate =
@@ -705,13 +1052,22 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
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();
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
+
+ if (!PermissionBubbleManager::Enabled()) {
+ 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();
+ } else {
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ AcceptBubble(mgr);
+ }
+
CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
@@ -722,7 +1078,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, true);
// Permission has been used three seconds later.
EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
@@ -731,7 +1088,11 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
13);
}
-TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
+TEST_F(GeolocationPermissionContextTests,
+ LastUsageAuditedMultipleFramesInfobar) {
+ if (PermissionBubbleManager::Enabled())
+ return;
+
base::SimpleTestClock* test_clock = new base::SimpleTestClock;
test_clock->SetNow(base::Time::UnixEpoch() +
base::TimeDelta::FromSeconds(10));
@@ -757,9 +1118,9 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, true);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, true);
// Ensure only one infobar is created.
ASSERT_EQ(1U, infobar_service()->infobar_count());
@@ -769,6 +1130,7 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
// Accept the first frame.
infobar_delegate_0->Accept();
+
CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
CheckPermissionMessageSent(0, true);
infobar_service()->RemoveInfoBar(infobar_0);
@@ -809,7 +1171,96 @@ 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, true);
+
+ // Verify that requesting permission in one frame doesn't update other where
+ // it is the embedder.
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 13);
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 11);
+}
+
+TEST_F(GeolocationPermissionContextTests,
+ LastUsageAuditedMultipleFramesBubble) {
+ if (!PermissionBubbleManager::Enabled())
+ return;
+
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock;
+ test_clock->SetNow(base::Time::UnixEpoch() +
+ base::TimeDelta::FromSeconds(10));
+
+ HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
+ map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
+
+ GURL requesting_frame_0("http://www.example.com/geolocation");
+ GURL requesting_frame_1("http://www.example-2.com/geolocation");
+
+ // The permission shouldn't have been used yet.
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 0);
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 0);
+
+ NavigateAndCommit(requesting_frame_0);
+ BubbleManagerDocumentLoadCompleted();
+ PermissionBubbleManager* mgr =
+ PermissionBubbleManager::FromWebContents(web_contents());
+ EXPECT_EQ(0, GetBubblesQueueSize(mgr));
+
+ // Request permission for two frames.
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame_0, true);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(1), requesting_frame_1, true);
+ EXPECT_EQ(1, GetBubblesQueueSize(mgr)); // 1 in request queue, 1 in pending
+ content::RunAllPendingInMessageLoop();
+
+ // Accept the first frame.
+ AcceptBubble(mgr);
+
+LOG(INFO) << "Checking state after accepting requesting_frame_0";
+ CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(0, true);
+
+ // Verify that accepting the first didn't accept because it's embedder
+ // in the other.
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 10);
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 0);
+
+ test_clock->Advance(base::TimeDelta::FromSeconds(1));
+ AcceptBubble(mgr);
+LOG(INFO) << "Checking state after accepting second bubble.";
+ CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(1, true);
+
+ // Verify that the times are different.
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 10);
+ EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
+ requesting_frame_0.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
+ 11);
+
+ test_clock->Advance(base::TimeDelta::FromSeconds(2));
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame_0, true);
// Verify that requesting permission in one frame doesn't update other where
// it is the embedder.

Powered by Google App Engine
This is Rietveld 408576698