mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
7a0b06ad0b
As ExpandoObject implements IDictionary we can use it interchangeable with only minor breaking changes. Those expecting Dictionary<string, object> should change to IDictionary<string, object> or ExpandoObject for their param types This will also impact anyone who has implemented their own custom IBinder I'd suggest changing the type checking from explicitly checking Dictionary<string, object> to use Type.IsAssignableFrom or another method of comparison DefaultBinder binder has been updated to accommodate ExpandoObject (now being returned by ObjectsSerialization.cpp) Add new async binding for testing new assignment method Rewrite some of the async bound object tests to use await and let - modernize them
326 lines
12 KiB
HTML
326 lines
12 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<title>Binding Test</title>
|
|
</head>
|
|
<body>
|
|
<p>
|
|
Async Binding Test
|
|
<span id="asyncresult"></span>
|
|
<script type="text/javascript">
|
|
var asResult = document.getElementById('asyncresult');
|
|
|
|
function writeAsyncResult(call, end)
|
|
{
|
|
var p = document.createElement('p');
|
|
var br = document.createElement('br');
|
|
var br2 = document.createElement('br');
|
|
var hr = document.createElement('hr');
|
|
var title = document.createTextNode('Async Call: ');
|
|
var callText = document.createTextNode(call);
|
|
var endText = document.createTextNode(end);
|
|
|
|
p.appendChild(title);
|
|
p.appendChild(br);
|
|
p.appendChild(callText);
|
|
p.appendChild(br2);
|
|
p.appendChild(endText);
|
|
p.appendChild(hr);
|
|
|
|
asResult.appendChild(p);
|
|
}
|
|
|
|
function asyncError()
|
|
{
|
|
let call = "Async call (Throw Exception): " + Date();
|
|
boundAsync.error().catch(function (e)
|
|
{
|
|
var end = "Error: " + e + "(" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
});
|
|
}
|
|
|
|
async function asyncDivOk()
|
|
{
|
|
let call = "Async call (Divide 16 / 2): " + Date();
|
|
|
|
let res = await boundAsync.div(16, 2);
|
|
|
|
let end = "Result: " + res + "(" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
}
|
|
|
|
function asyncDivFail()
|
|
{
|
|
var call = "Async call (Divide 16 /0): " + Date();
|
|
boundAsync.div(16, 0).then(function (res)
|
|
{
|
|
var end = "Result: " + res + "(" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
},
|
|
function (e)
|
|
{
|
|
var end = "Error: " + e + "(" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
});
|
|
}
|
|
|
|
async function asyncHello()
|
|
{
|
|
let call = "Async call (Hello): " + Date();
|
|
let res = await boundAsync.hello('CefSharp');
|
|
|
|
var end = "Result: " + res + "(" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
|
|
return end;
|
|
}
|
|
|
|
async function asyncDoSomething()
|
|
{
|
|
let call = "Async call (Long Running Task): " + Date();
|
|
let res = await boundAsync.doSomething();
|
|
|
|
let end = "Result: " + res + "(" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
}
|
|
|
|
async function asyncObject()
|
|
{
|
|
let call = "Async call (Object): " + Date();
|
|
var res = await boundAsync.returnObject('CefSharp');
|
|
var end = "Result: " + JSON.stringify(res) + " (" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
}
|
|
|
|
async function asyncObjectArray()
|
|
{
|
|
let call = "Async call (ObjectArray): " + Date();
|
|
let res = await boundAsync.objectArray('CefSharp');
|
|
let end = "Result: [ " + res.map(function (item) { return item.Value }) + " ] (" + Date() + ")";
|
|
writeAsyncResult(call, end);
|
|
}
|
|
|
|
async function asyncDictionaryPassedAsParam()
|
|
{
|
|
let call = [{ Name : "Chrome", Engine : {Name : "WebKit"} }, { Name : "Chromium", Engine : {Name : "WebKit"} }, { Name : "Opera", Engine : {Name : "WebKit"} }];
|
|
let res = await boundAsync.dynamiObjectList(call);
|
|
writeAsyncResult(call, res);
|
|
}
|
|
|
|
asyncError();
|
|
asyncDivOk();
|
|
asyncDivFail();
|
|
asyncDoSomething();
|
|
asyncHello();
|
|
asyncObject();
|
|
asyncObjectArray();
|
|
asyncDictionaryPassedAsParam();
|
|
</script>
|
|
</p>
|
|
<p>
|
|
Javascript Callback Test
|
|
<br />
|
|
<script type="text/javascript">
|
|
function callback(s)
|
|
{
|
|
var result = document.getElementById('cbresult');
|
|
result.innerText += "Callback: " + s.Response + "" + Date();
|
|
}
|
|
|
|
function testCallback()
|
|
{
|
|
bound.testCallback(callback);
|
|
|
|
var result = document.getElementById('cbresult');
|
|
result.innerText = "The function has returned: " + Date() + "\n";
|
|
}
|
|
</script>
|
|
<button onclick="testCallback()">Test Callback</button>
|
|
<br />
|
|
<span id="cbresult"></span>
|
|
</p>
|
|
|
|
<p>
|
|
Disposed Javscript Callback Test (navigates to www.google.com before callback fires)
|
|
<br />
|
|
<script type="text/javascript">
|
|
function disposedCallback(s)
|
|
{
|
|
// This callback should be disposed and should not be called
|
|
window.alert("This callback should not have been called");
|
|
|
|
var result = document.getElementById('disposedcbresult');
|
|
result.innerText += "Callback: " + s + "" + Date();
|
|
}
|
|
|
|
function testDisposedCallback()
|
|
{
|
|
bound.testCallback(callback);
|
|
|
|
var result = document.getElementById('disposedcbresult');
|
|
result.innerText = "The function has returned: " + Date() + "\n";
|
|
|
|
window.location.assign("http://www.google.com");
|
|
}
|
|
</script>
|
|
<button onclick="testDisposedCallback()">Test Disposed Callback</button>
|
|
<br />
|
|
<span id="disposedcbresult"></span>
|
|
</p>
|
|
|
|
<p>
|
|
Javascript Callback Test using object as parameter
|
|
<br />
|
|
<script type="text/javascript">
|
|
function objectCallback(s)
|
|
{
|
|
var result = document.getElementById('cbobjresult');
|
|
result.innerText += "Callback: " + s + "" + Date();
|
|
}
|
|
|
|
function testCallbackWithObject()
|
|
{
|
|
bound.testCallbackFromObject({
|
|
Callback: objectCallback, TestString: "Hello", SubClasses: [
|
|
{ PropertyOne: "Test Property One", Numbers: [1, 2, 3] },
|
|
{ PropertyOne: "Test Property Two", Numbers: [4, 5, 6] }
|
|
]
|
|
});
|
|
|
|
var result = document.getElementById('cbobjresult');
|
|
result.innerText = "The function has returned: " + Date() + "\n ...Waiting for callback response...";
|
|
}
|
|
</script>
|
|
<button onclick="testCallbackWithObject()">Test Callback with object param</button>
|
|
<br />
|
|
<span id="cbobjresult"></span>
|
|
</p>
|
|
|
|
<p>
|
|
Result of calling bound.repeat("hi ", 5) =
|
|
<script type="text/javascript">
|
|
var result = bound.repeat("hi ", 5);
|
|
document.write('"' + result + '"');
|
|
if (result === "hi hi hi hi hi ")
|
|
{
|
|
document.write(" SUCCESS");
|
|
} else
|
|
{
|
|
document.write(" FAIL!");
|
|
}
|
|
</script>
|
|
</p>
|
|
|
|
<p>
|
|
Function delegate to c# method
|
|
<br />
|
|
<script type="text/javascript">
|
|
function myFunction(functionParam)
|
|
{
|
|
return functionParam();
|
|
}
|
|
|
|
document.write("echoMyProperty result: " + myFunction(bound.echoMyProperty));
|
|
</script>
|
|
</p>
|
|
|
|
<p>
|
|
Function returning complex type
|
|
<br />
|
|
<script type="text/javascript">
|
|
document.write("bound.getSubObject().simpleProperty result: " + bound.getSubObject().simpleProperty);
|
|
</script>
|
|
</p>
|
|
|
|
<p>
|
|
Stress Test
|
|
<br />
|
|
<script type="text/javascript">
|
|
var stressTestCallCount = 1000;
|
|
for (var i = 1; i <= stressTestCallCount; i++)
|
|
{
|
|
bound.repeat("hi ", 5);
|
|
}
|
|
|
|
document.write("Stress Test done with : " + stressTestCallCount + " call to bound.repeat(\"hi \", 5)");
|
|
</script>
|
|
</p>
|
|
|
|
<p>
|
|
JSON Serializer Test
|
|
<br />
|
|
<script type="text/javascript">
|
|
var json = bound.returnJsonEmployeeList();
|
|
var jsonObj = JSON.parse(json);
|
|
|
|
document.write("Employee Count : " + jsonObj.employees.length + "<br/>");
|
|
|
|
for (var i = 0; i < jsonObj.employees.length; i++)
|
|
{
|
|
var employee = jsonObj.employees[i];
|
|
document.write("Employee : " + employee.firstName + " " + employee.lastName + "<br/>");
|
|
}
|
|
</script>
|
|
</p>
|
|
|
|
Methods on bound object 'bound':<br />
|
|
<ul>
|
|
<script type="text/javascript">
|
|
for (var name in bound)
|
|
{
|
|
if (bound[name].constructor.name != 'Function') continue;
|
|
document.write("<li>" + name + "</li>");
|
|
}
|
|
</script>
|
|
</ul>
|
|
|
|
Properties in bound object 'bound':<br />
|
|
<ul>
|
|
<script type="text/javascript">
|
|
for (var name in bound)
|
|
{
|
|
if (bound[name].constructor.name === 'Function') continue;
|
|
|
|
document.write("<li>" + name + "</li>");
|
|
if (typeof bound[name] == "object" && bound[name] !== null)
|
|
{
|
|
for (var sub in bound[name])
|
|
{
|
|
var type = bound[name][sub].constructor.name === 'Function' ? "Function" : "Property";
|
|
document.write("<li>" + name + "." + sub + "(" + type + ")" + "</li>");
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</ul>
|
|
<p>
|
|
Javascript function sending variable number of parameters to Bound Object. (ParamArray Test)
|
|
<script type="text/javascript">
|
|
function str2ab(str)
|
|
{
|
|
var enc = new TextEncoder("utf-8");
|
|
return enc.encode(str).buffer;
|
|
}
|
|
|
|
document.write(bound.methodWithParams('With 1 Params', 'hello-world') + "<br/>");
|
|
document.write(bound.methodWithParams('With 2 Params', 'hello-world', 'chris was here') + "<br/>");
|
|
document.write(bound.methodWithParams('With no Params') + "<br/>");
|
|
document.write(bound.methodWithoutParams('Normal Method', 'hello') + "<br/>");
|
|
document.write(bound.methodWithoutAnything() + "<br/>");
|
|
|
|
document.write(bound.methodWithThreeParamsOneOptionalOneArray(null) + "<br/>");
|
|
document.write(bound.methodWithThreeParamsOneOptionalOneArray(null, null) + "<br/>");
|
|
document.write(bound.methodWithThreeParamsOneOptionalOneArray("Test", null) + "<br/>");
|
|
document.write(bound.methodWithThreeParamsOneOptionalOneArray(null, null, "Arg1", "Arg2") + "<br/>");
|
|
|
|
//CEF Does not currently support ArrayBuffer directly
|
|
//https://bitbucket.org/chromiumembedded/cef/issues/244
|
|
//https://bitbucket.org/chromiumembedded/cef/pull-requests/12/v8-renderer-add-basic-arraybuffer-support/diff
|
|
//var buffer = str2ab("Testing array buffer");
|
|
//document.write(bound.complexParamObject(buffer));
|
|
</script>
|
|
</p>
|
|
</body>
|
|
</html>
|