summaryrefslogtreecommitdiff
path: root/tests/actions.vala
blob: b44c891c72466b7583f45d0f7b05aa20a8e37759 (plain)
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
59
60
61
62
63
/*
 Copyright (C) 2013 Christian Dywan <christian@twotoasts.de>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 See the file COPYING for the full license text.
*/

void actions_view_page () {
    var browser = new Midori.Browser ();
    var view = new Midori.View.with_title (null, new Midori.WebSettings ());
    browser.add_tab (view);
    browser.show ();
    view.set_html ("<body>The earth is <em>flat</em> for a fact.</body>");
    var loop = MainContext.default ();
    do { loop.iteration (true); } while (view.load_status != Midori.LoadStatus.FINISHED);

    var hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.DOCUMENT) as WebKit.HitTestResult;
    var menu = view.get_page_context_action (hit_test_result);
    assert (menu.name == "PageContextMenu");
    assert (menu.get_by_name ("Back") != null);

#if !HAVE_WEBKIT2
    hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.EDITABLE) as WebKit.HitTestResult;
    menu = view.get_page_context_action (hit_test_result);
    var copy = menu.get_by_name ("Copy");
    assert (!copy.sensitive);
    assert (view.web_view.search_text ("flat", true, false, false));
    menu = view.get_page_context_action (hit_test_result);
    copy = menu.get_by_name ("Copy");
    assert (copy.sensitive);
#endif

    /* Reload contents to clear selection */
    view.set_html ("<body>The earth is <em>flat</em> for a fact.</body>");
    do { loop.iteration (true); } while (view.load_status != Midori.LoadStatus.FINISHED);

#if !HAVE_WEBKIT2
    hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.SELECTION) as WebKit.HitTestResult;
    menu = view.get_page_context_action (hit_test_result);
    copy = menu.get_by_name ("Copy");
    assert (!copy.sensitive);
    assert (view.web_view.search_text ("flat", true, false, false));
    menu = view.get_page_context_action (hit_test_result);
    copy = menu.get_by_name ("Copy");
    assert (copy.sensitive);
#endif
}

void main (string[] args) {
    Test.init (ref args);
    Midori.App.setup (ref args, null);
    Midori.Paths.init (Midori.RuntimeMode.NORMAL, null);
#if !HAVE_WEBKIT2
    WebKit.get_default_session ().set_data<bool> ("midori-session-initialized", true);
#endif
    Test.add_func ("/actions/view/page", actions_view_page);
    Test.run ();
}