diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2012-04-26 05:19:21 -0400 |
|---|---|---|
| committer | Tarmac <> | 2012-04-26 05:19:21 -0400 |
| commit | 0a6e5d16093e802e6d6ea693c2fe4c40a3d61dc0 (patch) | |
| tree | 3c8437932278b7a8e8e180856c01f3092a598ca4 | |
| parent | 98202ab0f76a6001811f6685f1057c223520c568 (diff) | |
| parent | 05e4a777505bf06c64002e179d3f0245239ff5d2 (diff) | |
We need to flag a bamf view that we control using an icon using the "unity-seen" qdata, or unity will duplicate it on bamfdaemon respawn. (LP: #928912). Fixes: https://bugs.launchpad.net/bugs/928912. Approved by Michal Hruby, Tim Penhey.
Original authors: - Marco Trevisan (Treviño) <mail@3v1n0.net> - Thomi Richards <thomi.richards@canonical.com> (bzr r2345)
| -rw-r--r-- | plugins/unityshell/src/BamfLauncherIcon.cpp | 3 | ||||
| -rw-r--r-- | plugins/unityshell/src/LauncherController.cpp | 7 | ||||
| -rw-r--r-- | tests/autopilot/autopilot/emulators/bamf.py | 10 | ||||
| -rw-r--r-- | tests/autopilot/autopilot/emulators/unity/launcher.py | 24 | ||||
| -rw-r--r-- | tests/autopilot/autopilot/tests/__init__.py | 8 | ||||
| -rw-r--r-- | tests/autopilot/autopilot/tests/test_launcher.py | 49 |
6 files changed, 84 insertions, 17 deletions
diff --git a/plugins/unityshell/src/BamfLauncherIcon.cpp b/plugins/unityshell/src/BamfLauncherIcon.cpp index 01205fc24..32cfe7baa 100644 --- a/plugins/unityshell/src/BamfLauncherIcon.cpp +++ b/plugins/unityshell/src/BamfLauncherIcon.cpp @@ -144,7 +144,7 @@ BamfLauncherIcon::~BamfLauncherIcon() { g_object_set_qdata(G_OBJECT(_bamf_app.RawPtr()), g_quark_from_static_string("unity-seen"), - GINT_TO_POINTER(0)); + GUINT_TO_POINTER(0)); if (_fill_supported_types_id != 0) g_source_remove(_fill_supported_types_id); @@ -500,6 +500,7 @@ void BamfLauncherIcon::AddProperties(GVariantBuilder* builder) variant::BuilderWrapper(builder) .add("desktop_file", DesktopFile()) .add("desktop_id", GetDesktopID()) + .add("application_id", GPOINTER_TO_UINT(_bamf_app.RawPtr())) .add("xids", g_variant_builder_end(&xids_builder)) .add("sticky", IsSticky()); } diff --git a/plugins/unityshell/src/LauncherController.cpp b/plugins/unityshell/src/LauncherController.cpp index a2e0868a2..f6cb5b753 100644 --- a/plugins/unityshell/src/LauncherController.cpp +++ b/plugins/unityshell/src/LauncherController.cpp @@ -740,6 +740,7 @@ void Controller::Impl::OnViewOpened(BamfMatcher* matcher, BamfView* view, gpoint return; } + g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1)); AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app)); icon->visibility_changed.connect(sigc::mem_fun(self, &Impl::SortAndUpdate)); icon->SetSortPriority(self->sort_priority_++); @@ -762,9 +763,8 @@ AbstractLauncherIcon::Ptr Controller::Impl::CreateFavorite(const char* file_path return result; } - g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GINT_TO_POINTER(1)); - bamf_view_set_sticky(BAMF_VIEW(app), true); + g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1)); AbstractLauncherIcon::Ptr icon (new BamfLauncherIcon(app)); icon->SetSortPriority(sort_priority_++); result = icon; @@ -790,6 +790,7 @@ SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::stri } bamf_view_set_sticky(BAMF_VIEW(app), true); + g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1)); result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path); result->SetSortPriority(sort_priority_++); @@ -831,8 +832,8 @@ void Controller::Impl::SetupBamf() if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"))) continue; - g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GINT_TO_POINTER(1)); + g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"), GUINT_TO_POINTER(1)); AbstractLauncherIcon::Ptr icon(new BamfLauncherIcon(app)); icon->SetSortPriority(sort_priority_++); RegisterIcon(icon); diff --git a/tests/autopilot/autopilot/emulators/bamf.py b/tests/autopilot/autopilot/emulators/bamf.py index 88553fbbd..b0901d50f 100644 --- a/tests/autopilot/autopilot/emulators/bamf.py +++ b/tests/autopilot/autopilot/emulators/bamf.py @@ -254,6 +254,16 @@ class BamfWindow(object): return self._x_win @property + def name(self): + """Get the window name. + + Note: This may change according to the current locale. If you want a unique + string to match windows against, use the x_id instead. + + """ + return self._view_iface.Name() + + @property def title(self): """Get the window title. diff --git a/tests/autopilot/autopilot/emulators/unity/launcher.py b/tests/autopilot/autopilot/emulators/unity/launcher.py index 2a11ceda6..a6b028972 100644 --- a/tests/autopilot/autopilot/emulators/unity/launcher.py +++ b/tests/autopilot/autopilot/emulators/unity/launcher.py @@ -327,17 +327,6 @@ class LauncherModel(UnityIntrospectionObject): return icon return None - def get_icon_by_desktop_file(self, desktop_file): - """Gets a launcher icon with the specified desktop file. - - Returns None if there is no such launcher icon. - """ - icons = self.get_children_by_type(SimpleLauncherIcon, desktop_file=desktop_file) - if len(icons): - return icons[0] - - return None - def get_icon_by_desktop_id(self, desktop_id): """Gets a launcher icon with the specified desktop id. @@ -349,6 +338,19 @@ class LauncherModel(UnityIntrospectionObject): return None + def get_icons_by_filter(self, **kwargs): + """Get a list of icons that satisfy the given filters. + + For example: + + >>> get_icons_by_filter(tooltip_text="My Application") + ... [...] + + Returns an empty list if no icons matched the filter. + + """ + return self.get_children_by_type(SimpleLauncherIcon, **kwargs) + def num_launcher_icons(self): """Get the number of icons in the launcher model.""" return len(self.get_launcher_icons()) diff --git a/tests/autopilot/autopilot/tests/__init__.py b/tests/autopilot/autopilot/tests/__init__.py index d472d562f..e8ed05af0 100644 --- a/tests/autopilot/autopilot/tests/__init__.py +++ b/tests/autopilot/autopilot/tests/__init__.py @@ -224,6 +224,10 @@ class AutopilotTestCase(VideoCapturedTestCase, KeybindingsHelper): 'desktop-file': 'remmina.desktop', 'process-name': 'remmina', }, + 'System Settings' : { + 'desktop-file': 'gnome-control-center.desktop', + 'process-name': 'gnome-control-center', + }, 'Text Editor' : { 'desktop-file': 'gedit.desktop', 'process-name': 'gedit', @@ -266,14 +270,14 @@ class AutopilotTestCase(VideoCapturedTestCase, KeybindingsHelper): app = self.KNOWN_APPS[app_name] self.bamf.launch_application(app['desktop-file'], files) apps = self.bamf.get_running_applications_by_desktop_file(app['desktop-file']) - self.addCleanup(call, ["killall", app['process-name']]) + self.addCleanup(call, "kill `pidof %s`" % (app['process-name']), shell=True) self.assertThat(len(apps), Equals(1)) return apps[0] def close_all_app(self, app_name): """Close all instances of the app_name.""" app = self.KNOWN_APPS[app_name] - call(["killall", app['process-name']]) + self.addCleanup(call, "kill `pidof %s`" % (app['process-name']), shell=True) super(LoggedTestCase, self).tearDown() def get_app_instances(self, app_name): diff --git a/tests/autopilot/autopilot/tests/test_launcher.py b/tests/autopilot/autopilot/tests/test_launcher.py index ed0518f5c..24cd3a2c4 100644 --- a/tests/autopilot/autopilot/tests/test_launcher.py +++ b/tests/autopilot/autopilot/tests/test_launcher.py @@ -8,9 +8,12 @@ # by the Free Software Foundation. import logging +import os +from subprocess import call from testtools.matchers import Equals, NotEquals, LessThan, GreaterThan from time import sleep +from autopilot.emulators.bamf import Bamf from autopilot.emulators.unity.icons import BFBLauncherIcon from autopilot.emulators.X11 import ScreenGeometry from autopilot.matchers import Eventually @@ -568,6 +571,52 @@ class LauncherVisualTests(LauncherTestCase): for icon in self.launcher.model.get_launcher_icons(): self.assertThat(icon.desaturated, Eventually(Equals(False))) +class BamfDaemonTests(LauncherTestCase): + """Test interaction between the launcher and the BAMF Daemon.""" + + def start_test_apps(self): + """Starts some test applications.""" + self.start_app("Calculator") + self.start_app("System Settings") + + def get_test_apps(self): + """Return a tuple of test application instances. + + We don't store these since when we kill the bamf daemon all references + to the old apps will die. + + """ + [calc] = self.get_app_instances("Calculator") + [sys_settings] = self.get_app_instances("System Settings") + return (calc, sys_settings) + + 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.""" + for i in range(10): + #pgrep returns 0 if it matched something: + if call(["pgrep", "bamfdaemon"]) == 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() + + call(["pkill", "bamfdaemon"]) + sleep(1) + + # trigger the bamfdaemon to be reloaded again, and wait for it to appear: + self.bamf = Bamf() + self.wait_for_bamf_daemon() + + for test_app in self.get_test_apps(): + self.assertOnlyOneLauncherIcon(desktop_id=test_app.desktop_file) + class LauncherCaptureTests(AutopilotTestCase): """Test the launchers ability to capture/not capture the mouse.""" |
