Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c22b181 authored by Steve Block's avatar Steve Block Committed by Android (Google) Code Review
Browse files

Merge "Switch Geolocation DRT methods to control client-based mock"

parents 0c1e7d33 f3f60d93
Loading
Loading
Loading
Loading
+27 −17
Original line number Diff line number Diff line
@@ -17,21 +17,29 @@
package android.webkit;

/**
 * This class is simply a container for the methods used to configure WebKit's
 * mock Geolocation service for use in LayoutTests.
 * Used to configure the mock Geolocation client for the LayoutTests.
 * @hide
 */
public final class MockGeolocation {
    private WebViewCore mWebViewCore;

    // Global instance of a MockGeolocation
    private static MockGeolocation sMockGeolocation;
    public MockGeolocation(WebViewCore webViewCore) {
        mWebViewCore = webViewCore;
    }

    /**
     * Sets use of the mock Geolocation client. Also resets that client.
     */
    public void setUseMock() {
        nativeSetUseMock(mWebViewCore);
    }

    /**
     * Set the position for the mock Geolocation service.
     */
    public void setPosition(double latitude, double longitude, double accuracy) {
        // This should only ever be called on the WebKit thread.
        nativeSetPosition(latitude, longitude, accuracy);
        nativeSetPosition(mWebViewCore, latitude, longitude, accuracy);
    }

    /**
@@ -39,21 +47,23 @@ public final class MockGeolocation {
     */
    public void setError(int code, String message) {
        // This should only ever be called on the WebKit thread.
        nativeSetError(code, message);
        nativeSetError(mWebViewCore, code, message);
    }

    /**
     * Get the global instance of MockGeolocation.
     * @return The global MockGeolocation instance.
     */
    public static MockGeolocation getInstance() {
      if (sMockGeolocation == null) {
          sMockGeolocation = new MockGeolocation();
      }
      return sMockGeolocation;
    public void setPermission(boolean allow) {
        // This should only ever be called on the WebKit thread.
        nativeSetPermission(mWebViewCore, allow);
    }

    // Native functions
    private static native void nativeSetPosition(double latitude, double longitude, double accuracy);
    private static native void nativeSetError(int code, String message);
    private static native void nativeSetUseMock(WebViewCore webViewCore);
    private static native void nativeSetPosition(WebViewCore webViewCore,
                                                 double latitude,
                                                 double longitude,
                                                 double accuracy);
    private static native void nativeSetError(WebViewCore webViewCore,
                                              int code,
                                              String message);
    private static native void nativeSetPermission(WebViewCore webViewCore,
                                                   boolean allow);
}
+37 −0
Original line number Diff line number Diff line
@@ -4777,6 +4777,43 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
        mWebViewCore.sendMessage(EventHub.SET_USE_MOCK_DEVICE_ORIENTATION);
    }

    /**
     * Sets use of the Geolocation mock client. Also resets that client. Called
     * by DRT on UI thread, need to proxy to WebCore thread.
     *
     * debug only
     */
    public void setUseMockGeolocation() {
        mWebViewCore.sendMessage(EventHub.SET_USE_MOCK_GEOLOCATION);
    }

    /**
     * Called by DRT on WebCore thread.
     *
     * debug only
     */
    public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) {
        mWebViewCore.setMockGeolocationPosition(latitude, longitude, accuracy);
    }

    /**
     * Called by DRT on WebCore thread.
     *
     * debug only
     */
    public void setMockGeolocationError(int code, String message) {
        mWebViewCore.setMockGeolocationError(code, message);
    }

    /**
     * Called by DRT on WebCore thread.
     *
     * debug only
     */
    public void setMockGeolocationPermission(boolean allow) {
        mWebViewCore.setMockGeolocationPermission(allow);
    }

    /**
     * Called by DRT on WebCore thread.
     *
+23 −0
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ public final class WebViewCore {
    private int mRestoredX = 0;
    private int mRestoredY = 0;

    private MockGeolocation mMockGeolocation = new MockGeolocation(this);

    private DeviceMotionAndOrientationManager mDeviceMotionAndOrientationManager =
            new DeviceMotionAndOrientationManager(this);
    private DeviceMotionService mDeviceMotionService;
@@ -1187,6 +1189,7 @@ public final class WebViewCore {
        static final int SET_INITIAL_FOCUS = 224;

        static final int SAVE_VIEW_STATE = 225;
        static final int SET_USE_MOCK_GEOLOCATION = 226;

        // Private handler for WebCore messages.
        private Handler mHandler;
@@ -1648,6 +1651,10 @@ public final class WebViewCore {
                                    (Set<String>) msg.obj);
                            break;

                        case SET_USE_MOCK_GEOLOCATION:
                            setUseMockGeolocation();
                            break;

                        case SET_USE_MOCK_DEVICE_ORIENTATION:
                            setUseMockDeviceOrientation();
                            break;
@@ -3039,6 +3046,22 @@ public final class WebViewCore {
        mDeviceMotionAndOrientationManager.setUseMock();
    }

    private void setUseMockGeolocation() {
        mMockGeolocation.setUseMock();
    }

    public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) {
        mMockGeolocation.setPosition(latitude, longitude, accuracy);
    }

    public void setMockGeolocationError(int code, String message) {
        mMockGeolocation.setError(code, message);
    }

    public void setMockGeolocationPermission(boolean allow) {
        mMockGeolocation.setPermission(allow);
    }

    public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
            boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) {
        mDeviceMotionAndOrientationManager.setMockOrientation(canProvideAlpha, alpha,
+14 −16
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.dumprendertree;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.webkit.MockGeolocation;
import android.webkit.WebStorage;

import java.util.HashMap;
@@ -48,7 +47,6 @@ public class CallbackProxy extends Handler implements EventSender, LayoutTestCon
    private static final int EVENT_CLEAR_TOUCH_POINTS = 17;
    private static final int EVENT_CANCEL_TOUCH_POINT = 18;
    private static final int EVENT_SET_TOUCH_MODIFIER = 19;
    
    private static final int LAYOUT_CLEAR_LIST = 20;
    private static final int LAYOUT_DISPLAY = 21;
    private static final int LAYOUT_DUMP_TEXT = 22;
@@ -72,10 +70,9 @@ public class CallbackProxy extends Handler implements EventSender, LayoutTestCon
    private static final int LAYOUT_WAIT_UNTIL_DONE = 40;
    private static final int LAYOUT_DUMP_DATABASE_CALLBACKS = 41;
    private static final int LAYOUT_SET_CAN_OPEN_WINDOWS = 42;
    private static final int SET_GEOLOCATION_PERMISSION = 43;
    private static final int OVERRIDE_PREFERENCE = 44;
    private static final int LAYOUT_DUMP_CHILD_FRAMES_TEXT = 45;
    private static final int SET_XSS_AUDITOR_ENABLED = 46;
    private static final int OVERRIDE_PREFERENCE = 43;
    private static final int LAYOUT_DUMP_CHILD_FRAMES_TEXT = 44;
    private static final int SET_XSS_AUDITOR_ENABLED = 45;
    
    CallbackProxy(EventSender eventSender, 
            LayoutTestController layoutTestController) {
@@ -269,11 +266,6 @@ public class CallbackProxy extends Handler implements EventSender, LayoutTestCon
            mLayoutTestController.setCanOpenWindows();
            break;

        case SET_GEOLOCATION_PERMISSION:
            mLayoutTestController.setGeolocationPermission(
                    msg.arg1 == 1 ? true : false);
            break;

        case OVERRIDE_PREFERENCE:
            String key = msg.getData().getString("key");
            boolean value = msg.getData().getBoolean("value");
@@ -497,17 +489,23 @@ public class CallbackProxy extends Handler implements EventSender, LayoutTestCon
    public void setMockGeolocationPosition(double latitude,
                                           double longitude,
                                           double accuracy) {
        MockGeolocation.getInstance().setPosition(latitude,
        // Configuration is in WebKit, so stay on WebCore thread, but go via the TestShellActivity
        // as we need access to the Webview.
        mLayoutTestController.setMockGeolocationPosition(latitude,
                                                         longitude,
                                                         accuracy);
    }

    public void setMockGeolocationError(int code, String message) {
        MockGeolocation.getInstance().setError(code, message);
        // Configuration is in WebKit, so stay on WebCore thread, but go via the TestShellActivity
        // as we need access to the Webview.
        mLayoutTestController.setMockGeolocationError(code, message);
    }

    public void setGeolocationPermission(boolean allow) {
        obtainMessage(SET_GEOLOCATION_PERMISSION, allow ? 1 : 0, 0).sendToTarget();
        // Configuration is in WebKit, so stay on WebCore thread, but go via the TestShellActivity
        // as we need access to the Webview.
        mLayoutTestController.setGeolocationPermission(allow);
    }

    public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
+4 −0
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@ public interface LayoutTestController {
    // For XSSAuditor tests
    public void setXSSAuditorEnabled(boolean flag);

    // For Geolocation tests
    public void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
    public void setMockGeolocationError(int code, String message);

    // For DeviceOrientation tests
    public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
            boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma);
Loading