Unreviewed changes
3 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: chrome/browser/geolocation/geolocation_browsertest.cc
Insertions: 30, Deletions: 40.
@@ -27,6 +27,8 @@
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/browser/permission_settings_info.h"
+#include "components/content_settings/core/browser/permission_settings_registry.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/content_settings/core/common/features.h"
@@ -216,9 +218,7 @@
PermissionSetting GetGeolocationContentSetting(const GURL& url);
void SetGeolocationContentSetting(const GURL& url, PermissionSetting setting);
- PermissionSetting ExpectedAllowPermissionSetting();
- PermissionSetting ExpectedBlockPermissionSetting();
- PermissionSetting ExpectedAskPermissionSetting();
+ PermissionSetting ExpectedPermissionSetting(ContentSetting setting);
// Calls watchPosition in JavaScript and accepts or denies the resulting
// permission request. Returns |true| if the expected behavior happened.
@@ -370,8 +370,7 @@
auto* manager =
permissions::PermissionRequestManager::FromWebContents(web_contents());
manager->set_auto_response_for_test(request_response);
- if (base::FeatureList::IsEnabled(
- content_settings::features::kApproximateGeolocationPermission) &&
+ if (IsParamFeatureEnabled() &&
(request_response == permissions::PermissionRequestManager::ACCEPT_ALL ||
request_response ==
permissions::PermissionRequestManager::ACCEPT_ONCE)) {
@@ -442,30 +441,12 @@
url, url, content_settings::GeolocationContentSettingsType(), setting);
}
-PermissionSetting GeolocationBrowserTest::ExpectedAllowPermissionSetting() {
- if (base::FeatureList::IsEnabled(
- content_settings::features::kApproximateGeolocationPermission)) {
- return GeolocationSetting{PermissionOption::kAllowed,
- PermissionOption::kAllowed};
- }
- return CONTENT_SETTING_ALLOW;
-}
-
-PermissionSetting GeolocationBrowserTest::ExpectedBlockPermissionSetting() {
- if (base::FeatureList::IsEnabled(
- content_settings::features::kApproximateGeolocationPermission)) {
- return GeolocationSetting{PermissionOption::kDenied,
- PermissionOption::kDenied};
- }
- return CONTENT_SETTING_BLOCK;
-}
-
-PermissionSetting GeolocationBrowserTest::ExpectedAskPermissionSetting() {
- if (base::FeatureList::IsEnabled(
- content_settings::features::kApproximateGeolocationPermission)) {
- return GeolocationSetting{PermissionOption::kAsk, PermissionOption::kAsk};
- }
- return CONTENT_SETTING_ASK;
+PermissionSetting GeolocationBrowserTest::ExpectedPermissionSetting(
+ ContentSetting setting) {
+ return content_settings::PermissionSettingsRegistry::GetInstance()
+ ->Get(content_settings::GeolocationContentSettingsType())
+ ->delegate()
+ .ToPermissionSetting(setting);
}
// Tests ----------------------------------------------------------------------
@@ -474,7 +455,7 @@
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
ASSERT_TRUE(WatchPositionAndGrantPermission());
- EXPECT_EQ(ExpectedAllowPermissionSetting(),
+ EXPECT_EQ(ExpectedPermissionSetting(CONTENT_SETTING_ALLOW),
GetGeolocationContentSetting(GetTestURL()));
// Ensure a second request doesn't create a prompt in this tab.
@@ -492,7 +473,7 @@
EXPECT_TRUE(WatchPositionAndDenyPermission());
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
- EXPECT_EQ(ExpectedBlockPermissionSetting(),
+ EXPECT_EQ(ExpectedPermissionSetting(CONTENT_SETTING_BLOCK),
GetGeolocationContentSetting(GetTestURL()));
// Ensure a second request doesn't create a prompt in this tab.
@@ -511,7 +492,8 @@
IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForDeniedOrigin) {
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
- SetGeolocationContentSetting(GetTestURL(), ExpectedBlockPermissionSetting());
+ SetGeolocationContentSetting(
+ GetTestURL(), ExpectedPermissionSetting(CONTENT_SETTING_BLOCK));
// Check that the request wasn't shown but we get an error for this origin.
WatchPositionAndObservePermissionRequest(false);
@@ -525,7 +507,8 @@
IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForAllowedOrigin) {
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
- SetGeolocationContentSetting(GetTestURL(), ExpectedAllowPermissionSetting());
+ SetGeolocationContentSetting(
+ GetTestURL(), ExpectedPermissionSetting(CONTENT_SETTING_ALLOW));
// The request is not shown, there is no error, and the position gets to the
// script.
WatchPositionAndObservePermissionRequest(false);
@@ -737,7 +720,8 @@
ASSERT_TRUE(WatchPositionAndGrantPermission());
ExpectPosition(fake_latitude(), fake_longitude());
- SetGeolocationContentSetting(GetTestURL(), ExpectedBlockPermissionSetting());
+ SetGeolocationContentSetting(
+ GetTestURL(), ExpectedPermissionSetting(CONTENT_SETTING_BLOCK));
EXPECT_TRUE(SetPositionAndWaitUntilUpdated(1, 2));
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
@@ -749,7 +733,8 @@
ASSERT_TRUE(WatchPositionAndGrantPermission());
ExpectPosition(fake_latitude(), fake_longitude());
- SetGeolocationContentSetting(GetTestURL(), ExpectedAskPermissionSetting());
+ SetGeolocationContentSetting(GetTestURL(),
+ ExpectedPermissionSetting(CONTENT_SETTING_ASK));
EXPECT_TRUE(SetPositionAndWaitUntilUpdated(1, 2));
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
@@ -762,12 +747,14 @@
ASSERT_TRUE(WatchPositionAndGrantPermission());
ExpectPosition(fake_latitude(), fake_longitude());
- SetGeolocationContentSetting(GetTestURL(), ExpectedBlockPermissionSetting());
+ SetGeolocationContentSetting(
+ GetTestURL(), ExpectedPermissionSetting(CONTENT_SETTING_BLOCK));
EXPECT_TRUE(SetPositionAndWaitUntilUpdated(1, 2));
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
- SetGeolocationContentSetting(GetTestURL(), ExpectedAllowPermissionSetting());
+ SetGeolocationContentSetting(
+ GetTestURL(), ExpectedPermissionSetting(CONTENT_SETTING_ALLOW));
ASSERT_TRUE(WatchPositionAndGrantPermission());
ExpectPosition(fake_latitude(), fake_longitude());
}
@@ -783,7 +770,8 @@
ExpectPosition(fake_latitude(), fake_longitude());
// Toggle to deny on a.test
- SetGeolocationContentSetting(a_test_gurl, ExpectedBlockPermissionSetting());
+ SetGeolocationContentSetting(
+ a_test_gurl, ExpectedPermissionSetting(CONTENT_SETTING_BLOCK));
EXPECT_TRUE(SetPositionAndWaitUntilUpdated(1, 2));
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
@@ -799,7 +787,8 @@
GURL b_test_gurl = GetTestURLForHostname("b.test");
// Set up geolocation as allowed on b.test
- SetGeolocationContentSetting(b_test_gurl, ExpectedAllowPermissionSetting());
+ SetGeolocationContentSetting(
+ b_test_gurl, ExpectedPermissionSetting(CONTENT_SETTING_ALLOW));
// Open a.test and allow geolocation.
ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT, a_test_gurl));
@@ -807,7 +796,8 @@
ExpectPosition(fake_latitude(), fake_longitude());
// Toggle grant to block.
- SetGeolocationContentSetting(a_test_gurl, ExpectedBlockPermissionSetting());
+ SetGeolocationContentSetting(
+ a_test_gurl, ExpectedPermissionSetting(CONTENT_SETTING_BLOCK));
EXPECT_TRUE(SetPositionAndWaitUntilUpdated(1, 2));
ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
```