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

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

Issue 692933002: [Android] Add JavaBridgeBasicsTest#testReplaceJavascriptInterface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
index 17cbbd6c479db99352bfe76fa83dad12e2732265..6745a4085c73ae196401f1cc6449d8efa068f284 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
@@ -138,12 +138,12 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
// 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);" +
- "}");
+ executeJavaScript("try {"
+ + script + ";"
+ + " testController.setBooleanValue(false);"
+ + "} catch (exception) {"
+ + " testController.setBooleanValue(true);"
+ + "}");
assertTrue(mTestController.waitForBooleanValue());
}
@@ -461,9 +461,9 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
// Initially, store a reference to the inner object in JS to make sure it's not
// garbage-collected prematurely.
assertEquals("object", executeJavaScriptAndGetStringResult(
- "(function() { " +
- "globalInner = testObject.getInnerObject(); return typeof globalInner; " +
- "})()"));
+ "(function() { "
+ + "globalInner = testObject.getInnerObject(); return typeof globalInner; "
+ + "})()"));
assertTrue(object.mWeakRefForInner.get() != null);
// Check that returned Java object is being held by the Java bridge, thus it's not
// collected. Note that despite that what JavaDoc says about invoking "gc()", both Dalvik
@@ -472,9 +472,9 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
assertTrue(object.mWeakRefForInner.get() != null);
// Now dereference the inner object in JS and run GC to collect the interface object.
assertEquals("true", executeJavaScriptAndGetStringResult(
- "(function() { " +
- "delete globalInner; gc(); return (typeof globalInner == 'undefined'); " +
- "})()"));
+ "(function() { "
+ + "delete globalInner; gc(); return (typeof globalInner == 'undefined'); "
+ + "})()"));
// Force GC on the Java side again. The bridge had to release the inner object, so it must
// be collected this time.
Runtime.getRuntime().gc();
@@ -576,9 +576,9 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
private int mPrivateField;
}, "testObject");
executeJavaScript(
- "var result = \"\"; " +
- "for (x in testObject) { result += \" \" + x } " +
- "testController.setStringValue(result);");
+ "var result = \"\"; "
+ + "for (x in testObject) { result += \" \" + x } "
+ + "testController.setStringValue(result);");
assertEquals(" equals getClass hashCode method notify notifyAll toString wait",
mTestController.waitForStringValue());
}
@@ -596,8 +596,8 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
}
}, "testObject");
assertEquals("foo", executeJavaScriptAndGetStringResult(
- "testObject.myGetClass().getMethod('method', null).invoke(testObject, null)" +
- ".toString()"));
+ "testObject.myGetClass().getMethod('method', null).invoke(testObject, null)"
+ + ".toString()"));
}
@SmallTest
@@ -628,8 +628,8 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
// getDeclaredMethod() is able to access a private method, but invoke()
// throws a Java exception.
assertRaisesException(
- "testObject.myGetClass().getDeclaredMethod('method', null)." +
- "invoke(testObject, null)");
+ "testObject.myGetClass().getDeclaredMethod('method', null)."
+ + "invoke(testObject, null)");
}
@SmallTest
@@ -873,9 +873,9 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
final String jsObjectKeysTestTemplate = "Object.keys(%s).toString()";
final String jsForInTestTemplate =
- "(function(){" +
- " var s=[]; for(var m in %s) s.push(m); return s.join(\",\")" +
- "})()";
+ "(function(){"
+ + " var s=[]; for(var m in %s) s.push(m); return s.join(\",\")"
+ + "})()";
final String inspectableObjectName = "testObj1";
final String nonInspectableObjectName = "testObj2";
@@ -909,4 +909,26 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
assertEquals("function", executeJavaScriptAndGetStringResult("typeof testObject.getClass"));
assertRaisesException("testObject.getClass()");
}
+
+ @SmallTest
+ @Feature({"AndroidWebView", "Android-JavaBridge"})
+ public void testReplaceJavascriptInterface() throws Throwable {
+ class Test {
+ public Test(int value) {
+ mValue = value;
+ }
+ @JavascriptInterface
+ public int getValue() {
+ return mValue;
+ }
+ private int mValue;
+ }
+ injectObjectAndReload(new Test(13), "testObject");
+ assertEquals("13", executeJavaScriptAndGetStringResult("testObject.getValue()"));
+ // The documentation doesn't specify, what happens if the embedder is trying
+ // to inject a different object under the same name. The current implementation
+ // simply replaces the old object with the new one.
+ injectObjectAndReload(new Test(42), "testObject");
+ assertEquals("42", executeJavaScriptAndGetStringResult("testObject.getValue()"));
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698