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

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

View file

@ -103,12 +103,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
public void is_descendant_of() throws GLib.Error {
load_body_fixture("<blockquote><div id='test'>ohhai</div></blockquote>");
assert(
Util.WebKit.to_bool(
Util.JS.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
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 {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert(
Util.WebKit.to_bool(
Util.JS.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
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 {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert(
Util.WebKit.to_bool(
Util.JS.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
document.getElementById('test'), "DIV"
);
""")
.get_js_value()
)
);
}
@ -142,12 +145,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
public void is_descendant_of_lax() throws GLib.Error {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert(
Util.WebKit.to_bool(
Util.JS.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
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) {
try {
return (uint) Util.WebKit.to_int32(
return (uint) Util.JS.to_int32(
run_javascript(@"ConversationPageState.isDeceptiveText(\"$text\", \"$href\")")
.get_js_value()
);
} catch (Util.JS.Error err) {
print("Util.JS.Error: %s\n", err.message);