summaryrefslogtreecommitdiff
path: root/tests
diff options
authorAlan Pope <alan.pope@canonical.com>2012-05-23 14:51:35 +0100
committerAlan Pope <alan.pope@canonical.com>2012-05-23 14:51:35 +0100
commit3dcbb1ea0af69d3737430d135809ea6263cb32f7 (patch)
treebaae739a952948b2546e469c57e6ef06330477ba /tests
parent3bc3bc99aeed192f93faf7c34c79a1b897e5cfd4 (diff)
parent6ca8dc56cf9bc22ff0e587757a39f4fcc2d8a113 (diff)
Cherry pick 2349
(bzr r55.8.2)
Diffstat (limited to 'tests')
-rw-r--r--tests/autopilot/autopilot/emulators/bamf.py23
-rw-r--r--tests/autopilot/autopilot/emulators/unity/icons.py9
-rw-r--r--tests/autopilot/autopilot/emulators/unity/launcher.py8
-rw-r--r--tests/autopilot/autopilot/tests/__init__.py5
-rw-r--r--tests/autopilot/autopilot/tests/test_launcher.py84
5 files changed, 106 insertions, 23 deletions
diff --git a/tests/autopilot/autopilot/emulators/bamf.py b/tests/autopilot/autopilot/emulators/bamf.py
index b0901d50f..1cdc1779f 100644
--- a/tests/autopilot/autopilot/emulators/bamf.py
+++ b/tests/autopilot/autopilot/emulators/bamf.py
@@ -75,6 +75,14 @@ class Bamf(object):
"""
return [a for a in self.get_running_applications() if a.desktop_file == desktop_file]
+ def get_application_by_xid(self, xid):
+ """Return the application that has a child with the requested xid or None."""
+
+ app_path = self.matcher_interface.ApplicationForXid(xid)
+ if len(app_path):
+ return BamfApplication(app_path)
+ return None
+
def get_open_windows(self, user_visible_only=True):
"""Get a list of currently open windows.
@@ -85,17 +93,16 @@ class Bamf(object):
"""
- # Get the stacking order from the root window.
- root_win = _X_DISPLAY.screen().root
- prop = root_win.get_full_property(
- _X_DISPLAY.get_atom('_NET_CLIENT_LIST_STACKING'), X.AnyPropertyType)
- stack = prop.value.tolist()
-
- windows = [BamfWindow(w) for w in self.matcher_interface.WindowPaths()]
+ windows = [BamfWindow(w) for w in self.matcher_interface.WindowStackForMonitor(-1)]
if user_visible_only:
windows = filter(_filter_user_visible, windows)
# Now sort on stacking order.
- return sorted(windows, key=lambda w: stack.index(w.x_id), reverse=True)
+ return reversed(windows)
+
+ def get_window_by_xid(self, xid):
+ """Get the BamfWindow that matches the provided 'xid'."""
+ windows = [BamfWindow(w) for w in self.matcher_interface.WindowPaths() if BamfWindow(w).x_id == xid]
+ return windows[0] if windows else None
def wait_until_application_is_running(self, desktop_file, timeout):
"""Wait until a given application is running.
diff --git a/tests/autopilot/autopilot/emulators/unity/icons.py b/tests/autopilot/autopilot/emulators/unity/icons.py
index 3b027e435..34a387bac 100644
--- a/tests/autopilot/autopilot/emulators/unity/icons.py
+++ b/tests/autopilot/autopilot/emulators/unity/icons.py
@@ -21,7 +21,7 @@ class SimpleLauncherIcon(UnityIntrospectionObject):
@property
def center_position(self):
- """Get the center point of an icon, returns a tuple with (x, y, z)"""
+ """Get the center point of an icon, returns a tuple with (x, y, z)."""
return (self.center_x, self.center_y, self.center_z)
def get_quicklist(self):
@@ -45,12 +45,17 @@ class SimpleLauncherIcon(UnityIntrospectionObject):
return matches[0] if matches else None
def is_on_monitor(self, monitor):
- """Returns True if the icon is available in the defined monitor"""
+ """Returns True if the icon is available in the defined monitor."""
if monitor >= 0 and monitor < len(self.monitors_visibility):
return self.monitors_visibility[monitor]
return False
+ def controls_window(self, xid):
+ """Returns true if the icon controls the specified xid."""
+
+ return self.xids.contains(xid)
+
class BFBLauncherIcon(SimpleLauncherIcon):
"""Represents the BFB button in the launcher."""
diff --git a/tests/autopilot/autopilot/emulators/unity/launcher.py b/tests/autopilot/autopilot/emulators/unity/launcher.py
index a6b028972..742dcf77c 100644
--- a/tests/autopilot/autopilot/emulators/unity/launcher.py
+++ b/tests/autopilot/autopilot/emulators/unity/launcher.py
@@ -338,6 +338,14 @@ class LauncherModel(UnityIntrospectionObject):
return None
+ def get_icon_by_window_xid(self, xid):
+ """Gets a launcher icon that controls the specified window xid."""
+ icons = [i for i in self.get_children_by_type(SimpleLauncherIcon) if i.xids.contains(xid)]
+ if (len(icons)):
+ return icons[0]
+
+ return None
+
def get_icons_by_filter(self, **kwargs):
"""Get a list of icons that satisfy the given filters.
diff --git a/tests/autopilot/autopilot/tests/__init__.py b/tests/autopilot/autopilot/tests/__init__.py
index e8ed05af0..f6dd1d47d 100644
--- a/tests/autopilot/autopilot/tests/__init__.py
+++ b/tests/autopilot/autopilot/tests/__init__.py
@@ -277,8 +277,9 @@ class AutopilotTestCase(VideoCapturedTestCase, KeybindingsHelper):
def close_all_app(self, app_name):
"""Close all instances of the app_name."""
app = self.KNOWN_APPS[app_name]
- self.addCleanup(call, "kill `pidof %s`" % (app['process-name']), shell=True)
- super(LoggedTestCase, self).tearDown()
+ pids = check_output(["pidof", app['process-name']]).split()
+ if len(pids):
+ call(["kill"] + pids)
def get_app_instances(self, app_name):
"""Get BamfApplication instances for app_name."""
diff --git a/tests/autopilot/autopilot/tests/test_launcher.py b/tests/autopilot/autopilot/tests/test_launcher.py
index 371351d96..0401149ea 100644
--- a/tests/autopilot/autopilot/tests/test_launcher.py
+++ b/tests/autopilot/autopilot/tests/test_launcher.py
@@ -417,7 +417,6 @@ class LauncherIconsBehaviorTests(LauncherTestCase):
sleep(1)
[mah_win2] = [w for w in mahj.get_windows() if w.x_id != mah_win1.x_id]
self.assertTrue(mah_win2.is_focused)
-
self.assertVisibleWindowStack([mah_win2, calc_win, mah_win1])
mahj_icon = self.launcher.model.get_icon_by_desktop_id(mahj.desktop_file)
@@ -446,6 +445,20 @@ class LauncherIconsBehaviorTests(LauncherTestCase):
self.assertTrue(mah_win2.is_hidden)
self.assertVisibleWindowStack([mah_win1, calc_win])
+ def test_icon_shows_on_quick_application_reopen(self):
+ """Icons should stay on launcher when an application is quickly closed/reopened."""
+ calc = self.start_app("Calculator")
+ desktop_file = calc.desktop_file
+ calc_icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
+ self.assertThat(calc_icon.visible, Eventually(Equals(True)))
+
+ self.close_all_app("Calculator")
+ calc = self.start_app("Calculator")
+ sleep(2)
+
+ calc_icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
+ self.assertThat(calc_icon, NotEquals(None))
+ self.assertThat(calc_icon.visible, Eventually(Equals(True)))
class LauncherRevealTests(LauncherTestCase):
"""Test the launcher reveal behavior when in autohide mode."""
@@ -579,6 +592,15 @@ class BamfDaemonTests(LauncherTestCase):
self.start_app("Calculator")
self.start_app("System Settings")
+ def start_desktopless_test_apps(self):
+ """Start test applications with no .desktop file associated."""
+ test_apps = ["xclock"]
+
+ for app in test_apps:
+ os.spawnlp(os.P_NOWAIT, app, app)
+ self.addCleanup(call, ["killall", app])
+ self.wait_for_process_started(app)
+
def get_test_apps(self):
"""Return a tuple of test application instances.
@@ -588,35 +610,75 @@ class BamfDaemonTests(LauncherTestCase):
"""
[calc] = self.get_app_instances("Calculator")
[sys_settings] = self.get_app_instances("System Settings")
- return (calc, sys_settings)
+ return [calc, sys_settings]
+
+ def get_desktopless_test_apps(self):
+ """Return a tuple of test application with no .desktop files instances."""
+ [xclock_win] = [w for w in self.bamf.get_open_windows() if w.name == "xclock"]
+ return [xclock_win.application]
def assertOnlyOneLauncherIcon(self, **kwargs):
"""Asserts that there is only one launcher icon with the given filter."""
icons = self.launcher.model.get_icons_by_filter(**kwargs)
self.assertThat(len(icons), Equals(1))
- def wait_for_bamf_daemon(self):
- """Wait until the bamf daemon has been started."""
+ def wait_for_process_started(self, app):
+ """Wait until the application app has been started."""
for i in range(10):
+ sleep(1)
#pgrep returns 0 if it matched something:
- if call(["pgrep", "bamfdaemon"]) == 0:
+ if call(["pgrep", app]) == 0:
return
- sleep(1)
- def test_killing_bamfdaemon_does_not_duplicate_desktop_ids(self):
- """Killing bamfdaemon should not duplicate any desktop ids in the model."""
- self.start_test_apps()
+ def wait_for_process_killed(self, app):
+ """Wait until the application app has been killed."""
+ for i in range(10):
+ #pgrep returns 0 if it matched something:
+ if call(["pgrep", app]) != 0:
+ return
+ sleep(1)
+ def kill_and_restart_bamfdaemon(self):
+ """Kills and resumes bamfdaemon."""
call(["pkill", "bamfdaemon"])
- sleep(1)
+ self.wait_for_process_killed("bamfdaemon")
# trigger the bamfdaemon to be reloaded again, and wait for it to appear:
self.bamf = Bamf()
- self.wait_for_bamf_daemon()
+ self.wait_for_process_started("bamfdaemon")
+
+ def test_killing_bamfdaemon_does_not_duplicate_desktop_ids(self):
+ """Killing bamfdaemon should not duplicate any desktop ids in the model."""
+ self.start_test_apps()
+ self.kill_and_restart_bamfdaemon()
for test_app in self.get_test_apps():
+ logger.info("Checking for duplicated launcher icon for application %s", test_app.name)
self.assertOnlyOneLauncherIcon(desktop_id=test_app.desktop_file)
+ def test_killing_bamfdaemon_does_not_duplicate_application_xids(self):
+ """Killing bamfdaemon should not duplicate any xid in the model."""
+ self.start_test_apps()
+ self.start_desktopless_test_apps()
+ self.kill_and_restart_bamfdaemon()
+
+ test_apps = self.get_test_apps() + self.get_desktopless_test_apps()
+
+ for test_app in test_apps:
+ logger.info("Checking for duplicated launcher icon for application %s", test_app.name)
+ test_windows = [w.x_id for w in test_app.get_windows()]
+ self.assertOnlyOneLauncherIcon(xids=test_windows)
+
+ def test_killing_bamfdaemon_does_not_duplicate_any_icon_application_id(self):
+ """Killing bamfdaemon should not duplicate any application ids in the model."""
+ self.start_test_apps()
+ self.start_desktopless_test_apps()
+ self.kill_and_restart_bamfdaemon()
+
+ for icon in self.launcher.model.get_bamf_launcher_icons():
+ logger.info("Checking for duplicated launcher icon %s", icon.tooltip_text)
+ self.assertOnlyOneLauncherIcon(application_id=icon.application_id)
+
class LauncherCaptureTests(AutopilotTestCase):
"""Test the launchers ability to capture/not capture the mouse."""