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 /tests | |
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"
Diffstat (limited to 'tests')
5 files changed, 66 insertions, 98 deletions
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, |