Back to index

unity  6.0.0
test_showdesktop.py
Go to the documentation of this file.
00001 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
00002 # Copyright 2010 Canonical
00003 # Author: Thomi Richards
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License version 3, as published
00007 # by the Free Software Foundation.
00008 
00009 from __future__ import absolute_import
00010 
00011 from time import sleep
00012 
00013 from unity.emulators.icons import DesktopLauncherIcon
00014 from unity.tests import UnityTestCase
00015 
00016 
00017 class ShowDesktopTests(UnityTestCase):
00018     """Test the 'Show Desktop' functionality."""
00019 
00020     def setUp(self):
00021         super(ShowDesktopTests, self).setUp()
00022         self.set_unity_log_level("unity.plugin", "DEBUG")
00023         # we need this to let the unity models update after we shutdown apps
00024         # before we start the next test.
00025         sleep(2)
00026 
00027     def launch_test_apps(self):
00028         """Launch character map and calculator apps."""
00029         self.start_app('Character Map', locale='C')
00030         self.start_app('Calculator', locale='C')
00031         sleep(1)
00032 
00033     def test_showdesktop_hides_apps(self):
00034         """Show Desktop keyboard shortcut must hide applications."""
00035         self.launch_test_apps()
00036 
00037         # show desktop, verify all windows are hidden:
00038         self.window_manager.enter_show_desktop()
00039         self.addCleanup(self.window_manager.leave_show_desktop)
00040 
00041         open_wins = self.bamf.get_open_windows()
00042         self.assertGreaterEqual(len(open_wins), 2)
00043         for win in open_wins:
00044             self.assertTrue(win.is_valid)
00045             self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
00046 
00047     def test_showdesktop_unhides_apps(self):
00048         """Show desktop shortcut must re-show all hidden apps."""
00049         self.launch_test_apps()
00050 
00051         # show desktop, verify all windows are hidden:
00052         self.window_manager.enter_show_desktop()
00053         self.addCleanup(self.window_manager.leave_show_desktop)
00054 
00055         open_wins = self.bamf.get_open_windows()
00056         self.assertGreaterEqual(len(open_wins), 2)
00057         for win in open_wins:
00058             self.assertTrue(win.is_valid)
00059             self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
00060 
00061         # un-show desktop, verify all windows are shown:
00062         self.window_manager.leave_show_desktop()
00063 
00064         for win in self.bamf.get_open_windows():
00065             self.assertTrue(win.is_valid)
00066             self.assertFalse(win.is_hidden, "Window '%s' is shown after show desktop deactivated." % (win.title))
00067 
00068     def test_unhide_single_app(self):
00069         """Un-hide a single app from launcher after hiding all apps."""
00070         self.launch_test_apps()
00071 
00072         # show desktop, verify all windows are hidden:
00073         self.window_manager.enter_show_desktop()
00074         self.addCleanup(self.window_manager.leave_show_desktop)
00075 
00076         open_wins = self.bamf.get_open_windows()
00077         self.assertGreaterEqual(len(open_wins), 2)
00078         for win in open_wins:
00079             self.assertTrue(win.is_valid)
00080             self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))
00081 
00082         # We'll un-minimise the character map - find it's launcherIcon in the launcher:
00083         charmap_icon = self.launcher.model.get_icon_by_desktop_id("gucharmap.desktop")
00084         if charmap_icon:
00085             self.launcher.get_launcher_for_monitor(0).click_launcher_icon(charmap_icon)
00086         else:
00087             self.fail("Could not find launcher icon in launcher.")
00088 
00089         sleep(3)
00090         for win in self.bamf.get_open_windows():
00091             if win.is_valid:
00092                 if win.title == 'Character Map':
00093                     self.assertFalse(win.is_hidden, "Character map did not un-hide from launcher.")
00094                 else:
00095                     self.assertTrue(win.is_hidden, "Window '%s' should still be hidden." % (win.title))
00096 
00097         # hide desktop - now all windows should be visible:
00098         self.window_manager.leave_show_desktop()
00099 
00100         for win in self.bamf.get_open_windows():
00101             if win.is_valid:
00102                 self.assertFalse(win.is_hidden, "Window '%s' is not shown after show desktop deactivated." % (win.title))
00103 
00104     def test_showdesktop_switcher(self):
00105         """Show desktop item in switcher should hide all hidden apps."""
00106         self.launch_test_apps()
00107 
00108         # show desktop, verify all windows are hidden:
00109         self.switcher.initiate()
00110         sleep(0.5)
00111         found = False
00112         switcher_model = self.switcher.controller.model
00113         for i in switcher_model.icons:
00114             current_icon = self.switcher.current_icon
00115             self.assertIsNotNone(current_icon)
00116             if isinstance(current_icon, DesktopLauncherIcon):
00117                 found = True
00118                 break
00119             self.switcher.previous_icon()
00120             sleep(0.25)
00121         self.assertTrue(found, "Could not find 'Show Desktop' entry in switcher.")
00122         self.addCleanup(self.window_manager.leave_show_desktop)
00123 
00124         self.switcher.select()
00125 
00126         sleep(3)
00127         open_wins = self.bamf.get_open_windows()
00128         self.assertGreaterEqual(len(open_wins), 2)
00129         for win in open_wins:
00130             self.assertTrue(win.is_valid)
00131             self.assertTrue(win.is_hidden, "Window '%s' is not hidden after show desktop activated." % (win.title))