Minor tweaks for ConversationPageState.isDescendantOf

Use uppercase since that is what the DOM for HTML defaults to, use
nodeName rather than tagName for cases when there the check is false and
ancestor is the document element, add unit tests.
This commit is contained in:
Michael Gratton 2019-01-21 20:55:03 +11:00 committed by Michael James Gratton
parent 44d871f6f1
commit c83f07a9f1
2 changed files with 48 additions and 5 deletions

View file

@ -17,6 +17,9 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
add_test("is_deceptive_text_deceptive_href", is_deceptive_text_deceptive_href);
add_test("is_deceptive_text_non_matching_subdomain", is_deceptive_text_non_matching_subdomain);
add_test("is_deceptive_text_different_domain", is_deceptive_text_different_domain);
add_test("is_descendant_of", is_descendant_of);
add_test("is_descendant_of_with_class", is_descendant_of_with_class);
add_test("is_descendant_of_no_match", is_descendant_of_no_match);
try {
ConversationWebView.load_resources(File.new_for_path(""));
@ -73,6 +76,46 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
ConversationWebView.DeceptiveText.DECEPTIVE_DOMAIN);
}
public void is_descendant_of() throws GLib.Error {
load_body_fixture("<blockquote><div id='test'>ohhai</div></blockquote>");
assert(
WebKitUtil.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
document.getElementById('test'), "BLOCKQUOTE"
);
""")
)
);
}
public void is_descendant_of_with_class() throws GLib.Error {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert(
WebKitUtil.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
document.getElementById('test'), "BLOCKQUOTE", "test-class"
);
""")
)
);
}
public void is_descendant_of_no_match() throws GLib.Error {
load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
assert(
WebKitUtil.to_bool(
run_javascript("""
ConversationPageState.isDescendantOf(
document.getElementById('test'), "DIV"
);
""")
)
);
}
protected override ConversationWebView set_up_test_view() {
return new ConversationWebView(this.config);
}