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

Proposed by Paweł Stołowski
Status: Merged
Approved by: Gerry Boland
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 (community) Approve
Michał Sawicz Needs Fixing
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.
Revision history for this message
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
956. By Paweł Stołowski

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

Revision history for this message
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.

Revision history for this message
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
957. By Paweł Stołowski

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

Revision history for this message
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.

Revision history for this message
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
=== modified file 'libunity-2d-private/src/application.cpp'
--- libunity-2d-private/src/application.cpp 2012-03-05 11:28:54 +0000
+++ libunity-2d-private/src/application.cpp 2012-03-09 10:17:20 +0000
@@ -1137,6 +1137,13 @@
1137Application::updateOverlaysState(const QString& sender, const QMap<QString, QVariant>& properties)1137Application::updateOverlaysState(const QString& sender, const QMap<QString, QVariant>& properties)
1138{1138{
1139 if (updateOverlayState(properties, "progress", &m_progress)) {1139 if (updateOverlayState(properties, "progress", &m_progress)) {
1140 if (m_progress < 0.0f) {
1141 m_progress = 0.0f;
1142 } else {
1143 if (m_progress > 1.0f) {
1144 m_progress = 1.0f;
1145 }
1146 }
1140 Q_EMIT progressChanged(m_progress);1147 Q_EMIT progressChanged(m_progress);
1141 }1148 }
1142 if (updateOverlayState(properties, "progress-visible", &m_progressBarVisible)) {1149 if (updateOverlayState(properties, "progress-visible", &m_progressBarVisible)) {
11431150
=== modified file 'tests/README'
--- tests/README 2012-01-24 11:47:05 +0000
+++ tests/README 2012-03-09 10:17:20 +0000
@@ -61,7 +61,9 @@
6161
62$ sudo apt-get install rubygems testability-qttas \62$ sudo apt-get install rubygems testability-qttas \
63 ruby-testability-driver-qt-sut-plugin testability-visualizer \63 ruby-testability-driver-qt-sut-plugin testability-visualizer \
64 librmagick-ruby1.8 xdotool xsel x11-utils64 librmagick-ruby1.8 xdotool xsel x11-utils gir1.2-unity-5.0 python-gi
65
66Note: gir1.2-unity-5.0 and python-gi are required by fake_progress.py.
6567
66You need to configure Testability for your usage. Assuming you’ll be testing on 68You need to configure Testability for your usage. Assuming you’ll be testing on
67your host machine, this involves editing /etc/tdriver/tdriver_parameters.xml to 69your host machine, this involves editing /etc/tdriver/tdriver_parameters.xml to
6870
=== added file 'tests/launcher/launcher_item_progress.rb'
--- tests/launcher/launcher_item_progress.rb 1970-01-01 00:00:00 +0000
+++ tests/launcher/launcher_item_progress.rb 2012-03-09 10:17:20 +0000
@@ -0,0 +1,144 @@
1#!/usr/bin/env ruby1.8
2=begin
3/*
4 * This file is part of unity-2d
5 *
6 * Copyright 2012 Canonical Ltd.
7 *
8 * Authors:
9 * - Pawel Stolowski <pawel.stolowski@canonical.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23=end
24
25require '../run-tests.rb' unless $INIT_COMPLETED
26require 'xdo/xwindow'
27require 'tmpwindow'
28require 'launchercli'
29
30############################# Test Suite #############################
31context "Sizing tests" do
32 # Run once at the beginning of this test suite
33 startup do
34 $SUT.execute_shell_command 'killall unity-2d-shell'
35 $SUT.execute_shell_command 'killall unity-2d-shell'
36
37 # Minimize all windows
38 XDo::XWindow.toggle_minimize_all
39 end
40
41 # Run once at the end of this test suite
42 shutdown do
43 end
44
45 # Run before each test case begins
46 setup do
47 # Execute the application
48 @app = $SUT.run( :name => UNITY_2D_SHELL,
49 :arguments => "-testability",
50 :sleeptime => 2 )
51
52 # Make certain application is ready for testing
53 verify{ @app.Launcher() }
54 end
55
56 # Run after each test case completes
57 teardown do
58 #Need to kill Launcher as it does not shutdown when politely asked
59 $SUT.execute_shell_command 'pkill -nf unity-2d-shell'
60 end
61
62 #####################################################################################
63 # Test cases
64
65 # Test case objectives:
66 # * Check that progress bar in Launcher item is correctly updated for progress values 0-100%.
67 # Pre-conditions
68 # * 'Home Folder' item (nautilus) is present in the launcher.
69 # Test steps
70 # * Report progress = 0% from nautilus, verify progress bar width is 0.
71 # * Report progress = 50% from nautilus, verify progress bar width is 1/2 of normal width
72 # * Report progress = 100% from nautilus, verify progress bar width is at full.
73 # * Hide progress bar of nautilus.
74 # Post-conditions
75 # * None
76 # References
77 # * None
78 test "Valid progress bar values" do
79 lcli = LauncherItemClient.new('nautilus-home.desktop')
80 lcli.set_progress(0.0)
81
82 progressTopImg = @app.Launcher().QDeclarativeFocusScope().LauncherList(:name=>"main").QDeclarativeItem(:name=>"Home Folder").QDeclarativeImage(:name=>"progressBar")
83 progressImg = progressTopImg.QDeclarativeImage()
84
85 verify_equal( '', TIMEOUT, "Progress bar is visible" ) {
86 progressTopImg['state']
87 }
88
89 verify_equal( 0, TIMEOUT, "Progress bar at 0%" ) {
90 progressImg['width'].to_i
91 }
92
93 lcli.set_progress(0.5)
94 verify_equal( progressImg['implicitWidth'].to_i / 2, TIMEOUT, "Progress bar at 50%" ) {
95 progressImg['width'].to_i
96 }
97
98 lcli.set_progress(1.0)
99 verify_equal( progressImg['implicitWidth'].to_i, TIMEOUT, "Progress bar at 100%" ) {
100 progressImg['width'].to_i
101 }
102
103 lcli.hide_progress()
104 verify_equal( 'hidden', TIMEOUT, "Progress bar is not visible" ) {
105 progressTopImg['state']
106 }
107 end
108
109 # Test case objectives:
110 # * Check that progress bar in Launcher item is correctly updated for invalid values (outside of 0-100% range).
111 # Pre-conditions
112 # * 'Home Folder' item (nautilus) is present in the launcher.
113 # Test steps
114 # * Report progress = -1 from nautilus, verify progress bar width is 0.
115 # * Report progress = 200% from nautilus, verify progress bar width is at full.
116 # * Hide progress bar of nautilus.
117 # Post-conditions
118 # * None
119 # References
120 # * None
121
122 test "Invalid progress bar values" do
123 lcli = LauncherItemClient.new('nautilus-home.desktop')
124 lcli.set_progress(-1.0)
125
126 progressTopImg = @app.Launcher().QDeclarativeFocusScope().LauncherList(:name=>"main").QDeclarativeItem(:name=>"Home Folder").QDeclarativeImage(:name=>"progressBar")
127 progressImg = progressTopImg.QDeclarativeImage()
128
129 verify_equal( 0, TIMEOUT, "Attempt to set negative progress value; progress set to 0%" ) {
130 progressImg['width'].to_i
131 }
132
133 lcli.set_progress(2.0)
134 verify_equal( progressImg['implicitWidth'].to_i, TIMEOUT, "Attempt to set big progress value; progress set to 100%" ) {
135 progressImg['width'].to_i
136 }
137
138 lcli.hide_progress()
139 verify_equal( 'hidden', TIMEOUT, "Progress bar is not visible" ) {
140 progressTopImg['state']
141 }
142 end
143
144end
0145
=== added file 'tests/misc/fake_progress.py'
--- tests/misc/fake_progress.py 1970-01-01 00:00:00 +0000
+++ tests/misc/fake_progress.py 2012-03-09 10:17:20 +0000
@@ -0,0 +1,61 @@
1#!/usr/bin/python
2
3#
4# Simple script to fake progress updates on Unity Launcher items.
5# Run without arguments for usage.
6#
7# Author: Pawel Stolowski <pawel.stolowski@canonical.com>
8#
9
10from gi.repository import Unity, GObject
11import sys
12
13usage = """Usage:
14fake_progress.py [-t|-f] <app> [value]
15
16 -t Show progress_visible = true property
17 -f Send progress_visible = false property
18 app Name of application .desktop file on the Launcher (e.g. "nautilus-home.desktop")
19 value Progress bar value (normally 0.0 - 1.0, but invalid values may be used for testing)
20"""
21
22loop = GObject.MainLoop()
23
24def force_quit():
25 loop.quit()
26
27send_show = False
28send_hide = False
29
30i = 1
31if len(sys.argv) > i:
32 if sys.argv[i] == '-f':
33 send_hide = True
34 i = i+1
35 if sys.argv[i] == '-t':
36 send_show = True
37 i = i+1
38
39ctx = GObject.MainContext()
40if len(sys.argv) > i:
41 appname = sys.argv[i]
42 i = i+1
43 launcher = Unity.LauncherEntry.get_for_desktop_id(appname)
44
45 if len(sys.argv) > i:
46 progress = float(sys.argv[i])
47 print 'send: progress = ' + sys.argv[i]
48 launcher.set_property("progress", progress)
49
50 if send_show:
51 print 'send: progress_visible = true'
52 launcher.set_property("progress_visible", True)
53
54 if send_hide:
55 print 'send: progress_visible = false'
56 launcher.set_property("progress_visible", False)
57else:
58 sys.exit(usage)
59
60GObject.timeout_add(100, force_quit)
61loop.run()
062
=== added file 'tests/misc/lib/launchercli.rb'
--- tests/misc/lib/launchercli.rb 1970-01-01 00:00:00 +0000
+++ tests/misc/lib/launchercli.rb 2012-03-09 10:17:20 +0000
@@ -0,0 +1,42 @@
1#!/usr/bin/env ruby1.8
2=begin
3/*
4 * This file is part of unity-2d
5 *
6 * Copyright 2012 Canonical Ltd.
7 *
8 * Authors:
9 * - Pawel Stolowski <pawel.stolowski@canonical.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23=end
24
25# Helper class to interact with Launcher items.
26class LauncherItemClient
27
28 # fake_progress.py location relative to the directory of current script
29 @@FAKE_PROGRESS_SCRIPT = File.dirname(__FILE__) + '/../fake_progress.py'
30
31 def initialize(desktop_file)
32 @desktop_file = desktop_file
33 end
34
35 def set_progress(value)
36 `#{@@FAKE_PROGRESS_SCRIPT} -t #{@desktop_file} #{value}`
37 end
38
39 def hide_progress()
40 `#{@@FAKE_PROGRESS_SCRIPT} -f #{@desktop_file}`
41 end
42end

Subscribers

People subscribed via source and target branches