OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.content.browser; | |
6 | |
7 import android.test.suitebuilder.annotation.SmallTest; | |
8 | |
9 import org.chromium.base.test.util.Feature; | |
10 | |
11 /** | |
12 * Part of the test suite for the Java Bridge. This test tests the | |
13 * use of fields. | |
14 */ | |
15 public class JavaBridgeFieldsTest extends JavaBridgeTestBase { | |
16 private class TestObject extends Controller { | |
17 private String mStringValue; | |
18 | |
19 // These methods are used to control the test. | |
20 public synchronized void setStringValue(String x) { | |
21 mStringValue = x; | |
22 notifyResultIsReady(); | |
23 } | |
24 public synchronized String waitForStringValue() { | |
25 waitForResult(); | |
26 return mStringValue; | |
27 } | |
28 | |
29 public boolean booleanField = true; | |
30 public byte byteField = 42; | |
31 public char charField = '\u002A'; | |
32 public short shortField = 42; | |
33 public int intField = 42; | |
34 public long longField = 42L; | |
35 public float floatField = 42.0f; | |
36 public double doubleField = 42.0; | |
37 public String stringField = "foo"; | |
38 public Object objectField = new Object(); | |
39 public CustomType customTypeField = new CustomType(); | |
40 } | |
41 | |
42 // A custom type used when testing passing objects. | |
43 private static class CustomType { | |
44 } | |
45 | |
46 TestObject mTestObject; | |
47 | |
48 @Override | |
49 protected void setUp() throws Exception { | |
50 super.setUp(); | |
51 mTestObject = new TestObject(); | |
52 setUpContentView(mTestObject, "testObject"); | |
53 } | |
54 | |
55 // Note that this requires that we can pass a JavaScript string to Java. | |
56 protected String executeJavaScriptAndGetStringResult(String script) throws T
hrowable { | |
57 executeJavaScript("testObject.setStringValue(" + script + ");"); | |
58 return mTestObject.waitForStringValue(); | |
59 } | |
60 | |
61 // The Java bridge does not provide access to fields. | |
62 // FIXME: Consider providing support for this. See See b/4408210. | |
63 @SmallTest | |
64 @Feature({"AndroidWebView", "Android-JavaBridge"}) | |
65 public void testFieldTypes() throws Throwable { | |
66 assertEquals("undefined", | |
67 executeJavaScriptAndGetStringResult("typeof testObject.booleanFi
eld")); | |
68 assertEquals("undefined", | |
69 executeJavaScriptAndGetStringResult("typeof testObject.byteField
")); | |
70 assertEquals("undefined", | |
71 executeJavaScriptAndGetStringResult("typeof testObject.charField
")); | |
72 assertEquals("undefined", | |
73 executeJavaScriptAndGetStringResult("typeof testObject.shortFiel
d")); | |
74 assertEquals("undefined", | |
75 executeJavaScriptAndGetStringResult("typeof testObject.intField"
)); | |
76 assertEquals("undefined", | |
77 executeJavaScriptAndGetStringResult("typeof testObject.longField
")); | |
78 assertEquals("undefined", | |
79 executeJavaScriptAndGetStringResult("typeof testObject.floatFiel
d")); | |
80 assertEquals("undefined", | |
81 executeJavaScriptAndGetStringResult("typeof testObject.doubleFie
ld")); | |
82 assertEquals("undefined", | |
83 executeJavaScriptAndGetStringResult("typeof testObject.objectFie
ld")); | |
84 assertEquals("undefined", | |
85 executeJavaScriptAndGetStringResult("typeof testObject.stringFie
ld")); | |
86 assertEquals("undefined", | |
87 executeJavaScriptAndGetStringResult("typeof testObject.customTyp
eField")); | |
88 } | |
89 } | |
OLD | NEW |