Merge lp:~haggai-eran/unity-2d/rtl-keyboard-navigation-886686 into lp:unity-2d

Proposed by Haggai Eran
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 953
Merged at revision: 995
Proposed branch: lp:~haggai-eran/unity-2d/rtl-keyboard-navigation-886686
Merge into: lp:unity-2d
Diff against target: 818 lines (+454/-190)
12 files modified
libunity-2d-private/src/CMakeLists.txt (+1/-0)
libunity-2d-private/src/focuspath.cpp (+2/-1)
libunity-2d-private/src/launchermenu.cpp (+2/-1)
libunity-2d-private/src/utils.cpp (+43/-0)
libunity-2d-private/src/utils.h (+30/-0)
shell/common/utils.js (+14/-0)
shell/dash/LensBar.qml (+2/-1)
shell/dash/RatingStars.qml (+1/-1)
shell/launcher/LauncherList.qml (+6/-4)
tests/launcher/menu_tests.rb (+18/-182)
tests/launcher/menu_tests_common.rb (+225/-0)
tests/launcher/menu_tests_rtl.rb (+110/-0)
To merge this branch: bzr merge lp:~haggai-eran/unity-2d/rtl-keyboard-navigation-886686
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
Review via email: mp+96010@code.launchpad.net

Commit message

Fix right-to-left keyboard navigation in the dash and in the launcher (LP: #886686)

Description of the change

This is an attempt to solve bug #886686. When using a right-to-left locale, and the user interface is mirrored, the left and right key often need to change their meaning, so that the left key moves the cursor to the next logical position, and the right key moves the cursor back to the previous logical position.

This MR makes these changes in the launcher (when opening item's menus), and in the dash.

@Gerry, in a previous comment you mentioned you had reservations about this fix, and perhaps it was possible to make the required changes in unity-panel-service. If I'm not mistaken, unity-panel-service is responsible for displaying the panel menus for applications and indicators, isn't it? The keyboard navigation through the panel menus will also need to be changed, but this MR is targeted at keyboard navigation in the dash and launcher.

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

The code works fine. I am interested in the QML code you used the switchLeftRightKeys way but in focuspath.cpp instead of applying the same principle you decided to change the flow. I think it'd would be easier to understand if you used the switchLeftRightKeys same construct here too.

Revision history for this message
Haggai Eran (haggai-eran) wrote :

When I wrote the code in focuspath.cpp I noticed that the flow feature already implemented some kind of mirroring, so I thought it would be nice to use it. You are probably right and switching the keys would probably make the code more robust to future changes. I'll upload an updated version soon.

949. By Haggai Eran

In RTL, switch the left and right keys in focuspath.cpp, instead of switching the flow.

Revision history for this message
Haggai Eran (haggai-eran) wrote :

I've changed the C++ code to switch the left and right keys, similarly to the QML code.

Revision history for this message
Albert Astals Cid (aacid) wrote :

Could you move the C++ code that does the left/right switching to a Utils.cpp/Utils.h file and then use that function also in LauncherContextualMenu::keyPressEvent ?

950. By Haggai Eran

Create a common switchLeftRightKeys() function, and use it in focuspath.cpp and launchermenu.cpp.

Revision history for this message
Haggai Eran (haggai-eran) wrote :

Sure, how about this? I moved the switching code to another function.

Revision history for this message
Albert Astals Cid (aacid) wrote :

You have a conflict in CMakeLists.txt, can you merge the latest lp:unity-2d into your branch?

Also i'd prefer if you added a namespace to the utils.h i.e.

namespace Unity2dUtils {

/* If using a right-to-left locale, switch the left and right keys. */
int switchLeftRightKeys(int key);

}

review: Needs Fixing
951. By Haggai Eran

Merge trunk in order to resolve conflicts in libunity-2d-private/src/CMakeLists.txt.

952. By Haggai Eran

Move switchLeftRightKeys function to a namespace.

Revision history for this message
Haggai Eran (haggai-eran) wrote :

Thanks for pointing out the conflict. I merged the latest trunk, and moved the new function to a namespace as you requested.

Revision history for this message
Gerry Boland (gerboland) wrote :

Hey Haggai,
this is nice to automatically test, so I'm writing a test for this now, which I'll write and make a merge request into this branch shortly.
Thanks for your patience
-Gerry

Revision history for this message
Haggai Eran (haggai-eran) wrote :

Sure, thank you for writing the test.

953. By Haggai Eran

[tests] Merge Gerry's launcher menu tests.

Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks great :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/CMakeLists.txt'
2--- libunity-2d-private/src/CMakeLists.txt 2012-03-06 18:06:03 +0000
3+++ libunity-2d-private/src/CMakeLists.txt 2012-03-12 18:36:25 +0000
4@@ -80,6 +80,7 @@
5 inputshaperectangle.cpp
6 inputshapemask.cpp
7 strutmanager.cpp
8+ utils.cpp
9 pointerbarrier.cpp
10 pointerbarriermanager.cpp
11 decayedvalue.cpp
12
13=== modified file 'libunity-2d-private/src/focuspath.cpp'
14--- libunity-2d-private/src/focuspath.cpp 2011-12-21 18:14:22 +0000
15+++ libunity-2d-private/src/focuspath.cpp 2012-03-12 18:36:25 +0000
16@@ -18,6 +18,7 @@
17 */
18
19 #include "focuspath.h"
20+#include "utils.h"
21
22 #include <QtCore/qmath.h>
23 #include <QEvent>
24@@ -345,7 +346,7 @@
25 int nextFocus = m_currentPosition;
26
27 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
28- switch(keyEvent->key()) {
29+ switch(Unity2dUtils::switchLeftRightKeys(keyEvent->key())) {
30 case Qt::Key_Right:
31 if ((m_direction & FocusPath::Horizontal) == FocusPath::Horizontal) {
32 switch(m_flow) {
33
34=== modified file 'libunity-2d-private/src/launchermenu.cpp'
35--- libunity-2d-private/src/launchermenu.cpp 2011-12-05 06:49:40 +0000
36+++ libunity-2d-private/src/launchermenu.cpp 2012-03-12 18:36:25 +0000
37@@ -19,6 +19,7 @@
38
39 #include "launchermenu.h"
40 #include "launcheritem.h"
41+#include "utils.h"
42
43 #include <QAction>
44 #include <QFile>
45@@ -330,7 +331,7 @@
46 void
47 LauncherContextualMenu::keyPressEvent(QKeyEvent* event)
48 {
49- int key = event->key();
50+ int key = Unity2dUtils::switchLeftRightKeys(event->key());
51 if (key == Qt::Key_Left || key == Qt::Key_Escape) {
52 Q_EMIT dismissedByKeyEvent();
53 hide();
54
55=== added file 'libunity-2d-private/src/utils.cpp'
56--- libunity-2d-private/src/utils.cpp 1970-01-01 00:00:00 +0000
57+++ libunity-2d-private/src/utils.cpp 2012-03-12 18:36:25 +0000
58@@ -0,0 +1,43 @@
59+/*
60+ * Copyright (C) 2011 Canonical, Ltd.
61+ *
62+ * Authors:
63+ * Haggai Eran <haggai.eran@gmail.com>
64+ *
65+ * This program is free software; you can redistribute it and/or modify
66+ * it under the terms of the GNU General Public License as published by
67+ * the Free Software Foundation; version 3.
68+ *
69+ * This program is distributed in the hope that it will be useful,
70+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
71+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72+ * GNU General Public License for more details.
73+ *
74+ * You should have received a copy of the GNU General Public License
75+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
76+ */
77+
78+#include "utils.h"
79+
80+#include <QApplication>
81+
82+namespace Unity2dUtils {
83+
84+/* If using a right-to-left locale, switch the left and right keys. */
85+int switchLeftRightKeys(int key)
86+{
87+ if (QApplication::isRightToLeft()) {
88+ switch(key) {
89+ case Qt::Key_Right:
90+ return Qt::Key_Left;
91+ case Qt::Key_Left:
92+ return Qt::Key_Right;
93+ default:
94+ return key;
95+ }
96+ }
97+ return key;
98+}
99+
100+} // namespace
101+
102
103=== added file 'libunity-2d-private/src/utils.h'
104--- libunity-2d-private/src/utils.h 1970-01-01 00:00:00 +0000
105+++ libunity-2d-private/src/utils.h 2012-03-12 18:36:25 +0000
106@@ -0,0 +1,30 @@
107+/*
108+ * Copyright (C) 2011 Canonical, Ltd.
109+ *
110+ * Authors:
111+ * Haggai Eran <haggai.eran@gmail.com>
112+ *
113+ * This program is free software; you can redistribute it and/or modify
114+ * it under the terms of the GNU General Public License as published by
115+ * the Free Software Foundation; version 3.
116+ *
117+ * This program is distributed in the hope that it will be useful,
118+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
119+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120+ * GNU General Public License for more details.
121+ *
122+ * You should have received a copy of the GNU General Public License
123+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
124+ */
125+
126+#ifndef UTILS_H
127+#define UTILS_H
128+
129+namespace Unity2dUtils {
130+
131+/* If using a right-to-left locale, switch the left and right keys. */
132+int switchLeftRightKeys(int key);
133+
134+} // namespace
135+
136+#endif // UTILS_H
137
138=== modified file 'shell/common/utils.js'
139--- shell/common/utils.js 2012-02-17 15:17:41 +0000
140+++ shell/common/utils.js 2012-03-12 18:36:25 +0000
141@@ -44,3 +44,17 @@
142 function isRightToLeft() {
143 return Qt.application.layoutDirection == Qt.RightToLeft
144 }
145+
146+function switchLeftRightKeys(key) {
147+ if (isRightToLeft()) {
148+ switch (key) {
149+ case Qt.Key_Right:
150+ return Qt.Key_Left
151+ case Qt.Key_Left:
152+ return Qt.Key_Right
153+ default:
154+ return key
155+ }
156+ }
157+ return key
158+}
159
160=== modified file 'shell/dash/LensBar.qml'
161--- shell/dash/LensBar.qml 2012-03-06 13:05:19 +0000
162+++ shell/dash/LensBar.qml 2012-03-12 18:36:25 +0000
163@@ -18,6 +18,7 @@
164
165 import QtQuick 1.0
166 import Unity2d 1.0
167+import "../common/utils.js" as Utils
168
169 FocusScope {
170 id: lensBar
171@@ -71,7 +72,7 @@
172 }
173
174 function handleKeyPress(key) {
175- switch (key) {
176+ switch (Utils.switchLeftRightKeys(key)) {
177 case Qt.Key_Right:
178 return selectChild(currentIndex+1)
179 case Qt.Key_Left:
180
181=== modified file 'shell/dash/RatingStars.qml'
182--- shell/dash/RatingStars.qml 2012-03-03 17:59:53 +0000
183+++ shell/dash/RatingStars.qml 2012-03-12 18:36:25 +0000
184@@ -47,7 +47,7 @@
185
186 Keys.onPressed: if (handleKeyPress(event.key)) event.accepted = true
187 function handleKeyPress(key) {
188- switch (key) {
189+ switch (Utils.switchLeftRightKeys(key)) {
190 case Qt.Key_Right:
191 incrementRating()
192 return true
193
194=== modified file 'shell/launcher/LauncherList.qml'
195--- shell/launcher/LauncherList.qml 2012-02-24 12:48:13 +0000
196+++ shell/launcher/LauncherList.qml 2012-03-12 18:36:25 +0000
197@@ -18,6 +18,7 @@
198
199 import QtQuick 1.0
200 import Unity2d 1.0 /* required for drag’n’drop handling */
201+import "../common/utils.js" as Utils
202
203 AutoScrollingListView {
204 id: list
205@@ -198,13 +199,14 @@
206 }
207
208 Keys.onPressed: {
209- if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter || event.key == Qt.Key_Space) {
210+ var key = Utils.switchLeftRightKeys(event.key)
211+ if (key == Qt.Key_Return || key == Qt.Key_Enter || key == Qt.Key_Space) {
212 item.menu.hide()
213 item.activate()
214 event.accepted = true
215 }
216- else if ((event.key == Qt.Key_Right && list.showMenus) ||
217- (event.key == Qt.Key_F10 && (event.modifiers & Qt.ShiftModifier))) {
218+ else if ((key == Qt.Key_Right && list.showMenus) ||
219+ (key == Qt.Key_F10 && (event.modifiers & Qt.ShiftModifier))) {
220 /* Show the menu first, then unfold it. Doing things in this
221 order is required because at the moment the code path that
222 adjusts the position of the menu in case it goes offscreen
223@@ -215,7 +217,7 @@
224 item.menu.setFocus()
225 event.accepted = true
226 }
227- else if (event.key == Qt.Key_Left) {
228+ else if (key == Qt.Key_Left) {
229 item.menu.hide()
230 event.accepted = true
231 }
232
233=== modified file 'tests/launcher/menu_tests.rb'
234--- tests/launcher/menu_tests.rb 2012-03-06 10:36:41 +0000
235+++ tests/launcher/menu_tests.rb 2012-03-12 18:36:25 +0000
236@@ -27,9 +27,19 @@
237 require 'xdo/keyboard'
238 require 'xdo/mouse'
239 require 'tmpwindow'
240+require $library_path + '/../../launcher/menu_tests_common.rb'
241
242 ############################# Test Suite #############################
243 context "Launcher Contextual Menu Tests" do
244+
245+ def keyboard_tap_right()
246+ XDo::Keyboard.right
247+ end
248+
249+ def keyboard_tap_left()
250+ XDo::Keyboard.left
251+ end
252+
253 # Run once at the beginning of this test suite
254 startup do
255 $SUT.execute_shell_command 'killall unity-2d-shell'
256@@ -66,209 +76,35 @@
257
258 #####################################################################################
259 # Test cases
260-
261- # Test case objectives:
262- # * Check that the hint is displayed on mouse hover
263- # Pre-conditions
264- # * Desktop with no running applications
265- # Test steps
266- # * Hover the cursor over the first application entry
267- # * Check that the hint is displayed
268- # * Check that there are two QActions (there is a "ghost" QAction there)
269- # Post-conditions
270- # * None
271- # References
272- # * None
273 test "Display launcher item hint" do
274- tiles = ""
275- verify( TIMEOUT, 'Could not find any application tile' ) {
276- tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
277- }
278- tile = tiles[0]
279- tile.move_mouse()
280- verify(TIMEOUT, 'The launcher item hint is not visible' ) {
281- @app.LauncherContextualMenu()
282- }
283- actions = ""
284- verify( TIMEOUT, 'Could not find any actions in the menu' ) {
285- actions = @app.LauncherContextualMenu().children( { :type => "QAction" } )
286- }
287- verify_equal( 2, TIMEOUT, 'There was an unexpected number of actions in the menu' ) {
288- actions.count
289- }
290+ test_display_launcher_item_hint()
291 end
292
293- # Test case objectives:
294- # * Check that the menu is displayed on right click
295- # Pre-conditions
296- # * Desktop with no running applications
297- # Test steps
298- # * Right click the first application entry
299- # * Check that the menu is displayed
300- # * Check that there are at least four QActions (two actions and separator, plus a "ghost" one)
301- # Post-conditions
302- # * None
303- # References
304- # * None
305 test "Display launcher menu after right click" do
306- tiles = ""
307- verify( TIMEOUT, 'Could not find any application tile' ) {
308- tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
309- }
310- tile = tiles[0]
311- tile.move_mouse()
312- tile.tap(1, :Right)
313- verify(TIMEOUT, 'The launcher menu is not visible' ) {
314- @app.LauncherContextualMenu()
315- }
316- actions = ""
317- verify( TIMEOUT, 'Could not find any actions in the menu' ) {
318- actions = @app.LauncherContextualMenu().children( { :type => "QAction" } )
319- }
320- verify_true( TIMEOUT, 'There was not enough actions in the menu' ) {
321- actions.count >= 4
322- }
323+ test_display_launcher_menu_after_right_click()
324 end
325
326- # Test case objectives:
327- # * Check that the menu is displayed on right key from item
328- # Pre-conditions
329- # * Desktop with no running applications
330- # Test steps
331- # * Focus the launcher, go down and right
332- # * Check that the menu is displayed
333- # * Check that there are at least four QActions (two actions and separator, plus a "ghost" one)
334- # Post-conditions
335- # * None
336- # References
337- # * None
338 test "Display launcher menu with keyboard navigation" do
339- XDo::Keyboard.alt_F1
340- XDo::Keyboard.down
341- XDo::Keyboard.right
342- verify(TIMEOUT, 'The launcher menu is not visible' ) {
343- @app.LauncherContextualMenu()
344- }
345- actions = ""
346- verify( TIMEOUT, 'Could not find any actions in the menu' ) {
347- actions = @app.LauncherContextualMenu().children( { :type => "QAction" } )
348- }
349- verify_true( TIMEOUT, 'There was not enough actions in the menu' ) {
350- actions.count >= 4
351- }
352+ test_display_launcher_menu_with_keyboard_navigation()
353 end
354
355- # Test case objectives:
356- # * Check that the menu is being closed on Esc
357- # Pre-conditions
358- # * Desktop with no running applications
359- # Test steps
360- # * Focus the launcher, go down and right, press Esc
361- # * Check that the menu is no longer there
362- # Post-conditions
363- # * None
364- # References
365- # * None
366 test "Close launcher menu when pressing Esc" do
367- XDo::Keyboard.alt_F1
368- XDo::Keyboard.down
369- XDo::Keyboard.right
370- XDo::Keyboard.escape
371- verify_not(TIMEOUT, 'The launcher menu is not visible' ) {
372- @app.LauncherContextualMenu()
373- }
374+ test_close_launcher_menu_when_pressing_esc()
375 end
376
377- # Test case objectives:
378- # * Check that the menu is being closed on left key
379- # Pre-conditions
380- # * Desktop with no running applications
381- # Test steps
382- # * Focus the launcher, go down and right, then left
383- # * Check that the menu is no longer there
384- # Post-conditions
385- # * None
386- # References
387- # * None
388 test "Close launcher menu when navigating back to the launcher" do
389- XDo::Keyboard.alt_F1
390- XDo::Keyboard.down
391- XDo::Keyboard.right
392- XDo::Keyboard.left
393- verify_not(TIMEOUT, 'The launcher menu is not visible' ) {
394- @app.LauncherContextualMenu()
395- }
396+ test_close_launcher_menu_when_navigating_back_to_the_launcher()
397 end
398
399- # Test case objectives:
400- # * Check that the focus goes back to the launcher item when menu was dismissed with Esc
401- # Pre-conditions
402- # * Desktop with no running applications
403- # Test steps
404- # * Focus the launcher, go down and right, press Esc
405- # * Check that the launcher item has focus
406- # Post-conditions
407- # * None
408- # References
409- # * None
410 test "Verify launcher tile gets focus after dismissing the menu with Esc" do
411- XDo::Keyboard.alt_F1
412- XDo::Keyboard.down
413- XDo::Keyboard.right
414- XDo::Keyboard.escape
415- tiles = ""
416- verify( TIMEOUT, 'Could not find any application tile' ) {
417- tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
418- }
419- tile = tiles[0]
420- verify_equal( "true", TIMEOUT, 'Launcher item didn\'t regain focus' ) {
421- tile['activeFocus']
422- }
423+ test_verify_launcher_tile_gets_focus_after_dismissing_the_menu_with_esc()
424 end
425
426- # Test case objectives:
427- # * Check that the focus goes back to the launcher item when menu was dismissed with keyboard navigation
428- # Pre-conditions
429- # * Desktop with no running applications
430- # Test steps
431- # * Focus the launcher, go down and right, press Esc
432- # * Check that the launcher item has focus
433- # Post-conditions
434- # * None
435- # References
436- # * None
437 test "Verify launcher tile gets focus after dismissing the menu with keyboard navigation" do
438- XDo::Keyboard.alt_F1
439- XDo::Keyboard.down
440- XDo::Keyboard.right
441- XDo::Keyboard.left
442- tiles = ""
443- verify( TIMEOUT, 'Could not find any application tile' ) {
444- tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
445- }
446- tile = tiles[0]
447- verify_equal( "true", TIMEOUT, 'Launcher item didn\'t regain focus' ) {
448- tile['activeFocus']
449- }
450+ test_verify_launcher_tile_gets_focus_after_dismissing_the_menu_with_keyboard_navigation()
451 end
452
453- # Test case objectives:
454- # * Check that the focus goes from launcher menu to dash
455- # Pre-conditions
456- # * Desktop with no running applications
457- # Test steps
458- # * Focus the launcher, go right, press Super
459- # * Check that the dash search entry has focus
460- # Post-conditions
461- # * None
462- # References
463- # * None
464 test "Verify dash search entry gets focus after dismissing the menu with Super" do
465- XDo::Keyboard.alt_F1
466- XDo::Keyboard.right
467- XDo::Keyboard.super
468- verify_equal( "true", TIMEOUT, 'Dash search entry doesn\'t have focus' ) {
469- @app.SearchEntry()['activeFocus']
470- }
471+ test_verify_dash_search_entry_gets_focus_after_dismissing_the_menu_with_super()
472 end
473 end
474
475=== added file 'tests/launcher/menu_tests_common.rb'
476--- tests/launcher/menu_tests_common.rb 1970-01-01 00:00:00 +0000
477+++ tests/launcher/menu_tests_common.rb 2012-03-12 18:36:25 +0000
478@@ -0,0 +1,225 @@
479+=begin
480+/*
481+ * This file is part of unity-2d
482+ *
483+ * Copyright 2012 Canonical Ltd.
484+ *
485+ * This program is free software; you can redistribute it and/or modify
486+ * it under the terms of the GNU General Public License as published by
487+ * the Free Software Foundation; version 3.
488+ *
489+ * This program is distributed in the hope that it will be useful,
490+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
491+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
492+ * GNU General Public License for more details.
493+ *
494+ * You should have received a copy of the GNU General Public License
495+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
496+ */
497+=end
498+
499+# Test case objectives:
500+# * Check that the hint is displayed on mouse hover
501+# Pre-conditions
502+# * Desktop with no running applications
503+# Test steps
504+# * Hover the cursor over the first application entry
505+# * Check that the hint is displayed
506+# * Check that there are two QActions (there is a "ghost" QAction there)
507+# Post-conditions
508+# * None
509+# References
510+# * None
511+def test_display_launcher_item_hint()
512+ tiles = ""
513+ verify( TIMEOUT, 'Could not find any application tile' ) {
514+ tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
515+ }
516+ tile = tiles[0]
517+ tile.move_mouse()
518+ verify(TIMEOUT, 'The launcher item hint is not visible' ) {
519+ @app.LauncherContextualMenu()
520+ }
521+ actions = ""
522+ verify( TIMEOUT, 'Could not find any actions in the menu' ) {
523+ actions = @app.LauncherContextualMenu().children( { :type => "QAction" } )
524+ }
525+ verify_equal( 2, TIMEOUT, 'There was an unexpected number of actions in the menu' ) {
526+ actions.count
527+ }
528+end
529+
530+# Test case objectives:
531+# * Check that the menu is displayed on right click
532+# Pre-conditions
533+# * Desktop with no running applications
534+# Test steps
535+# * Right click the first application entry
536+# * Check that the menu is displayed
537+# * Check that there are at least four QActions (two actions and separator, plus a "ghost" one)
538+# Post-conditions
539+# * None
540+# References
541+# * None
542+def test_display_launcher_menu_after_right_click()
543+ tiles = ""
544+ verify( TIMEOUT, 'Could not find any application tile' ) {
545+ tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
546+ }
547+ tile = tiles[0]
548+ tile.move_mouse()
549+ tile.tap(1, :Right)
550+ verify(TIMEOUT, 'The launcher menu is not visible' ) {
551+ @app.LauncherContextualMenu()
552+ }
553+ actions = ""
554+ verify( TIMEOUT, 'Could not find any actions in the menu' ) {
555+ actions = @app.LauncherContextualMenu().children( { :type => "QAction" } )
556+ }
557+ verify_true( TIMEOUT, 'There was not enough actions in the menu' ) {
558+ actions.count >= 4
559+ }
560+end
561+
562+# Test case objectives:
563+# * Check that the menu is displayed on right key from item
564+# Pre-conditions
565+# * Desktop with no running applications
566+# Test steps
567+# * Focus the launcher, go down and right
568+# * Check that the menu is displayed
569+# * Check that there are at least four QActions (two actions and separator, plus a "ghost" one)
570+# Post-conditions
571+# * None
572+# References
573+# * None
574+def test_display_launcher_menu_with_keyboard_navigation()
575+ XDo::Keyboard.alt_F1
576+ XDo::Keyboard.down
577+ keyboard_tap_right()
578+ verify(TIMEOUT, 'The launcher menu is not visible' ) {
579+ @app.LauncherContextualMenu()
580+ }
581+ actions = ""
582+ verify( TIMEOUT, 'Could not find any actions in the menu' ) {
583+ actions = @app.LauncherContextualMenu().children( { :type => "QAction" } )
584+ }
585+ verify_true( TIMEOUT, 'There was not enough actions in the menu' ) {
586+ actions.count >= 4
587+ }
588+end
589+
590+# Test case objectives:
591+# * Check that the menu is being closed on Esc
592+# Pre-conditions
593+# * Desktop with no running applications
594+# Test steps
595+# * Focus the launcher, go down and right, press Esc
596+# * Check that the menu is no longer there
597+# Post-conditions
598+# * None
599+# References
600+# * None
601+def test_close_launcher_menu_when_pressing_esc()
602+ XDo::Keyboard.alt_F1
603+ XDo::Keyboard.down
604+ keyboard_tap_right()
605+ XDo::Keyboard.escape
606+ verify_not(TIMEOUT, 'The launcher menu is not visible' ) {
607+ @app.LauncherContextualMenu()
608+ }
609+end
610+
611+# Test case objectives:
612+# * Check that the menu is being closed on left key
613+# Pre-conditions
614+# * Desktop with no running applications
615+# Test steps
616+# * Focus the launcher, go down and right, then left
617+# * Check that the menu is no longer there
618+# Post-conditions
619+# * None
620+# References
621+# * None
622+def test_close_launcher_menu_when_navigating_back_to_the_launcher()
623+ XDo::Keyboard.alt_F1
624+ XDo::Keyboard.down
625+ keyboard_tap_right()
626+ keyboard_tap_left()
627+ verify_not(TIMEOUT, 'The launcher menu is not visible' ) {
628+ @app.LauncherContextualMenu()
629+ }
630+end
631+
632+# Test case objectives:
633+# * Check that the focus goes back to the launcher item when menu was dismissed with Esc
634+# Pre-conditions
635+# * Desktop with no running applications
636+# Test steps
637+# * Focus the launcher, go down and right, press Esc
638+# * Check that the launcher item has focus
639+# Post-conditions
640+# * None
641+# References
642+# * None
643+def test_verify_launcher_tile_gets_focus_after_dismissing_the_menu_with_esc()
644+ XDo::Keyboard.alt_F1
645+ XDo::Keyboard.down
646+ keyboard_tap_right()
647+ XDo::Keyboard.escape
648+ tiles = ""
649+ verify( TIMEOUT, 'Could not find any application tile' ) {
650+ tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
651+ }
652+ tile = tiles[0]
653+ verify_equal( "true", TIMEOUT, 'Launcher item didn\'t regain focus' ) {
654+ tile['activeFocus']
655+ }
656+end
657+
658+# Test case objectives:
659+# * Check that the focus goes back to the launcher item when menu was dismissed with keyboard navigation
660+# Pre-conditions
661+# * Desktop with no running applications
662+# Test steps
663+# * Focus the launcher, go down and right, press Esc
664+# * Check that the launcher item has focus
665+# Post-conditions
666+# * None
667+# References
668+# * None
669+def test_verify_launcher_tile_gets_focus_after_dismissing_the_menu_with_keyboard_navigation()
670+ XDo::Keyboard.alt_F1
671+ XDo::Keyboard.down
672+ keyboard_tap_right()
673+ keyboard_tap_left()
674+ tiles = ""
675+ verify( TIMEOUT, 'Could not find any application tile' ) {
676+ tiles = @app.LauncherList( :name => 'main' ).children( { :desktopFile => /^.*.desktop$/ } )
677+ }
678+ tile = tiles[0]
679+ verify_equal( "true", TIMEOUT, 'Launcher item didn\'t regain focus' ) {
680+ tile['activeFocus']
681+ }
682+end
683+
684+# Test case objectives:
685+# * Check that the focus goes from launcher menu to dash
686+# Pre-conditions
687+# * Desktop with no running applications
688+# Test steps
689+# * Focus the launcher, go right, press Super
690+# * Check that the dash search entry has focus
691+# Post-conditions
692+# * None
693+# References
694+# * None
695+def test_verify_dash_search_entry_gets_focus_after_dismissing_the_menu_with_super()
696+ XDo::Keyboard.alt_F1
697+ keyboard_tap_right()
698+ XDo::Keyboard.super
699+ verify_equal( "true", TIMEOUT, 'Dash search entry doesn\'t have focus' ) {
700+ @app.SearchEntry()['activeFocus']
701+ }
702+end
703+
704
705=== added file 'tests/launcher/menu_tests_rtl.rb'
706--- tests/launcher/menu_tests_rtl.rb 1970-01-01 00:00:00 +0000
707+++ tests/launcher/menu_tests_rtl.rb 2012-03-12 18:36:25 +0000
708@@ -0,0 +1,110 @@
709+#!/usr/bin/env ruby1.8
710+=begin
711+/*
712+ * This file is part of unity-2d
713+ *
714+ * Copyright 2012 Canonical Ltd.
715+ *
716+ * Authors:
717+ * - MichaƂ Sawicz <michal.sawicz@canonical.com>
718+ *
719+ * This program is free software; you can redistribute it and/or modify
720+ * it under the terms of the GNU General Public License as published by
721+ * the Free Software Foundation; version 3.
722+ *
723+ * This program is distributed in the hope that it will be useful,
724+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
725+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
726+ * GNU General Public License for more details.
727+ *
728+ * You should have received a copy of the GNU General Public License
729+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
730+ */
731+=end
732+
733+require '../run-tests.rb' unless $INIT_COMPLETED
734+require 'xdo/xwindow'
735+require 'xdo/keyboard'
736+require 'xdo/mouse'
737+require 'tmpwindow'
738+require $library_path + '/../../launcher/menu_tests_common.rb'
739+
740+############################# Test Suite #############################
741+context "Launcher Contextual Menu Tests" do
742+
743+ def keyboard_tap_right()
744+ XDo::Keyboard.left
745+ end
746+
747+ def keyboard_tap_left()
748+ XDo::Keyboard.right
749+ end
750+
751+ # Run once at the beginning of this test suite
752+ startup do
753+ $SUT.execute_shell_command 'killall unity-2d-shell'
754+ $SUT.execute_shell_command 'killall unity-2d-shell'
755+
756+ # Minimize all windows
757+ XDo::XWindow.toggle_minimize_all
758+ end
759+
760+ # Run once at the end of this test suite
761+ shutdown do
762+ end
763+
764+ # Run before each test case begins
765+ setup do
766+ # Ensure mouse out of the way
767+ XDo::Mouse.move(200,200,10,true)
768+
769+ # Execute the application
770+ @app = $SUT.run( :name => UNITY_2D_SHELL,
771+ :arguments => "-testability,-reverse",
772+ :sleeptime => 2)
773+ # Make certain application is ready for testing
774+ verify{ @app.Launcher() }
775+ end
776+
777+ # Run after each test case completes
778+ teardown do
779+ #@app.close
780+ #@app.close
781+ #Need to kill Shell as it does not shutdown when politely asked
782+ $SUT.execute_shell_command 'pkill -nf unity-2d-shell'
783+ end
784+
785+ #####################################################################################
786+ # Test cases
787+ test "Display launcher item hint" do
788+ test_display_launcher_item_hint()
789+ end
790+
791+ test "Display launcher menu after right click" do
792+ test_display_launcher_menu_after_right_click()
793+ end
794+
795+ test "Display launcher menu with keyboard navigation" do
796+ test_display_launcher_menu_with_keyboard_navigation()
797+ end
798+
799+ test "Close launcher menu when pressing Esc" do
800+ test_close_launcher_menu_when_pressing_esc()
801+ end
802+
803+ test "Close launcher menu when navigating back to the launcher" do
804+ test_close_launcher_menu_when_navigating_back_to_the_launcher()
805+ end
806+
807+ test "Verify launcher tile gets focus after dismissing the menu with Esc" do
808+ test_verify_launcher_tile_gets_focus_after_dismissing_the_menu_with_esc()
809+ end
810+
811+ test "Verify launcher tile gets focus after dismissing the menu with keyboard navigation" do
812+ test_verify_launcher_tile_gets_focus_after_dismissing_the_menu_with_keyboard_navigation()
813+ end
814+
815+ test "Verify dash search entry gets focus after dismissing the menu with Super" do
816+ test_verify_dash_search_entry_gets_focus_after_dismissing_the_menu_with_super()
817+ end
818+end

Subscribers

People subscribed via source and target branches