diff options
author | Steve Block <steveblock@google.com> | 2012-05-22 06:15:07 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-22 06:15:07 -0700 |
commit | 7c22b1810cce5738f026eec801f4ec11a8df40f6 (patch) | |
tree | 82b359e2eeafa052a8ba785a625ba0ac0d35a057 | |
parent | 0c1e7d339c1ae707cae2acf42f2b5e83dfa9cf43 (diff) | |
parent | f3f60d9328d8acfedf987a73631fc90c39bf5447 (diff) | |
download | frameworks_base-7c22b1810cce5738f026eec801f4ec11a8df40f6.zip frameworks_base-7c22b1810cce5738f026eec801f4ec11a8df40f6.tar.gz frameworks_base-7c22b1810cce5738f026eec801f4ec11a8df40f6.tar.bz2 |
Merge "Switch Geolocation DRT methods to control client-based mock"
8 files changed, 153 insertions, 115 deletions
diff --git a/core/java/android/webkit/MockGeolocation.java b/core/java/android/webkit/MockGeolocation.java index fbda492..d8dc724 100644 --- a/core/java/android/webkit/MockGeolocation.java +++ b/core/java/android/webkit/MockGeolocation.java @@ -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); } diff --git a/core/java/android/webkit/WebViewClassic.java b/core/java/android/webkit/WebViewClassic.java index ab8bc64..8e8d2b6 100644 --- a/core/java/android/webkit/WebViewClassic.java +++ b/core/java/android/webkit/WebViewClassic.java @@ -4778,6 +4778,43 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc } /** + * 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. * * debug only diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index af7914e..bec3b78 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -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, diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/CallbackProxy.java b/tests/DumpRenderTree/src/com/android/dumprendertree/CallbackProxy.java index d74f5f7..9d621d6 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/CallbackProxy.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/CallbackProxy.java @@ -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, - longitude, - accuracy); + // 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, diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestController.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestController.java index 9be2f1c..c936a6c 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestController.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestController.java @@ -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); diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java index bbfbfc4..2b58f14 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java @@ -539,24 +539,22 @@ public class TestShellActivity extends Activity implements LayoutTestController mCanOpenWindows = true; } - /** - * Sets the Geolocation permission state to be used for all future requests. - */ + @Override + public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) { + WebViewClassic.fromWebView(mWebView).setMockGeolocationPosition(latitude, + longitude, + accuracy); + } + + @Override + public void setMockGeolocationError(int code, String message) { + WebViewClassic.fromWebView(mWebView).setMockGeolocationError(code, message); + } + @Override public void setGeolocationPermission(boolean allow) { - mIsGeolocationPermissionSet = true; - mGeolocationPermission = allow; - - if (mPendingGeolocationPermissionCallbacks != null) { - Iterator iter = mPendingGeolocationPermissionCallbacks.keySet().iterator(); - while (iter.hasNext()) { - GeolocationPermissions.Callback callback = - (GeolocationPermissions.Callback) iter.next(); - String origin = (String) mPendingGeolocationPermissionCallbacks.get(callback); - callback.invoke(origin, mGeolocationPermission, false); - } - mPendingGeolocationPermissionCallbacks = null; - } + Log.v(LOGTAG, "setGeolocationPermission() allow=" + allow); + WebViewClassic.fromWebView(mWebView).setMockGeolocationPermission(allow); } @Override @@ -749,22 +747,11 @@ public class TestShellActivity extends Activity implements LayoutTestController callback.updateQuota(currentQuota + 1024 * 1024 * 5); } - /** - * Instructs the client to show a prompt to ask the user to set the - * Geolocation permission state for the specified origin. - */ @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { - if (mIsGeolocationPermissionSet) { - callback.invoke(origin, mGeolocationPermission, false); - return; - } - if (mPendingGeolocationPermissionCallbacks == null) { - mPendingGeolocationPermissionCallbacks = - new HashMap<GeolocationPermissions.Callback, String>(); - } - mPendingGeolocationPermissionCallbacks.put(callback, origin); + throw new RuntimeException( + "The WebCore mock used by DRT should bypass the usual permissions flow."); } @Override @@ -849,9 +836,8 @@ public class TestShellActivity extends Activity implements LayoutTestController mPageFinished = false; mDumpWebKitData = false; setDefaultWebSettings(mWebView); - mIsGeolocationPermissionSet = false; - mPendingGeolocationPermissionCallbacks = null; CookieManager.getInstance().removeAllCookie(); + mWebViewClassic.setUseMockGeolocation(); } private boolean canMoveToNextTest() { @@ -958,8 +944,4 @@ public class TestShellActivity extends Activity implements LayoutTestController static final int DRAW_RUNS = 5; static final String DRAW_TIME_LOG = Environment.getExternalStorageDirectory() + "/android/page_draw_time.txt"; - - private boolean mIsGeolocationPermissionSet; - private boolean mGeolocationPermission; - private Map mPendingGeolocationPermissionCallbacks; } diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestController.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestController.java index d0c59d3..bb3bf62 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestController.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestController.java @@ -80,6 +80,21 @@ public class LayoutTestController { quota); } + public void setMockGeolocationPosition(double latitude, + double longitude, + double accuracy) { + Log.i(LOG_TAG, "setMockGeolocationPosition(): " + "latitude=" + latitude + + " longitude=" + longitude + " accuracy=" + accuracy); + mLayoutTestsExecutor.setMockGeolocationPosition(latitude, + longitude, + accuracy); + } + + public void setMockGeolocationError(int code, String message) { + Log.i(LOG_TAG, "setMockGeolocationError(): " + "code=" + code + " message=" + message); + mLayoutTestsExecutor.setMockGeolocationError(code, message); + } + public void setGeolocationPermission(boolean allow) { mLayoutTestsExecutor.setGeolocationPermission(allow); } @@ -95,17 +110,6 @@ public class LayoutTestController { canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma); } - public void setMockGeolocationError(int code, String message) { - Log.i(LOG_TAG, "setMockGeolocationError(): " + "code=" + code + " message=" + message); - MockGeolocation.getInstance().setError(code, message); - } - - public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) { - Log.i(LOG_TAG, "setMockGeolocationPosition(): " + "latitude=" + latitude + - " longitude=" + longitude + " accuracy=" + accuracy); - MockGeolocation.getInstance().setPosition(latitude, longitude, accuracy); - } - public void setXSSAuditorEnabled(boolean flag) { mLayoutTestsExecutor.setXSSAuditorEnabled(flag); } diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java index f958ade..b2fbfd5 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java @@ -109,9 +109,6 @@ public class LayoutTestsExecutor extends Activity { private LayoutTestController mLayoutTestController = new LayoutTestController(this); private boolean mCanOpenWindows; private boolean mDumpDatabaseCallbacks; - private boolean mIsGeolocationPermissionSet; - private boolean mGeolocationPermission; - private Map<GeolocationPermissions.Callback, String> mPendingGeolocationPermissionCallbacks; private EventSender mEventSender = new EventSender(); @@ -255,15 +252,8 @@ public class LayoutTestsExecutor extends Activity { @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { - if (mIsGeolocationPermissionSet) { - callback.invoke(origin, mGeolocationPermission, false); - return; - } - if (mPendingGeolocationPermissionCallbacks == null) { - mPendingGeolocationPermissionCallbacks = - new HashMap<GeolocationPermissions.Callback, String>(); - } - mPendingGeolocationPermissionCallbacks.put(callback, origin); + throw new RuntimeException( + "The WebCore mock used by DRT should bypass the usual permissions flow."); } }; @@ -394,6 +384,7 @@ public class LayoutTestsExecutor extends Activity { webViewSettings.setPageCacheCapacity(0); // This is asynchronous, but it gets processed by WebCore before it starts loading pages. + WebViewClassic.fromWebView(mCurrentWebView).setUseMockGeolocation(); WebViewClassic.fromWebView(mCurrentWebView).setUseMockDeviceOrientation(); // Must do this after setting the AppCache path. @@ -573,9 +564,8 @@ public class LayoutTestsExecutor extends Activity { private static final int MSG_DUMP_CHILD_FRAMES_AS_TEXT = 3; private static final int MSG_SET_CAN_OPEN_WINDOWS = 4; private static final int MSG_DUMP_DATABASE_CALLBACKS = 5; - private static final int MSG_SET_GEOLOCATION_PERMISSION = 6; - private static final int MSG_OVERRIDE_PREFERENCE = 7; - private static final int MSG_SET_XSS_AUDITOR_ENABLED = 8; + private static final int MSG_OVERRIDE_PREFERENCE = 6; + private static final int MSG_SET_XSS_AUDITOR_ENABLED = 7; /** String constants for use with layoutTestController.overridePreference() */ private final String WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED = @@ -644,22 +634,6 @@ public class LayoutTestsExecutor extends Activity { mCanOpenWindows = true; break; - case MSG_SET_GEOLOCATION_PERMISSION: - mIsGeolocationPermissionSet = true; - mGeolocationPermission = msg.arg1 == 1; - - if (mPendingGeolocationPermissionCallbacks != null) { - Iterator<GeolocationPermissions.Callback> iter = - mPendingGeolocationPermissionCallbacks.keySet().iterator(); - while (iter.hasNext()) { - GeolocationPermissions.Callback callback = iter.next(); - String origin = mPendingGeolocationPermissionCallbacks.get(callback); - callback.invoke(origin, mGeolocationPermission, false); - } - mPendingGeolocationPermissionCallbacks = null; - } - break; - case MSG_SET_XSS_AUDITOR_ENABLED: WebViewClassic.fromWebView(mCurrentWebView).getSettings(). setXSSAuditorEnabled(msg.arg1 == 1); @@ -679,8 +653,6 @@ public class LayoutTestsExecutor extends Activity { private void resetLayoutTestController() { mCanOpenWindows = false; mDumpDatabaseCallbacks = false; - mIsGeolocationPermissionSet = false; - mPendingGeolocationPermissionCallbacks = null; } public void dumpAsText(boolean enablePixelTest) { @@ -721,12 +693,20 @@ public class LayoutTestsExecutor extends Activity { mLayoutTestControllerHandler.sendEmptyMessage(MSG_SET_CAN_OPEN_WINDOWS); } + public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) { + WebViewClassic.fromWebView(mCurrentWebView).setMockGeolocationPosition(latitude, + longitude, + accuracy); + } + + public void setMockGeolocationError(int code, String message) { + WebViewClassic.fromWebView(mCurrentWebView).setMockGeolocationError(code, message); + } + public void setGeolocationPermission(boolean allow) { Log.i(LOG_TAG, mCurrentTestRelativePath + ": setGeolocationPermission(" + allow + ") called"); - Message msg = mLayoutTestControllerHandler.obtainMessage(MSG_SET_GEOLOCATION_PERMISSION); - msg.arg1 = allow ? 1 : 0; - msg.sendToTarget(); + WebViewClassic.fromWebView(mCurrentWebView).setMockGeolocationPermission(allow); } public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha, |