Commit c2726ec8 authored by dominickn's avatar dominickn Committed by Commit bot

Improve permission persistence tests.

This CL adds a browser test for desktop geolocation where persistence is
toggled off, ensuring that the underlying content setting isn't changed.
Additional checks of the content setting are added to the existing grant
and block tests.

This CL also simplifies the feature list setting used in the
PermissionContextBase test.

BUG=632269

Review-Url: https://codereview.chromium.org/2338173002
Cr-Commit-Position: refs/heads/master@{#418841}
parent e17f77ca
...@@ -254,6 +254,9 @@ class GeolocationBrowserTest : public InProcessBrowserTest { ...@@ -254,6 +254,9 @@ class GeolocationBrowserTest : public InProcessBrowserTest {
// Convenience method to look up the number of queued permission requests. // Convenience method to look up the number of queued permission requests.
int GetRequestQueueSize(PermissionRequestManager* manager); int GetRequestQueueSize(PermissionRequestManager* manager);
// Toggle whether the prompt decision should be persisted.
void TogglePersist(bool persist);
private: private:
// Calls watchPosition() in JavaScript and accepts or denies the resulting // Calls watchPosition() in JavaScript and accepts or denies the resulting
// permission request. Returns the JavaScript response. // permission request. Returns the JavaScript response.
...@@ -429,6 +432,13 @@ int GeolocationBrowserTest::GetRequestQueueSize( ...@@ -429,6 +432,13 @@ int GeolocationBrowserTest::GetRequestQueueSize(
return static_cast<int>(manager->requests_.size()); 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 ---------------------------------------------------------------------- // Tests ----------------------------------------------------------------------
#if defined(OS_LINUX) #if defined(OS_LINUX)
...@@ -440,6 +450,14 @@ int GeolocationBrowserTest::GetRequestQueueSize( ...@@ -440,6 +450,14 @@ int GeolocationBrowserTest::GetRequestQueueSize(
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPrompt) { IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPrompt) {
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
ASSERT_TRUE(WatchPositionAndGrantPermission()); 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) #if defined(OS_LINUX)
...@@ -458,6 +476,14 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) { ...@@ -458,6 +476,14 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) {
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
EXPECT_TRUE(WatchPositionAndDenyPermission()); EXPECT_TRUE(WatchPositionAndDenyPermission());
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); 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) #if defined(OS_LINUX)
...@@ -540,6 +566,46 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ...@@ -540,6 +566,46 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
ExpectPosition(fake_latitude(), fake_longitude()); 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) #if defined(OS_LINUX)
// http://crbug.com/527437 // http://crbug.com/527437
#define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/test/histogram_tester.h" #include "base/test/histogram_tester.h"
#include "base/test/mock_entropy_provider.h" #include "base/test/mock_entropy_provider.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
...@@ -301,19 +302,8 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { ...@@ -301,19 +302,8 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
->ClearSettingsForOneType( ->ClearSettingsForOneType(
CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT); CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT);
// Set up the custom parameter. base::test::ScopedFeatureList feature_list;
base::FieldTrialList field_trials_(nullptr); feature_list.InitAndEnableFeature(features::kBlockPromptsIfDismissedOften);
base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
kPromptTrialName, kPromptGroupName);
base::FeatureList::ClearInstanceForTesting();
std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
feature_list->RegisterFieldTrialOverride(
features::kBlockPromptsIfDismissedOften.name,
base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial);
base::FeatureList::SetInstance(std::move(feature_list));
EXPECT_EQ(base::FeatureList::GetFieldTrial(
features::kBlockPromptsIfDismissedOften),
trial);
EXPECT_TRUE( EXPECT_TRUE(
base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften)); base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften));
...@@ -325,7 +315,6 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { ...@@ -325,7 +315,6 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
DismissMultipleTimesAndExpectBlock(url, DismissMultipleTimesAndExpectBlock(url,
content::PermissionType::NOTIFICATIONS, content::PermissionType::NOTIFICATIONS,
CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 3); CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 3);
base::FeatureList::ClearInstanceForTesting();
} }
void TestVariationBlockOnSeveralDismissals_TestContent() { void TestVariationBlockOnSeveralDismissals_TestContent() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment