Merge lp:~aacid/unity/fix_panek_title_escaping_1067357 into lp:unity

Proposed by Albert Astals Cid
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2865
Proposed branch: lp:~aacid/unity/fix_panek_title_escaping_1067357
Merge into: lp:unity
Diff against target: 332 lines (+170/-47)
6 files modified
panel/PanelMenuView.cpp (+48/-42)
panel/PanelMenuView.h (+4/-2)
tests/CMakeLists.txt (+2/-1)
tests/test_panel_menu_view.cpp (+96/-0)
unity-shared/StandaloneWindowManager.cpp (+14/-2)
unity-shared/StandaloneWindowManager.h (+6/-0)
To merge this branch: bzr merge lp:~aacid/unity/fix_panek_title_escaping_1067357
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Marco Trevisan (Treviño) Approve
Review via email: mp+130111@code.launchpad.net

Commit message

Fix escaping of _panel_title

It only has to be escpaed if comes from new_title
if coming from UBUS_LAUNCHER_SELECTION_CHANGED data it is already escaped
Fixes bug #1067357

Description of the change

Fix escaping of _panel_title

It only has to be escpaed if comes from new_title
if coming from UBUS_LAUNCHER_SELECTION_CHANGED data it is already escaped
Fixes bug #1067357

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

89 + const std::string prevTitle = _panel_title;
90 + RefreshTitle();
91 + if (prevTitle == _panel_title && !force && _last_geo == geo && _title_texture)
92 + {
93 + // No need to redraw the title, let's save some CPU time!
94 + return;
95 }

Mh, at this point I think it's better to make RefreshTitle to return a string... Channging it to GetCurrentTitle() so we can:

std::string const& new_title = GetCurrentTitle() // always use not-capital chars on variables

if (new_title == prev_title_) ....

130 + std::string _panel_title;

Please don't make it public, put it back as private.

If you need to access it on testing, just add a: friend class TestPanelMenuView;
Doing so in your struct TestPanelMenuView you can access to this member (see LauncherController or Launcher tests for reference).

+ EXPECT_EQ(panelMenuView._panel_title, "");
Better EXPECT_TRUE( ... .empty()).

264 + EXPECT_TRUE(wm != nullptr);
Use an assert here, so that there won't be crashes:
ASSERT_NE(wm, nullptr);

Revision history for this message
Albert Astals Cid (aacid) wrote :

Suggestions integrated

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Nice, thanks!

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

Reapproving now that the merger is not broken anymore

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

Fixed merge conflict

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'panel/PanelMenuView.cpp'
2--- panel/PanelMenuView.cpp 2012-10-11 01:44:15 +0000
3+++ panel/PanelMenuView.cpp 2012-10-22 09:33:20 +0000
4@@ -785,6 +785,46 @@
5 gtk_style_context_restore(style_context);
6 }
7
8+std::string PanelMenuView::GetCurrentTitle() const
9+{
10+ if (!_switcher_showing && !_launcher_keynav)
11+ {
12+ WindowManager& wm = WindowManager::Default();
13+ std::string new_title;
14+
15+ if (wm.IsScaleActive())
16+ {
17+ if (wm.IsScaleActiveForGroup())
18+ new_title = GetActiveViewName(true);
19+ else if (_we_control_active)
20+ new_title = _desktop_name;
21+ }
22+ else if (wm.IsExpoActive())
23+ {
24+ new_title = _desktop_name;
25+ }
26+ else if (!_we_control_active)
27+ {
28+ new_title = "";
29+ }
30+ else
31+ {
32+ new_title = GetActiveViewName();
33+ _window_buttons->SetControlledWindow(_active_xid);
34+ }
35+
36+ // _panel_title needs to be only escaped when computed
37+ // in this function, if it comes from OnLauncherSelectionChanged
38+ // it is already escaped
39+ glib::String escaped(g_markup_escape_text(new_title.c_str(), -1));
40+ return escaped.Str();
41+ }
42+ else
43+ {
44+ return _panel_title;
45+ }
46+}
47+
48 void PanelMenuView::Refresh(bool force)
49 {
50 nux::Geometry const& geo = GetGeometry();
51@@ -794,42 +834,13 @@
52 if (geo.width > _monitor_geo.width)
53 return;
54
55- WindowManager& wm = WindowManager::Default();
56- std::string new_title;
57-
58- if (wm.IsScaleActive())
59- {
60- if (wm.IsScaleActiveForGroup())
61- new_title = GetActiveViewName(true);
62- else if (_we_control_active)
63- new_title = _desktop_name;
64- }
65- else if (wm.IsExpoActive())
66- {
67- new_title = _desktop_name;
68- }
69- else if (!_we_control_active)
70- {
71- new_title = "";
72- }
73- else if (!_switcher_showing && !_launcher_keynav)
74- {
75- new_title = GetActiveViewName();
76- _window_buttons->SetControlledWindow(_active_xid);
77- }
78-
79- if (!_switcher_showing && !_launcher_keynav)
80- {
81- if (_panel_title != new_title)
82- {
83- _panel_title = new_title;
84- }
85- else if (!force && _last_geo == geo && _title_texture)
86- {
87- // No need to redraw the title, let's save some CPU time!
88- return;
89- }
90- }
91+ const std::string& new_title = GetCurrentTitle();
92+ if (new_title == _panel_title && !force && _last_geo == geo && _title_texture)
93+ {
94+ // No need to redraw the title, let's save some CPU time!
95+ return;
96+ }
97+ _panel_title = new_title;
98
99 if (_panel_title.empty())
100 {
101@@ -843,12 +854,7 @@
102 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
103 cairo_paint(cr);
104
105- glib::String escaped(g_markup_escape_text(_panel_title.c_str(), -1));
106-
107- std::ostringstream bold_label;
108- bold_label << "<b>" << escaped.Str() << "</b>";
109-
110- DrawTitle(cr, geo, bold_label.str());
111+ DrawTitle(cr, geo, _panel_title);
112
113 cairo_destroy(cr);
114
115
116=== modified file 'panel/PanelMenuView.h'
117--- panel/PanelMenuView.h 2012-10-11 01:44:15 +0000
118+++ panel/PanelMenuView.h 2012-10-22 09:33:20 +0000
119@@ -68,8 +68,11 @@
120 virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position,
121 nux::NuxEventType event_type);
122 virtual void OnEntryAdded(indicator::Entry::Ptr const& entry);
123+ virtual std::string GetActiveViewName(bool use_appname = false) const;
124
125 private:
126+ friend class TestPanelMenuView;
127+
128 void OnActiveChanged(PanelIndicatorEntryView* view, bool is_active);
129 void OnViewOpened(BamfMatcher* matcher, BamfView* view);
130 void OnViewClosed(BamfMatcher* matcher, BamfView* view);
131@@ -100,6 +103,7 @@
132 void OnMaximizedGrabEnd(int x, int y);
133
134 void FullRedraw();
135+ std::string GetCurrentTitle() const;
136 void Refresh(bool force = false);
137 void DrawTitle(cairo_t *cr_real, nux::Geometry const& geo, std::string const& label) const;
138
139@@ -109,8 +113,6 @@
140
141 BamfWindow* GetBamfWindowForXid(Window xid) const;
142
143- std::string GetActiveViewName(bool use_appname = false) const;
144-
145 void OnSwitcherShown(GVariant* data);
146 void OnLauncherKeyNavStarted(GVariant* data);
147 void OnLauncherKeyNavEnded(GVariant* data);
148
149=== modified file 'tests/CMakeLists.txt'
150--- tests/CMakeLists.txt 2012-10-19 14:37:49 +0000
151+++ tests/CMakeLists.txt 2012-10-22 09:33:20 +0000
152@@ -200,6 +200,7 @@
153 test_launcher_icon.cpp
154 test_keyboard_util.cpp
155 test_panel_style.cpp
156+ test_panel_menu_view.cpp
157 test_places_group.cpp
158 test_previews_application.cpp
159 test_previews_generic.cpp
160@@ -226,7 +227,7 @@
161 gmockvolume.c
162 ${CMAKE_SOURCE_DIR}/plugins/unityshell/src/WindowMinimizeSpeedController.cpp
163 )
164- target_link_libraries(test-gtest gtest gmock unity-shared ${LIBS} launcher-lib unity-shared-standalone shortcuts-lib previews-lib hud-lib switcher-lib dash-lib)
165+ target_link_libraries(test-gtest gtest gmock unity-shared ${LIBS} launcher-lib unity-shared-standalone shortcuts-lib previews-lib hud-lib switcher-lib dash-lib panel-lib)
166 add_test(UnityGTest test-gtest)
167 add_dependencies(test-gtest unity-core-${UNITY_API_VERSION} gtest gmock)
168
169
170=== added file 'tests/test_panel_menu_view.cpp'
171--- tests/test_panel_menu_view.cpp 1970-01-01 00:00:00 +0000
172+++ tests/test_panel_menu_view.cpp 2012-10-22 09:33:20 +0000
173@@ -0,0 +1,96 @@
174+/*
175+ * Copyright 2012 Canonical Ltd.
176+ *
177+ * This program is free software: you can redistribute it and/or modify it
178+ * under the terms of the GNU General Public License version 3, as published
179+ * by the Free Software Foundation.
180+ *
181+ * This program is distributed in the hope that it will be useful, but
182+ * WITHOUT ANY WARRANTY; without even the implied warranties of
183+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
184+ * PURPOSE. See the GNU General Public License for more details.
185+ *
186+ * You should have received a copy of the GNU General Public License
187+ * version 3 along with this program. If not, see
188+ * <http://www.gnu.org/licenses/>
189+ *
190+ */
191+
192+#include <gmock/gmock.h>
193+
194+#include <Nux/Nux.h>
195+#include "PanelMenuView.h"
196+#include "PanelStyle.h"
197+#include "UnitySettings.h"
198+#include "UBusMessages.h"
199+#include "StandaloneWindowManager.h"
200+#include "test_utils.h"
201+
202+using namespace testing;
203+
204+namespace unity
205+{
206+
207+class MockPanelMenuView : public PanelMenuView
208+{
209+ protected:
210+ virtual std::string GetActiveViewName(bool use_appname) const
211+ {
212+ return "<>'";
213+ }
214+};
215+
216+struct TestPanelMenuView : public testing::Test
217+{
218+ virtual void SetUp()
219+ {
220+ }
221+
222+ void ProcessUBusMessages()
223+ {
224+ bool expired = false;
225+ glib::Idle idle([&] { expired = true; return false; },
226+ glib::Source::Priority::LOW);
227+ Utils::WaitUntil(expired);
228+ }
229+
230+ std::string panelTitle() const
231+ {
232+ const PanelMenuView *panel = &panelMenuView;
233+ return panel->GetCurrentTitle();
234+ }
235+
236+private:
237+ // The order is important, i.e. PanelMenuView needs
238+ // panel::Style that needs Settings
239+ Settings settings;
240+ panel::Style panelStyle;
241+ MockPanelMenuView panelMenuView;
242+};
243+
244+TEST_F(TestPanelMenuView, Escaping)
245+{
246+ static const char *escapedText = "Panel d&amp;Inici";
247+ EXPECT_TRUE(panelTitle().empty());
248+
249+ UBusManager ubus;
250+ ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV, NULL);
251+ ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED,
252+ g_variant_new_string(escapedText));
253+ ProcessUBusMessages();
254+
255+ EXPECT_EQ(panelTitle(), escapedText);
256+
257+ ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV, NULL);
258+ ProcessUBusMessages();
259+
260+ StandaloneWindowManager *wm = dynamic_cast<StandaloneWindowManager *>(&WindowManager::Default());
261+ ASSERT_NE(wm, nullptr);
262+ // Change the wm to trick PanelMenuView::RefreshTitle to call GetActiveViewName
263+ wm->SetScaleActive(true);
264+ wm->SetScaleActiveForGroup(true);
265+
266+ EXPECT_EQ(panelTitle(), "&lt;&gt;&apos;");
267+}
268+
269+}
270
271=== modified file 'unity-shared/StandaloneWindowManager.cpp'
272--- unity-shared/StandaloneWindowManager.cpp 2012-10-11 01:44:15 +0000
273+++ unity-shared/StandaloneWindowManager.cpp 2012-10-22 09:33:20 +0000
274@@ -44,6 +44,8 @@
275 StandaloneWindowManager::StandaloneWindowManager()
276 : expo_state_(false)
277 , in_show_desktop_(false)
278+ , scale_active_(false)
279+ , scale_active_for_group_(false)
280 {
281 }
282
283@@ -136,14 +138,24 @@
284 void StandaloneWindowManager::TerminateScale()
285 {}
286
287+void StandaloneWindowManager::SetScaleActive(bool scale_active)
288+{
289+ scale_active_ = scale_active;
290+}
291+
292 bool StandaloneWindowManager::IsScaleActive() const
293 {
294- return false;
295+ return scale_active_;
296+}
297+
298+void StandaloneWindowManager::SetScaleActiveForGroup(bool scale_active_for_group)
299+{
300+ scale_active_for_group_ = scale_active_for_group;
301 }
302
303 bool StandaloneWindowManager::IsScaleActiveForGroup() const
304 {
305- return false;
306+ return scale_active_for_group_;
307 }
308
309 void StandaloneWindowManager::InitiateExpo()
310
311=== modified file 'unity-shared/StandaloneWindowManager.h'
312--- unity-shared/StandaloneWindowManager.h 2012-10-04 07:10:39 +0000
313+++ unity-shared/StandaloneWindowManager.h 2012-10-22 09:33:20 +0000
314@@ -95,12 +95,18 @@
315
316 virtual std::string GetWindowName(Window window_id) const;
317
318+ // Mock functions
319+ void SetScaleActive(bool scale_active);
320+ void SetScaleActiveForGroup(bool scale_active_for_group);
321+
322 protected:
323 virtual void AddProperties(GVariantBuilder* builder);
324
325 private:
326 bool expo_state_;
327 bool in_show_desktop_;
328+ bool scale_active_;
329+ bool scale_active_for_group_;
330 };
331
332 }