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

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: 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..913905f2e57835566fbfca88ba5297d22cd7308f 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -180,6 +180,13 @@ class GeolocationPermissionContextTests
void DenyBubble(PermissionRequestManager* manager);
void CloseBubble(PermissionRequestManager* manager);
#endif
+#if defined(OS_ANDROID)
+ void CheckThatLSDIsShown(const GURL& origin, bool expected_shown);
+ void CheckThatLSDIsShownWithPermissionPrompt(const GURL& origin,
+ bool expected_shown);
+ void AddDayOffsetForTesting(int days);
+ void SetDSEOriginForTesting(const GURL& dse_origin);
+#endif
void RequestManagerDocumentLoadCompleted();
void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents);
ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
@@ -373,6 +380,45 @@ void GeolocationPermissionContextTests::CloseBubble(
}
#endif
+#if defined(OS_ANDROID)
+void GeolocationPermissionContextTests::CheckThatLSDIsShown(
+ const GURL& origin,
+ bool expected_shown) {
+ NavigateAndCommit(origin);
+ MockLocationSettings::ClearHasShownLocationSettingsDialog();
+ RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
+
+ EXPECT_EQ(MockLocationSettings::HasShownLocationSettingsDialog(),
+ expected_shown);
raymes 2017/03/15 04:28:25 optional: alternatively you can return HasShownLoc
benwells 2017/03/15 23:10:49 Yeah that's much nicer, done.
+}
+
+void GeolocationPermissionContextTests::CheckThatLSDIsShownWithPermissionPrompt(
+ const GURL& origin,
+ bool expected_shown) {
+ 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();
+ ASSERT_TRUE(infobar_delegate);
+ infobar_delegate->Accept();
+
+ EXPECT_EQ(MockLocationSettings::HasShownLocationSettingsDialog(),
+ expected_shown);
+}
+
+void GeolocationPermissionContextTests::AddDayOffsetForTesting(int days) {
+ GeolocationPermissionContextAndroid::AddDayOffsetForTesting(days);
+}
+
+void GeolocationPermissionContextTests::SetDSEOriginForTesting(
+ const GURL& dse_origin) {
+ GeolocationPermissionContextAndroid::SetDSEOriginForTesting(dse_origin);
+}
+#endif
+
void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() {
GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted(
web_contents());
@@ -618,6 +664,228 @@ 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");
+ GURL requesting_frame_dse("https://www.dse.com/geolocation");
+
+ SetDSEOriginForTesting(requesting_frame_dse);
+
+ // 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, DENIED);
raymes 2017/03/15 04:28:25 nit: here and elsewhere, please document the boole
benwells 2017/03/15 23:10:49 Done.
+
+ // 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 LSE prompt on the first non-DSE origin to go into backoff.
+ CheckThatLSDIsShown(requesting_frame_1, true /* expected_shown */);
+
+ // Now check that the LSD is prevented on this origin.
+ CheckThatLSDIsShown(requesting_frame_1, false /* expected_shown */);
+
+ // Now ask on the other non-DSE origin and check backoff prevented the prompt.
+ CheckThatLSDIsShown(requesting_frame_2, false /* expected_shown */);
+
+ // Now request on the DSE and check that the LSD is shown, as the non-DSE
+ // backoff should not apply.
+ CheckThatLSDIsShown(requesting_frame_dse, true /* expected_shown */);
+
+ // Now check that the DSE is in backoff.
+ CheckThatLSDIsShown(requesting_frame_dse, false /* expected_shown */);
+}
+
+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, DENIED);
+
+ // First, cancel a LSE prompt on the first non-DSE origin to go into backoff.
raymes 2017/03/15 04:28:25 nit: LSD
benwells 2017/03/15 23:10:49 Done.
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check the LSD is prevented in 6 days time.
+ AddDayOffsetForTesting(6);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check that it isn't shown 29 days after that.
+ AddDayOffsetForTesting(29);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check that it isn't shown 89 days after that.
+ AddDayOffsetForTesting(89);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check that it isn't shown 89 days after that.
+ AddDayOffsetForTesting(89);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+
+ // Check it is shown in one more days time, but then not straight after..
+ AddDayOffsetForTesting(1);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+}
+
+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, 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));
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+
+ // Now that the LSD is in backoff, the permission status should reflect it.
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+ 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, DENIED);
+
+ // First, cancel a LSE prompt on the first non-DSE origin to go into backoff.
raymes 2017/03/15 04:28:25 nit: LSD
benwells 2017/03/15 23:10:49 Done.
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false) /* expected_shown */;
+
+ // 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));
+ CheckThatLSDIsShownWithPermissionPrompt(requesting_frame,
+ true /* expected_shown */);
+}
+
+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, DENIED);
+
+ // First, get into the highest backoff state.
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ AddDayOffsetForTesting(7);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ AddDayOffsetForTesting(30);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ AddDayOffsetForTesting(90);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+
+ // Now accept a permissions prompt.
+ SetGeolocationContentSetting(requesting_frame, requesting_frame,
+ CONTENT_SETTING_ASK);
+ CheckThatLSDIsShownWithPermissionPrompt(requesting_frame,
+ true /* expected_shown */);
+
+ // And check that back in the lowest backoff state.
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+ AddDayOffsetForTesting(7);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+}
+
+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, DENIED);
+
+ // First, get into the highest backoff state.
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ AddDayOffsetForTesting(7);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ AddDayOffsetForTesting(30);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+
+ // Now accept the LSD.
+ AddDayOffsetForTesting(90);
+ MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+
+ // Check that not in backoff, and that at the lowest backoff state.
+ MockLocationSettings::SetLocationSettingsDialogStatus(true, DENIED);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+ CheckThatLSDIsShown(requesting_frame, false /* expected_shown */);
+ AddDayOffsetForTesting(7);
+ CheckThatLSDIsShown(requesting_frame, true /* expected_shown */);
+}
#endif
TEST_F(GeolocationPermissionContextTests, QueuedPermission) {

Powered by Google App Engine
This is Rietveld 408576698