File: components-web-view-test-case.vala

package info (click to toggle)
geary 46.0-13
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,092 kB
  • sloc: javascript: 972; ansic: 722; sql: 247; xml: 183; python: 30; makefile: 28; sh: 24
file content (58 lines) | stat: -rw-r--r-- 1,794 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * 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 abstract class Components.WebViewTestCase<V> : TestCase {

    protected V? test_view = null;
    protected Application.Configuration? config = null;

    protected WebViewTestCase(string name) {
        base(name);
    }

    public override void set_up() {
        this.config = new Application.Configuration(Application.Client.SCHEMA_ID);
        this.config.enable_debug = true;

        WebView.init_web_context(
            this.config,
            File.new_for_path(_BUILD_ROOT_DIR).get_child("src"),
            File.new_for_path("/tmp"), // XXX use something better here
            false // https://bugs.webkit.org/show_bug.cgi?id=213174
        );
        try {
            WebView.load_resources(GLib.File.new_for_path("/tmp"));
        } catch (GLib.Error err) {
            GLib.assert_not_reached();
        }

        this.test_view = set_up_test_view();
    }

    protected override void tear_down() {
        this.config = null;
        this.test_view = null;
    }

    protected abstract V set_up_test_view();

    protected virtual void load_body_fixture(string html = "") {
        WebView client_view = (WebView) this.test_view;
        client_view.load_html_headless(html);
        while (!client_view.is_content_loaded) {
            Gtk.main_iteration();
        }
    }

    protected JSC.Value? run_javascript(string command) throws Error {
        WebView view = (WebView) this.test_view;
        view.evaluate_javascript.begin(command, -1, null, null, null, this.async_completion);
        return view.evaluate_javascript.end(async_result());
    }

}