Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2616)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeArrayTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeArrayTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeArrayTest.java b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeArrayTest.java
index 2be60b5ab3f10993bf6138a40b49c7ca6996cc10..f4001b8fd00308071f22a2659bec0a26bc6c48df 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeArrayTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeArrayTest.java
@@ -6,7 +6,14 @@ package org.chromium.content.browser;
import android.support.test.filters.SmallTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.annotations.SuppressFBWarnings;
+import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeTestCommon.Controller;
@@ -20,7 +27,11 @@ import org.chromium.content.browser.JavaBridgeTestCommon.Controller;
* FIXME: Consider making our implementation more compliant, if it will not
* break backwards-compatibility. See b/4408210.
*/
-public class JavaBridgeArrayTest extends JavaBridgeTestBase {
+@RunWith(BaseJUnit4ClassRunner.class)
+public class JavaBridgeArrayTest {
+ @Rule
+ public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
+
@SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD")
private static class TestObject extends Controller {
private boolean mBooleanValue;
@@ -88,128 +99,140 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
private TestObject mTestObject;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mTestObject = new TestObject();
- injectObjectAndReload(mTestObject, "testObject");
+ mActivityTestRule.injectObjectAndReload(mTestObject, "testObject");
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testArrayLength() throws Throwable {
- executeJavaScript("testObject.setIntArray([42, 43, 44]);");
+ mActivityTestRule.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]);
+ Assert.assertEquals(3, result.length);
+ Assert.assertEquals(42, result[0]);
+ Assert.assertEquals(43, result[1]);
+ Assert.assertEquals(44, result[2]);
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassNull() throws Throwable {
- executeJavaScript("testObject.setIntArray(null);");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray(null);");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassUndefined() throws Throwable {
- executeJavaScript("testObject.setIntArray(undefined);");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray(undefined);");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassEmptyArray() throws Throwable {
- executeJavaScript("testObject.setIntArray([]);");
- assertEquals(0, mTestObject.waitForIntArray().length);
+ mActivityTestRule.executeJavaScript("testObject.setIntArray([]);");
+ Assert.assertEquals(0, mTestObject.waitForIntArray().length);
}
// Note that this requires being able to pass a string from JavaScript to
// Java.
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassArrayToStringMethod() throws Throwable {
// LIVECONNECT_COMPLIANCE: Should call toString() on array.
- executeJavaScript("testObject.setStringValue([42, 42, 42]);");
- assertEquals("undefined", mTestObject.waitForStringValue());
+ mActivityTestRule.executeJavaScript("testObject.setStringValue([42, 42, 42]);");
+ Assert.assertEquals("undefined", mTestObject.waitForStringValue());
}
// Note that this requires being able to pass an integer from JavaScript to
// Java.
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassArrayToNonStringNonArrayMethod() throws Throwable {
// LIVECONNECT_COMPLIANCE: Should raise JavaScript exception.
- executeJavaScript("testObject.setIntValue([42, 42, 42]);");
- assertEquals(0, mTestObject.waitForIntValue());
+ mActivityTestRule.executeJavaScript("testObject.setIntValue([42, 42, 42]);");
+ Assert.assertEquals(0, mTestObject.waitForIntValue());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassNonArrayToArrayMethod() throws Throwable {
// LIVECONNECT_COMPLIANCE: Should raise JavaScript exception.
- executeJavaScript("testObject.setIntArray(42);");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray(42);");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testObjectWithLengthProperty() throws Throwable {
- executeJavaScript("testObject.setIntArray({length: 3, 1: 42});");
+ mActivityTestRule.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]);
+ Assert.assertEquals(3, result.length);
+ Assert.assertEquals(0, result[0]);
+ Assert.assertEquals(42, result[1]);
+ Assert.assertEquals(0, result[2]);
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
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());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray({length: \"foo\"});");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
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());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray({length: -1});");
+ Assert.assertNull(mTestObject.waitForIntArray());
// LIVECONNECT_COMPLIANCE: This should not count as an array, so we
// should raise a JavaScript exception.
long length = Integer.MAX_VALUE + 1L;
- executeJavaScript("testObject.setIntArray({length: " + length + "});");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray({length: " + length + "});");
+ Assert.assertNull(mTestObject.waitForIntArray());
// LIVECONNECT_COMPLIANCE: This should not count as an array, so we
// should raise a JavaScript exception.
length = Integer.MAX_VALUE + 1L - Integer.MIN_VALUE + 1L;
- executeJavaScript("testObject.setIntArray({length: " + length + "});");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("testObject.setIntArray({length: " + length + "});");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testSparseArray() throws Throwable {
- executeJavaScript("var x = [42, 43]; x[3] = 45; testObject.setIntArray(x);");
+ mActivityTestRule.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]);
+ Assert.assertEquals(4, result.length);
+ Assert.assertEquals(42, result[0]);
+ Assert.assertEquals(43, result[1]);
+ Assert.assertEquals(0, result[2]);
+ Assert.assertEquals(45, result[3]);
}
// Note that this requires being able to pass a boolean from JavaScript to
// Java.
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testMethodReturningArrayNotCalled() throws Throwable {
@@ -217,39 +240,43 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
// 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());
+ mActivityTestRule.executeJavaScript(
+ "testObject.setBooleanValue(undefined === testObject.arrayMethod())");
+ Assert.assertTrue(mTestObject.waitForBooleanValue());
+ Assert.assertFalse(mTestObject.wasArrayMethodCalled());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testMultiDimensionalArrayMethod() throws Throwable {
// LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays.
- executeJavaScript("testObject.setIntIntArray([ [42, 43], [44, 45] ]);");
- assertNull(mTestObject.waitForIntIntArray());
+ mActivityTestRule.executeJavaScript("testObject.setIntIntArray([ [42, 43], [44, 45] ]);");
+ Assert.assertNull(mTestObject.waitForIntIntArray());
}
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassMultiDimensionalArray() throws Throwable {
// LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays.
- executeJavaScript("testObject.setIntArray([ [42, 43], [44, 45] ]);");
+ mActivityTestRule.executeJavaScript("testObject.setIntArray([ [42, 43], [44, 45] ]);");
int[] result = mTestObject.waitForIntArray();
- assertEquals(2, result.length);
- assertEquals(0, result[0]);
- assertEquals(0, result[1]);
+ Assert.assertEquals(2, result.length);
+ Assert.assertEquals(0, result[0]);
+ Assert.assertEquals(0, result[1]);
}
// Verify that ArrayBuffers are not converted into arrays when passed to Java.
// The LiveConnect spec doesn't mention ArrayBuffers, so it doesn't seem to
// be a compliance issue.
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassArrayBuffer() throws Throwable {
- executeJavaScript("buffer = new ArrayBuffer(16);");
- executeJavaScript("testObject.setIntArray(buffer);");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(16);");
+ mActivityTestRule.executeJavaScript("testObject.setIntArray(buffer);");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
// Verify that ArrayBufferViews are not converted into arrays when passed to Java.
@@ -258,11 +285,12 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
// Here, a DataView is used as an ArrayBufferView instance (since the latter is
// an interface and can't be instantiated directly). See also JavaBridgeArrayCoercionTest
// for typed arrays (that also subclass ArrayBufferView) tests.
+ @Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPassDataView() throws Throwable {
- executeJavaScript("buffer = new ArrayBuffer(16);");
- executeJavaScript("testObject.setIntArray(new DataView(buffer));");
- assertNull(mTestObject.waitForIntArray());
+ mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(16);");
+ mActivityTestRule.executeJavaScript("testObject.setIntArray(new DataView(buffer));");
+ Assert.assertNull(mTestObject.waitForIntArray());
}
}

Powered by Google App Engine
This is Rietveld 408576698