Components.WebView: Convert to using messages for JS method invocation

Use WebKitGTK UserMessage objects for invoking JS methods rather than
serialising to JS strings and running those. This is possibly slightly
less efficient, but removes the onus on serialising to and parsing from
JS and once switched over from message handlers to UserMessage objects
will be using a single uniform IPC interface for both.
This commit is contained in:
Michael Gratton 2020-08-27 12:12:22 +10:00 committed by Michael James Gratton
parent 1ba2bd0f5b
commit ff565bc6ef
8 changed files with 268 additions and 74 deletions

View file

@ -14,12 +14,24 @@ class Components.PageStateTest : WebViewTestCase<WebView> {
base(config);
}
public new async void call_void(Util.JS.Callable callable)
throws GLib.Error {
yield base.call_void(callable, null);
}
public new async string call_returning(Util.JS.Callable callable)
throws GLib.Error {
return yield base.call_returning<string>(callable, null);
}
}
public PageStateTest() {
base("Components.PageStateTest");
add_test("content_loaded", content_loaded);
add_test("call_void", call_void);
add_test("call_returning", call_returning);
try {
WebView.load_resources(GLib.File.new_for_path("/tmp"));
@ -45,6 +57,30 @@ class Components.PageStateTest : WebViewTestCase<WebView> {
assert(content_loaded_triggered);
}
public void call_void() throws GLib.Error {
load_body_fixture("OHHAI");
var test_article = this.test_view as TestWebView;
test_article.call_void.begin(
new Util.JS.Callable("testVoid"), this.async_completion
);
test_article.call_void.end(this.async_result());
assert_test_result("void");
}
public void call_returning() throws GLib.Error {
load_body_fixture("OHHAI");
var test_article = this.test_view as TestWebView;
test_article.call_returning.begin(
new Util.JS.Callable("testReturn").string("check 1-2"),
this.async_completion
);
string ret = test_article.call_returning.end(this.async_result());
assert_equal(ret, "check 1-2");
assert_test_result("check 1-2");
}
protected override WebView set_up_test_view() {
WebKit.UserScript test_script;
test_script = new WebKit.UserScript(
@ -60,4 +96,13 @@ class Components.PageStateTest : WebViewTestCase<WebView> {
return view;
}
private void assert_test_result(string expected)
throws GLib.Error {
string? result = Util.JS.to_string(
run_javascript("geary.testResult")
.get_js_value()
);
assert_equal(result, expected);
}
}