From e9f13e171d5c506c0f2ef7389e03d787f9fd6f7b Mon Sep 17 00:00:00 2001 From: Selim Gurun Date: Thu, 25 Jun 2015 10:35:51 -0700 Subject: Remove Webviewtests in frameworks Bug: 22090564 These tests were not touched for at least 3 years, and with webview moving to chromium, they are tested at the chromium side. Change-Id: I4424871dd97c5dc23bb3dbdcee0915d5ab893c7e --- tests/WebViewTests/Android.mk | 27 - tests/WebViewTests/AndroidManifest.xml | 32 - tests/WebViewTests/res/layout/webview_layout.xml | 25 - .../webviewtests/JavaBridgeArrayCoercionTest.java | 625 -------------------- .../android/webviewtests/JavaBridgeArrayTest.java | 226 ------- .../android/webviewtests/JavaBridgeBasicsTest.java | 442 -------------- .../webviewtests/JavaBridgeChildFrameTest.java | 63 -- .../webviewtests/JavaBridgeCoercionTest.java | 646 --------------------- .../android/webviewtests/JavaBridgeFieldsTest.java | 100 ---- .../webviewtests/JavaBridgeReturnValuesTest.java | 199 ------- .../android/webviewtests/JavaBridgeTestBase.java | 122 ---- .../android/webviewtests/WebViewStubActivity.java | 38 -- 12 files changed, 2545 deletions(-) delete mode 100644 tests/WebViewTests/Android.mk delete mode 100644 tests/WebViewTests/AndroidManifest.xml delete mode 100644 tests/WebViewTests/res/layout/webview_layout.xml delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeCoercionTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeFieldsTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeReturnValuesTest.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/JavaBridgeTestBase.java delete mode 100644 tests/WebViewTests/src/com/android/webviewtests/WebViewStubActivity.java (limited to 'tests') diff --git a/tests/WebViewTests/Android.mk b/tests/WebViewTests/Android.mk deleted file mode 100644 index b118845..0000000 --- a/tests/WebViewTests/Android.mk +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright (C) 2011 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. -# -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_SRC_FILES := $(call all-subdir-java-files) - -LOCAL_JAVA_LIBRARIES := android.test.runner - -LOCAL_PACKAGE_NAME := WebViewTests - -include $(BUILD_PACKAGE) diff --git a/tests/WebViewTests/AndroidManifest.xml b/tests/WebViewTests/AndroidManifest.xml deleted file mode 100644 index 8b080c1..0000000 --- a/tests/WebViewTests/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/tests/WebViewTests/res/layout/webview_layout.xml b/tests/WebViewTests/res/layout/webview_layout.xml deleted file mode 100644 index d266d21..0000000 --- a/tests/WebViewTests/res/layout/webview_layout.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java deleted file mode 100644 index c2bbdf5..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayCoercionTest.java +++ /dev/null @@ -1,625 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This class tests that - * we correctly convert JavaScript arrays to Java arrays when passing them to - * the methods of injected Java objects. - * - * The conversions should follow - * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in - * which the implementation differs from the spec are marked with - * LIVECONNECT_COMPLIANCE. - * FIXME: Consider making our implementation more compliant, if it will not - * break backwards-compatibility. See b/4408210. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeArrayCoercionTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeArrayCoercionTest extends JavaBridgeTestBase { - private class TestObject extends Controller { - private Object mObjectInstance; - private CustomType mCustomTypeInstance; - - private boolean[] mBooleanArray; - private byte[] mByteArray; - private char[] mCharArray; - private short[] mShortArray; - private int[] mIntArray; - private long[] mLongArray; - private float[] mFloatArray; - private double[] mDoubleArray; - private String[] mStringArray; - private Object[] mObjectArray; - private CustomType[] mCustomTypeArray; - - public TestObject() { - mObjectInstance = new Object(); - mCustomTypeInstance = new CustomType(); - } - - public Object getObjectInstance() { - return mObjectInstance; - } - public CustomType getCustomTypeInstance() { - return mCustomTypeInstance; - } - - public synchronized void setBooleanArray(boolean[] x) { - mBooleanArray = x; - notifyResultIsReady(); - } - public synchronized void setByteArray(byte[] x) { - mByteArray = x; - notifyResultIsReady(); - } - public synchronized void setCharArray(char[] x) { - mCharArray = x; - notifyResultIsReady(); - } - public synchronized void setShortArray(short[] x) { - mShortArray = x; - notifyResultIsReady(); - } - public synchronized void setIntArray(int[] x) { - mIntArray = x; - notifyResultIsReady(); - } - public synchronized void setLongArray(long[] x) { - mLongArray = x; - notifyResultIsReady(); - } - public synchronized void setFloatArray(float[] x) { - mFloatArray = x; - notifyResultIsReady(); - } - public synchronized void setDoubleArray(double[] x) { - mDoubleArray = x; - notifyResultIsReady(); - } - public synchronized void setStringArray(String[] x) { - mStringArray = x; - notifyResultIsReady(); - } - public synchronized void setObjectArray(Object[] x) { - mObjectArray = x; - notifyResultIsReady(); - } - public synchronized void setCustomTypeArray(CustomType[] x) { - mCustomTypeArray = x; - notifyResultIsReady(); - } - - public synchronized boolean[] waitForBooleanArray() { - waitForResult(); - return mBooleanArray; - } - public synchronized byte[] waitForByteArray() { - waitForResult(); - return mByteArray; - } - public synchronized char[] waitForCharArray() { - waitForResult(); - return mCharArray; - } - public synchronized short[] waitForShortArray() { - waitForResult(); - return mShortArray; - } - public synchronized int[] waitForIntArray() { - waitForResult(); - return mIntArray; - } - public synchronized long[] waitForLongArray() { - waitForResult(); - return mLongArray; - } - public synchronized float[] waitForFloatArray() { - waitForResult(); - return mFloatArray; - } - public synchronized double[] waitForDoubleArray() { - waitForResult(); - return mDoubleArray; - } - public synchronized String[] waitForStringArray() { - waitForResult(); - return mStringArray; - } - public synchronized Object[] waitForObjectArray() { - waitForResult(); - return mObjectArray; - } - public synchronized CustomType[] waitForCustomTypeArray() { - waitForResult(); - return mCustomTypeArray; - } - } - - // Two custom types used when testing passing objects. - private class CustomType { - } - - private TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - // Note that all tests use a single element array for simplicity. We test - // multiple elements elsewhere. - - // Test passing an array of JavaScript numbers in the int32 range to a - // method which takes a Java array. - public void testPassNumberInt32() throws Throwable { - executeJavaScript("testObject.setBooleanArray([0]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - // LIVECONNECT_COMPLIANCE: Should convert to boolean. - executeJavaScript("testObject.setBooleanArray([42]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([42]);"); - assertEquals(42, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value. - executeJavaScript("testObject.setCharArray([42]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([42]);"); - assertEquals(42, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([42]);"); - assertEquals(42, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([42]);"); - assertEquals(42L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([42]);"); - assertEquals(42.0f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([42]);"); - assertEquals(42.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([42]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([42]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([42]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript numbers in the double range to a - // method which takes a Java array. - public void testPassNumberDouble() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should convert to boolean. - executeJavaScript("testObject.setBooleanArray([42.1]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([42.1]);"); - assertEquals(42, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value. - executeJavaScript("testObject.setCharArray([42.1]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([42.1]);"); - assertEquals(42, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([42.1]);"); - assertEquals(42, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([42.1]);"); - assertEquals(42L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([42.1]);"); - assertEquals(42.1f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([42.1]);"); - assertEquals(42.1, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([42.1]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([42.1]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([42.1]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript NaN values to a method which takes a - // Java array. - public void testPassNumberNaN() throws Throwable { - executeJavaScript("testObject.setBooleanArray([Number.NaN]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([Number.NaN]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - executeJavaScript("testObject.setCharArray([Number.NaN]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([Number.NaN]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([Number.NaN]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([Number.NaN]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([Number.NaN]);"); - assertEquals(Float.NaN, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([Number.NaN]);"); - assertEquals(Double.NaN, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([Number.NaN]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([Number.NaN]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([Number.NaN]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript infinity values to a method which - // takes a Java array. - public void testPassNumberInfinity() throws Throwable { - executeJavaScript("testObject.setBooleanArray([Infinity]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - executeJavaScript("testObject.setByteArray([Infinity]);"); - assertEquals(-1, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to maximum numeric char value. - executeJavaScript("testObject.setCharArray([Infinity]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([Infinity]);"); - assertEquals(-1, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([Infinity]);"); - assertEquals(Integer.MAX_VALUE, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be Long.MAX_VALUE. - executeJavaScript("testObject.setLongArray([Infinity]);"); - assertEquals(-1L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([Infinity]);"); - assertEquals(Float.POSITIVE_INFINITY, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([Infinity]);"); - assertEquals(Double.POSITIVE_INFINITY, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([Infinity]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([Infinity]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([Infinity]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript boolean values to a method which - // takes a Java array. - public void testPassBoolean() throws Throwable { - executeJavaScript("testObject.setBooleanArray([true]);"); - assertTrue(mTestObject.waitForBooleanArray()[0]); - executeJavaScript("testObject.setBooleanArray([false]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setByteArray([true]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - executeJavaScript("testObject.setByteArray([false]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should convert to numeric char value 1. - executeJavaScript("testObject.setCharArray([true]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - executeJavaScript("testObject.setCharArray([false]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setShortArray([true]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - executeJavaScript("testObject.setShortArray([false]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setIntArray([true]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - executeJavaScript("testObject.setIntArray([false]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1. - executeJavaScript("testObject.setLongArray([true]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - executeJavaScript("testObject.setLongArray([false]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1.0. - executeJavaScript("testObject.setFloatArray([true]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - executeJavaScript("testObject.setFloatArray([false]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should be 1.0. - executeJavaScript("testObject.setDoubleArray([true]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - executeJavaScript("testObject.setDoubleArray([false]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([true]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String. - executeJavaScript("testObject.setStringArray([true]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([true]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript strings to a method which takes a - // Java array. - public void testPassString() throws Throwable { - // LIVECONNECT_COMPLIANCE: Non-empty string should convert to true. - executeJavaScript("testObject.setBooleanArray([\"+042.10\"]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setByteArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should decode and convert to numeric char value. - executeJavaScript("testObject.setCharArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setShortArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setIntArray([\"+042.10\"]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setLongArray([\"+042.10\"]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setFloatArray([\"+042.10\"]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type. - executeJavaScript("testObject.setDoubleArray([\"+042.10\"]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number. - executeJavaScript("testObject.setObjectArray([\"+042.10\"]);"); - assertNull(mTestObject.waitForObjectArray()); - - executeJavaScript("testObject.setStringArray([\"+042.10\"]);"); - assertEquals("+042.10", mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([\"+042.10\"]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript objects to a method which takes a - // Java array. - public void testPassJavaScriptObject() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setBooleanArray([{foo: 42}]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setByteArray([{foo: 42}]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCharArray([{foo: 42}]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setShortArray([{foo: 42}]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray([{foo: 42}]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setLongArray([{foo: 42}]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setFloatArray([{foo: 42}]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setDoubleArray([{foo: 42}]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setObjectArray([{foo: 42}]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should call toString() on object. - executeJavaScript("testObject.setStringArray([{foo: 42}]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCustomTypeArray([{foo: 42}]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of Java objects to a method which takes a Java - // array. - public void testPassJavaObject() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setBooleanArray([testObject.getObjectInstance()]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setByteArray([testObject.getObjectInstance()]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setCharArray([testObject.getObjectInstance()]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setShortArray([testObject.getObjectInstance()]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray([testObject.getObjectInstance()]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setLongArray([testObject.getObjectInstance()]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setFloatArray([testObject.getObjectInstance()]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception. - executeJavaScript("testObject.setDoubleArray([testObject.getObjectInstance()]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create an array and pass Java object. - executeJavaScript("testObject.setObjectArray([testObject.getObjectInstance()]);"); - assertNull(mTestObject.waitForObjectArray()); - - // LIVECONNECT_COMPLIANCE: Should call toString() on object. - executeJavaScript("testObject.setStringArray([testObject.getObjectInstance()]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass Java object. - executeJavaScript("testObject.setCustomTypeArray([testObject.getObjectInstance()]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - executeJavaScript("testObject.setCustomTypeArray([testObject.getCustomTypeInstance()]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript null values to a method which takes - // a Java array. - public void testPassNull() throws Throwable { - executeJavaScript("testObject.setByteArray([null]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - executeJavaScript("testObject.setCharArray([null]);"); - assertEquals('\u0000', mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([null]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([null]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([null]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([null]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([null]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - executeJavaScript("testObject.setBooleanArray([null]);"); - assertFalse(mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setObjectArray([null]);"); - assertNull(mTestObject.waitForObjectArray()); - - executeJavaScript("testObject.setStringArray([null]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setCustomTypeArray([null]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } - - // Test passing an array of JavaScript undefined values to a method which - // takes a Java array. - public void testPassUndefined() throws Throwable { - executeJavaScript("testObject.setByteArray([undefined]);"); - assertEquals(0, mTestObject.waitForByteArray()[0]); - - executeJavaScript("testObject.setCharArray([undefined]);"); - assertEquals(0, mTestObject.waitForCharArray()[0]); - - executeJavaScript("testObject.setShortArray([undefined]);"); - assertEquals(0, mTestObject.waitForShortArray()[0]); - - executeJavaScript("testObject.setIntArray([undefined]);"); - assertEquals(0, mTestObject.waitForIntArray()[0]); - - executeJavaScript("testObject.setLongArray([undefined]);"); - assertEquals(0L, mTestObject.waitForLongArray()[0]); - - executeJavaScript("testObject.setFloatArray([undefined]);"); - assertEquals(0.0f, mTestObject.waitForFloatArray()[0]); - - executeJavaScript("testObject.setDoubleArray([undefined]);"); - assertEquals(0.0, mTestObject.waitForDoubleArray()[0]); - - executeJavaScript("testObject.setBooleanArray([undefined]);"); - assertEquals(false, mTestObject.waitForBooleanArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setObjectArray([undefined]);"); - assertNull(mTestObject.waitForObjectArray()); - - executeJavaScript("testObject.setStringArray([undefined]);"); - assertNull(mTestObject.waitForStringArray()[0]); - - // LIVECONNECT_COMPLIANCE: Should create array and pass null. - executeJavaScript("testObject.setCustomTypeArray([undefined]);"); - assertNull(mTestObject.waitForCustomTypeArray()); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java deleted file mode 100644 index 2fd42a7..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. This class tests the - * general use of arrays. - * - * The conversions should follow - * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in - * which the implementation differs from the spec are marked with - * LIVECONNECT_COMPLIANCE. - * FIXME: Consider making our implementation more compliant, if it will not - * break backwards-compatibility. See b/4408210. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeArrayTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeArrayTest extends JavaBridgeTestBase { - private class TestObject extends Controller { - private boolean mBooleanValue; - private int mIntValue; - private String mStringValue; - - private int[] mIntArray; - private int[][] mIntIntArray; - - private boolean mWasArrayMethodCalled; - - public synchronized void setBooleanValue(boolean x) { - mBooleanValue = x; - notifyResultIsReady(); - } - public synchronized void setIntValue(int x) { - mIntValue = x; - notifyResultIsReady(); - } - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - - public synchronized boolean waitForBooleanValue() { - waitForResult(); - return mBooleanValue; - } - public synchronized int waitForIntValue() { - waitForResult(); - return mIntValue; - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - - public synchronized void setIntArray(int[] x) { - mIntArray = x; - notifyResultIsReady(); - } - public synchronized void setIntIntArray(int[][] x) { - mIntIntArray = x; - notifyResultIsReady(); - } - - public synchronized int[] waitForIntArray() { - waitForResult(); - return mIntArray; - } - public synchronized int[][] waitForIntIntArray() { - waitForResult(); - return mIntIntArray; - } - - public synchronized int[] arrayMethod() { - mWasArrayMethodCalled = true; - return new int[] {42, 43, 44}; - } - - public synchronized boolean wasArrayMethodCalled() { - return mWasArrayMethodCalled; - } - } - - private TestObject mTestObject; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestObject = new TestObject(); - setUpWebView(mTestObject, "testObject"); - } - - public void testArrayLength() throws Throwable { - executeJavaScript("testObject.setIntArray([42, 43, 44]);"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(3, result.length); - assertEquals(42, result[0]); - assertEquals(43, result[1]); - assertEquals(44, result[2]); - } - - public void testPassNull() throws Throwable { - executeJavaScript("testObject.setIntArray(null);"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testPassUndefined() throws Throwable { - executeJavaScript("testObject.setIntArray(undefined);"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testPassEmptyArray() throws Throwable { - executeJavaScript("testObject.setIntArray([]);"); - assertEquals(0, mTestObject.waitForIntArray().length); - } - - // Note that this requires being able to pass a string from JavaScript to - // Java. - public void testPassArrayToStringMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should call toString() on array. - executeJavaScript("testObject.setStringValue([42, 42, 42]);"); - assertEquals("undefined", mTestObject.waitForStringValue()); - } - - // Note that this requires being able to pass an integer from JavaScript to - // Java. - public void testPassArrayToNonStringNonArrayMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise JavaScript exception. - executeJavaScript("testObject.setIntValue([42, 42, 42]);"); - assertEquals(0, mTestObject.waitForIntValue()); - } - - public void testPassNonArrayToArrayMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should raise JavaScript exception. - executeJavaScript("testObject.setIntArray(42);"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testObjectWithLengthProperty() throws Throwable { - executeJavaScript("testObject.setIntArray({length: 3, 1: 42});"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(3, result.length); - assertEquals(0, result[0]); - assertEquals(42, result[1]); - assertEquals(0, result[2]); - } - - public void testNonNumericLengthProperty() throws Throwable { - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray({length: \"foo\"});"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testLengthOutOfBounds() throws Throwable { - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - executeJavaScript("testObject.setIntArray({length: -1});"); - assertNull(mTestObject.waitForIntArray()); - - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - long length = (long)Integer.MAX_VALUE + 1L; - executeJavaScript("testObject.setIntArray({length: " + length + "});"); - assertNull(mTestObject.waitForIntArray()); - - // LIVECONNECT_COMPLIANCE: This should not count as an array, so we - // should raise a JavaScript exception. - length = (long)Integer.MAX_VALUE + 1L - (long)Integer.MIN_VALUE + 1L; - executeJavaScript("testObject.setIntArray({length: " + length + "});"); - assertNull(mTestObject.waitForIntArray()); - } - - public void testSparseArray() throws Throwable { - executeJavaScript("var x = [42, 43]; x[3] = 45; testObject.setIntArray(x);"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(4, result.length); - assertEquals(42, result[0]); - assertEquals(43, result[1]); - assertEquals(0, result[2]); - assertEquals(45, result[3]); - } - - // Note that this requires being able to pass a boolean from JavaScript to - // Java. - public void testMethodReturningArrayNotCalled() throws Throwable { - // We don't invoke methods which return arrays, but note that no - // exception is raised. - // LIVECONNECT_COMPLIANCE: Should call method and convert result to - // JavaScript array. - executeJavaScript("testObject.setBooleanValue(undefined === testObject.arrayMethod())"); - assertTrue(mTestObject.waitForBooleanValue()); - assertFalse(mTestObject.wasArrayMethodCalled()); - } - - public void testMultiDimensionalArrayMethod() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays. - executeJavaScript("testObject.setIntIntArray([ [42, 43], [44, 45] ]);"); - assertNull(mTestObject.waitForIntIntArray()); - } - - public void testPassMultiDimensionalArray() throws Throwable { - // LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays. - executeJavaScript("testObject.setIntArray([ [42, 43], [44, 45] ]);"); - int[] result = mTestObject.waitForIntArray(); - assertEquals(2, result.length); - assertEquals(0, result[0]); - assertEquals(0, result[1]); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java deleted file mode 100644 index 1ecccf6..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. Tests a number of features including ... - * - The type of injected objects - * - The type of their methods - * - Replacing objects - * - Removing objects - * - Access control - * - Calling methods on returned objects - * - Multiply injected objects - * - Threading - * - Inheritance - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeBasicsTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeBasicsTest extends JavaBridgeTestBase { - private class TestController extends Controller { - private int mIntValue; - private long mLongValue; - private String mStringValue; - private boolean mBooleanValue; - - public synchronized void setIntValue(int x) { - mIntValue = x; - notifyResultIsReady(); - } - public synchronized void setLongValue(long x) { - mLongValue = x; - notifyResultIsReady(); - } - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized void setBooleanValue(boolean x) { - mBooleanValue = x; - notifyResultIsReady(); - } - - public synchronized int waitForIntValue() { - waitForResult(); - return mIntValue; - } - public synchronized long waitForLongValue() { - waitForResult(); - return mLongValue; - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - public synchronized boolean waitForBooleanValue() { - waitForResult(); - return mBooleanValue; - } - } - - private static class ObjectWithStaticMethod { - public static String staticMethod() { - return "foo"; - } - } - - TestController mTestController; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestController = new TestController(); - setUpWebView(mTestController, "testController"); - } - - // Note that this requires that we can pass a JavaScript string to Java. - protected String executeJavaScriptAndGetStringResult(String script) throws Throwable { - executeJavaScript("testController.setStringValue(" + script + ");"); - return mTestController.waitForStringValue(); - } - - protected void injectObjectAndReload(final Object object, final String name) throws Throwable { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(object, name); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - } - - // Note that this requires that we can pass a JavaScript boolean to Java. - private void assertRaisesException(String script) throws Throwable { - executeJavaScript("try {" + - script + ";" + - " testController.setBooleanValue(false);" + - "} catch (exception) {" + - " testController.setBooleanValue(true);" + - "}"); - assertTrue(mTestController.waitForBooleanValue()); - } - - public void testTypeOfInjectedObject() throws Throwable { - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController")); - } - - public void testAdditionNotReflectedUntilReload() throws Throwable { - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(new Object(), "testObject"); - } - }); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testRemovalNotReflectedUntilReload() throws Throwable { - injectObjectAndReload(new Object(), "testObject"); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().removeJavascriptInterface("testObject"); - } - }); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testRemoveObjectNotAdded() throws Throwable { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().removeJavascriptInterface("foo"); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof foo")); - } - - public void testTypeOfMethod() throws Throwable { - assertEquals("function", - executeJavaScriptAndGetStringResult("typeof testController.setStringValue")); - } - - public void testTypeOfInvalidMethod() throws Throwable { - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testController.foo")); - } - - public void testCallingInvalidMethodRaisesException() throws Throwable { - assertRaisesException("testController.foo()"); - } - - public void testUncaughtJavaExceptionRaisesJavaException() throws Throwable { - injectObjectAndReload(new Object() { - public void method() { throw new RuntimeException("foo"); } - }, "testObject"); - assertRaisesException("testObject.method()"); - } - - // Note that this requires that we can pass a JavaScript string to Java. - public void testTypeOfStaticMethod() throws Throwable { - injectObjectAndReload(new ObjectWithStaticMethod(), "testObject"); - executeJavaScript("testController.setStringValue(typeof testObject.staticMethod)"); - assertEquals("function", mTestController.waitForStringValue()); - } - - // Note that this requires that we can pass a JavaScript string to Java. - public void testCallStaticMethod() throws Throwable { - injectObjectAndReload(new ObjectWithStaticMethod(), "testObject"); - executeJavaScript("testController.setStringValue(testObject.staticMethod())"); - assertEquals("foo", mTestController.waitForStringValue()); - } - - public void testPrivateMethodNotExposed() throws Throwable { - injectObjectAndReload(new Object() { - private void method() {} - }, "testObject"); - assertEquals("undefined", - executeJavaScriptAndGetStringResult("typeof testObject.method")); - } - - public void testReplaceInjectedObject() throws Throwable { - injectObjectAndReload(new Object() { - public void method() { mTestController.setStringValue("object 1"); } - }, "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("object 1", mTestController.waitForStringValue()); - - injectObjectAndReload(new Object() { - public void method() { mTestController.setStringValue("object 2"); } - }, "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("object 2", mTestController.waitForStringValue()); - } - - public void testInjectNullObjectIsIgnored() throws Throwable { - injectObjectAndReload(null, "testObject"); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testReplaceInjectedObjectWithNullObjectIsIgnored() throws Throwable { - injectObjectAndReload(new Object(), "testObject"); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - injectObjectAndReload(null, "testObject"); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testObject")); - } - - public void testCallOverloadedMethodWithDifferentNumberOfArguments() throws Throwable { - injectObjectAndReload(new Object() { - public void method() { mTestController.setStringValue("0 args"); } - public void method(int x) { mTestController.setStringValue("1 arg"); } - public void method(int x, int y) { mTestController.setStringValue("2 args"); } - }, "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("0 args", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(42)"); - assertEquals("1 arg", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(null)"); - assertEquals("1 arg", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(undefined)"); - assertEquals("1 arg", mTestController.waitForStringValue()); - executeJavaScript("testObject.method(42, 42)"); - assertEquals("2 args", mTestController.waitForStringValue()); - } - - public void testCallMethodWithWrongNumberOfArgumentsRaisesException() throws Throwable { - assertRaisesException("testController.setIntValue()"); - assertRaisesException("testController.setIntValue(42, 42)"); - } - - public void testObjectPersistsAcrossPageLoads() throws Throwable { - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController")); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController")); - } - - public void testSameObjectInjectedMultipleTimes() throws Throwable { - class TestObject { - private int mNumMethodInvocations; - public void method() { mTestController.setIntValue(++mNumMethodInvocations); } - } - final TestObject testObject = new TestObject(); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(testObject, "testObject1"); - getWebView().addJavascriptInterface(testObject, "testObject2"); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - executeJavaScript("testObject1.method()"); - assertEquals(1, mTestController.waitForIntValue()); - executeJavaScript("testObject2.method()"); - assertEquals(2, mTestController.waitForIntValue()); - } - - public void testCallMethodOnReturnedObject() throws Throwable { - injectObjectAndReload(new Object() { - public Object getInnerObject() { - return new Object() { - public void method(int x) { mTestController.setIntValue(x); } - }; - } - }, "testObject"); - executeJavaScript("testObject.getInnerObject().method(42)"); - assertEquals(42, mTestController.waitForIntValue()); - } - - public void testReturnedObjectInjectedElsewhere() throws Throwable { - class InnerObject { - private int mNumMethodInvocations; - public void method() { mTestController.setIntValue(++mNumMethodInvocations); } - } - final InnerObject innerObject = new InnerObject(); - final Object object = new Object() { - public InnerObject getInnerObject() { - return innerObject; - } - }; - runTestOnUiThread(new Runnable() { - @Override - public void run() { - getWebView().addJavascriptInterface(object, "testObject"); - getWebView().addJavascriptInterface(innerObject, "innerObject"); - getWebView().reload(); - } - }); - mWebViewClient.waitForOnPageFinished(); - executeJavaScript("testObject.getInnerObject().method()"); - assertEquals(1, mTestController.waitForIntValue()); - executeJavaScript("innerObject.method()"); - assertEquals(2, mTestController.waitForIntValue()); - } - - public void testMethodInvokedOnBackgroundThread() throws Throwable { - injectObjectAndReload(new Object() { - public void captureThreadId() { - mTestController.setLongValue(Thread.currentThread().getId()); - } - }, "testObject"); - executeJavaScript("testObject.captureThreadId()"); - final long threadId = mTestController.waitForLongValue(); - assertFalse(threadId == Thread.currentThread().getId()); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - assertFalse(threadId == Thread.currentThread().getId()); - } - }); - } - - public void testPublicInheritedMethod() throws Throwable { - class Base { - public void method(int x) { mTestController.setIntValue(x); } - } - class Derived extends Base { - } - injectObjectAndReload(new Derived(), "testObject"); - assertEquals("function", executeJavaScriptAndGetStringResult("typeof testObject.method")); - executeJavaScript("testObject.method(42)"); - assertEquals(42, mTestController.waitForIntValue()); - } - - public void testPrivateInheritedMethod() throws Throwable { - class Base { - private void method() {} - } - class Derived extends Base { - } - injectObjectAndReload(new Derived(), "testObject"); - assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testObject.method")); - } - - public void testOverriddenMethod() throws Throwable { - class Base { - public void method() { mTestController.setStringValue("base"); } - } - class Derived extends Base { - public void method() { mTestController.setStringValue("derived"); } - } - injectObjectAndReload(new Derived(), "testObject"); - executeJavaScript("testObject.method()"); - assertEquals("derived", mTestController.waitForStringValue()); - } - - public void testEnumerateMembers() throws Throwable { - injectObjectAndReload(new Object() { - public void method() {} - private void privateMethod() {} - public int field; - private int privateField; - }, "testObject"); - executeJavaScript( - "var result = \"\"; " + - "for (x in testObject) { result += \" \" + x } " + - "testController.setStringValue(result);"); - // LIVECONNECT_COMPLIANCE: Should be able to enumerate members. - assertEquals("", mTestController.waitForStringValue()); - } - - public void testReflectPublicMethod() throws Throwable { - injectObjectAndReload(new Object() { - public String method() { return "foo"; } - }, "testObject"); - assertEquals("foo", executeJavaScriptAndGetStringResult( - "testObject.getClass().getMethod('method', null).invoke(testObject, null)" + - ".toString()")); - } - - public void testReflectPublicField() throws Throwable { - injectObjectAndReload(new Object() { - public String field = "foo"; - }, "testObject"); - assertEquals("foo", executeJavaScriptAndGetStringResult( - "testObject.getClass().getField('field').get(testObject).toString()")); - } - - public void testReflectPrivateMethodRaisesException() throws Throwable { - injectObjectAndReload(new Object() { - private void method() {}; - }, "testObject"); - assertRaisesException("testObject.getClass().getMethod('method', null)"); - // getDeclaredMethod() is able to access a private method, but invoke() - // throws a Java exception. - assertRaisesException( - "testObject.getClass().getDeclaredMethod('method', null).invoke(testObject, null)"); - } - - public void testReflectPrivateFieldRaisesException() throws Throwable { - injectObjectAndReload(new Object() { - private int field; - }, "testObject"); - assertRaisesException("testObject.getClass().getField('field')"); - // getDeclaredField() is able to access a private field, but getInt() - // throws a Java exception. - assertRaisesException( - "testObject.getClass().getDeclaredField('field').getInt(testObject)"); - } -} diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java deleted file mode 100644 index 3f0e2b3..0000000 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeChildFrameTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -/** - * Part of the test suite for the WebView's Java Bridge. - * - * Ensures that injected objects are exposed to child frames as well as the - * main frame. - * - * To run this test ... - * adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeChildFrameTest \ - * com.android.webviewtests/android.test.InstrumentationTestRunner - */ - -package com.android.webviewtests; - -public class JavaBridgeChildFrameTest extends JavaBridgeTestBase { - private class TestController extends Controller { - private String mStringValue; - - public synchronized void setStringValue(String x) { - mStringValue = x; - notifyResultIsReady(); - } - public synchronized String waitForStringValue() { - waitForResult(); - return mStringValue; - } - } - - TestController mTestController; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mTestController = new TestController(); - setUpWebView(mTestController, "testController"); - } - - public void testInjectedObjectPresentInChildFrame() throws Throwable { - // In the case that the test fails (i.e. the child frame doesn't get the injected object, - // the call to testController.setStringValue in the child frame's onload handler will - // not be made. - getActivity().getWebView().loadData( - "" + - "