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

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

Issue 2742373003: Limit the amount the Location Settings Dialog will be shown to users. (Closed)
Patch Set: Woops, missed one Created 3 years, 9 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
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 5f13e5943d6c4018c77bb50d4b00c72e8d8e4185..c7a798edd844c2a7f4ffd1561eb3e4eb181e41c7 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -180,6 +180,12 @@ class GeolocationPermissionContextTests
void DenyBubble(PermissionRequestManager* manager);
void CloseBubble(PermissionRequestManager* manager);
#endif
+#if defined(OS_ANDROID)
+ bool RequestPermissionIsLSDShown(const GURL& origin);
+ bool RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin);
+ void AddDayOffsetForTesting(int days);
+ void SetDSEOriginForTesting(const char* dse_origin);
+#endif
void RequestManagerDocumentLoadCompleted();
void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents);
ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
@@ -373,6 +379,41 @@ void GeolocationPermissionContextTests::CloseBubble(
}
#endif
+#if defined(OS_ANDROID)
+bool GeolocationPermissionContextTests::RequestPermissionIsLSDShown(
+ const GURL& origin) {
+ NavigateAndCommit(origin);
+ MockLocationSettings::ClearHasShownLocationSettingsDialog();
+ RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
+
+ return MockLocationSettings::HasShownLocationSettingsDialog();
+}
+
+bool GeolocationPermissionContextTests::
+ RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin) {
+ NavigateAndCommit(origin);
+ MockLocationSettings::ClearHasShownLocationSettingsDialog();
+ RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
+
+ EXPECT_EQ(1U, infobar_service()->infobar_count());
+ ConfirmInfoBarDelegate* infobar_delegate =
+ infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
+ EXPECT_TRUE(infobar_delegate);
+ infobar_delegate->Accept();
+
+ return MockLocationSettings::HasShownLocationSettingsDialog();
+}
+
+void GeolocationPermissionContextTests::AddDayOffsetForTesting(int days) {
+ GeolocationPermissionContextAndroid::AddDayOffsetForTesting(days);
+}
+
+void GeolocationPermissionContextTests::SetDSEOriginForTesting(
+ const char* dse_origin) {
+ GeolocationPermissionContextAndroid::SetDSEOriginForTesting(dse_origin);
+}
+#endif
+
void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() {
GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted(
web_contents());
@@ -583,7 +624,8 @@ TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) {
NavigateAndCommit(requesting_frame);
MockLocationSettings::SetLocationStatus(true /* android */,
false /* system */);
- MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ GRANTED);
EXPECT_EQ(0U, infobar_service()->infobar_count());
RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
true);
@@ -605,7 +647,8 @@ TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) {
NavigateAndCommit(requesting_frame);
MockLocationSettings::SetLocationStatus(true /* android */,
false /* system */);
- MockLocationSettings::SetLocationSettingsDialogStatus(true, DENIED);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
EXPECT_EQ(0U, infobar_service()->infobar_count());
RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
true);
@@ -618,6 +661,237 @@ TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) {
CheckPermissionMessageSent(0, false);
EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
}
+
+TEST_F(GeolocationPermissionContextTests, LSDBackOffDifferentSites) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
+
+ GURL requesting_frame_1("https://www.example.com/geolocation");
+ GURL requesting_frame_2("https://www.example-2.com/geolocation");
+ const char* requesting_frame_dse_ptr = "https://www.dse.com/geolocation";
+ GURL requesting_frame_dse(requesting_frame_dse_ptr);
+
+ SetDSEOriginForTesting(requesting_frame_dse_ptr);
+
+ // Set all origin geolocation permissions to ALLOW.
+ SetGeolocationContentSetting(requesting_frame_1, requesting_frame_1,
+ CONTENT_SETTING_ALLOW);
+ SetGeolocationContentSetting(requesting_frame_2, requesting_frame_2,
+ CONTENT_SETTING_ALLOW);
+ SetGeolocationContentSetting(requesting_frame_dse, requesting_frame_dse,
+ CONTENT_SETTING_ALLOW);
+
+ // Turn off system location but allow the LSD to be shown, and denied.
+ MockLocationSettings::SetLocationStatus(true /* android */,
+ false /* system */);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+
+ // Now permission requests should trigger the LSD, but the LSD will be denied,
+ // putting the requesting origins into backoff. Check that the two non-DSE
+ // origins share the same backoff, which is distinct to the DSE origin.
+ // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame_1));
+
+ // Now check that the LSD is prevented on this origin.
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_1));
+
+ // Now ask on the other non-DSE origin and check backoff prevented the prompt.
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_2));
+
+ // Now request on the DSE and check that the LSD is shown, as the non-DSE
+ // backoff should not apply.
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame_dse));
+
+ // Now check that the DSE is in backoff.
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_dse));
+}
+
+TEST_F(GeolocationPermissionContextTests, LSDBackOffTiming) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
+
+ GURL requesting_frame("https://www.example.com/geolocation");
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ALLOW);
+
+ // Turn off system location but allow the LSD to be shown, and denied.
+ MockLocationSettings::SetLocationStatus(true /* android */,
+ false /* system */);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+
+ // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check the LSD is prevented in 6 days time.
+ AddDayOffsetForTesting(6);
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check that it isn't shown 29 days after that.
+ AddDayOffsetForTesting(29);
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check that it isn't shown 89 days after that.
+ AddDayOffsetForTesting(89);
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check that it isn't shown 89 days after that.
+ AddDayOffsetForTesting(89);
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+}
+
+TEST_F(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
+
+ GURL requesting_frame("https://www.example.com/geolocation");
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ALLOW);
+
+ // Turn off system location but allow the LSD to be shown, and denied.
+ MockLocationSettings::SetLocationStatus(true /* android */,
+ false /* system */);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+
+ // The permission status should reflect that the LSD will be shown.
+ ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
+ PermissionManager::Get(profile())->GetPermissionStatus(
+ content::PermissionType::GEOLOCATION, requesting_frame,
+ requesting_frame));
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Now that the LSD is in backoff, the permission status should reflect it.
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+ ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
+ PermissionManager::Get(profile())->GetPermissionStatus(
+ content::PermissionType::GEOLOCATION, requesting_frame,
+ requesting_frame));
+}
+
+TEST_F(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
+
+ GURL requesting_frame("https://www.example.com/geolocation");
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ALLOW);
+
+ // Turn off system location but allow the LSD to be shown, and denied.
+ MockLocationSettings::SetLocationStatus(true /* android */,
+ false /* system */);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+
+ // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Set the content setting back to ASK. The permission status should be
+ // prompt, and the LSD prompt should now be shown.
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ASK);
+ ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
+ PermissionManager::Get(profile())->GetPermissionStatus(
+ content::PermissionType::GEOLOCATION, requesting_frame,
+ requesting_frame));
+ EXPECT_TRUE(
+ RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame));
+}
+
+TEST_F(GeolocationPermissionContextTests,
+ LSDBackOffAcceptPermissionResetsBackOff) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
+
+ GURL requesting_frame("https://www.example.com/geolocation");
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ALLOW);
+
+ // Turn off system location but allow the LSD to be shown, and denied.
+ MockLocationSettings::SetLocationStatus(true /* android */,
+ false /* system */);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+
+ // First, get into the highest backoff state.
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(7);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(30);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(90);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Now accept a permissions prompt.
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ASK);
+ EXPECT_TRUE(
+ RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame));
+
+ // And check that back in the lowest backoff state.
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(7);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+}
+
+TEST_F(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
+
+ GURL requesting_frame("https://www.example.com/geolocation");
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ALLOW);
+
+ // Turn off system location but allow the LSD to be shown, and denied.
+ MockLocationSettings::SetLocationStatus(true /* android */,
+ false /* system */);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+
+ // First, get into the highest backoff state.
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(7);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(30);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Now accept the LSD.
+ AddDayOffsetForTesting(90);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ GRANTED);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+
+ // Check that not in backoff, and that at the lowest backoff state.
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ DENIED);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+ EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
+ AddDayOffsetForTesting(7);
+ EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
+}
#endif
TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
@@ -1139,7 +1413,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) {
content::PermissionType::GEOLOCATION, requesting_frame,
requesting_frame));
- MockLocationSettings::SetLocationSettingsDialogStatus(false, GRANTED);
+ MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
+ GRANTED);
ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
PermissionManager::Get(profile())->GetPermissionStatus(
content::PermissionType::GEOLOCATION, requesting_frame,
@@ -1148,13 +1423,15 @@ TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) {
// The result should be the same if the location permission is ASK.
SetGeolocationContentSetting(requesting_frame, requesting_frame,
CONTENT_SETTING_ASK);
- MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ GRANTED);
ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
PermissionManager::Get(profile())->GetPermissionStatus(
content::PermissionType::GEOLOCATION, requesting_frame,
requesting_frame));
- MockLocationSettings::SetLocationSettingsDialogStatus(false, GRANTED);
+ MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
+ GRANTED);
ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
PermissionManager::Get(profile())->GetPermissionStatus(
content::PermissionType::GEOLOCATION, requesting_frame,
@@ -1164,7 +1441,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) {
// permission status should still be BLOCK.
SetGeolocationContentSetting(requesting_frame, requesting_frame,
CONTENT_SETTING_BLOCK);
- MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
+ GRANTED);
ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
PermissionManager::Get(profile())->GetPermissionStatus(
content::PermissionType::GEOLOCATION, requesting_frame,

Powered by Google App Engine
This is Rietveld 408576698