Merge lp:~thomir/unity/ap-test-quicklist-actions-are-shown into lp:unity

Proposed by Thomi Richards on 2012-03-06
Status: Merged
Approved by: Thomi Richards on 2012-03-07
Approved revision: 2060
Merged at revision: 2064
Proposed branch: lp:~thomir/unity/ap-test-quicklist-actions-are-shown
Merge into: lp:unity
Diff against target: 202 lines (+96/-54)
5 files modified
plugins/unityshell/src/BamfLauncherIcon.cpp (+39/-53)
tests/autopilot/autopilot/emulators/unity/quicklist.py (+1/-1)
tests/autopilot/autopilot/tests/__init__.py (+4/-0)
tests/autopilot/autopilot/tests/test_quicklist.py (+51/-0)
tools/autopilot (+1/-0)
To merge this branch: bzr merge lp:~thomir/unity/ap-test-quicklist-actions-are-shown
Reviewer Review Type Date Requested Status
Tim Penhey (community) 2012-03-06 Approve on 2012-03-07
Review via email: mp+96252@code.launchpad.net

Description of the change

This branch adds autopilot tests to verify the fix for bug lp:942042.

UNBLOCK

To post a comment you must log in.
Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/BamfLauncherIcon.cpp'
2--- plugins/unityshell/src/BamfLauncherIcon.cpp 2012-02-28 23:51:12 +0000
3+++ plugins/unityshell/src/BamfLauncherIcon.cpp 2012-03-06 21:47:15 +0000
4@@ -663,64 +663,50 @@
5
6 void BamfLauncherIcon::UpdateDesktopQuickList()
7 {
8- GKeyFile* keyfile;
9- glib::Error error;
10 std::string const& desktop_file = DesktopFile();
11
12 if (desktop_file.empty())
13 return;
14
15- // check that we have the X-Ayatana-Desktop-Shortcuts flag
16- // not sure if we should do this or if libindicator should shut up
17- // and not report errors when it can't find the key.
18- // so FIXME when ted is around
19- keyfile = g_key_file_new();
20- g_key_file_load_from_file(keyfile, desktop_file.c_str(), G_KEY_FILE_NONE, &error);
21-
22- if (error)
23- {
24- g_warning("Could not load desktop file for: %s", desktop_file.c_str());
25- g_key_file_free(keyfile);
26- return;
27- }
28-
29- if (g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP,
30- "X-Ayatana-Desktop-Shortcuts", nullptr))
31- {
32- for (GList *l = dbusmenu_menuitem_get_children(_menu_desktop_shortcuts); l; l = l->next)
33- _gsignals.Disconnect(l->data, "item-activated");
34-
35- _menu_desktop_shortcuts = dbusmenu_menuitem_new();
36- dbusmenu_menuitem_set_root(_menu_desktop_shortcuts, TRUE);
37-
38- _desktop_shortcuts = indicator_desktop_shortcuts_new(desktop_file.c_str(), "Unity");
39- const gchar** nicks = indicator_desktop_shortcuts_get_nicks(_desktop_shortcuts);
40-
41- int index = 0;
42- while (nicks[index])
43- {
44- glib::String name(indicator_desktop_shortcuts_nick_get_name(_desktop_shortcuts,
45- nicks[index]));
46- glib::Object<DbusmenuMenuitem> item(dbusmenu_menuitem_new());
47- dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, name);
48- dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
49- dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
50- dbusmenu_menuitem_property_set(item, "shortcut-nick", nicks[index]);
51-
52- auto sig = new glib::Signal<void, DbusmenuMenuitem*, gint>(item, "item-activated",
53- [&] (DbusmenuMenuitem* item, gint) {
54- const gchar *nick;
55- nick = dbusmenu_menuitem_property_get(item, "shortcut-nick");
56- indicator_desktop_shortcuts_nick_exec(_desktop_shortcuts, nick);
57- });
58- _gsignals.Add(sig);
59-
60- dbusmenu_menuitem_child_append(_menu_desktop_shortcuts, item);
61- index++;
62- }
63- }
64-
65- g_key_file_free(keyfile);
66+ for (GList *l = dbusmenu_menuitem_get_children(_menu_desktop_shortcuts); l; l = l->next)
67+ _gsignals.Disconnect(l->data, "item-activated");
68+
69+ _menu_desktop_shortcuts = dbusmenu_menuitem_new();
70+ dbusmenu_menuitem_set_root(_menu_desktop_shortcuts, TRUE);
71+
72+ // Build a desktop shortcuts object and tell it that our
73+ // environment is Unity to handle the filtering
74+ _desktop_shortcuts = indicator_desktop_shortcuts_new(desktop_file.c_str(), "Unity");
75+ // This will get us a list of the nicks available, it should
76+ // always be at least one entry of NULL if there either aren't
77+ // any or they're filtered for the environment we're in
78+ const gchar** nicks = indicator_desktop_shortcuts_get_nicks(_desktop_shortcuts);
79+
80+ int index = 0;
81+ while (nicks[index]) {
82+
83+ // Build a dbusmenu item for each nick that is the desktop
84+ // file that is built from it's name and includes a callback
85+ // to the desktop shortcuts object to execute the nick
86+ glib::String name(indicator_desktop_shortcuts_nick_get_name(_desktop_shortcuts,
87+ nicks[index]));
88+ glib::Object<DbusmenuMenuitem> item(dbusmenu_menuitem_new());
89+ dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, name);
90+ dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
91+ dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
92+ dbusmenu_menuitem_property_set(item, "shortcut-nick", nicks[index]);
93+
94+ auto sig = new glib::Signal<void, DbusmenuMenuitem*, gint>(item, "item-activated",
95+ [&] (DbusmenuMenuitem* item, gint) {
96+ const gchar *nick;
97+ nick = dbusmenu_menuitem_property_get(item, "shortcut-nick");
98+ indicator_desktop_shortcuts_nick_exec(_desktop_shortcuts, nick);
99+ });
100+ _gsignals.Add(sig);
101+
102+ dbusmenu_menuitem_child_append(_menu_desktop_shortcuts, item);
103+ index++;
104+ }
105 }
106
107 void BamfLauncherIcon::UpdateMenus()
108
109=== modified file 'tests/autopilot/autopilot/emulators/unity/quicklist.py'
110--- tests/autopilot/autopilot/emulators/unity/quicklist.py 2012-03-04 23:12:19 +0000
111+++ tests/autopilot/autopilot/emulators/unity/quicklist.py 2012-03-06 21:47:15 +0000
112@@ -23,7 +23,7 @@
113 @property
114 def items(self):
115 """Individual items in the quicklist."""
116- return [self.__make_quicklist_from_data(ctype, cdata) for ctype, cdata in self._children]
117+ return self.get_children_by_type(QuicklistMenuItem)
118
119 def get_quicklist_item_by_text(self, text):
120 """Returns a QuicklistMenuItemLabel object with the given text, or None."""
121
122=== modified file 'tests/autopilot/autopilot/tests/__init__.py'
123--- tests/autopilot/autopilot/tests/__init__.py 2012-03-06 20:12:33 +0000
124+++ tests/autopilot/autopilot/tests/__init__.py 2012-03-06 21:47:15 +0000
125@@ -153,6 +153,10 @@
126 'desktop-file': 'mahjongg.desktop',
127 'process-name': 'mahjongg',
128 },
129+ 'Remmina' : {
130+ 'desktop-file': 'remmina.desktop',
131+ 'process-name': 'remmina',
132+ }
133 }
134
135 def setUp(self):
136
137=== added file 'tests/autopilot/autopilot/tests/test_quicklist.py'
138--- tests/autopilot/autopilot/tests/test_quicklist.py 1970-01-01 00:00:00 +0000
139+++ tests/autopilot/autopilot/tests/test_quicklist.py 2012-03-06 21:47:15 +0000
140@@ -0,0 +1,51 @@
141+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
142+# Copyright 2012 Canonical
143+# Author: Thomi Richards
144+#
145+# This program is free software: you can redistribute it and/or modify it
146+# under the terms of the GNU General Public License version 3, as published
147+# by the Free Software Foundation.
148+
149+import os.path
150+from testtools.matchers import Not, Is, Contains
151+from xdg.DesktopEntry import DesktopEntry
152+
153+from autopilot.emulators.unity.quicklist import QuicklistMenuItemLabel
154+from autopilot.tests import AutopilotTestCase
155+
156+class QuicklistActionTests(AutopilotTestCase):
157+ """Tests for quicklist actions."""
158+
159+ scenarios = [
160+ ('remmina', {'app_name': 'Remmina'}),
161+ ]
162+
163+ def test_quicklist_actions(self):
164+ """Test that all actions present in the destop file are shown in the quicklist."""
165+ self.start_app(self.app_name)
166+
167+ # load the desktop file from disk:
168+ desktop_file = os.path.join('/usr/share/applications',
169+ self.KNOWN_APPS[self.app_name]['desktop-file']
170+ )
171+ de = DesktopEntry(desktop_file)
172+ # get the launcher icon from the launcher:
173+ launcher_icon = self.launcher.model.get_icon_by_tooltip_text(de.getName())
174+ self.assertThat(launcher_icon, Not(Is(None)))
175+
176+ # open the icon quicklist, and get all the text labels:
177+ launcher = self.launcher.get_launcher_for_monitor(0)
178+ launcher.click_launcher_icon(launcher_icon, button=3)
179+ ql = launcher_icon.get_quicklist()
180+ ql_item_texts = [i.text for i in ql.items if type(i) is QuicklistMenuItemLabel]
181+
182+ # iterate over all the actions from the desktop file, make sure they're
183+ # present in the quicklist texts.
184+ actions = de.getActions()
185+ for action in actions:
186+ key = 'Desktop Action ' + action
187+ self.assertThat(de.content, Contains(key))
188+ name = de.content[key]['Name']
189+ self.assertThat(ql_item_texts, Contains(name))
190+
191+
192
193=== modified file 'tools/autopilot'
194--- tools/autopilot 2012-03-06 20:12:33 +0000
195+++ tools/autopilot 2012-03-06 21:47:15 +0000
196@@ -21,6 +21,7 @@
197 ('junitxml', 'python-junitxml'),
198 ('testscenarios', 'python-testscenarios'),
199 ('testtools', 'python-testtools'),
200+ ('xdg', 'python-xdg'),
201 ('Xlib', 'python-xlib'),
202 ]
203