Remove Util.Webkit namespace and functions

After the JSC migration they were all a bunch of simple inline
one-liners, so were just making the code more complex than it needed to
be.
This commit is contained in:
Michael Gratton 2019-07-21 10:46:42 +10:00
parent 83309d2d83
commit 2a0de1ce41
8 changed files with 167 additions and 156 deletions

View file

@ -98,7 +98,6 @@ src/client/util/util-gtk.vala
src/client/util/util-international.vala src/client/util/util-international.vala
src/client/util/util-js.vala src/client/util/util-js.vala
src/client/util/util-migrate.vala src/client/util/util-migrate.vala
src/client/util/util-webkit.vala
src/client/web-process/web-process-extension.vala src/client/web-process/web-process-extension.vala
src/console/main.vala src/console/main.vala
src/engine/api/geary.vala src/engine/api/geary.vala

View file

@ -392,7 +392,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
* Returns the view's content as an HTML string. * Returns the view's content as an HTML string.
*/ */
public async string? get_html() throws Error { public async string? get_html() throws Error {
return Util.WebKit.to_string( return Util.JS.to_string(
yield call(Util.JS.callable("geary.getHtml"), null) yield call(Util.JS.callable("geary.getHtml"), null)
); );
} }
@ -491,10 +491,13 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
/** /**
* Invokes a {@link Util.JS.Callable} on this web view. * Invokes a {@link Util.JS.Callable} on this web view.
*/ */
protected async WebKit.JavascriptResult call(Util.JS.Callable target, protected async JSC.Value call(Util.JS.Callable target,
Cancellable? cancellable) GLib.Cancellable? cancellable)
throws Error { throws GLib.Error {
return yield run_javascript(target.to_string(), cancellable); WebKit.JavascriptResult result = yield run_javascript(
target.to_string(), cancellable
);
return result.get_js_value();
} }
/** /**
@ -617,7 +620,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
private void on_preferred_height_changed(WebKit.JavascriptResult result) { private void on_preferred_height_changed(WebKit.JavascriptResult result) {
double height = this.webkit_reported_height; double height = this.webkit_reported_height;
try { try {
height = Util.WebKit.to_double(result); height = Util.JS.to_double(result.get_js_value());
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
debug("Could not get preferred height: %s", err.message); debug("Could not get preferred height: %s", err.message);
} }
@ -630,7 +633,8 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
private void on_command_stack_changed(WebKit.JavascriptResult result) { private void on_command_stack_changed(WebKit.JavascriptResult result) {
try { try {
string[] values = Util.WebKit.to_string(result).split(","); string[] values =
Util.JS.to_string(result.get_js_value()).split(",");
command_stack_changed(values[0] == "true", values[1] == "true"); command_stack_changed(values[0] == "true", values[1] == "true");
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
debug("Could not get command stack state: %s", err.message); debug("Could not get command stack state: %s", err.message);
@ -652,7 +656,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
private void on_selection_changed(WebKit.JavascriptResult result) { private void on_selection_changed(WebKit.JavascriptResult result) {
try { try {
bool has_selection = Util.WebKit.to_bool(result); bool has_selection = Util.JS.to_bool(result.get_js_value());
// Avoid firing multiple notifies if the value hasn't // Avoid firing multiple notifies if the value hasn't
// changed // changed
if (this.has_selection != has_selection) { if (this.has_selection != has_selection) {

View file

@ -218,7 +218,7 @@ public class ComposerWebView : ClientWebView {
* subsequent calls. * subsequent calls.
*/ */
public async string save_selection() throws Error { public async string save_selection() throws Error {
return Util.WebKit.to_string( return Util.JS.to_string(
yield call(Util.JS.callable("geary.saveSelection"), null) yield call(Util.JS.callable("geary.saveSelection"), null)
); );
} }
@ -400,7 +400,7 @@ public class ComposerWebView : ClientWebView {
public async bool contains_attachment_keywords(string keyword_spec, public async bool contains_attachment_keywords(string keyword_spec,
string subject) { string subject) {
try { try {
return Util.WebKit.to_bool( return Util.JS.to_bool(
yield call( yield call(
Util.JS.callable("geary.containsAttachmentKeyword") Util.JS.callable("geary.containsAttachmentKeyword")
.string(keyword_spec) .string(keyword_spec)
@ -430,7 +430,7 @@ public class ComposerWebView : ClientWebView {
const int MAX_BREAKABLE_LEN = 72; // F=F recommended line limit const int MAX_BREAKABLE_LEN = 72; // F=F recommended line limit
const int MAX_UNBREAKABLE_LEN = 998; // SMTP line limit const int MAX_UNBREAKABLE_LEN = 998; // SMTP line limit
string body_text = Util.WebKit.to_string( string body_text = Util.JS.to_string(
yield call(Util.JS.callable("geary.getText"), null) yield call(Util.JS.callable("geary.getText"), null)
); );
string[] lines = body_text.split("\n"); string[] lines = body_text.split("\n");
@ -506,7 +506,9 @@ public class ComposerWebView : ClientWebView {
private void on_cursor_context_changed(WebKit.JavascriptResult result) { private void on_cursor_context_changed(WebKit.JavascriptResult result) {
try { try {
cursor_context_changed(new EditContext(Util.WebKit.to_string(result))); cursor_context_changed(
new EditContext(Util.JS.to_string(result.get_js_value()))
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
debug("Could not get text cursor style: %s", err.message); debug("Could not get text cursor style: %s", err.message);
} }

View file

@ -72,20 +72,20 @@ public class ConversationWebView : ClientWebView {
* Returns the current selection, for prefill as find text. * Returns the current selection, for prefill as find text.
*/ */
public async string? get_selection_for_find() throws Error{ public async string? get_selection_for_find() throws Error{
WebKit.JavascriptResult result = yield call( JSC.Value result = yield call(
Util.JS.callable("geary.getSelectionForFind"), null Util.JS.callable("geary.getSelectionForFind"), null
); );
return Util.WebKit.to_string(result); return Util.JS.to_string(result);
} }
/** /**
* Returns the current selection, for quoting in a message. * Returns the current selection, for quoting in a message.
*/ */
public async string? get_selection_for_quoting() throws Error { public async string? get_selection_for_quoting() throws Error {
WebKit.JavascriptResult result = yield call( JSC.Value result = yield call(
Util.JS.callable("geary.getSelectionForQuoting"), null Util.JS.callable("geary.getSelectionForQuoting"), null
); );
return Util.WebKit.to_string(result); return Util.JS.to_string(result);
} }
/** /**
@ -93,11 +93,10 @@ public class ConversationWebView : ClientWebView {
*/ */
public async int? get_anchor_target_y(string anchor_body) public async int? get_anchor_target_y(string anchor_body)
throws GLib.Error { throws GLib.Error {
WebKit.JavascriptResult result = yield call( JSC.Value result = yield call(
Util.JS.callable("geary.getAnchorTargetY") Util.JS.callable("geary.getAnchorTargetY").string(anchor_body), null
.string(anchor_body), null
); );
return (int) Util.WebKit.to_int32(result); return (int) Util.JS.to_int32(result);
} }
/** /**

View file

@ -106,7 +106,6 @@ geary_client_vala_sources = files(
'util/util-international.vala', 'util/util-international.vala',
'util/util-js.vala', 'util/util-js.vala',
'util/util-migrate.vala', 'util/util-migrate.vala',
'util/util-webkit.vala',
) )
geary_client_sources = [ geary_client_sources = [

View file

@ -1,72 +0,0 @@
/*
* Copyright 2017-2019 Michael James Gratton <mike@vee.net>
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
/**
* Utility functions for WebKit objects.
*/
namespace Util.WebKit {
/**
* Returns a WebKit JavascriptResult as a `bool`.
*
* This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `Boolean`.
*/
public bool to_bool(global::WebKit.JavascriptResult result)
throws Util.JS.Error {
return Util.JS.to_bool(result.get_js_value());
}
/**
* Returns a WebKit JavascriptResult as a `double`.
*
* This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `Number`.
*/
public inline double to_int32(global::WebKit.JavascriptResult result)
throws Util.JS.Error {
return Util.JS.to_double(result.get_js_value());
}
/**
* Returns a WebKit JavascriptResult as a `int32`.
*
* This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `Number`.
*/
public inline int32 to_double(global::WebKit.JavascriptResult result)
throws Util.JS.Error {
return Util.JS.to_int32(result.get_js_value());
}
/**
* Returns a WebKit JavascriptResult as a GLib string.
*
* This will raise a {@link Util.JS.Error.TYPE} error if the
* result is not a JavaScript `String`.
*/
public inline string to_string(global::WebKit.JavascriptResult result)
throws Util.JS.Error {
return Util.JS.to_string(result.get_js_value());
}
/**
* Converts a WebKit JavascriptResult to a GLib string.
*
* Unlike the other `get_foo_result` methods, this will coax the
* result to a string, effectively by calling the JavaScript
* `toString()` method on it, and returning that value.
*/
public string as_string(global::WebKit.JavascriptResult result)
throws Util.JS.Error {
JSC.Value value = result.get_js_value();
string str = value.to_string();
Util.JS.check_exception(value.context);
return str;
}
}

View file

@ -38,8 +38,11 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
load_body_fixture(html); load_body_fixture(html);
try { try {
assert(Util.WebKit.to_string(run_javascript(@"new EditContext(document.getElementById('test')).encode()")) assert(
.has_prefix("1,url,")); Util.JS.to_string(
run_javascript(@"new EditContext(document.getElementById('test')).encode()")
.get_js_value()
).has_prefix("1,url,"));
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -54,8 +57,11 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
load_body_fixture(html); load_body_fixture(html);
try { try {
assert(Util.WebKit.to_string(run_javascript(@"new EditContext(document.getElementById('test')).encode()")) == assert(
"0,,Comic Sans,144"); Util.JS.to_string(
run_javascript(@"new EditContext(document.getElementById('test')).encode()")
.get_js_value()
) == "0,,Comic Sans,144");
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -70,9 +76,18 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
try { try {
run_javascript(@"SelectionUtil.selectNode(document.getElementById('test'))"); run_javascript(@"SelectionUtil.selectNode(document.getElementById('test'))");
run_javascript(@"geary.indentLine()"); run_javascript(@"geary.indentLine()");
assert(Util.WebKit.to_int32(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').length")) == 1); assert(
assert(Util.WebKit.to_string(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').item(0).innerText")) == Util.JS.to_int32(
"some text"); run_javascript(@"document.querySelectorAll('blockquote[type=cite]').length")
.get_js_value()
) == 1
);
assert(
Util.JS.to_string(
run_javascript(@"document.querySelectorAll('blockquote[type=cite]').item(0).innerText")
.get_js_value()
) == "some text"
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -94,18 +109,30 @@ some text
true true
); );
try { try {
assert(Util.WebKit.to_bool(run_javascript( assert(
@"geary.containsAttachmentKeyword(\"some\", \"subject text\");" Util.JS.to_bool(
))); run_javascript(@"geary.containsAttachmentKeyword(\"some\", \"subject text\");")
assert(Util.WebKit.to_bool(run_javascript( .get_js_value()
@"geary.containsAttachmentKeyword(\"subject\", \"subject text\");" )
))); );
assert(!Util.WebKit.to_bool(run_javascript( assert(
@"geary.containsAttachmentKeyword(\"innerquote\", \"subject text\");" Util.JS.to_bool(
))); run_javascript(@"geary.containsAttachmentKeyword(\"subject\", \"subject text\");")
assert(!Util.WebKit.to_bool(run_javascript( .get_js_value()
@"geary.containsAttachmentKeyword(\"outerquote\", \"subject text\");" )
))); );
assert(
!Util.JS.to_bool(
run_javascript(@"geary.containsAttachmentKeyword(\"innerquote\", \"subject text\");")
.get_js_value()
)
);
assert(
!Util.JS.to_bool(
run_javascript(@"geary.containsAttachmentKeyword(\"outerquote\", \"subject text\");")
.get_js_value()
)
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -143,8 +170,12 @@ unknown://example6.com
try { try {
run_javascript("geary.cleanContent();"); run_javascript("geary.cleanContent();");
assert(Util.WebKit.to_string(run_javascript("geary.bodyPart.innerHTML;")) == assert(
CLEAN_BODY_TEMPLATE.printf(expected)); Util.JS.to_string(
run_javascript("geary.bodyPart.innerHTML;")
.get_js_value()
) == CLEAN_BODY_TEMPLATE.printf(expected)
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -158,8 +189,12 @@ unknown://example6.com
string html = "<p>para</p>"; string html = "<p>para</p>";
load_body_fixture(html); load_body_fixture(html);
try { try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getHtml();")) == assert(
COMPLETE_BODY_TEMPLATE.printf(html)); Util.JS.to_string(
run_javascript(@"window.geary.getHtml();")
.get_js_value()
) == COMPLETE_BODY_TEMPLATE.printf(html)
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -172,8 +207,12 @@ unknown://example6.com
public void get_text() throws Error { public void get_text() throws Error {
load_body_fixture("<p>para</p>"); load_body_fixture("<p>para</p>");
try { try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) == assert(
"para\n\n\n\n"); Util.JS.to_string(
run_javascript(@"window.geary.getText();")
.get_js_value()
) == "para\n\n\n\n"
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -187,8 +226,12 @@ unknown://example6.com
unichar q_marker = Geary.RFC822.Utils.QUOTE_MARKER; unichar q_marker = Geary.RFC822.Utils.QUOTE_MARKER;
load_body_fixture("<p>pre</p> <blockquote><p>quote</p></blockquote> <p>post</p>"); load_body_fixture("<p>pre</p> <blockquote><p>quote</p></blockquote> <p>post</p>");
try { try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) == assert(
@"pre\n\n$(q_marker)quote\n$(q_marker)\npost\n\n\n\n"); Util.JS.to_string(
run_javascript(@"window.geary.getText();")
.get_js_value()
) == @"pre\n\n$(q_marker)quote\n$(q_marker)\npost\n\n\n\n"
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s", err.message); print("Util.JS.Error: %s", err.message);
assert_not_reached(); assert_not_reached();
@ -202,8 +245,12 @@ unknown://example6.com
unichar q_marker = Geary.RFC822.Utils.QUOTE_MARKER; unichar q_marker = Geary.RFC822.Utils.QUOTE_MARKER;
load_body_fixture("<p>pre</p> <blockquote><p>quote1</p> <blockquote><p>quote2</p></blockquote></blockquote> <p>post</p>"); load_body_fixture("<p>pre</p> <blockquote><p>quote1</p> <blockquote><p>quote2</p></blockquote></blockquote> <p>post</p>");
try { try {
assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) == assert(
@"pre\n\n$(q_marker)quote1\n$(q_marker)\n$(q_marker)$(q_marker)quote2\n$(q_marker)$(q_marker)\npost\n\n\n\n"); Util.JS.to_string(
run_javascript(@"window.geary.getText();")
.get_js_value()
) == @"pre\n\n$(q_marker)quote1\n$(q_marker)\n$(q_marker)$(q_marker)quote2\n$(q_marker)$(q_marker)\npost\n\n\n\n"
);
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -219,44 +266,66 @@ unknown://example6.com
string suffix_keys = """new Set(["sf1", "sf2"])"""; string suffix_keys = """new Set(["sf1", "sf2"])""";
try { try {
// Doesn't contain // Doesn't contain
assert(!Util.WebKit.to_bool(run_javascript( assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('notcontained', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('notcontained', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(!Util.WebKit.to_bool(run_javascript( ));
assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('not contained', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('not contained', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(!Util.WebKit.to_bool(run_javascript( ));
assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('not\tcontained', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('not\tcontained', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(!Util.WebKit.to_bool(run_javascript( ));
assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('http://www.keyword1.com', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('http://www.keyword1.com', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(!Util.WebKit.to_bool(run_javascript( ));
assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('http://www.something.com/something.sf1', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('http://www.something.com/something.sf1', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(!Util.WebKit.to_bool(run_javascript( ));
assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('sf1', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('sf1', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(!Util.WebKit.to_bool(run_javascript( ));
assert(!Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('.sf1', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('.sf1', $complete_keys, $suffix_keys);"
))); ).get_js_value()
));
// Does contain // Does contain
assert(Util.WebKit.to_bool(run_javascript( assert(Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('keyword1', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('keyword1', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(Util.WebKit.to_bool(run_javascript( ));
assert(Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('keyword2 contained', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('keyword2 contained', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(Util.WebKit.to_bool(run_javascript( ));
assert(Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('keyword2\tcontained', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('keyword2\tcontained', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(Util.WebKit.to_bool(run_javascript( ));
assert(Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('something.sf1', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('something.sf1', $complete_keys, $suffix_keys);"
))); ).get_js_value()
assert(Util.WebKit.to_bool(run_javascript( ));
assert(Util.JS.to_bool(run_javascript(
@"ComposerPageState.containsKeywords('something.something.sf2', $complete_keys, $suffix_keys);" @"ComposerPageState.containsKeywords('something.something.sf2', $complete_keys, $suffix_keys);"
))); ).get_js_value()
));
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();
@ -271,10 +340,16 @@ unknown://example6.com
string single_nbsp = "a b"; string single_nbsp = "a b";
string multiple_nbsp = "a b c"; string multiple_nbsp = "a b c";
try { try {
assert(Util.WebKit.to_string(run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(single_nbsp)');")) == assert(
"a b"); Util.JS.to_string(
assert(Util.WebKit.to_string(run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(multiple_nbsp)');")) == run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(single_nbsp)');")
"a b c"); .get_js_value()
) == "a b");
assert(
Util.JS.to_string(
run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(multiple_nbsp)');")
.get_js_value()
) == "a b c");
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);
assert_not_reached(); assert_not_reached();

View file

@ -103,12 +103,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
public void is_descendant_of() throws GLib.Error { public void is_descendant_of() throws GLib.Error {
load_body_fixture("<blockquote><div id='test'>ohhai</div></blockquote>"); load_body_fixture("<blockquote><div id='test'>ohhai</div></blockquote>");
assert( assert(
Util.WebKit.to_bool( Util.JS.to_bool(
run_javascript(""" run_javascript("""
ConversationPageState.isDescendantOf( ConversationPageState.isDescendantOf(
document.getElementById('test'), "BLOCKQUOTE" document.getElementById('test'), "BLOCKQUOTE"
); );
""") """)
.get_js_value()
) )
); );
} }
@ -116,12 +117,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
public void is_descendant_of_with_class() throws GLib.Error { public void is_descendant_of_with_class() throws GLib.Error {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>"); load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert( assert(
Util.WebKit.to_bool( Util.JS.to_bool(
run_javascript(""" run_javascript("""
ConversationPageState.isDescendantOf( ConversationPageState.isDescendantOf(
document.getElementById('test'), "BLOCKQUOTE", "test-class" document.getElementById('test'), "BLOCKQUOTE", "test-class"
); );
""") """)
.get_js_value()
) )
); );
} }
@ -129,12 +131,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
public void is_descendant_of_no_match() throws GLib.Error { public void is_descendant_of_no_match() throws GLib.Error {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>"); load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert( assert(
Util.WebKit.to_bool( Util.JS.to_bool(
run_javascript(""" run_javascript("""
ConversationPageState.isDescendantOf( ConversationPageState.isDescendantOf(
document.getElementById('test'), "DIV" document.getElementById('test'), "DIV"
); );
""") """)
.get_js_value()
) )
); );
} }
@ -142,12 +145,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
public void is_descendant_of_lax() throws GLib.Error { public void is_descendant_of_lax() throws GLib.Error {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>"); load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert( assert(
Util.WebKit.to_bool( Util.JS.to_bool(
run_javascript(""" run_javascript("""
ConversationPageState.isDescendantOf( ConversationPageState.isDescendantOf(
document.getElementById('test'), "DIV", null, false document.getElementById('test'), "DIV", null, false
); );
""") """)
.get_js_value()
) )
); );
} }
@ -159,8 +163,9 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
private uint exec_is_deceptive_text(string text, string href) { private uint exec_is_deceptive_text(string text, string href) {
try { try {
return (uint) Util.WebKit.to_int32( return (uint) Util.JS.to_int32(
run_javascript(@"ConversationPageState.isDeceptiveText(\"$text\", \"$href\")") run_javascript(@"ConversationPageState.isDeceptiveText(\"$text\", \"$href\")")
.get_js_value()
); );
} catch (Util.JS.Error err) { } catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message); print("Util.JS.Error: %s\n", err.message);