~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to tests/autopilot/autopilot/tests/test_dash.py

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
Merged latest lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from testtools import TestCase
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2010 Canonical
 
3
# Author: Alex Launi
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
 
 
9
from gtk import Clipboard
2
10
from time import sleep
3
11
 
4
 
from autopilot.emulators.unity import Dash
5
 
from autopilot.emulators.X11 import Keyboard
6
 
from autopilot.glibrunner import GlibRunner
7
 
 
8
 
 
9
 
class DashTests(TestCase):
10
 
    """
11
 
    Test the unity Dash.
12
 
    """
13
 
    run_test_with = GlibRunner
14
 
    
 
12
from autopilot.emulators.X11 import Keyboard, Mouse
 
13
from autopilot.tests import AutopilotTestCase
 
14
 
 
15
 
 
16
class DashRevealTests(AutopilotTestCase):
 
17
    """Test the unity Dash Reveal."""
 
18
 
15
19
    def setUp(self):
16
 
        super(DashTests, self).setUp()
17
 
        self.dash = Dash()
 
20
        super(DashRevealTests, self).setUp()
 
21
        self.dash.ensure_hidden()
 
22
 
 
23
    def tearDown(self):
 
24
        super(DashRevealTests, self).tearDown()
 
25
        self.dash.ensure_hidden()
18
26
 
19
27
    def test_dash_reveal(self):
20
 
        """
21
 
        Ensure we can show and hide the dash.
22
 
        """
23
 
        self.dash.ensure_hidden()
24
 
 
 
28
        """Ensure we can show and hide the dash."""
25
29
        self.assertFalse(self.dash.get_is_visible())
26
30
        self.dash.toggle_reveal()
27
31
        self.assertTrue(self.dash.get_is_visible())
29
33
        self.assertFalse(self.dash.get_is_visible())
30
34
 
31
35
    def test_dash_keyboard_focus(self):
32
 
        """
33
 
        Dash must put keyboard focus on the search bar at all times.
34
 
        """
35
 
        self.dash.ensure_hidden()
36
 
 
37
 
        self.assertFalse(self.dash.get_is_visible())
 
36
        """Dash must put keyboard focus on the search bar at all times."""
 
37
        self.dash.ensure_visible()
38
38
        kb = Keyboard()
39
 
        self.dash.toggle_reveal()
40
39
        kb.type("Hello")
41
40
        sleep(1)
42
 
        self.assertEqual(self.dash.get_search_string(), u'Hello')
43
 
        self.dash.toggle_reveal()
 
41
        searchbar = self.dash.get_searchbar()
 
42
        self.assertEqual(searchbar.search_string, u'Hello')
 
43
 
 
44
    def test_application_lens_shortcut(self):
 
45
        """Application lense must reveal when Super+a is pressed."""
 
46
        self.dash.reveal_application_lens()
 
47
        lensbar = self.dash.view.get_lensbar()
 
48
        self.assertEqual(lensbar.active_lens, u'applications.lens')
 
49
 
 
50
    def test_music_lens_shortcut(self):
 
51
        """Music lense must reveal when Super+w is pressed."""
 
52
        self.dash.reveal_music_lens()
 
53
        lensbar = self.dash.view.get_lensbar()
 
54
        self.assertEqual(lensbar.active_lens, u'music.lens')
 
55
 
 
56
    def test_file_lens_shortcut(self):
 
57
        """File lense must reveal when Super+f is pressed."""
 
58
        self.dash.reveal_file_lens()
 
59
        lensbar = self.dash.view.get_lensbar()
 
60
        self.assertEqual(lensbar.active_lens, u'files.lens')
 
61
 
 
62
    def test_command_lens_shortcut(self):
 
63
        """Run Command lens must reveat on alt+F2."""
 
64
        self.dash.reveal_command_lens()
 
65
        lensbar = self.dash.view.get_lensbar()
 
66
        self.assertEqual(lensbar.active_lens, u'commands.lens')
 
67
    
 
68
    def test_alt_f4_close_dash(self):
 
69
        """Dash must close on alt+F4."""
 
70
        self.dash.ensure_visible()
 
71
        self.dash.close_with_alt_f4()
 
72
        sleep(0.5)
44
73
        self.assertFalse(self.dash.get_is_visible())
45
74
 
46
75
 
47
 
        
 
76
class DashKeyNavTests(AutopilotTestCase):
 
77
    """Test the unity Dash keyboard navigation."""
 
78
 
 
79
    def setUp(self):
 
80
        super(DashKeyNavTests, self).setUp()
 
81
        self.dash.ensure_hidden()
 
82
 
 
83
    def tearDown(self):
 
84
        super(DashKeyNavTests, self).tearDown()
 
85
        self.dash.ensure_hidden()
 
86
 
 
87
    def test_lensbar_gets_keyfocus(self):
 
88
        """Test that the lensbar gets key focus after using Down keypresses."""
 
89
        self.dash.ensure_visible()
 
90
        kb = Keyboard()
 
91
        # Make sure that the lens bar can get the focus
 
92
        for i in range(self.dash.get_num_rows()):
 
93
            kb.press_and_release("Down")
 
94
        lensbar = self.dash.view.get_lensbar()
 
95
        self.assertIsNot(lensbar.focused_lens_icon, '')
 
96
 
 
97
    def test_lensbar_focus_changes(self):
 
98
        """Lensbar focused icon should change with Left and Right keypresses."""
 
99
        self.dash.ensure_visible()
 
100
        kb = Keyboard()
 
101
        #put KB focus on lensbar again:
 
102
        for i in range(self.dash.get_num_rows()):
 
103
            kb.press_and_release("Down")
 
104
 
 
105
        lensbar = self.dash.view.get_lensbar()
 
106
        current_focused_icon = lensbar.focused_lens_icon
 
107
        kb.press_and_release("Right");
 
108
        lensbar.refresh_state()
 
109
        self.assertNotEqual(lensbar.focused_lens_icon, current_focused_icon)
 
110
        kb.press_and_release("Left")
 
111
        lensbar.refresh_state()
 
112
        self.assertEqual(lensbar.focused_lens_icon, current_focused_icon)
 
113
 
 
114
    def test_lensbar_enter_activation(self):
 
115
        """Must be able to activate LensBar icons that have focus with an Enter keypress."""
 
116
        self.dash.ensure_visible()
 
117
        kb = Keyboard()
 
118
        #put KB focus on lensbar again:
 
119
        for i in range(self.dash.get_num_rows()):
 
120
            kb.press_and_release("Down")
 
121
        kb.press_and_release("Right");
 
122
        lensbar = self.dash.view.get_lensbar()
 
123
        focused_icon = lensbar.focused_lens_icon
 
124
        kb.press_and_release("Enter");
 
125
        lensbar.refresh_state()
 
126
        self.assertEqual(lensbar.active_lens, focused_icon)
 
127
        self.assertEqual(lensbar.focused_lens_icon, "")
 
128
 
 
129
    def test_category_header_keynav_autoscroll(self):
 
130
        """Test that the dash autoscroll when a category header gets
 
131
        the focus.
 
132
        """
 
133
        self.dash.reveal_application_lens()
 
134
        app_lens = self.dash.get_current_lens()
 
135
 
 
136
        kb = Keyboard()
 
137
        mouse = Mouse()
 
138
 
 
139
        # Expand the first category
 
140
        kb.press_and_release("Down")
 
141
        kb.press_and_release("Enter")
 
142
        category = app_lens.get_focused_category()
 
143
 
 
144
        # Get the geometry of that category header.
 
145
        x = category.header_x
 
146
        y = category.header_y
 
147
        w = category.header_width
 
148
 
 
149
        # Manually scroll the dash.
 
150
        mouse.move(x+w+10, y+w+10, True)
 
151
        mouse.click(5)
 
152
        mouse.click(5)
 
153
        mouse.click(5)
 
154
 
 
155
        cached_y = y
 
156
 
 
157
        # Focus the search bar with the mouse
 
158
        searchbar = self.dash.get_searchbar()
 
159
        mouse.move(searchbar.x + 100,
 
160
                searchbar.y + searchbar.height / 2,
 
161
                True)
 
162
        mouse.click()
 
163
        sleep(2)
 
164
 
 
165
        # Then focus again the first category header
 
166
        kb.press_and_release("Down")
 
167
        kb.press_and_release("Enter")
 
168
        category = app_lens.get_focused_category()
 
169
        y = category.header_y
 
170
 
 
171
        # Make sure the dash autoscroll
 
172
        self.assertTrue(abs(y - cached_y) < 30)
 
173
 
 
174
    def test_category_header_keynav(self):
 
175
        """ This test makes sure that:
 
176
        1. A category header can get the focus.
 
177
        2. A category header stays highlight when it loses the focus
 
178
         and mouse is close to it (but not inside).
 
179
        """
 
180
        self.dash.reveal_application_lens()
 
181
 
 
182
        kb = Keyboard()
 
183
        mouse = Mouse()
 
184
 
 
185
        # Make sure that a category have the focus.
 
186
        kb.press_and_release("Down")
 
187
        app_lens = self.dash.get_current_lens()
 
188
        category = app_lens.get_focused_category()
 
189
        self.assertIsNot(category, None)
 
190
 
 
191
        # Make sure that the category is highlighted.
 
192
        self.assertTrue(category.header_is_highlighted)
 
193
 
 
194
        # Get the geometry of that category header.
 
195
        x = category.header_x
 
196
        y = category.header_y
 
197
        w = category.header_width
 
198
        h = category.header_height
 
199
 
 
200
        # Move the mouse close the view, and press down.
 
201
        mouse.move(x + w + 10,
 
202
                    y + h / 2,
 
203
                    True)
 
204
        sleep(1)
 
205
        kb.press_and_release("Down")
 
206
        sleep(1)
 
207
        category = app_lens.get_focused_category()
 
208
        self.assertEqual(category, None)
 
209
 
 
210
    def test_cltr_tab(self):
 
211
        """ This test makes sure that Ctlr + Tab works well."""
 
212
        self.dash.toggle_reveal()
 
213
 
 
214
        kb = Keyboard()
 
215
        lensbar = self.dash.view.get_lensbar()
 
216
 
 
217
        kb.press('Control')
 
218
        kb.press_and_release('Tab')
 
219
        kb.release('Control')
 
220
        lensbar.refresh_state()
 
221
        self.assertEqual(lensbar.active_lens, u'applications.lens')
 
222
 
 
223
        kb.press('Control')
 
224
        kb.press('Shift')
 
225
        kb.press_and_release('Tab')
 
226
        kb.release('Control')
 
227
        kb.release('Shift')
 
228
 
 
229
        lensbar.refresh_state()
 
230
        self.assertEqual(lensbar.active_lens, u'home.lens')
 
231
 
 
232
    def test_tab(self):
 
233
        """ This test makes sure that Tab works well."""
 
234
        self.dash.reveal_application_lens()
 
235
        app_lens = self.dash.get_current_lens()
 
236
 
 
237
        kb = Keyboard()
 
238
 
 
239
        for i in range(app_lens.get_num_visible_categories()):
 
240
            kb.press_and_release('Tab')
 
241
            category = app_lens.get_focused_category()
 
242
            self.assertIsNot(category, None)
 
243
 
 
244
        kb.press_and_release('Tab')
 
245
        searchbar = self.dash.get_searchbar()
 
246
        self.assertTrue(searchbar.expander_has_focus)
 
247
 
 
248
        if not searchbar.showing_filters:
 
249
            kb.press_and_release('Enter')
 
250
            searchbar.refresh_state()
 
251
            self.assertTrue(searchbar.showing_filters)
 
252
 
 
253
        filter_bar = app_lens.get_filterbar()
 
254
        for i in range(filter_bar.get_num_filters()):
 
255
            kb.press_and_release('Tab')
 
256
            new_focused_filter = filter_bar.get_focused_filter()
 
257
            self.assertIsNotNone(new_focused_filter)
 
258
 
 
259
        kb.press_and_release('Tab')
 
260
        category = app_lens.get_focused_category()
 
261
        self.assertIsNot(category, None)
 
262
 
 
263
 
 
264
class DashClipboardTests(AutopilotTestCase):
 
265
    """Test the Unity clipboard"""
 
266
 
 
267
    def setUp(self):
 
268
        super(DashClipboardTests, self).setUp()
 
269
        self.dash.ensure_hidden()
 
270
 
 
271
    def tearDown(self):
 
272
        super(DashClipboardTests, self).tearDown()
 
273
        self.dash.ensure_hidden()
 
274
 
 
275
    def test_ctrl_a(self):
 
276
        """ This test if ctrl+a selects all text """
 
277
        self.dash.toggle_reveal()
 
278
 
 
279
        kb = Keyboard();
 
280
        kb.type("SelectAll")
 
281
        sleep(1)
 
282
 
 
283
        kb.press_and_release("Ctrl+a")
 
284
        kb.press_and_release("Delete")
 
285
 
 
286
        searchbar = self.dash.get_searchbar()
 
287
        self.assertEqual(searchbar.search_string, u'')
 
288
 
 
289
    def test_ctrl_c(self):
 
290
        """ This test if ctrl+c copies text into the clipboard """
 
291
        self.dash.toggle_reveal()
 
292
 
 
293
        kb = Keyboard();
 
294
        kb.type("Copy")
 
295
        sleep(1)
 
296
 
 
297
        kb.press_and_release("Ctrl+a")
 
298
        kb.press_and_release("Ctrl+c")
 
299
 
 
300
        cb = Clipboard(selection="CLIPBOARD")
 
301
 
 
302
        searchbar = self.dash.get_searchbar()
 
303
        self.assertEqual(searchbar.search_string, cb.wait_for_text())
 
304
 
 
305
    def test_ctrl_x(self):
 
306
        """ This test if ctrl+x deletes all text and copys it """
 
307
        self.dash.toggle_reveal()
 
308
 
 
309
        kb = Keyboard();
 
310
        kb.type("Cut")
 
311
        sleep(1)
 
312
 
 
313
        kb.press_and_release("Ctrl+a")
 
314
        kb.press_and_release("Ctrl+x")
 
315
        sleep(1)
 
316
 
 
317
        searchbar = self.dash.get_searchbar()
 
318
        self.assertEqual(searchbar.search_string, u'')
 
319
 
 
320
        cb = Clipboard(selection="CLIPBOARD")
 
321
        self.assertEqual(cb.wait_for_text(), u'Cut')
 
322
 
 
323
    def test_ctrl_c_v(self):
 
324
        """ This test if ctrl+c and ctrl+v copies and pastes text"""
 
325
        self.dash.toggle_reveal()
 
326
 
 
327
        kb = Keyboard();
 
328
        kb.type("CopyPaste")
 
329
        sleep(1)
 
330
 
 
331
        kb.press_and_release("Ctrl+a")
 
332
        kb.press_and_release("Ctrl+c")
 
333
        kb.press_and_release("Ctrl+v")
 
334
        kb.press_and_release("Ctrl+v")
 
335
 
 
336
        searchbar = self.dash.get_searchbar()
 
337
        self.assertEqual(searchbar.search_string, u'CopyPasteCopyPaste')
 
338
 
 
339
    def test_ctrl_x_v(self):
 
340
        """ This test if ctrl+x and ctrl+v cuts and pastes text"""
 
341
        self.dash.toggle_reveal()
 
342
 
 
343
        kb = Keyboard();
 
344
        kb.type("CutPaste")
 
345
        sleep(1)
 
346
 
 
347
        kb.press_and_release("Ctrl+a")
 
348
        kb.press_and_release("Ctrl+x")
 
349
        kb.press_and_release("Ctrl+v")
 
350
        kb.press_and_release("Ctrl+v")
 
351
 
 
352
        searchbar = self.dash.get_searchbar()
 
353
        self.assertEqual(searchbar.search_string, u'CutPasteCutPaste')
 
354
 
 
355
 
 
356
class DashKeyboardFocusTests(AutopilotTestCase):
 
357
    """Tests that keyboard focus works."""
 
358
 
 
359
    def setUp(self):
 
360
        super(DashKeyboardFocusTests, self).setUp()
 
361
        self.dash.ensure_hidden()
 
362
 
 
363
    def tearDown(self):
 
364
        super(DashKeyboardFocusTests, self).tearDown()
 
365
        self.dash.ensure_hidden()
 
366
 
 
367
    def test_filterbar_expansion_leaves_kb_focus(self):
 
368
        """Expanding or collapsing the filterbar must keave keyboard focus in the
 
369
        search bar.
 
370
        """
 
371
        self.dash.reveal_application_lens()
 
372
        filter_bar = self.dash.get_current_lens().get_filterbar()
 
373
        filter_bar.ensure_collapsed()
 
374
 
 
375
        kb = Keyboard()
 
376
        kb.type("hello")
 
377
        filter_bar.ensure_expanded()
 
378
        kb.type(" world")
 
379
 
 
380
        searchbar = self.dash.get_searchbar()
 
381
        self.assertEqual("hello world", searchbar.search_string)
 
382
 
 
383
class DashLensResultsTests(AutopilotTestCase):
 
384
    """ Tests results from the lens view """
 
385
 
 
386
    def setUp(self):
 
387
        super(DashLensResultsTests, self).setUp()
 
388
        self.dash.ensure_hidden()
 
389
 
 
390
    def tearDown(self):
 
391
        super(DashLensResultsTests, self).tearDown()
 
392
        self.dash.ensure_hidden()
 
393
    
 
394
    def test_results_message_empty_search(self): 
 
395
        """ This tests a message is not shown when there is no text""" 
 
396
        self.dash.reveal_application_lens()
 
397
        lens = self.dash.get_current_lens()
 
398
 
 
399
        lens.refresh_state() 
 
400
        self.assertFalse(lens.no_results_active)
 
401
 
 
402
    def test_results_message(self): 
 
403
        """ This test no mesage will be shown when results are there""" 
 
404
        self.dash.reveal_application_lens()
 
405
        lens = self.dash.get_current_lens()
 
406
 
 
407
        kb = Keyboard();
 
408
        kb.type("Terminal")
 
409
        sleep(1)
 
410
      
 
411
        lens.refresh_state() 
 
412
        self.assertFalse(lens.no_results_active)
 
413
 
 
414
    def test_no_results_message(self): 
 
415
        """ This test shows a message will appear in the lens""" 
 
416
        self.dash.reveal_application_lens()
 
417
        lens = self.dash.get_current_lens()
 
418
 
 
419
        kb = Keyboard();
 
420
        kb.type("qwerlkjzvxc")
 
421
        sleep(1)
 
422
 
 
423
        lens.refresh_state() 
 
424
        self.assertTrue(lens.no_results_active)
 
425
 
 
426
class DashVisualTests(AutopilotTestCase):
 
427
    """Tests that the dash visual is correct."""
 
428
    def setUp(self):
 
429
        super(DashVisualTests, self).setUp()
 
430
        self.dash.ensure_hidden()
 
431
 
 
432
    def tearDown(self):
 
433
        super(DashVisualTests, self).tearDown()
 
434
        self.dash.ensure_hidden()
 
435
 
 
436
    def test_see_more_result_alignment(self):
 
437
        """The see more results label should be baseline aligned
 
438
        with the category name label.
 
439
        """
 
440
        self.dash.reveal_application_lens()
 
441
 
 
442
        lens = self.dash.get_current_lens()
 
443
        groups = lens.get_groups()
 
444
 
 
445
        for group in groups:
 
446
            if (group.is_visible):
 
447
                self.assertTrue(not group.expand_label_is_visible or
 
448
                                (group.expand_label_y + group.expand_label_baseline == group.name_label_y + group.name_label_baseline))
 
449
 
 
450
class DashSpecialKeysTests(AutopilotTestCase):
 
451
    """Tests composition sequences, dead keys or any other special keys."""
 
452
    def setUp(self):
 
453
        super(DashSpecialKeysTests, self).setUp()
 
454
        self.dash.ensure_hidden()
 
455
 
 
456
    def tearDown(self):
 
457
        super(DashSpecialKeysTests, self).tearDown()
 
458
        self.dash.ensure_hidden()
 
459
 
 
460
    def test_multi_key(self):
 
461
        """Pressing 'Multi_key' must not add any characters to the search."""
 
462
        self.dash.reveal_application_lens()
 
463
      
 
464
        kb = Keyboard();
 
465
        kb.press_and_release('Multi_key')
 
466
        kb.type("o")
 
467
        sleep(1)
 
468
 
 
469
        searchbar = self.dash.get_searchbar()
 
470
        self.assertEqual("", searchbar.search_string)
 
471
 
 
472
    def test_multi_key_o(self):
 
473
        """Pressing the sequences 'Multi_key' + '^' + 'o' must produce 'ô'."""
 
474
        self.dash.reveal_application_lens()
 
475
      
 
476
        kb = Keyboard();
 
477
        kb.press_and_release('Multi_key')
 
478
        kb.type("^o")
 
479
        sleep(1)
 
480
 
 
481
        searchbar = self.dash.get_searchbar()
 
482
        self.assertEqual("ô", searchbar.search_string)
 
483
 
 
484
    def test_multi_key_copyright(self):
 
485
        """Pressing the sequences 'Multi_key' + 'c' + 'o' must produce '©'."""
 
486
        self.dash.reveal_application_lens()
 
487
      
 
488
        kb = Keyboard();
 
489
        kb.press_and_release('Multi_key')
 
490
        kb.type("oc")
 
491
        sleep(1)
 
492
 
 
493
        searchbar = self.dash.get_searchbar()
 
494
        self.assertEqual("©", searchbar.search_string)
 
495
 
 
496
    def test_multi_key_delete(self):
 
497
        """Pressing 'Multi_key' must not get stuck looking for a sequence."""
 
498
        self.dash.reveal_application_lens()
 
499
 
 
500
        kb = Keyboard();
 
501
        kb.type("dd")
 
502
        sleep(1)
 
503
        kb.press_and_release('Multi_key')
 
504
        kb.press_and_release('BackSpace')
 
505
        kb.press_and_release('BackSpace')
 
506
        sleep(1)
 
507
 
 
508
        searchbar = self.dash.get_searchbar()
 
509
        self.assertEqual("d", searchbar.search_string)