Commit 5a228308 authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Add test for using postMessage around loadData API

Test that source origin is a non-null string of n,u,l,l when posting
a message from loadData API.

Bug: 1021622
Change-Id: I93fff4ac9962fd9d0637a53e51162f55e7777a42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900153Reviewed-by: default avatarShimi Zhang <ctzsm@chromium.org>
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713525}
parent 8148412d
......@@ -128,6 +128,32 @@ public class JsJavaInteractionTest {
Assert.assertTrue(mListener.hasNoMoreOnPostMessage());
}
@Test
@SmallTest
@Feature({"AndroidWebView", "JsJavaInteraction"})
public void testPostMessage_LoadData_MessageHasStringNullOrigin() throws Throwable {
addWebMessageListenerOnUiThread(mAwContents, JS_OBJECT_NAME, new String[] {"*"}, mListener);
final String html = "<html><head><script>myObject.postMessage('Hello');</script></head>"
+ "<body></body></html>";
// This uses loadDataAsync() which is equivalent to WebView#loadData(...).
mActivityTestRule.loadHtmlSync(
mAwContents, mContentsClient.getOnPageFinishedHelper(), html);
TestWebMessageListener.Data data = mListener.waitForOnPostMessage();
// Note that the source origin is a non-null string of n, u, l, l.
Assert.assertNotNull(data.mSourceOrigin);
Assert.assertEquals("null", data.mSourceOrigin.toString());
Assert.assertEquals(HELLO, data.mMessage);
Assert.assertTrue(data.mIsMainFrame);
Assert.assertEquals(0, data.mPorts.length);
Assert.assertTrue(mListener.hasNoMoreOnPostMessage());
}
@Test
@SmallTest
@Feature({"AndroidWebView", "JsJavaInteraction"})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment