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

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

Issue 2110343002: Reintroduce plumbing for user gesture into permission system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 6 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 4779afc57222f62d70625b4f42852669df5043f6..810b3a53fa8ef0f6e63093efde2aacc4e7fc0f1e 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -136,7 +136,8 @@ class GeolocationPermissionContextTests
void RequestGeolocationPermission(content::WebContents* web_contents,
const PermissionRequestID& id,
- const GURL& requesting_frame);
+ const GURL& requesting_frame,
+ bool user_gesture);
void PermissionResponse(const PermissionRequestID& id,
ContentSetting content_setting);
@@ -196,9 +197,10 @@ PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab(
void GeolocationPermissionContextTests::RequestGeolocationPermission(
content::WebContents* web_contents,
const PermissionRequestID& id,
- const GURL& requesting_frame) {
+ const GURL& requesting_frame,
+ bool user_gesture) {
geolocation_permission_context_->RequestPermission(
- web_contents, id, requesting_frame,
+ web_contents, id, requesting_frame, user_gesture,
base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
base::Unretained(this), id));
content::RunAllBlockingPoolTasksUntilIdle();
@@ -410,7 +412,8 @@ TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) {
BubbleManagerDocumentLoadCompleted();
EXPECT_EQ(0U, GetNumberOfPrompts());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
ASSERT_EQ(1U, GetNumberOfPrompts());
}
@@ -421,7 +424,8 @@ TEST_F(GeolocationPermissionContextTests,
BubbleManagerDocumentLoadCompleted();
EXPECT_EQ(0U, GetNumberOfPrompts());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
+ true);
ASSERT_EQ(0U, GetNumberOfPrompts());
}
@@ -430,7 +434,8 @@ TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) {
GURL requesting_frame("https://www.example.com/geolocation");
NavigateAndCommit(requesting_frame);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
ASSERT_EQ(1U, infobar_service()->infobar_count());
infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
ConfirmInfoBarDelegate* infobar_delegate =
@@ -448,7 +453,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
NavigateAndCommit(requesting_frame);
MockLocationSettings::SetLocationStatus(true, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(1U, infobar_service()->infobar_count());
ConfirmInfoBarDelegate* infobar_delegate_0 =
infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
@@ -459,7 +465,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
Reload();
MockLocationSettings::SetLocationStatus(true, false);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
}
@@ -468,7 +475,8 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
NavigateAndCommit(requesting_frame);
MockLocationSettings::SetLocationStatus(true, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(1U, infobar_service()->infobar_count());
ConfirmInfoBarDelegate* infobar_delegate =
infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
@@ -483,7 +491,8 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
NavigateAndCommit(requesting_frame);
MockLocationSettings::SetLocationStatus(true, false);
EXPECT_EQ(0U, infobar_service()->infobar_count());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(0U, infobar_service()->infobar_count());
}
#endif
@@ -506,9 +515,9 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, true);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, true);
// Ensure only one infobar is created.
ASSERT_EQ(1U, GetNumberOfPrompts());
base::string16 text_0 = GetPromptText();
@@ -564,7 +573,13 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
// Check permission is requested.
ASSERT_EQ(0U, GetNumberOfPrompts());
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
+#if BUILDFLAG(ANDROID_JAVA_UI)
+ const bool user_gesture = false;
+#else
+ const bool user_gesture = true;
+#endif
+ RequestGeolocationPermission(web_contents(), RequestID(0), url_a,
+ user_gesture);
ASSERT_EQ(1U, GetNumberOfPrompts());
// Change the hash, we'll still be on the same page.
@@ -600,7 +615,8 @@ TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) {
// Check permission is requested.
ASSERT_EQ(0U, GetNumberOfPrompts());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(1U, GetNumberOfPrompts());
// Accept the frame.
@@ -628,8 +644,10 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
ASSERT_EQ(0U, GetNumberOfPrompts());
// Request permission for two frames.
- RequestGeolocationPermission(web_contents(), RequestID(0), frame_0);
- RequestGeolocationPermission(web_contents(), RequestID(1), frame_1);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), frame_0, true);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(1), frame_1, true);
// Get the first permission request text.
ASSERT_EQ(1U, GetNumberOfPrompts());
@@ -671,7 +689,8 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) {
// Nothing should be displayed.
EXPECT_EQ(0U, GetNumberOfPrompts());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, true);
EXPECT_EQ(0U, GetNumberOfPrompts());
CheckPermissionMessageSent(0, false);
}
@@ -695,11 +714,12 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
#endif
// Request permission in all three tabs.
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
RequestGeolocationPermission(
- extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b);
+ web_contents(), RequestID(0), url_a, true);
RequestGeolocationPermission(
- extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a);
+ extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b, true);
+ RequestGeolocationPermission(
+ extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true);
ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0.
#if !BUILDFLAG(ANDROID_JAVA_UI)
ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
@@ -752,11 +772,12 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
// Request permission in both tabs; the extra tab will have two permission
// requests from two origins.
- RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
RequestGeolocationPermission(
- extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a);
+ web_contents(), RequestID(0), url_a, true);
+ RequestGeolocationPermission(
+ extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true);
RequestGeolocationPermission(
- extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b);
+ extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true);
#if !BUILDFLAG(ANDROID_JAVA_UI)
ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0));
ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
@@ -825,9 +846,9 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, false);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, false);
// Ensure only one prompt is created.
ASSERT_EQ(1U, GetNumberOfPrompts());
@@ -868,7 +889,8 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
0);
ASSERT_EQ(0U, GetNumberOfPrompts());
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, false);
ASSERT_EQ(1U, GetNumberOfPrompts());
AcceptPrompt();
@@ -882,7 +904,8 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
10);
test_clock->Advance(base::TimeDelta::FromSeconds(3));
- RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ RequestGeolocationPermission(
+ web_contents(), RequestID(0), requesting_frame, false);
// Permission has been used three seconds later.
EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
@@ -920,9 +943,9 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
// Request permission for two frames.
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, false);
RequestGeolocationPermission(
- web_contents(), RequestID(1), requesting_frame_1);
+ web_contents(), RequestID(1), requesting_frame_1, false);
// Ensure only one infobar is created.
ASSERT_EQ(1U, GetNumberOfPrompts());
@@ -970,7 +993,7 @@ TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
test_clock->Advance(base::TimeDelta::FromSeconds(2));
RequestGeolocationPermission(
- web_contents(), RequestID(0), requesting_frame_0);
+ web_contents(), RequestID(0), requesting_frame_0, false);
// Verify that requesting permission in one frame doesn't update other where
// it is the embedder.

Powered by Google App Engine
This is Rietveld 408576698