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

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

Issue 2338173002: Improve permission persistence tests. (Closed)
Patch Set: Address comments Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/geolocation/geolocation_browsertest.cc
diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc
index e0212fdc6850ab3a20d3111d34e9dcde53f7ce0e..74583ce68862e07c0cca5ed509a146034b610a12 100644
--- a/chrome/browser/geolocation/geolocation_browsertest.cc
+++ b/chrome/browser/geolocation/geolocation_browsertest.cc
@@ -254,6 +254,9 @@ class GeolocationBrowserTest : public InProcessBrowserTest {
// Convenience method to look up the number of queued permission requests.
int GetRequestQueueSize(PermissionRequestManager* manager);
+ // Toggle whether the prompt decision should be persisted.
+ void TogglePersist(bool persist);
+
private:
// Calls watchPosition() in JavaScript and accepts or denies the resulting
// permission request. Returns the JavaScript response.
@@ -429,6 +432,13 @@ int GeolocationBrowserTest::GetRequestQueueSize(
return static_cast<int>(manager->requests_.size());
}
+void GeolocationBrowserTest::TogglePersist(bool persist) {
+ content::WebContents* web_contents =
+ current_browser()->tab_strip_model()->GetActiveWebContents();
+ PermissionRequestManager::FromWebContents(web_contents)
+ ->TogglePersist(persist);
+}
+
// Tests ----------------------------------------------------------------------
#if defined(OS_LINUX)
@@ -440,6 +450,14 @@ int GeolocationBrowserTest::GetRequestQueueSize(
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPrompt) {
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
ASSERT_TRUE(WatchPositionAndGrantPermission());
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ GetHostContentSettingsMap()->GetContentSetting(
+ current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string()));
+
+ // Ensure a second request doesn't create a prompt in this tab.
+ WatchPositionAndObservePermissionRequest(false);
}
#if defined(OS_LINUX)
@@ -458,6 +476,14 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) {
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
EXPECT_TRUE(WatchPositionAndDenyPermission());
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
+
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ GetHostContentSettingsMap()->GetContentSetting(
+ current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string()));
+
+ // Ensure a second request doesn't create a prompt in this tab.
+ WatchPositionAndObservePermissionRequest(false);
}
#if defined(OS_LINUX)
@@ -540,6 +566,46 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
ExpectPosition(fake_latitude(), fake_longitude());
}
+IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TogglePersistGranted) {
+ // Initialize and turn persistence off.
+ ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
+ TogglePersist(false);
+
+ ASSERT_TRUE(WatchPositionAndGrantPermission());
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ GetHostContentSettingsMap()->GetContentSetting(
+ current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string()));
+
+ // Expect the grant to be remembered at the blink layer, so a second request
+ // on this page doesn't create a request.
+ WatchPositionAndObservePermissionRequest(false);
+
+ // Navigate and ensure that a prompt is shown when we request again.
+ ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
+ WatchPositionAndObservePermissionRequest(true);
+}
+
+IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TogglePersistBlocked) {
+ // Initialize and turn persistence off.
+ ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
+ TogglePersist(false);
+
+ ASSERT_TRUE(WatchPositionAndDenyPermission());
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ GetHostContentSettingsMap()->GetContentSetting(
+ current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string()));
+
+ // Expect the block to be remembered at the blink layer, so a second request
+ // on this page doesn't create a request.
+ WatchPositionAndObservePermissionRequest(false);
+
+ // Navigate and ensure that a prompt is shown when we request again.
+ ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
+ WatchPositionAndObservePermissionRequest(true);
+}
+
#if defined(OS_LINUX)
// http://crbug.com/527437
#define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698