This file is indexed.

/usr/lib/python2.7/dist-packages/unity/tests/test_switcher.py is in unity-autopilot 7.5.0+18.04.20180413-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2010 Canonical
# Author: Thomi Richards
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.

from __future__ import absolute_import

from autopilot.display import move_mouse_to_screen
from autopilot.matchers import Eventually
from autopilot.testcase import multiply_scenarios
import logging
from testtools.matchers import Equals, Contains, Not
from time import sleep

from unity.emulators.switcher import SwitcherDirection, SwitcherMode
from unity.tests import UnityTestCase

logger = logging.getLogger(__name__)

class SwitcherTestCase(UnityTestCase):

    scenarios = [
        ('show_desktop_icon_true', {'show_desktop_option': True}),
        ('show_desktop_icon_false', {'show_desktop_option': False}),
    ]

    def setUp(self):
        super(SwitcherTestCase, self).setUp()
        self.set_show_desktop(self.show_desktop_option)

    def set_show_desktop(self, state):
        if type(state) is not bool:
            raise TypeError("'state' must be boolean, not %r" % type(state))
        self.set_unity_option("disable_show_desktop", state)
        self.assertThat(self.unity.switcher.show_desktop_disabled, Eventually(Equals(state)))

    def set_timeout_setting(self, state):
        if type(state) is not bool:
            raise TypeError("'state' must be boolean, not %r" % type(state))
        self.set_unity_option("alt_tab_timeout", state)
        sleep(1)

    def start_applications(self, *args):
        """Start some applications, returning their windows.

        If no applications are specified, the following will be started:
         * Calculator
         * Character Map
         * Character Map

         Windows are always started in the order that they are specified (which
        means the last specified application will *probably* be at the top of the
        window stack after calling this method). Windows are returned in the same
        order they are specified in.

        """
        if len(args) == 0:
            args = ('Calculator', 'Character Map', 'Character Map')
        windows = []
        for app in args:
            windows.append(self.process_manager.start_app_window(app))

        return windows


class SwitcherTests(SwitcherTestCase):
    """Test the switcher."""

    def setUp(self):
        super(SwitcherTests, self).setUp()
        self.set_timeout_setting(False)

    def tearDown(self):
        super(SwitcherTests, self).tearDown()

    def test_switcher_starts_in_normal_mode(self):
        """Switcher must start in normal (i.e.- not details) mode."""
        self.process_manager.start_app("Character Map")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)
        self.assertProperty(self.unity.switcher, mode=SwitcherMode.NORMAL)

    def test_label_matches_application_name(self):
        """The switcher label must match the selected application name in normal mode."""
        windows = self.start_applications()
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        for win in windows:
            app_name = win.application.name
            self.unity.switcher.select_icon(SwitcherDirection.FORWARDS, tooltip_text=app_name)
            self.assertThat(self.unity.switcher.label_visible, Eventually(Equals(True)))
            self.assertThat(self.unity.switcher.label, Eventually(Equals(app_name)))

    def test_application_window_is_fake_decorated(self):
        """When the switcher is in details mode must not show the focused window title."""
        window = self.process_manager.start_app_window("Text Editor")
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        self.unity.switcher.select_icon(SwitcherDirection.BACKWARDS, tooltip_text=window.application.name)

        self.unity.switcher.show_details()
        self.assertThat(self.unity.switcher.label_visible, Eventually(Equals(False)))
        self.assertThat(self.unity.screen.window(window.x_id).fake_decorated, Eventually(Equals(True)))

    def test_application_window_is_fake_decorated_in_detail_mode(self):
        """Starting switcher in details mode must not show the focused window title."""
        window = self.process_manager.start_app_window("Text Editor")
        self.unity.switcher.initiate(SwitcherMode.DETAIL)
        self.addCleanup(self.unity.switcher.terminate)

        self.assertThat(self.unity.switcher.label_visible, Eventually(Equals(False)))
        self.assertThat(self.unity.screen.window(window.x_id).fake_decorated, Eventually(Equals(True)))

    def test_switcher_move_next(self):
        """Test that pressing the next icon binding moves to the next icon"""
        self.start_applications()
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        start = self.unity.switcher.selection_index
        self.unity.switcher.next_icon()
        # Allow for wrap-around to first icon in switcher
        next_index = (start + 1) % len(self.unity.switcher.icons)

        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(next_index)))

    def test_switcher_move_prev(self):
        """Test that pressing the previous icon binding moves to the previous icon"""
        self.start_applications()
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        start = self.unity.switcher.selection_index
        self.unity.switcher.previous_icon()
        # Allow for wrap-around to last icon in switcher
        prev_index = (start - 1) % len(self.unity.switcher.icons)

        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(prev_index)))

    def test_switcher_scroll_next(self):
        """Test that scrolling the mouse wheel down moves to the next icon"""
        self.start_applications()
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        start = self.unity.switcher.selection_index
        self.unity.switcher.next_via_mouse()
        # Allow for wrap-around to first icon in switcher
        next_index = (start + 1) % len(self.unity.switcher.icons)

        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(next_index)))

    def test_switcher_scroll_prev(self):
        """Test that scrolling the mouse wheel up moves to the previous icon"""
        self.start_applications()
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        start = self.unity.switcher.selection_index
        self.unity.switcher.previous_via_mouse()
        # Allow for wrap-around to last icon in switcher
        prev_index = (start - 1) % len(self.unity.switcher.icons)

        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(prev_index)))

    def test_switcher_arrow_key_does_not_init(self):
        """Ensure that Alt+Right does not initiate switcher.

        Regression test for LP:??????

        """
        self.keyboard.press_and_release('Alt+Right')
        self.assertThat(self.unity.switcher.visible, Equals(False))

    def test_lazy_switcher_initiate(self):
        """Inserting a long delay between the Alt press and the Tab tab must still
        open the switcher.

        """
        self.process_manager.start_app("Character Map")

        self.keybinding_hold("switcher/reveal_normal")
        self.addCleanup(self.keybinding_release, "switcher/reveal_normal")
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(False)))
        sleep(5)
        self.keybinding_tap("switcher/reveal_normal")
        self.addCleanup(self.keybinding, "switcher/cancel")
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(True)))

    def test_switcher_cancel(self):
        """Pressing the switcher cancel keystroke must cancel the switcher."""
        self.process_manager.start_app("Character Map")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        self.assertThat(self.unity.switcher.visible, Eventually(Equals(True)))
        self.unity.switcher.cancel()
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(False)))

    def test_lazy_switcher_cancel(self):
        """Must be able to cancel the switcher after a 'lazy' initiation."""
        self.process_manager.start_app("Character Map")

        self.keybinding_hold("switcher/reveal_normal")
        self.addCleanup(self.keybinding_release, "switcher/reveal_normal")
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(False)))
        sleep(5)
        self.keybinding_tap("switcher/reveal_normal")
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(True)))
        self.unity.switcher.cancel()
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(False)))

    def test_switcher_appears_on_monitor_with_mouse(self):
        """Tests that the switches appears on the correct monitor.

        This is defined as the monitor with the mouse.

        """
        # TODO - this test fails in multi-monitor setups. You can't use addCleanup
        # a better way would be to have a scenario'd class for multi-monitor
        # switcher tests.
        num_monitors = self.display.get_num_screens()
        if num_monitors == 1:
            self.skip("No point testing this on one monitor")

        charmap, calc, mahjongg = self.start_applications()

        self.addCleanup(self.unity.switcher.terminate)

        for monitor in range(num_monitors):
            move_mouse_to_screen(monitor)
            self.unity.switcher.initiate()
            self.assertThat(self.unity.switcher.monitor, Eventually(Equals(monitor)))
            self.unity.switcher.terminate()
            sleep(1)

    def test_switcher_alt_f4_is_disabled(self):
        """Tests that alt+f4 does not work while switcher is active."""

        win = self.process_manager.start_app_window("Text Editor")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(True)))

        self.keyboard.press_and_release("Alt+F4")
        # Need the sleep to allow the window time to close, for jenkins!
        sleep(10)
        self.assertProperty(win, is_valid=True)


class SwitcherWindowsManagementTests(SwitcherTestCase):
    """Test the switcher window management."""

    def setUp(self):
        super(SwitcherTestCase, self).setUp()

    def tearDown(self):
        super(SwitcherTestCase, self).tearDown()

    def test_switcher_raises_only_last_focused_window(self):
        """Tests that when we do an alt+tab only the previously focused window is raised.

        This is tests by opening 2 Calculators and a Mahjongg.
        Then we do a quick alt+tab twice.
        Then we close the currently focused window.

        """
        char_win1, calc_win, char_win2 = self.start_applications("Character Map", "Calculator", "Character Map")
        self.assertVisibleWindowStack([char_win2, calc_win, char_win1])

        self.keybinding("switcher/reveal_normal")
        self.assertProperty(calc_win, is_focused=True)
        self.assertVisibleWindowStack([calc_win, char_win2, char_win1])

        self.keybinding("switcher/reveal_normal")
        self.assertProperty(char_win2, is_focused=True)
        self.assertVisibleWindowStack([char_win2, calc_win, char_win1])

        self.keybinding("window/close")
        self.assertProperty(calc_win, is_focused=True)
        self.assertVisibleWindowStack([calc_win, char_win1])

    def test_switcher_rises_next_window_of_same_application(self):
        """Tests if alt+tab invoked normally switches to the next application
        window of the same type.

        """
        char_win1, char_win2 = self.start_applications("Character Map", "Character Map")
        self.assertVisibleWindowStack([char_win2, char_win1])

        self.keybinding("switcher/reveal_normal")
        self.assertProperty(char_win1, is_focused=True)

    def test_switcher_rises_other_application(self):
        """Tests if alt+tab invoked normally switches correctly to the other
        application window when the last focused application had 2 windows

        """
        char_win1, char_win2, calc_win = self.start_applications("Character Map", "Character Map", "Calculator")
        self.assertVisibleWindowStack([calc_win, char_win2, char_win1])

        self.keybinding("switcher/reveal_normal")
        self.assertProperty(char_win2, is_focused=True)

        self.keybinding("switcher/reveal_normal")
        self.assertProperty(calc_win, is_focused=True)


class SwitcherInteractionTests(SwitcherTestCase):
    """Test the switcher interactions with the rest of the shell."""

    def setUp(self):
        super(SwitcherTestCase, self).setUp()

    def tearDown(self):
        super(SwitcherTestCase, self).tearDown()

    def open_switcher_after_overlay(self, overlay):
        self.start_applications()
        self.addCleanup(overlay.ensure_hidden)
        overlay.ensure_visible()

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        self.assertThat(overlay.visible, Eventually(Equals(False)))
        self.assertThat(self.unity.switcher.visible, Eventually(Equals(True)))


class SwitcherOverlaysInteractionTests(SwitcherInteractionTests):
    """Test the switcher interactions with the shell overlays."""

    scenarios = multiply_scenarios(SwitcherTestCase.scenarios,
      [
          ('Dash', {'overlay': "self.unity.dash"}),
          ('Hud', {'overlay': "self.unity.hud"}),
      ]
      )

    def setUp(self):
        super(SwitcherOverlaysInteractionTests, self).setUp()
        self.overlay = eval(self.overlay)

    def tearDown(self):
        super(SwitcherOverlaysInteractionTests, self).tearDown()

    def test_switcher_shows_on_overlay_opened(self):
        """Tests if switcher shows when overlay is opened"""
        self.open_switcher_after_overlay(self.overlay)

    def test_switcher_tab_key_work_after_overlay_is_closed(self):
        """Tests that the switcher tab key work when initializing the
        switcher after closing the overlay
        """
        self.open_switcher_after_overlay(self.overlay)

        start = self.unity.switcher.selection_index
        next_index = (start + 1) % len(self.unity.switcher.icons)
        self.unity.switcher.next_icon()
        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(next_index)))

        self.unity.switcher.previous_icon()
        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(start)))

    def test_switcher_arrow_keys_work_after_overlay_is_closed(self):
        """Tests that the switcher arrow keys work when initializing the
        switcher after closing the overlay
        """
        self.open_switcher_after_overlay(self.overlay)

        start = self.unity.switcher.selection_index
        next_index = (start + 1) % len(self.unity.switcher.icons)
        self.keyboard.press_and_release('Right')
        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(next_index)))

        self.keyboard.press_and_release('Left')
        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(start)))

    def test_switcher_detail_mode_works_after_overlay_is_closed(self):
        """Tests that the switcher detail mode through the 'Down' arrow key
        work when initializing the switcher after closing the overlay
        """
        self.open_switcher_after_overlay(self.overlay)

        self.keyboard.press_and_release('Down')
        self.assertProperty(self.unity.switcher, mode=SwitcherMode.DETAIL)

        self.keyboard.press_and_release('Up')
        self.assertProperty(self.unity.switcher, mode=SwitcherMode.NORMAL)


class SwitcherDetailsTests(SwitcherTestCase):
    """Test the details mode for the switcher."""

    def setUp(self):
        super(SwitcherDetailsTests, self).setUp()
        self.set_timeout_setting(True)

    def test_details_mode_on_delay(self):
        """Test that details mode activates on a timeout."""
        if self.workspace.num_workspaces <= 1:
            self.skipTest("This test requires enabled more than one workspace.")
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)
        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
        self.start_applications("Character Map", "Character Map", "Mahjongg")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)
        # Wait longer than details mode.
        sleep(3)
        self.assertProperty(self.unity.switcher, mode=SwitcherMode.DETAIL)

    def test_no_details_for_apps_on_different_workspace(self):
        """Tests that details mode does not initiates when there are multiple windows

        of an application spread across different workspaces.
        Regression test for LP:933406.

        """
        if self.workspace.num_workspaces <= 1:
            self.skipTest("This test requires enabled more than one workspace.")
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)
        self.process_manager.start_app_window("Character Map")
        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
        self.start_applications("Character Map", "Mahjongg")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)
        # Wait longer than details mode.
        sleep(3)
        self.assertProperty(self.unity.switcher, mode=SwitcherMode.NORMAL)


class SwitcherDetailsModeTests(SwitcherTestCase):
    """Tests for the details mode of the switcher.

    Tests for initiation with both grave (`) and Down arrow.

    """

    scenarios = multiply_scenarios(SwitcherTestCase.scenarios,
      [
          ('initiate_with_grave', {'initiate_keycode': '`'}),
          ('initiate_with_down', {'initiate_keycode': 'Down'}),
      ]
      )

    def setUp(self):
        super(SwitcherDetailsModeTests, self).setUp()
        self.set_timeout_setting(False)

    def test_can_start_details_mode(self):
        """Must be able to switch to details mode using selected scenario keycode.

        """
        self.process_manager.start_app_window("Character Map")
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        self.keyboard.press_and_release(self.initiate_keycode)

        self.assertProperty(self.unity.switcher, mode=SwitcherMode.DETAIL)

    def test_next_icon_from_last_detail_works(self):
        """Pressing next while showing last switcher item in details mode
        must select first item in the model in non-details mode.

        """
        self.process_manager.start_app("Character Map")
        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)
        while self.unity.switcher.selection_index < len(self.unity.switcher.icons) - 1:
            self.unity.switcher.next_icon()
        self.keyboard.press_and_release(self.initiate_keycode)
        sleep(0.5)
        # Make sure we're at the end of the details list for this icon
        possible_details = self.unity.switcher.detail_current_count - 1
        while self.unity.switcher.detail_selection_index < possible_details:
            self.unity.switcher.next_detail()

        self.unity.switcher.next_icon()
        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(0)))

    def test_detail_mode_selects_last_active_window(self):
        """The active selection in detail mode must be the last focused window.
        If it was the currently active application type.
        """
        char_win1, char_win2 = self.start_applications("Character Map", "Character Map")
        self.assertVisibleWindowStack([char_win2, char_win1])

        self.unity.switcher.initiate()
        while self.unity.switcher.current_icon.tooltip_text != char_win2.application.name:
            self.unity.switcher.next_icon()
        self.keyboard.press_and_release(self.initiate_keycode)
        sleep(0.5)
        self.unity.switcher.select()

        self.assertProperty(char_win1, is_focused=True)

    def test_detail_mode_selects_third_window(self):
        """Pressing Alt+` twice must select the third last used window.
        LP:1061229
        """
        char_win1, char_win2, char_win3 = self.start_applications("Character Map", "Character Map", "Character Map")
        self.assertVisibleWindowStack([char_win3, char_win2, char_win1])

        self.unity.switcher.initiate(SwitcherMode.DETAIL)
        self.unity.switcher.next_detail()

        self.unity.switcher.select()
        self.assertVisibleWindowStack([char_win1, char_win3, char_win2])


class SwitcherWorkspaceTests(SwitcherTestCase):
    """Test Switcher behavior with respect to multiple workspaces."""

    def setUp(self):
        super(SwitcherWorkspaceTests, self).setUp()
        if self.workspace.num_workspaces <= 1:
            self.skipTest("This test requires enabled more than one workspace.")

    def test_switcher_shows_current_workspace_only(self):
        """Switcher must show apps from the current workspace only."""
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)

        calc = self.process_manager.start_app("Calculator")
        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
        char_map = self.process_manager.start_app("Character Map")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        get_icon_names = lambda: [i.tooltip_text for i in self.unity.switcher.icons]
        self.assertThat(get_icon_names, Eventually(Contains(char_map.name)))
        self.assertThat(get_icon_names, Eventually(Not(Contains(calc.name))))

    def test_switcher_switch_current_workspace_same_apps_diff_workspace(self):
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)

        char_map = self.process_manager.start_app_window("Character Map")
        calc1 = self.process_manager.start_app_window("Calculator")

        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)

        calc2 = self.process_manager.start_app_window("Calculator")

        self.workspace.switch_to(initial_workspace);

        self.unity.switcher.initiate()
        self.unity.switcher.select()

        self.assertProperty(char_map, is_focused=True)

    def test_switcher_all_mode_shows_all_apps(self):
        """Test switcher 'show_all' mode shows apps from all workspaces."""
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)

        calc = self.process_manager.start_app("Calculator")
        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
        char_map = self.process_manager.start_app("Character Map")

        self.unity.switcher.initiate(SwitcherMode.ALL)
        self.addCleanup(self.unity.switcher.terminate)

        get_icon_names = lambda: [i.tooltip_text for i in self.unity.switcher.icons]
        self.assertThat(get_icon_names, Eventually(Contains(calc.name)))
        self.assertThat(get_icon_names, Eventually(Contains(char_map.name)))

    def test_switcher_can_switch_to_minimised_window(self):
        """Switcher must be able to switch to a minimised window when there's

        another instance of the same application on a different workspace.

        """
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)

        # disable automatic gridding of the switcher after a timeout, since it makes
        # it harder to write the tests.
        self.set_unity_option("alt_tab_timeout", False)

        self.process_manager.start_app("Character Map")

        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
        char_win2 = self.process_manager.start_app_window("Character Map")
        self.keybinding("window/minimize")
        self.assertProperty(char_win2, is_hidden=True)

        self.process_manager.start_app("Calculator")

        self.unity.switcher.initiate()
        while self.unity.switcher.current_icon.tooltip_text != char_win2.application.name:
            self.unity.switcher.next_icon()
        self.unity.switcher.select()

        self.assertProperty(char_win2, is_hidden=False)

    def test_switcher_is_disabled_when_wall_plugin_active(self):
        """The switcher must not open when the wall plugin is active using ctrl+alt+<direction>."""
        initial_workspace = self.workspace.current_workspace
        self.addCleanup(self.workspace.switch_to, initial_workspace)

        self.workspace.switch_to(0)
        sleep(1)
        self.keyboard.press("Ctrl+Alt+Right")
        self.addCleanup(self.keyboard.release, "Ctrl+Alt+Right")
        sleep(1)
        self.keybinding_hold_part_then_tap("switcher/reveal_normal")
        self.addCleanup(self.unity.switcher.terminate)

        self.assertThat(self.unity.switcher.visible, Eventually(Equals(False)))

class SwitcherDetailsMouseTests(SwitcherTestCase):
    """ Test the interactions with the mouse and the switcher. """

    def setUp(self):
        super(SwitcherDetailsMouseTests, self).setUp()
        self.set_timeout_setting(False)
        self.mouse.move(0, 0, animate=False)

    def test_mouse_highlights_switcher_icons(self):
        """ Tests that the mouse can hightlight all the switcher icons. """

        self.process_manager.start_app("Character Map")

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        icon_args = self.unity.switcher.view.icon_args
        offset = self.unity.switcher.view.spread_offset
        icon_cords = []

        # Must collect the cords before moving mouse
        for args in icon_args:
            x = args.logical_center.x + offset
            y = args.logical_center.y + offset
            icon_cords.append((x,y))

        self.unity.switcher.view.break_mouse_bump_detection()

        index = 0;
        for cords in icon_cords:
            self.mouse.move(cords[0], cords[1])
            self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(index)))
            index += 1

    def test_mouse_clicks_activate_icon(self):
        """
        Opens 2 different applications, CharMap being opened before TextEditor.
        Then we get the index of the CharMap, and click on it, asserting CharMap is focused.
        """

        char_win1, char_win2 = self.start_applications("Character Map", "Text Editor")
        self.assertVisibleWindowStack([char_win2, char_win1])
        self.assertProperty(char_win1, is_focused=False)

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        index = self.unity.switcher.selection_index
        self.unity.switcher.view.move_over_icon(index);
        self.mouse.click()

        self.assertProperty(char_win1, is_focused=True)

    def test_mouse_doesnt_hightlight_icon_if_over_on_start(self):
        """
        First start the launcher and move the mosue over position of Text Editor icon,
        then close the switcher and open it again while moving the mouse a bit.
        Asserting that the icon does lose focus from Character Map.
        """

        char_win1, char_win2 = self.start_applications("Character Map", "Text Editor")
        self.assertVisibleWindowStack([char_win2, char_win1])
        self.assertProperty(char_win1, is_focused=False)

        self.unity.switcher.initiate()
        self.addCleanup(self.unity.switcher.terminate)

        mouse_index = self.unity.switcher.selection_index - 1

        self.unity.switcher.view.move_over_icon(mouse_index)
        # Assert we are over the icon we want to hover over.
        self.assertThat(self.unity.switcher.view.last_icon_selected, Eventually(Equals(mouse_index)))

        self.addCleanup(self.keybinding, "switcher/cancel")

        self.unity.switcher.terminate()
        self.unity.switcher.initiate()

        index = self.unity.switcher.selection_index

        pos = self.mouse.position()
        self.mouse.move(pos[0] + 5, pos[1] + 5)

        # Assert moving the mouse does not change the selection
        self.assertThat(self.unity.switcher.selection_index, Eventually(Equals(index)))

        # Also nice to know clicking still works, even without selection
        self.mouse.click()

        self.assertProperty(char_win2, is_focused=True)

    def test_mouse_highlights_switcher_deatil_icons_motion(self):
        """
        Gather the cords of all the detail icons, move the mouse through each
        asserting the index of each icon we move through.
        """

        self.start_applications("Character Map", "Character Map", "Character Map")

        self.unity.switcher.initiate(SwitcherMode.DETAIL)
        self.addCleanup(self.unity.switcher.terminate)

        for index in range(len(self.unity.switcher.view.detail_icons)):
          self.unity.switcher.view.move_over_detail_icon(index)
          self.assertThat(self.unity.switcher.detail_selection_index, Eventually(Equals(index)))

    def test_mouse_click_will_activate_detail_icon(self):
        """
        Start 2 application of the same type, then click on index 0 in detail mode. This
        will cause the focus from char_win2 to move to char_win1, showing clicking wokrs.
        """

        char_win1, char_win2 = self.start_applications("Character Map", "Character Map")
        self.assertVisibleWindowStack([char_win2, char_win1])

        self.unity.switcher.initiate(SwitcherMode.DETAIL)
        self.addCleanup(self.unity.switcher.terminate)

        self.unity.switcher.view.move_over_detail_icon(0);
        self.mouse.click()

        self.assertProperty(char_win1, is_focused=True)