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

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

Issue 1882783002: [WebView] Disallow geolocation on insecure origins for apps targeting N and higher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Torne's comment Created 4 years, 8 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 54e07e369bb6dda25842a8353dbb16fd7f15e7b9..0ed9bdce7604f98fcb91a8a794f5fa28b00e7b6e 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
@@ -4,11 +4,13 @@
package org.chromium.android_webview.test;
+import android.content.Context;
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.android_webview.AwSettings;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.LocationProviderFactory;
@@ -25,6 +27,7 @@ public class GeolocationTest extends AwTestBase {
private TestAwContentsClient mContentsClient;
private AwContents mAwContents;
private MockLocationProvider mMockLocationProvider;
+ private TestDependencyFactory mOverridenFactory;
private static final String RAW_HTML =
"<!DOCTYPE html>\n"
@@ -92,9 +95,15 @@ public class GeolocationTest extends AwTestBase {
@Override
public void tearDown() throws Exception {
mMockLocationProvider.stopUpdates();
+ mOverridenFactory = null;
super.tearDown();
}
+ @Override
+ protected TestDependencyFactory createTestDependencyFactory() {
+ return mOverridenFactory == null ? new TestDependencyFactory() : mOverridenFactory;
+ }
+
private int getPositionCountFromJS() {
int result = -1;
try {
@@ -115,6 +124,19 @@ public class GeolocationTest extends AwTestBase {
});
}
+ private static class GeolocationOnInsecureOriginsTestDependencyFactory
+ extends TestDependencyFactory {
+ private boolean mAllow;
+ public GeolocationOnInsecureOriginsTestDependencyFactory(boolean allow) {
+ mAllow = allow;
+ }
+
+ @Override
+ public AwSettings createAwSettings(Context context, boolean supportLegacyQuirks) {
+ return new AwSettings(context, false /* isAccessFromFileURLsGrantedByDefault */,
+ supportLegacyQuirks, false /* allowEmptyDocumentPersistence */, mAllow);
+ }
+ }
/**
* Ensure that a call to navigator.getCurrentPosition works in WebView.
@@ -297,4 +319,41 @@ public class GeolocationTest extends AwTestBase {
});
}
+ @Feature({"AndroidWebView"})
+ @SmallTest
+ public void testDenyOnInsecureOrigins() throws Throwable {
+ mOverridenFactory = new GeolocationOnInsecureOriginsTestDependencyFactory(false);
+ initAwContents(new GrantPermisionAwContentClient());
+ loadDataWithBaseUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), RAW_HTML,
+ "text/html", false, "http://google.com/", "about:blank");
+
+ mAwContents.evaluateJavaScriptForTests("initiate_getCurrentPosition();", null);
+
+ pollInstrumentationThread(new Callable<Boolean>() {
+ @SuppressFBWarnings("DM_GC")
+ @Override
+ public Boolean call() throws Exception {
+ Runtime.getRuntime().gc();
+ return "deny".equals(getTitleOnUiThread(mAwContents));
+ }
+ });
+ }
+
+ @Feature({"AndroidWebView"})
+ @SmallTest
+ public void testAllowOnInsecureOriginsByDefault() throws Throwable {
+ initAwContents(new GrantPermisionAwContentClient());
+ loadDataWithBaseUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), RAW_HTML,
+ "text/html", false, "http://google.com/", "about:blank");
+
+ mAwContents.evaluateJavaScriptForTests("initiate_getCurrentPosition();", null);
+
+ pollInstrumentationThread(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ return getPositionCountFromJS() > 0;
+ }
+ });
+ }
+
}
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java ('k') | android_webview/native/aw_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698