Merge lp:~kalikiana/midori/tstactfixcpy into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: André Stösel
Approved revision: 6309
Merged at revision: 6310
Proposed branch: lp:~kalikiana/midori/tstactfixcpy
Merge into: lp:midori
Diff against target: 142 lines (+82/-2)
5 files modified
midori/midori-contextaction.vala (+7/-0)
midori/midori-searchaction.c (+6/-2)
midori/midori-view.c (+5/-0)
midori/midori.vapi (+1/-0)
tests/actions.vala (+63/-0)
To merge this branch: bzr merge lp:~kalikiana/midori/tstactfixcpy
Reviewer Review Type Date Requested Status
gue5t gue5t Approve
Review via email: mp+178403@code.launchpad.net

Commit message

Add initial actions unit test starting with page context menu

Description of the change

As a a side effect of using ContextAction we not only gain proper extension API but also better unit test support. I'm making a first step here - for now now only the page menu exposes itself API-wise.

The test actually tests and fixes a bug where Copy may not be sensitive.

To post a comment you must log in.
Revision history for this message
gue5t gue5t (gue5t) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-contextaction.vala'
2--- midori/midori-contextaction.vala 2013-07-29 21:42:10 +0000
3+++ midori/midori-contextaction.vala 2013-08-02 23:50:36 +0000
4@@ -102,6 +102,13 @@
5 }
6 return menu;
7 }
8+
9+ public Gtk.Action? get_by_name (string name) {
10+ foreach (var action in children)
11+ if (action.name == name)
12+ return action;
13+ return null;
14+ }
15 }
16
17 public class SeparatorContextAction : ContextAction {
18
19=== modified file 'midori/midori-searchaction.c'
20--- midori/midori-searchaction.c 2013-06-21 20:49:53 +0000
21+++ midori/midori-searchaction.c 2013-08-02 23:50:36 +0000
22@@ -905,6 +905,7 @@
23 PangoEllipsizeMode ellipsize)
24 {
25 #ifndef HAVE_WEBKIT2
26+ WebKitWebFrame* focused_frame;
27 WebKitDOMDocument* doc;
28 WebKitDOMHTMLFormElement* active_form;
29 WebKitDOMHTMLCollection* form_nodes;
30@@ -918,10 +919,13 @@
31 KatzeItem* item;
32 gchar** parts;
33
34+ focused_frame = webkit_web_view_get_focused_frame (web_view);
35+ if (focused_frame == NULL)
36+ return NULL;
37 #if WEBKIT_CHECK_VERSION (1, 9, 5)
38- doc = webkit_web_frame_get_dom_document (webkit_web_view_get_focused_frame (web_view));
39+ doc = webkit_web_frame_get_dom_document (focused_frame);
40 #else
41- if (webkit_web_view_get_focused_frame (web_view) != webkit_web_view_get_main_frame (web_view))
42+ if (focused_frame != webkit_web_view_get_main_frame (web_view))
43 return NULL;
44 doc = webkit_web_view_get_dom_document (web_view);
45 #endif
46
47=== modified file 'midori/midori-view.c'
48--- midori/midori-view.c 2013-08-02 12:00:42 +0000
49+++ midori/midori-view.c 2013-08-02 23:50:36 +0000
50@@ -2398,7 +2398,12 @@
51
52 /* No need to have Copy twice, which is already in the editable menu */
53 if (!(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE))
54+ {
55+ /* Enforce update of copy action - there's no "selection-changed" signal */
56 midori_context_action_add_by_name (menu, "Copy");
57+ gtk_action_set_sensitive (gtk_action_group_get_action (actions, "Copy"),
58+ webkit_web_view_can_copy_clipboard (WEBKIT_WEB_VIEW (view->web_view)));
59+ }
60
61 /* Ensure view->selected_text */
62 midori_view_has_selection (view);
63
64=== modified file 'midori/midori.vapi'
65--- midori/midori.vapi 2013-08-02 18:00:42 +0000
66+++ midori/midori.vapi 2013-08-02 23:50:36 +0000
67@@ -190,6 +190,7 @@
68 public void populate_popup (Gtk.Menu menu, bool manual);
69 public void reload (bool from_cache);
70 public Gtk.Widget add_info_bar (Gtk.MessageType type, string message, GLib.Callback? callback, void* object, ...);
71+ public ContextAction get_page_context_action (WebKit.HitTestResult hit_test_result);
72
73 public string title { get; }
74 public Gdk.Pixbuf icon { get; }
75
76=== added file 'tests/actions.vala'
77--- tests/actions.vala 1970-01-01 00:00:00 +0000
78+++ tests/actions.vala 2013-08-02 23:50:36 +0000
79@@ -0,0 +1,63 @@
80+/*
81+ Copyright (C) 2013 Christian Dywan <christian@twotoasts.de>
82+
83+ This library is free software; you can redistribute it and/or
84+ modify it under the terms of the GNU Lesser General Public
85+ License as published by the Free Software Foundation; either
86+ version 2.1 of the License, or (at your option) any later version.
87+
88+ See the file COPYING for the full license text.
89+*/
90+
91+void actions_view_page () {
92+ var browser = new Midori.Browser ();
93+ var view = new Midori.View.with_title (null, new Midori.WebSettings ());
94+ browser.add_tab (view);
95+ browser.show ();
96+ view.set_html ("<body>The earth is <em>flat</em> for a fact.</body>");
97+ var loop = MainContext.default ();
98+ do { loop.iteration (true); } while (view.load_status != Midori.LoadStatus.FINISHED);
99+
100+ var hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.DOCUMENT) as WebKit.HitTestResult;
101+ var menu = view.get_page_context_action (hit_test_result);
102+ assert (menu.name == "PageContextMenu");
103+ assert (menu.get_by_name ("Back") != null);
104+
105+#if !HAVE_WEBKIT2
106+ hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.EDITABLE) as WebKit.HitTestResult;
107+ menu = view.get_page_context_action (hit_test_result);
108+ var copy = menu.get_by_name ("Copy");
109+ assert (!copy.sensitive);
110+ assert (view.web_view.search_text ("flat", true, false, false));
111+ menu = view.get_page_context_action (hit_test_result);
112+ copy = menu.get_by_name ("Copy");
113+ assert (copy.sensitive);
114+#endif
115+
116+ /* Reload contents to clear selection */
117+ view.set_html ("<body>The earth is <em>flat</em> for a fact.</body>");
118+ do { loop.iteration (true); } while (view.load_status != Midori.LoadStatus.FINISHED);
119+
120+#if !HAVE_WEBKIT2
121+ hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.SELECTION) as WebKit.HitTestResult;
122+ menu = view.get_page_context_action (hit_test_result);
123+ copy = menu.get_by_name ("Copy");
124+ assert (!copy.sensitive);
125+ assert (view.web_view.search_text ("flat", true, false, false));
126+ menu = view.get_page_context_action (hit_test_result);
127+ copy = menu.get_by_name ("Copy");
128+ assert (copy.sensitive);
129+#endif
130+}
131+
132+void main (string[] args) {
133+ Test.init (ref args);
134+ Midori.App.setup (ref args, null);
135+ Midori.Paths.init (Midori.RuntimeMode.NORMAL, null);
136+#if !HAVE_WEBKIT2
137+ WebKit.get_default_session ().set_data<bool> ("midori-session-initialized", true);
138+#endif
139+ Test.add_func ("/actions/view/page", actions_view_page);
140+ Test.run ();
141+}
142+

Subscribers

People subscribed via source and target branches

to all changes: