Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Add test case for .net extension binary data transfer - see XWALK-4615 #3847

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ public class XWalkExtensionInstance
public XWalkExtensionInstance(dynamic native)
{
native_ = native;
}

public void HandleMessage(String message)
}
public void HandleMessage(String message)
{
native_.PostMessageToJS("From dll async:" + message);
if (string.Equals(message, "BinaryTest", StringComparison.OrdinalIgnoreCase))
{
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
native_.PostBinaryMessageToJS(bytes, (ulong)bytes.Length);
}
else
{
native_.PostMessageToJS("From dll async:" + message);
}
}
public void HandleSyncMessage(String message)
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,32 @@
document.title = "Fail";
}
}

function testAsyncBinary(){
var div = document.getElementById("div");
try {
var str = "BinaryTest";
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var msg = echo.echo(str, function(buf){
var uint8View = new Uint8Array(buf);
div.innerHTML = div.innerHTML + uint8View.toString() + "<br/>";
if (uint8View.toString() === expected.toString()) {
div.innerHTML = div.innerHTML + "Binary test <font color=green>passed</font>.<br/>";
document.title = "Pass";
} else {
div.innerHTML = div.innerHTML + "Binary test <font color=red>failed</font>.<br/>";
document.title = "Fail";
}
});
} catch(e) {
div.innerHTML = div.innerHTML + e + "<br/>";
document.title = "Fail";
}
}
</script>
<button onclick="testSyncEcho()">Test Sync Echo</button>
<button onclick="testAsyncEcho()">Test Async Echo</button><br/><br/>
<button onclick="testAsyncEcho()">Test Async Echo</button>
<button onclick="testAsyncBinary()">Test Binary</button><br/><br/>
<div id="div"></div>
</body>
</html>