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 abae2eb98546a2eb7f35d176f90d995a8087adcb..e73d6d9fbb2c54a8b9b0a9cb3b569ee5d1e3534d 100644 |
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc |
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc |
@@ -20,6 +20,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/content_settings/core/common/permission_request_id.h" |
@@ -49,6 +52,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 ------------------------------------------------------- |
@@ -120,8 +148,9 @@ class GeolocationPermissionContextTests |
void RequestGeolocationPermission(content::WebContents* web_contents, |
const PermissionRequestID& id, |
- const GURL& requesting_frame); |
- |
+ const GURL& requesting_frame, |
+ bool user_gesture, |
+ base::Closure* cancel_callback); |
void PermissionResponse(const PermissionRequestID& id, |
bool allowed); |
void CheckPermissionMessageSent(int bridge_id, bool allowed); |
@@ -132,10 +161,16 @@ 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(); |
// 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 |
@@ -165,9 +200,20 @@ 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, 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, user_gesture, |
base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
base::Unretained(this), id)); |
content::RunAllBlockingPoolTasksUntilIdle(); |
@@ -228,13 +274,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() { |
@@ -251,6 +300,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() { |
@@ -258,13 +311,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 = |
@@ -276,13 +358,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(); |
@@ -293,8 +391,11 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
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()); |
+ RequestGeolocationPermission( |
+ web_contents(), RequestID(0), requesting_frame, true); |
+ RequestGeolocationPermission( |
+ web_contents(), RequestID(0), requesting_frame, true); |
+ EXPECT_EQ(1U, infobar_service()->infobar_count()); |
} |
TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
@@ -302,7 +403,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(); |
@@ -317,12 +419,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, |
@@ -338,9 +444,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); |
@@ -388,14 +494,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 = |
@@ -417,11 +585,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 = |
@@ -442,7 +644,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, |
@@ -460,9 +695,9 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
// Request permission for two frames. |
RequestGeolocationPermission( |
- web_contents(), RequestID(0), requesting_frame_0); |
+ 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); |
@@ -507,17 +742,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); |
@@ -525,13 +823,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 = |
@@ -565,20 +865,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); |
@@ -614,7 +919,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, |
@@ -631,9 +939,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); |
@@ -647,6 +955,78 @@ 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); |
+ NavigateAndCommit(requesting_frame_1); |
+ EXPECT_EQ(0U, infobar_service()->infobar_count()); |
+ // Go back: navigate to a pending entry before requesting geolocation |
+ // permission. |
+ web_contents()->GetController().GoBack(); |
+ // Request permission for the committed frame (not the pending one). |
+ RequestGeolocationPermission( |
+ web_contents(), RequestID(0), requesting_frame_1, true); |
+ // Ensure the infobar is created. |
+ ASSERT_EQ(1U, infobar_service()->infobar_count()); |
+ infobars::InfoBarDelegate* infobar_delegate = |
+ infobar_service()->infobar_at(0)->delegate(); |
+ ASSERT_TRUE(infobar_delegate); |
+ // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
+ content::LoadCommittedDetails details; |
+ details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
+ EXPECT_FALSE(infobar_delegate->ShouldExpire( |
+ InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); |
+ // Ensure the infobar will expire when we commit the pending navigation. |
+ details.entry = web_contents()->GetController().GetActiveEntry(); |
+ EXPECT_TRUE(infobar_delegate->ShouldExpire( |
+ InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); |
+ |
+ // Delete the tab contents. |
+ DeleteContents(); |
+} |
+ |
TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { |
GURL requesting_frame("http://www.example.com/geolocation"); |
NavigateAndCommit(requesting_frame); |
@@ -665,7 +1045,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 = |
@@ -682,7 +1063,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(), |
@@ -717,9 +1099,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,7 +1151,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. |