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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeFieldsTest.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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.support.test.filters.SmallTest; 7 import android.support.test.filters.SmallTest;
8 8
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14
9 import org.chromium.base.annotations.SuppressFBWarnings; 15 import org.chromium.base.annotations.SuppressFBWarnings;
16 import org.chromium.base.test.BaseJUnit4ClassRunner;
10 import org.chromium.base.test.util.Feature; 17 import org.chromium.base.test.util.Feature;
11 import org.chromium.content.browser.JavaBridgeTestCommon.Controller; 18 import org.chromium.content.browser.JavaBridgeTestCommon.Controller;
12 19
13 /** 20 /**
14 * Part of the test suite for the Java Bridge. This test tests the 21 * Part of the test suite for the Java Bridge. This test tests the
15 * use of fields. 22 * use of fields.
16 */ 23 */
17 public class JavaBridgeFieldsTest extends JavaBridgeTestBase { 24 @RunWith(BaseJUnit4ClassRunner.class)
25 public class JavaBridgeFieldsTest {
26 @Rule
27 public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivity TestRule();
28
18 @SuppressFBWarnings({"CHROMIUM_SYNCHRONIZED_METHOD", "URF_UNREAD_PUBLIC_OR_P ROTECTED_FIELD"}) 29 @SuppressFBWarnings({"CHROMIUM_SYNCHRONIZED_METHOD", "URF_UNREAD_PUBLIC_OR_P ROTECTED_FIELD"})
19 private static class TestObject extends Controller { 30 private static class TestObject extends Controller {
20 private String mStringValue; 31 private String mStringValue;
21 32
22 // These methods are used to control the test. 33 // These methods are used to control the test.
23 public synchronized void setStringValue(String x) { 34 public synchronized void setStringValue(String x) {
24 mStringValue = x; 35 mStringValue = x;
25 notifyResultIsReady(); 36 notifyResultIsReady();
26 } 37 }
27 public synchronized String waitForStringValue() { 38 public synchronized String waitForStringValue() {
(...skipping 13 matching lines...) Expand all
41 public Object objectField = new Object(); 52 public Object objectField = new Object();
42 public CustomType customTypeField = new CustomType(); 53 public CustomType customTypeField = new CustomType();
43 } 54 }
44 55
45 // A custom type used when testing passing objects. 56 // A custom type used when testing passing objects.
46 private static class CustomType { 57 private static class CustomType {
47 } 58 }
48 59
49 TestObject mTestObject; 60 TestObject mTestObject;
50 61
51 @Override 62 @Before
52 protected void setUp() throws Exception { 63 public void setUp() throws Exception {
53 super.setUp();
54 mTestObject = new TestObject(); 64 mTestObject = new TestObject();
55 injectObjectAndReload(mTestObject, "testObject"); 65 mActivityTestRule.injectObjectAndReload(mTestObject, "testObject");
56 } 66 }
57 67
58 // Note that this requires that we can pass a JavaScript string to Java. 68 // Note that this requires that we can pass a JavaScript string to Java.
59 protected String executeJavaScriptAndGetStringResult(String script) throws T hrowable { 69 protected String executeJavaScriptAndGetStringResult(String script) throws T hrowable {
60 executeJavaScript("testObject.setStringValue(" + script + ");"); 70 mActivityTestRule.executeJavaScript("testObject.setStringValue(" + scrip t + ");");
61 return mTestObject.waitForStringValue(); 71 return mTestObject.waitForStringValue();
62 } 72 }
63 73
64 // The Java bridge does not provide access to fields. 74 // The Java bridge does not provide access to fields.
65 // FIXME: Consider providing support for this. See See b/4408210. 75 // FIXME: Consider providing support for this. See See b/4408210.
76 @Test
66 @SmallTest 77 @SmallTest
67 @Feature({"AndroidWebView", "Android-JavaBridge"}) 78 @Feature({"AndroidWebView", "Android-JavaBridge"})
68 public void testFieldTypes() throws Throwable { 79 public void testFieldTypes() throws Throwable {
69 assertEquals("undefined", 80 Assert.assertEquals(
70 executeJavaScriptAndGetStringResult("typeof testObject.booleanFi eld")); 81 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.booleanField"));
71 assertEquals("undefined", 82 Assert.assertEquals(
72 executeJavaScriptAndGetStringResult("typeof testObject.byteField ")); 83 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.byteField"));
73 assertEquals("undefined", 84 Assert.assertEquals(
74 executeJavaScriptAndGetStringResult("typeof testObject.charField ")); 85 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.charField"));
75 assertEquals("undefined", 86 Assert.assertEquals(
76 executeJavaScriptAndGetStringResult("typeof testObject.shortFiel d")); 87 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.shortField"));
77 assertEquals("undefined", 88 Assert.assertEquals(
78 executeJavaScriptAndGetStringResult("typeof testObject.intField" )); 89 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.intField"));
79 assertEquals("undefined", 90 Assert.assertEquals(
80 executeJavaScriptAndGetStringResult("typeof testObject.longField ")); 91 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.longField"));
81 assertEquals("undefined", 92 Assert.assertEquals(
82 executeJavaScriptAndGetStringResult("typeof testObject.floatFiel d")); 93 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.floatField"));
83 assertEquals("undefined", 94 Assert.assertEquals(
84 executeJavaScriptAndGetStringResult("typeof testObject.doubleFie ld")); 95 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.doubleField"));
85 assertEquals("undefined", 96 Assert.assertEquals(
86 executeJavaScriptAndGetStringResult("typeof testObject.objectFie ld")); 97 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.objectField"));
87 assertEquals("undefined", 98 Assert.assertEquals(
88 executeJavaScriptAndGetStringResult("typeof testObject.stringFie ld")); 99 "undefined", executeJavaScriptAndGetStringResult("typeof testObj ect.stringField"));
89 assertEquals("undefined", 100 Assert.assertEquals("undefined",
90 executeJavaScriptAndGetStringResult("typeof testObject.customTyp eField")); 101 executeJavaScriptAndGetStringResult("typeof testObject.customTyp eField"));
91 } 102 }
92 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698