Merge lp:~3v1n0/unity/fix-icon-crash-on-null-app into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
Merged at revision: 3562
Proposed branch: lp:~3v1n0/unity/fix-icon-crash-on-null-app
Merge into: lp:unity
Diff against target: 116 lines (+45/-14)
3 files modified
launcher/ApplicationLauncherIcon.cpp (+14/-6)
launcher/SoftwareCenterLauncherIcon.cpp (+12/-8)
tests/test_software_center_launcher_icon.cpp (+19/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/fix-icon-crash-on-null-app
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+190017@code.launchpad.net

Commit message

ApplicationLauncherIcon: remove the icon when setting a null application

Description of the change

Handle with care a new application pointer if that's a null app... In this case we can just remove the icon.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/ApplicationLauncherIcon.cpp'
2--- launcher/ApplicationLauncherIcon.cpp 2013-10-07 18:35:17 +0000
3+++ launcher/ApplicationLauncherIcon.cpp 2013-10-09 02:41:21 +0000
4@@ -97,7 +97,11 @@
5
6 ApplicationLauncherIcon::~ApplicationLauncherIcon()
7 {
8- SetApplication(nullptr);
9+ if (app_)
10+ {
11+ app_->sticky = false;
12+ app_->seen = false;
13+ }
14 }
15
16 ApplicationPtr ApplicationLauncherIcon::GetApplication() const
17@@ -110,18 +114,20 @@
18 if (app_ == app)
19 return;
20
21+ if (!app)
22+ {
23+ Remove();
24+ return;
25+ }
26+
27 if (app_)
28 {
29 app_->sticky = false;
30 app_->seen = false;
31+ signals_conn_.Clear();
32 }
33
34- signals_conn_.Clear();
35 app_ = app;
36-
37- if (!app)
38- return;
39-
40 app_->seen = true;
41 SetupApplicationSignalsConnections();
42
43@@ -242,8 +248,10 @@
44 * launcher. Disconnecting from signals we make sure that this icon won't be
45 * reused (no duplicated icon). */
46 app_->seen = false;
47+ app_->sticky = false;
48 // Disconnect all our callbacks.
49 notify_callbacks(); // This is from sigc++::trackable
50+ signals_conn_.Clear();
51 SimpleLauncherIcon::Remove();
52 }
53
54
55=== modified file 'launcher/SoftwareCenterLauncherIcon.cpp'
56--- launcher/SoftwareCenterLauncherIcon.cpp 2013-09-10 15:26:39 +0000
57+++ launcher/SoftwareCenterLauncherIcon.cpp 2013-10-09 02:41:21 +0000
58@@ -222,16 +222,20 @@
59 auto const& new_app = app_manager.GetApplicationForDesktopFile(new_desktop_path);
60 if (new_app) new_app->sticky = IsSticky();
61 SetApplication(new_app);
62- Stick();
63-
64- _source_manager.AddIdle([this] {
65- ShowTooltip();
66- _source_manager.AddTimeout(INSTALL_TIP_DURATION, [this] {
67- HideTooltip();
68+
69+ if (new_app)
70+ {
71+ Stick();
72+
73+ _source_manager.AddIdle([this] {
74+ ShowTooltip();
75+ _source_manager.AddTimeout(INSTALL_TIP_DURATION, [this] {
76+ HideTooltip();
77+ return false;
78+ });
79 return false;
80 });
81- return false;
82- });
83+ }
84 }
85 else
86 {
87
88=== modified file 'tests/test_software_center_launcher_icon.cpp'
89--- tests/test_software_center_launcher_icon.cpp 2013-10-04 00:19:56 +0000
90+++ tests/test_software_center_launcher_icon.cpp 2013-10-09 02:41:21 +0000
91@@ -157,6 +157,25 @@
92 EXPECT_TRUE(usc->icon.changed.empty());
93 }
94
95+TEST_F(TestSoftwareCenterLauncherIcon, OnFinishedRemoveInvalidNewAppIcon)
96+{
97+ // Using an icon ptr, to get the removed signal to be properly emitted
98+ nux::ObjectPtr<MockSoftwareCenterLauncherIcon> icon_ptr(
99+ new MockSoftwareCenterLauncherIcon(usc, "/com/canonical/unity/test/object/path", PRE_INSTALL_ICON));
100+
101+ bool removed = false;
102+ auto& app_manager = unity::ApplicationManager::Default();
103+ auto mock_app_managed = dynamic_cast<MockApplicationManager*>(&app_manager);
104+
105+ EXPECT_CALL(*mock_app_managed, GetApplicationForDesktopFile(_)).WillOnce(Return(nullptr));
106+ icon_ptr->remove.connect([&removed] (AbstractLauncherIcon::Ptr const&) { removed = true; });
107+
108+ icon_ptr->OnFinished(glib::Variant(g_variant_new("(s)", "exit-success")));
109+
110+ Mock::VerifyAndClearExpectations(mock_app_managed);
111+ EXPECT_TRUE(removed);
112+}
113+
114 TEST_F(TestSoftwareCenterLauncherIcon, OnFinishedSticksIcon)
115 {
116 ASSERT_FALSE(icon.IsSticky());