| 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 b243ce6edda42370a22228032080bb10fc48a818..38bd046d75c1cb23ee6c860b68e8d25f34c4a878 100644
|
| --- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
|
| +++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
|
| @@ -22,6 +22,9 @@
|
| #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
|
| #include "chrome/browser/infobars/infobar_service.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"
|
| @@ -45,6 +48,31 @@
|
|
|
| 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 -------------------------------------------------------
|
|
|
| @@ -116,10 +144,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);
|
| @@ -131,9 +161,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
|
| @@ -163,17 +199,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);
|
| @@ -234,13 +273,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() {
|
| @@ -255,6 +297,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() {
|
| @@ -262,13 +308,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 =
|
| @@ -280,13 +355,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();
|
| @@ -297,7 +388,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(1U, infobar_service()->infobar_count());
|
| ConfirmInfoBarDelegate* infobar_delegate_1 =
|
| infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
|
| @@ -309,7 +401,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
|
| Reload();
|
| MockGoogleLocationSettingsHelper::SetLocationStatus(false, 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());
|
| }
|
|
|
| @@ -318,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();
|
| @@ -333,7 +427,8 @@ 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(1U, infobar_service()->infobar_count());
|
| ConfirmInfoBarDelegate* infobar_delegate =
|
| infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
|
| @@ -344,7 +439,10 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
|
| }
|
| #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,
|
| @@ -360,9 +458,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);
|
| @@ -410,14 +508,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 =
|
| @@ -439,11 +599,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 =
|
| @@ -464,7 +658,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,
|
| @@ -482,9 +709,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);
|
| @@ -528,17 +755,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);
|
| @@ -546,13 +836,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 =
|
| @@ -586,20 +878,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);
|
| @@ -635,7 +932,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,
|
| @@ -652,9 +952,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);
|
| @@ -668,7 +968,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);
|
| @@ -679,7 +1020,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 =
|
| @@ -717,7 +1058,8 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
|
| 0);
|
|
|
| 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 =
|
| @@ -734,7 +1076,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(),
|
| @@ -769,9 +1112,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());
|
| @@ -821,7 +1164,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, true);
|
|
|
| // Verify that requesting permission in one frame doesn't update other where
|
| // it is the embedder.
|
|
|