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

Commit 68dede3d authored by Steve Block's avatar Steve Block
Browse files

Hook up mock for testing DeviceOrientation in DRT

Change-Id: I99fbe328807428aa0d94893545bad0697ccb71d7
parent 8aff3c05
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.webkit;

import android.util.Log;

/**
 * This class is simply a container for the methods used to configure WebKit's
 * mock DeviceOrientationClient for use in LayoutTests.
 *
 * This could be part of WebViewCore, but have moved it to its own class to
 * avoid bloat there.
 * @hide
 */
public final class DeviceOrientationManager {
    /**
     * Sets whether the Page for the specified WebViewCore should use a mock DeviceOrientation
     * client.
     */
    public static void useMock(WebViewCore webViewCore) {
        assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
        nativeUseMock(webViewCore);
    }

    /**
     * Set the position for the mock DeviceOrientation service for the supplied WebViewCore.
     */
    public static void setMockOrientation(WebViewCore webViewCore, boolean canProvideAlpha,
            double alpha, boolean canProvideBeta, double beta, boolean canProvideGamma,
            double gamma) {
        assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
        nativeSetMockOrientation(webViewCore, canProvideAlpha, alpha, canProvideBeta, beta,
                canProvideGamma, gamma);
    }

    // Native functions
    private static native void nativeUseMock(WebViewCore webViewCore);
    private static native void nativeSetMockOrientation(WebViewCore webViewCore,
            boolean canProvideAlpha, double alpha, boolean canProvideBeta, double beta,
            boolean canProvideGamma, double gamma);
}
+21 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.webkit.DeviceOrientationManager;
import android.webkit.WebTextView.AutoCompleteAdapter;
import android.webkit.WebViewCore.EventHub;
import android.webkit.WebViewCore.TouchEventData;
@@ -3746,6 +3747,26 @@ public class WebView extends AbsoluteLayout
        mWebViewCore.sendMessage(EventHub.DUMP_RENDERTREE, toFile ? 1 : 0, 0);
    }

    /**
     * Called by DRT on UI thread, need to proxy to WebCore thread.
     *
     * @hide debug only
     */
    public void useMockDeviceOrientation() {
        mWebViewCore.sendMessage(EventHub.USE_MOCK_DEVICE_ORIENTATION);
    }

    /**
     * Called by DRT on WebCore thread.
     *
     * @hide debug only
     */
    public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
            boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) {
        DeviceOrientationManager.setMockOrientation(mWebViewCore, canProvideAlpha, alpha,
                canProvideBeta, beta, canProvideGamma, gamma);
    }

    /**
     * Dump the V8 counters to standard output.
     * Note that you need a build with V8 and WEBCORE_INSTRUMENTATION set to
+11 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.SparseBooleanArray;
import android.view.KeyEvent;
import android.view.SurfaceView;
import android.view.View;
import android.webkit.DeviceOrientationManager;

import java.util.ArrayList;
import java.util.Collection;
@@ -878,6 +879,8 @@ final class WebViewCore {
        // accessibility support
        static final int MODIFY_SELECTION = 190;

        static final int USE_MOCK_DEVICE_ORIENTATION = 191;

        // private message ids
        private static final int DESTROY =     200;

@@ -1409,6 +1412,10 @@ final class WebViewCore {
                                    WebView.SET_TOUCH_HIGHLIGHT_RECTS, null)
                                    .sendToTarget();
                            break;

                        case USE_MOCK_DEVICE_ORIENTATION:
                            useMockDeviceOrientation();
                            break;
                    }
                }
            };
@@ -2481,6 +2488,10 @@ final class WebViewCore {
                hMode, vMode).sendToTarget();
    }

    private void useMockDeviceOrientation() {
        DeviceOrientationManager.useMock(this);
    }

    private native void nativePause();
    private native void nativeResume();
    private native void nativeFreeMemory();
+8 −0
Original line number Diff line number Diff line
@@ -510,6 +510,14 @@ public class CallbackProxy extends Handler implements EventSender, LayoutTestCon
        obtainMessage(SET_GEOLOCATION_PERMISSION, allow ? 1 : 0, 0).sendToTarget();
    }

    public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
            boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) {
        // Configuration is in WebKit, so stay on WebCore thread, but go via the TestShellActivity
        // as we need access to the Webview.
        mLayoutTestController.setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta,
                canProvideGamma, gamma);
    }

    public void overridePreference(String key, boolean value) {
        Message message = obtainMessage(OVERRIDE_PREFERENCE);
        message.getData().putString("key", key);
+0 −1
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ public class FileFilter {

    static final String[] ignoreTestList = {
        "editing/selection/move-left-right.html", // Causes DumpRenderTree to hang
        "fast/dom/DeviceOrientation/basic-operation.html", // Will cause crash until mock DeviceOrientationClient is hooked up.
        "fast/js/excessive-comma-usage.html", // Tests huge initializer list, causes OOM.
        "fast/js/regexp-charclass-crash.html", // RegExp is too large, causing OOM
        "fast/regex/test1.html", // Causes DumpRenderTree to hang with V8
Loading