| 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;
|
| + }
|
| + });
|
| + }
|
| +
|
| }
|
|
|