Merge lp:~aacid/unity/fix_panek_title_escaping_1067357_for_6.0 into lp:unity/6.0

Proposed by Albert Astals Cid
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2791
Proposed branch: lp:~aacid/unity/fix_panek_title_escaping_1067357_for_6.0
Merge into: lp:unity/6.0
Diff against target: 350 lines (+232/-44)
4 files modified
panel/PanelMenuView.cpp (+48/-42)
panel/PanelMenuView.h (+4/-2)
tests/CMakeLists.txt (+6/-0)
tests/test_panel_menu_view.cpp (+174/-0)
To merge this branch: bzr merge lp:~aacid/unity/fix_panek_title_escaping_1067357_for_6.0
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+130545@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
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1545/console reported an error when processing this lp:~aacid/unity/fix_panek_title_escaping_1067357_for_6.0 branch.
Not merging it.

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

Reapproving after minor compile fix

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1546/console reported an error when processing this lp:~aacid/unity/fix_panek_title_escaping_1067357_for_6.0 branch.
Not merging it.

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

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-08-27 03:00:42 +0000
3+++ panel/PanelMenuView.cpp 2012-10-24 08:16:21 +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+ auto win_manager = WindowManager::Default();
13+ std::string new_title;
14+
15+ if (win_manager->IsScaleActive())
16+ {
17+ if (win_manager->IsScaleActiveForGroup())
18+ new_title = GetActiveViewName(true);
19+ else if (_we_control_active)
20+ new_title = _desktop_name;
21+ }
22+ else if (win_manager->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- auto win_manager = WindowManager::Default();
56- std::string new_title;
57-
58- if (win_manager->IsScaleActive())
59- {
60- if (win_manager->IsScaleActiveForGroup())
61- new_title = GetActiveViewName(true);
62- else if (_we_control_active)
63- new_title = _desktop_name;
64- }
65- else if (win_manager->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-09-07 14:29:09 +0000
118+++ panel/PanelMenuView.h 2012-10-24 08:16:21 +0000
119@@ -69,8 +69,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@@ -101,6 +104,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@@ -110,8 +114,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-12 16:34:45 +0000
151+++ tests/CMakeLists.txt 2012-10-24 08:16:21 +0000
152@@ -223,6 +223,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@@ -327,6 +328,11 @@
161 ${CMAKE_SOURCE_DIR}/launcher/VolumeImp.cpp
162 ${CMAKE_SOURCE_DIR}/launcher/VolumeLauncherIcon.cpp
163 ${CMAKE_SOURCE_DIR}/launcher/VolumeMonitorWrapper.cpp
164+ ${CMAKE_SOURCE_DIR}/panel/PanelIndicatorEntryView.cpp
165+ ${CMAKE_SOURCE_DIR}/panel/PanelIndicatorsView.cpp
166+ ${CMAKE_SOURCE_DIR}/panel/PanelMenuView.cpp
167+ ${CMAKE_SOURCE_DIR}/panel/PanelTitlebarGrabAreaView.cpp
168+ ${CMAKE_SOURCE_DIR}/panel/WindowButtons.cpp
169 ${CMAKE_SOURCE_DIR}/shortcuts/ShortcutController.cpp
170 ${CMAKE_SOURCE_DIR}/shortcuts/ShortcutModel.cpp
171 #${CMAKE_SOURCE_DIR}/shortcuts/ShortcutHintPrivate.cpp
172
173=== added file 'tests/test_panel_menu_view.cpp'
174--- tests/test_panel_menu_view.cpp 1970-01-01 00:00:00 +0000
175+++ tests/test_panel_menu_view.cpp 2012-10-24 08:16:21 +0000
176@@ -0,0 +1,174 @@
177+/*
178+ * Copyright 2012 Canonical Ltd.
179+ *
180+ * This program is free software: you can redistribute it and/or modify it
181+ * under the terms of the GNU General Public License version 3, as published
182+ * by the Free Software Foundation.
183+ *
184+ * This program is distributed in the hope that it will be useful, but
185+ * WITHOUT ANY WARRANTY; without even the implied warranties of
186+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
187+ * PURPOSE. See the GNU General Public License for more details.
188+ *
189+ * You should have received a copy of the GNU General Public License
190+ * version 3 along with this program. If not, see
191+ * <http://www.gnu.org/licenses/>
192+ *
193+ */
194+
195+#include <gmock/gmock.h>
196+
197+#include <Nux/Nux.h>
198+#include "PanelMenuView.h"
199+#include "PanelStyle.h"
200+#include "UnitySettings.h"
201+#include "UBusMessages.h"
202+#include "test_utils.h"
203+
204+using namespace testing;
205+
206+namespace unity
207+{
208+
209+class MockPanelMenuView : public PanelMenuView
210+{
211+ protected:
212+ virtual std::string GetActiveViewName(bool use_appname) const
213+ {
214+ return "<>'";
215+ }
216+};
217+
218+class MockWindowManager : public WindowManager
219+{
220+public:
221+ MockWindowManager() : _scale_active(false), _scale_active_group(false) {}
222+ guint32 GetActiveWindow() const { return 0; }
223+ unsigned long long GetWindowActiveNumber (guint32 xid) const { return 0; }
224+ bool IsScreenGrabbed() const { return false; }
225+ bool IsViewPortSwitchStarted() const { return false; }
226+ void ShowDesktop() { }
227+ bool InShowDesktop() const { return false; }
228+ bool IsWindowMaximized(guint32 xid) const { return false; }
229+ bool IsWindowDecorated(guint32 xid) { return true; }
230+ bool IsWindowOnCurrentDesktop(guint32 xid) const { return true; }
231+ bool IsWindowObscured(guint32 xid) const { return false; }
232+ bool IsWindowMapped(guint32 xid) const { return true; }
233+ bool IsWindowVisible(guint32 xid) const { return true; }
234+ bool IsWindowOnTop(guint32 xid) const { return false; }
235+ bool IsWindowClosable(guint32 xid) const { return true; }
236+ bool IsWindowMinimizable(guint32 xid) const { return true; }
237+ bool IsWindowMaximizable(guint32 xid) const { return true; }
238+ void Restore(guint32 xid) { }
239+ void RestoreAt(guint32 xid, int x, int y) { }
240+ void Minimize(guint32 xid) { }
241+ void Close(guint32 xid) { }
242+ void Activate(guint32 xid) { }
243+ void Raise(guint32 xid) { }
244+ void Lower(guint32 xid) { }
245+ void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor, bool only_top_win) { }
246+ bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force) { return false; }
247+ int GetWindowMonitor(guint32 xid) const { return -1; }
248+ void SetWindowIconGeometry(Window window, nux::Geometry const& geo) { }
249+ int WorkspaceCount () const { return 1; }
250+ void TerminateScale() { }
251+ void SetScaleActive(bool scale_active) { _scale_active = scale_active; }
252+ bool IsScaleActive() const { return _scale_active; }
253+ void SetScaleActiveForGroup(bool scale_active_group) { _scale_active_group = scale_active_group; }
254+ bool IsScaleActiveForGroup() const { return _scale_active_group; }
255+ void InitiateExpo() { }
256+ void TerminateExpo() { }
257+ bool IsExpoActive() const { return false; }
258+ bool IsWallActive() const { return false; }
259+ void MoveResizeWindow(guint32 xid, nux::Geometry geometry) { }
260+ bool saveInputFocus() { return false; }
261+ bool restoreInputFocus() { return false; }
262+ void AddProperties(GVariantBuilder* builder) {}
263+ std::string GetWindowName(guint32 xid) const { return ""; }
264+
265+ nux::Geometry GetWindowGeometry(guint xid) const
266+ {
267+ int width = (guint32)xid >> 16;
268+ int height = (guint32)xid & 0x0000FFFF;
269+ return nux::Geometry(0, 0, width, height);
270+ }
271+
272+ nux::Geometry GetWindowSavedGeometry(guint xid) const
273+ {
274+ return nux::Geometry(0, 0, 1, 1);
275+ }
276+
277+ nux::Geometry GetScreenGeometry() const
278+ {
279+ return nux::Geometry(0, 0, 1, 1);
280+ }
281+
282+ nux::Geometry GetWorkAreaGeometry(guint32 xid) const
283+ {
284+ return nux::Geometry(0, 0, 1, 1);
285+ }
286+
287+ void CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any)
288+ {
289+ active = false;
290+ any = false;
291+ }
292+
293+ bool _scale_active;
294+ bool _scale_active_group;
295+};
296+
297+struct TestPanelMenuView : public testing::Test
298+{
299+ virtual void SetUp()
300+ {
301+ }
302+
303+ void ProcessUBusMessages()
304+ {
305+ bool expired = false;
306+ glib::Idle idle([&] { expired = true; return false; },
307+ glib::Source::Priority::LOW);
308+ Utils::WaitUntil(expired);
309+ }
310+
311+ std::string panelTitle() const
312+ {
313+ const PanelMenuView *panel = &panelMenuView;
314+ return panel->GetCurrentTitle();
315+ }
316+
317+protected:
318+ // The order is important, i.e. PanelMenuView needs
319+ // panel::Style that needs Settings
320+ MockWindowManager windowManager;
321+ Settings settings;
322+ panel::Style panelStyle;
323+ MockPanelMenuView panelMenuView;
324+};
325+
326+TEST_F(TestPanelMenuView, Escaping)
327+{
328+ WindowManager::SetDefault(&windowManager);
329+ static const char *escapedText = "Panel d&amp;Inici";
330+ EXPECT_TRUE(panelTitle().empty());
331+
332+ UBusManager ubus;
333+ ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV, NULL);
334+ ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED,
335+ g_variant_new_string(escapedText));
336+ ProcessUBusMessages();
337+
338+ EXPECT_EQ(panelTitle(), escapedText);
339+
340+ ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV, NULL);
341+ ProcessUBusMessages();
342+
343+ // Change the wm to trick PanelMenuView::RefreshTitle to call GetActiveViewName
344+ windowManager.SetScaleActive(true);
345+ windowManager.SetScaleActiveForGroup(true);
346+
347+ EXPECT_EQ(panelTitle(), "&lt;&gt;&apos;");
348+}
349+
350+}

Subscribers

People subscribed via source and target branches