Make ClientWebView-based tests execute a bit faster.

* test/client/components/client-web-view-test.vala: New explicit tests
  for init'ing the WebContext and loading default resources.

* test/client/components/client-web-view-test-case.vala:
  Init the WebContext and load resources in the constructor rather than
  fixture setup, so it only happens once per suite, not once per
  test. Update subclasses to do same.

* test/client/composer/composer-web-view-test.vala: Add an explicit test
  for loading ComposerWebView resources.
This commit is contained in:
Michael James Gratton 2017-01-30 23:09:02 +11:00
parent 998fe70554
commit 355e4d37c1
7 changed files with 63 additions and 18 deletions

View file

@ -15,6 +15,7 @@ set(TEST_SRC
engine/util-timeout-manager-test.vala
client/application/geary-configuration-test.vala
client/components/client-web-view-test.vala
client/components/client-web-view-test-case.vala
client/composer/composer-web-view-test.vala

View file

@ -15,9 +15,6 @@ public abstract class ClientWebViewTestCase<V> : Gee.TestCase {
public ClientWebViewTestCase(string name) {
base(name);
}
public override void set_up() {
this.config = new Configuration(GearyApplication.APP_ID);
ClientWebView.init_web_context(
this.config,
@ -30,6 +27,9 @@ public abstract class ClientWebViewTestCase<V> : Gee.TestCase {
} catch (Error err) {
assert_not_reached();
}
}
public override void set_up() {
this.test_view = set_up_test_view();
}

View file

@ -0,0 +1,34 @@
/*
* Copyright 2016 Michael 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.
*/
public class ClientWebViewTest : Gee.TestCase {
public ClientWebViewTest() {
base("ClientWebViewTest");
add_test("init_web_context", init_web_context);
add_test("load_resources", load_resources);
}
public void init_web_context() {
Configuration config = new Configuration(GearyApplication.APP_ID);
ClientWebView.init_web_context(
config,
File.new_for_path(_BUILD_ROOT_DIR).get_child("src"),
File.new_for_path("/tmp"), // XXX use something better here
true
);
}
public void load_resources() {
try {
ClientWebView.load_scripts();
} catch (Error err) {
assert_not_reached();
}
}
}

View file

@ -9,6 +9,7 @@ public class ComposerWebViewTest : ClientWebViewTestCase<ComposerWebView> {
public ComposerWebViewTest() {
base("ComposerWebViewTest");
add_test("load_resources", load_resources);
add_test("edit_context", edit_context);
add_test("get_html", get_html);
add_test("get_text", get_text);
@ -19,6 +20,14 @@ public class ComposerWebViewTest : ClientWebViewTestCase<ComposerWebView> {
add_test("get_text_with_nbsp", get_text_with_nbsp);
}
public void load_resources() {
try {
ComposerWebView.load_resources();
} catch (Error err) {
assert_not_reached();
}
}
public void edit_context() {
assert(!(new ComposerWebView.EditContext("0,,,").is_link));
assert(new ComposerWebView.EditContext("1,,,").is_link);
@ -160,11 +169,6 @@ long, long, long, long, long, long, long, long, long, long,
}
protected override ComposerWebView set_up_test_view() {
try {
ComposerWebView.load_resources();
} catch (Error err) {
assert_not_reached();
}
return new ComposerWebView(this.config);
}

View file

@ -23,6 +23,12 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
add_test("quote_lines", quote_lines);
add_test("resolve_nesting", resolve_nesting);
add_test("replace_non_breaking_space", replace_non_breaking_space);
try {
ComposerWebView.load_resources();
} catch (Error err) {
assert_not_reached();
}
}
public void edit_context_link() {
@ -334,11 +340,6 @@ unknown://example6.com
}
protected override ComposerWebView set_up_test_view() {
try {
ComposerWebView.load_resources();
} catch (Error err) {
assert_not_reached();
}
return new ComposerWebView(this.config);
}

View file

@ -17,6 +17,12 @@ 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);
try {
ConversationWebView.load_resources(File.new_for_path(""));
} catch (Error err) {
assert_not_reached();
}
}
public void is_deceptive_text_not_url() {
@ -68,11 +74,6 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
}
protected override ConversationWebView set_up_test_view() {
try {
ConversationWebView.load_resources(File.new_for_path(""));
} catch (Error err) {
assert_not_reached();
}
return new ConversationWebView(this.config);
}

View file

@ -47,6 +47,10 @@ int main(string[] args) {
TestSuite client = new TestSuite("client");
// Keep this before other ClientWebView based tests since it tests
// WebContext init
client.add_suite(new ClientWebViewTest().get_suite());
client.add_suite(new ComposerWebViewTest().get_suite());
client.add_suite(new ConfigurationTest().get_suite());