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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/GeolocationTest.java

Issue 1277563002: Cherry-pick: Deny the geolocation permission request by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
Patch Set: Created 5 years, 4 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: android_webview/javatests/src/org/chromium/android_webview/test/GeolocationTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/GeolocationTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/GeolocationTest.java
index 98f45f7a8b82093c6f8b131f04efd376241ae023..5da48dc01650c45944b25567045d9503bbba08f7 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/GeolocationTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/GeolocationTest.java
@@ -6,9 +6,11 @@ package org.chromium.android_webview.test;
import android.os.Build;
import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
import android.webkit.GeolocationPermissions;
import org.chromium.android_webview.AwContents;
+import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.content.browser.LocationProviderFactory;
@@ -37,13 +39,17 @@ public class GeolocationTest extends AwTestBase {
+ " function gotPos(position) {\n"
+ " positionCount++;\n"
+ " }\n"
+ + " function errorCallback(error){"
+ + " window.document.title = 'deny';"
+ + " console.log('navigator.getCurrentPosition error: ', error);"
+ + " }"
+ " function initiate_getCurrentPosition() {\n"
+ " navigator.geolocation.getCurrentPosition(\n"
- + " gotPos, function() { }, { });\n"
+ + " gotPos, errorCallback, { });\n"
+ " }\n"
+ " function initiate_watchPosition() {\n"
+ " navigator.geolocation.watchPosition(\n"
- + " gotPos, function() { }, { });\n"
+ + " gotPos, errorCallback, { });\n"
+ " }\n"
+ " </script>\n"
+ " </head>\n"
@@ -51,38 +57,47 @@ public class GeolocationTest extends AwTestBase {
+ " </body>\n"
+ "</html>";
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mContentsClient = new TestAwContentsClient() {
- @Override
- public void onGeolocationPermissionsShowPrompt(String origin,
- GeolocationPermissions.Callback callback) {
- callback.invoke(origin, true, true);
- }
- };
- mAwContents = createAwTestContainerViewOnMainSync(mContentsClient).getAwContents();
- enableJavaScriptOnUiThread(mAwContents);
- setupGeolocation();
+ private static class GrantPermisionAwContentClient extends TestAwContentsClient {
+ @Override
+ public void onGeolocationPermissionsShowPrompt(String origin,
+ GeolocationPermissions.Callback callback) {
+ callback.invoke(origin, true, true);
+ }
}
- @Override
- public void tearDown() throws Exception {
- mMockLocationProvider.stopUpdates();
- super.tearDown();
+ private static class DefaultPermisionAwContentClient extends TestAwContentsClient {
+ @Override
+ public void onGeolocationPermissionsShowPrompt(String origin,
+ GeolocationPermissions.Callback callback) {
+ // This method is empty intentionally to simulate callback is not referenced.
+ }
}
- private void setupGeolocation() {
+ private void initAwContents(TestAwContentsClient contentsClient) throws Exception {
+ mContentsClient = contentsClient;
+ mAwContents = createAwTestContainerViewOnMainSync(mContentsClient).getAwContents();
+ enableJavaScriptOnUiThread(mAwContents);
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mAwContents.getSettings().setGeolocationEnabled(true);
}
});
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
mMockLocationProvider = new MockLocationProvider();
LocationProviderFactory.setLocationProviderImpl(mMockLocationProvider);
}
+ @Override
+ public void tearDown() throws Exception {
+ mMockLocationProvider.stopUpdates();
+ super.tearDown();
+ }
+
private int getPositionCountFromJS() {
int result = -1;
try {
@@ -110,6 +125,7 @@ public class GeolocationTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
public void testGetPosition() throws Throwable {
+ initAwContents(new GrantPermisionAwContentClient());
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
RAW_HTML, "text/html", false);
@@ -137,6 +153,7 @@ public class GeolocationTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
public void testWatchPosition() throws Throwable {
+ initAwContents(new GrantPermisionAwContentClient());
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
RAW_HTML, "text/html", false);
@@ -153,6 +170,7 @@ public class GeolocationTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
public void testPauseGeolocationOnPause() throws Throwable {
+ initAwContents(new GrantPermisionAwContentClient());
// Start a watch going.
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
RAW_HTML, "text/html", false);
@@ -204,6 +222,7 @@ public class GeolocationTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
public void testPauseAwContentsBeforeNavigating() throws Throwable {
+ initAwContents(new GrantPermisionAwContentClient());
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
@@ -241,6 +260,7 @@ public class GeolocationTest extends AwTestBase {
@MediumTest
@Feature({"AndroidWebView"})
public void testResumeWhenNotStarted() throws Throwable {
+ initAwContents(new GrantPermisionAwContentClient());
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
@@ -261,4 +281,23 @@ public class GeolocationTest extends AwTestBase {
ensureGeolocationRunning(false);
}
+ @Feature({"AndroidWebView"})
+ @SmallTest
+ public void testDenyAccessByDefault() throws Throwable {
+ initAwContents(new DefaultPermisionAwContentClient());
+ loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
+ RAW_HTML, "text/html", false);
+
+ mAwContents.evaluateJavaScriptForTests("initiate_getCurrentPosition();", null);
+
+ poll(new Callable<Boolean>() {
+ @SuppressFBWarnings("DM_GC")
+ @Override
+ public Boolean call() throws Exception {
+ Runtime.getRuntime().gc();
+ return "deny".equals(getTitleOnUiThread(mAwContents));
+ }
+ });
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698