Merge lp:~stolowski/unity-2d/fix-912777 into lp:unity-2d

Proposed by Paweł Stołowski on 2012-03-06
Status: Merged
Approved by: Gerry Boland on 2012-03-13
Approved revision: 957
Merged at revision: 986
Proposed branch: lp:~stolowski/unity-2d/fix-912777
Merge into: lp:unity-2d
Diff against target: 294 lines (+257/-1)
5 files modified
libunity-2d-private/src/application.cpp (+7/-0)
tests/README (+3/-1)
tests/launcher/launcher_item_progress.rb (+144/-0)
tests/misc/fake_progress.py (+61/-0)
tests/misc/lib/launchercli.rb (+42/-0)
To merge this branch: bzr merge lp:~stolowski/unity-2d/fix-912777
Reviewer Review Type Date Requested Status
Gerry Boland 2012-03-06 Approve on 2012-03-13
Michał Sawicz 2012-03-06 Needs Fixing on 2012-03-06
Review via email: mp+96103@code.launchpad.net

Commit message

[launcher] Prevent progress bar from "overflowing".
Application::updateOverlaysStateEnforce - enforce launcher item progress values reported by applications to be within 0.0 - 1.0 range.

Description of the change

[launcher] Fixes https://bugs.launchpad.net/bugs/912777 + adds testability test cases.

To post a comment you must log in.
Michał Sawicz (saviq) wrote :

Hey, in the case of this tests there's no need to kill / launch panel as it's unrelated.

review: Needs Fixing
lp:~stolowski/unity-2d/fix-912777 updated on 2012-03-06
956. By Paweł Stołowski on 2012-03-06

Launcher item progress testability tests - don't start/kill panels as
panel is unrelated. Removed 'sleep' from the last test case.

Paweł Stołowski (stolowski) wrote :

> Hey, in the case of this tests there's no need to kill / launch panel as it's
> unrelated.

Agreed. Fixed.

Gerry Boland (gerboland) wrote :

Can you please list what python modules are needed for this to run, which are not part of a default install? They'll need to be added to the list of test requirements.

That will require updating the README file at the least, with perhaps a check to only run the test if all dependencies are installed, else skip with a warning.

lp:~stolowski/unity-2d/fix-912777 updated on 2012-03-09
957. By Paweł Stołowski on 2012-03-09

Tests README file - added fake_progress.py to the list of dependencies.

Paweł Stołowski (stolowski) wrote :

> Can you please list what python modules are needed for this to run, which are
> not part of a default install? They'll need to be added to the list of test
> requirements.
>
> That will require updating the README file at the least, with perhaps a check
> to only run the test if all dependencies are installed, else skip with a
> warning.

Python modules needed by this test (python-gi, git1.2-unity-5.0) are in the default installation. Added them to the README - apt-get install ... step just in case.

Gerry Boland (gerboland) wrote :

Excellent, works perfect, test great too. Nice work

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/application.cpp'
2--- libunity-2d-private/src/application.cpp 2012-03-05 11:28:54 +0000
3+++ libunity-2d-private/src/application.cpp 2012-03-09 10:17:20 +0000
4@@ -1137,6 +1137,13 @@
5 Application::updateOverlaysState(const QString& sender, const QMap<QString, QVariant>& properties)
6 {
7 if (updateOverlayState(properties, "progress", &m_progress)) {
8+ if (m_progress < 0.0f) {
9+ m_progress = 0.0f;
10+ } else {
11+ if (m_progress > 1.0f) {
12+ m_progress = 1.0f;
13+ }
14+ }
15 Q_EMIT progressChanged(m_progress);
16 }
17 if (updateOverlayState(properties, "progress-visible", &m_progressBarVisible)) {
18
19=== modified file 'tests/README'
20--- tests/README 2012-01-24 11:47:05 +0000
21+++ tests/README 2012-03-09 10:17:20 +0000
22@@ -61,7 +61,9 @@
23
24 $ sudo apt-get install rubygems testability-qttas \
25 ruby-testability-driver-qt-sut-plugin testability-visualizer \
26- librmagick-ruby1.8 xdotool xsel x11-utils
27+ librmagick-ruby1.8 xdotool xsel x11-utils gir1.2-unity-5.0 python-gi
28+
29+Note: gir1.2-unity-5.0 and python-gi are required by fake_progress.py.
30
31 You need to configure Testability for your usage. Assuming you’ll be testing on
32 your host machine, this involves editing /etc/tdriver/tdriver_parameters.xml to
33
34=== added file 'tests/launcher/launcher_item_progress.rb'
35--- tests/launcher/launcher_item_progress.rb 1970-01-01 00:00:00 +0000
36+++ tests/launcher/launcher_item_progress.rb 2012-03-09 10:17:20 +0000
37@@ -0,0 +1,144 @@
38+#!/usr/bin/env ruby1.8
39+=begin
40+/*
41+ * This file is part of unity-2d
42+ *
43+ * Copyright 2012 Canonical Ltd.
44+ *
45+ * Authors:
46+ * - Pawel Stolowski <pawel.stolowski@canonical.com>
47+ *
48+ * This program is free software; you can redistribute it and/or modify
49+ * it under the terms of the GNU General Public License as published by
50+ * the Free Software Foundation; version 3.
51+ *
52+ * This program is distributed in the hope that it will be useful,
53+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
54+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55+ * GNU General Public License for more details.
56+ *
57+ * You should have received a copy of the GNU General Public License
58+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
59+ */
60+=end
61+
62+require '../run-tests.rb' unless $INIT_COMPLETED
63+require 'xdo/xwindow'
64+require 'tmpwindow'
65+require 'launchercli'
66+
67+############################# Test Suite #############################
68+context "Sizing tests" do
69+ # Run once at the beginning of this test suite
70+ startup do
71+ $SUT.execute_shell_command 'killall unity-2d-shell'
72+ $SUT.execute_shell_command 'killall unity-2d-shell'
73+
74+ # Minimize all windows
75+ XDo::XWindow.toggle_minimize_all
76+ end
77+
78+ # Run once at the end of this test suite
79+ shutdown do
80+ end
81+
82+ # Run before each test case begins
83+ setup do
84+ # Execute the application
85+ @app = $SUT.run( :name => UNITY_2D_SHELL,
86+ :arguments => "-testability",
87+ :sleeptime => 2 )
88+
89+ # Make certain application is ready for testing
90+ verify{ @app.Launcher() }
91+ end
92+
93+ # Run after each test case completes
94+ teardown do
95+ #Need to kill Launcher as it does not shutdown when politely asked
96+ $SUT.execute_shell_command 'pkill -nf unity-2d-shell'
97+ end
98+
99+ #####################################################################################
100+ # Test cases
101+
102+ # Test case objectives:
103+ # * Check that progress bar in Launcher item is correctly updated for progress values 0-100%.
104+ # Pre-conditions
105+ # * 'Home Folder' item (nautilus) is present in the launcher.
106+ # Test steps
107+ # * Report progress = 0% from nautilus, verify progress bar width is 0.
108+ # * Report progress = 50% from nautilus, verify progress bar width is 1/2 of normal width
109+ # * Report progress = 100% from nautilus, verify progress bar width is at full.
110+ # * Hide progress bar of nautilus.
111+ # Post-conditions
112+ # * None
113+ # References
114+ # * None
115+ test "Valid progress bar values" do
116+ lcli = LauncherItemClient.new('nautilus-home.desktop')
117+ lcli.set_progress(0.0)
118+
119+ progressTopImg = @app.Launcher().QDeclarativeFocusScope().LauncherList(:name=>"main").QDeclarativeItem(:name=>"Home Folder").QDeclarativeImage(:name=>"progressBar")
120+ progressImg = progressTopImg.QDeclarativeImage()
121+
122+ verify_equal( '', TIMEOUT, "Progress bar is visible" ) {
123+ progressTopImg['state']
124+ }
125+
126+ verify_equal( 0, TIMEOUT, "Progress bar at 0%" ) {
127+ progressImg['width'].to_i
128+ }
129+
130+ lcli.set_progress(0.5)
131+ verify_equal( progressImg['implicitWidth'].to_i / 2, TIMEOUT, "Progress bar at 50%" ) {
132+ progressImg['width'].to_i
133+ }
134+
135+ lcli.set_progress(1.0)
136+ verify_equal( progressImg['implicitWidth'].to_i, TIMEOUT, "Progress bar at 100%" ) {
137+ progressImg['width'].to_i
138+ }
139+
140+ lcli.hide_progress()
141+ verify_equal( 'hidden', TIMEOUT, "Progress bar is not visible" ) {
142+ progressTopImg['state']
143+ }
144+ end
145+
146+ # Test case objectives:
147+ # * Check that progress bar in Launcher item is correctly updated for invalid values (outside of 0-100% range).
148+ # Pre-conditions
149+ # * 'Home Folder' item (nautilus) is present in the launcher.
150+ # Test steps
151+ # * Report progress = -1 from nautilus, verify progress bar width is 0.
152+ # * Report progress = 200% from nautilus, verify progress bar width is at full.
153+ # * Hide progress bar of nautilus.
154+ # Post-conditions
155+ # * None
156+ # References
157+ # * None
158+
159+ test "Invalid progress bar values" do
160+ lcli = LauncherItemClient.new('nautilus-home.desktop')
161+ lcli.set_progress(-1.0)
162+
163+ progressTopImg = @app.Launcher().QDeclarativeFocusScope().LauncherList(:name=>"main").QDeclarativeItem(:name=>"Home Folder").QDeclarativeImage(:name=>"progressBar")
164+ progressImg = progressTopImg.QDeclarativeImage()
165+
166+ verify_equal( 0, TIMEOUT, "Attempt to set negative progress value; progress set to 0%" ) {
167+ progressImg['width'].to_i
168+ }
169+
170+ lcli.set_progress(2.0)
171+ verify_equal( progressImg['implicitWidth'].to_i, TIMEOUT, "Attempt to set big progress value; progress set to 100%" ) {
172+ progressImg['width'].to_i
173+ }
174+
175+ lcli.hide_progress()
176+ verify_equal( 'hidden', TIMEOUT, "Progress bar is not visible" ) {
177+ progressTopImg['state']
178+ }
179+ end
180+
181+end
182
183=== added file 'tests/misc/fake_progress.py'
184--- tests/misc/fake_progress.py 1970-01-01 00:00:00 +0000
185+++ tests/misc/fake_progress.py 2012-03-09 10:17:20 +0000
186@@ -0,0 +1,61 @@
187+#!/usr/bin/python
188+
189+#
190+# Simple script to fake progress updates on Unity Launcher items.
191+# Run without arguments for usage.
192+#
193+# Author: Pawel Stolowski <pawel.stolowski@canonical.com>
194+#
195+
196+from gi.repository import Unity, GObject
197+import sys
198+
199+usage = """Usage:
200+fake_progress.py [-t|-f] <app> [value]
201+
202+ -t Show progress_visible = true property
203+ -f Send progress_visible = false property
204+ app Name of application .desktop file on the Launcher (e.g. "nautilus-home.desktop")
205+ value Progress bar value (normally 0.0 - 1.0, but invalid values may be used for testing)
206+"""
207+
208+loop = GObject.MainLoop()
209+
210+def force_quit():
211+ loop.quit()
212+
213+send_show = False
214+send_hide = False
215+
216+i = 1
217+if len(sys.argv) > i:
218+ if sys.argv[i] == '-f':
219+ send_hide = True
220+ i = i+1
221+ if sys.argv[i] == '-t':
222+ send_show = True
223+ i = i+1
224+
225+ctx = GObject.MainContext()
226+if len(sys.argv) > i:
227+ appname = sys.argv[i]
228+ i = i+1
229+ launcher = Unity.LauncherEntry.get_for_desktop_id(appname)
230+
231+ if len(sys.argv) > i:
232+ progress = float(sys.argv[i])
233+ print 'send: progress = ' + sys.argv[i]
234+ launcher.set_property("progress", progress)
235+
236+ if send_show:
237+ print 'send: progress_visible = true'
238+ launcher.set_property("progress_visible", True)
239+
240+ if send_hide:
241+ print 'send: progress_visible = false'
242+ launcher.set_property("progress_visible", False)
243+else:
244+ sys.exit(usage)
245+
246+GObject.timeout_add(100, force_quit)
247+loop.run()
248
249=== added file 'tests/misc/lib/launchercli.rb'
250--- tests/misc/lib/launchercli.rb 1970-01-01 00:00:00 +0000
251+++ tests/misc/lib/launchercli.rb 2012-03-09 10:17:20 +0000
252@@ -0,0 +1,42 @@
253+#!/usr/bin/env ruby1.8
254+=begin
255+/*
256+ * This file is part of unity-2d
257+ *
258+ * Copyright 2012 Canonical Ltd.
259+ *
260+ * Authors:
261+ * - Pawel Stolowski <pawel.stolowski@canonical.com>
262+ *
263+ * This program is free software; you can redistribute it and/or modify
264+ * it under the terms of the GNU General Public License as published by
265+ * the Free Software Foundation; version 3.
266+ *
267+ * This program is distributed in the hope that it will be useful,
268+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
269+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
270+ * GNU General Public License for more details.
271+ *
272+ * You should have received a copy of the GNU General Public License
273+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
274+ */
275+=end
276+
277+# Helper class to interact with Launcher items.
278+class LauncherItemClient
279+
280+ # fake_progress.py location relative to the directory of current script
281+ @@FAKE_PROGRESS_SCRIPT = File.dirname(__FILE__) + '/../fake_progress.py'
282+
283+ def initialize(desktop_file)
284+ @desktop_file = desktop_file
285+ end
286+
287+ def set_progress(value)
288+ `#{@@FAKE_PROGRESS_SCRIPT} -t #{@desktop_file} #{value}`
289+ end
290+
291+ def hide_progress()
292+ `#{@@FAKE_PROGRESS_SCRIPT} -f #{@desktop_file}`
293+ end
294+end

Subscribers

People subscribed via source and target branches