Merge lp:~elopio/ubuntu-ui-toolkit/slider-autopilot_helper into lp:ubuntu-ui-toolkit/staging
- slider-autopilot_helper
- Merge into staging
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~elopio/ubuntu-ui-toolkit/slider-autopilot_helper | ||||
Merge into: | lp:ubuntu-ui-toolkit/staging | ||||
Diff against target: |
643 lines (+236/-170) 13 files modified
modules/Ubuntu/Components/Themes/Ambiance/SliderStyle.qml (+4/-1) tests/autopilot/ubuntuuitoolkit/__init__.py (+2/-0) tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py (+2/-0) tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_slider.py (+63/-0) tests/autopilot/ubuntuuitoolkit/tests/__init__.py (+1/-112) tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.SliderTestCase.qml (+32/-0) tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.py (+95/-0) tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py (+21/-7) tests/autopilot/ubuntuuitoolkit/tests/gallery/test_buttons.py (+1/-3) tests/autopilot/ubuntuuitoolkit/tests/gallery/test_gallery.py (+10/-30) tests/autopilot/ubuntuuitoolkit/tests/gallery/test_optionselector.py (+1/-3) tests/autopilot/ubuntuuitoolkit/tests/gallery/test_textinput.py (+2/-6) tests/autopilot/ubuntuuitoolkit/tests/gallery/test_toggles.py (+2/-8) |
||||
To merge this branch: | bzr merge lp:~elopio/ubuntu-ui-toolkit/slider-autopilot_helper | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu SDK team | Pending | ||
Review via email:
|
This proposal has been superseded by a proposal from 2014-06-06.
Commit message
Description of the change
- 1096. By Leo Arias
-
Remove the unused method.
- 1097. By Leo Arias
-
Fixed pep8.
- 1098. By Leo Arias
-
Added the last part of tests and checks to the slider helper.
- 1099. By Leo Arias
-
Added the docstring and logging.
- 1100. By Leo Arias
-
Removed the TODOs.
- 1101. By Leo Arias
-
Added a test for a negative float.
- 1102. By Leo Arias
-
Merged with staging.
- 1103. By Leo Arias
-
Changed the way we check for values not selectable, first try to select them.
- 1104. By Leo Arias
-
Merged with staging.
- 1105. By Leo Arias
-
Merged with staging.
- 1106. By Leo Arias
-
Use the device simulation scenarios to reproduce slider problems.
Unmerged revisions
- 1106. By Leo Arias
-
Use the device simulation scenarios to reproduce slider problems.
- 1105. By Leo Arias
-
Merged with staging.
- 1104. By Leo Arias
-
Merged with staging.
- 1103. By Leo Arias
-
Changed the way we check for values not selectable, first try to select them.
- 1102. By Leo Arias
-
Merged with staging.
- 1101. By Leo Arias
-
Added a test for a negative float.
- 1100. By Leo Arias
-
Removed the TODOs.
- 1099. By Leo Arias
-
Added the docstring and logging.
- 1098. By Leo Arias
-
Added the last part of tests and checks to the slider helper.
- 1097. By Leo Arias
-
Fixed pep8.
Preview Diff
1 | === modified file 'modules/Ubuntu/Components/Themes/Ambiance/SliderStyle.qml' | |||
2 | --- modules/Ubuntu/Components/Themes/Ambiance/SliderStyle.qml 2014-04-23 08:50:20 +0000 | |||
3 | +++ modules/Ubuntu/Components/Themes/Ambiance/SliderStyle.qml 2014-06-06 11:20:51 +0000 | |||
4 | @@ -1,5 +1,5 @@ | |||
5 | 1 | /* | 1 | /* |
7 | 2 | * Copyright 2013 Canonical Ltd. | 2 | * Copyright 2013, 2014 Canonical Ltd. |
8 | 3 | * | 3 | * |
9 | 4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
10 | 5 | * it under the terms of the GNU Lesser General Public License as published by | 5 | * it under the terms of the GNU Lesser General Public License as published by |
11 | @@ -35,6 +35,8 @@ | |||
12 | 35 | 35 | ||
13 | 36 | UbuntuShape { | 36 | UbuntuShape { |
14 | 37 | id: background | 37 | id: background |
15 | 38 | objectName: 'sliderBar' | ||
16 | 39 | |||
17 | 38 | anchors { | 40 | anchors { |
18 | 39 | verticalCenter: parent.verticalCenter | 41 | verticalCenter: parent.verticalCenter |
19 | 40 | right: parent.right | 42 | right: parent.right |
20 | @@ -56,6 +58,7 @@ | |||
21 | 56 | 58 | ||
22 | 57 | UbuntuShape { | 59 | UbuntuShape { |
23 | 58 | id: thumb | 60 | id: thumb |
24 | 61 | objectName: 'sliderThumb' | ||
25 | 59 | 62 | ||
26 | 60 | anchors { | 63 | anchors { |
27 | 61 | verticalCenter: parent.verticalCenter | 64 | verticalCenter: parent.verticalCenter |
28 | 62 | 65 | ||
29 | === modified file 'tests/autopilot/ubuntuuitoolkit/__init__.py' | |||
30 | --- tests/autopilot/ubuntuuitoolkit/__init__.py 2014-05-09 04:12:25 +0000 | |||
31 | +++ tests/autopilot/ubuntuuitoolkit/__init__.py 2014-06-06 11:20:51 +0000 | |||
32 | @@ -34,6 +34,7 @@ | |||
33 | 34 | 'popups', | 34 | 'popups', |
34 | 35 | 'QQuickFlickable', | 35 | 'QQuickFlickable', |
35 | 36 | 'QQuickListView', | 36 | 'QQuickListView', |
36 | 37 | 'Slider', | ||
37 | 37 | 'TabBar', | 38 | 'TabBar', |
38 | 38 | 'Tabs', | 39 | 'Tabs', |
39 | 39 | 'tests', | 40 | 'tests', |
40 | @@ -64,6 +65,7 @@ | |||
41 | 64 | popups, | 65 | popups, |
42 | 65 | QQuickFlickable, | 66 | QQuickFlickable, |
43 | 66 | QQuickListView, | 67 | QQuickListView, |
44 | 68 | Slider, | ||
45 | 67 | TabBar, | 69 | TabBar, |
46 | 68 | Tabs, | 70 | Tabs, |
47 | 69 | TextField, | 71 | TextField, |
48 | 70 | 72 | ||
49 | === modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py' | |||
50 | --- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py 2014-05-09 04:12:25 +0000 | |||
51 | +++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/__init__.py 2014-06-06 11:20:51 +0000 | |||
52 | @@ -30,6 +30,7 @@ | |||
53 | 30 | 'popups', | 30 | 'popups', |
54 | 31 | 'QQuickFlickable', | 31 | 'QQuickFlickable', |
55 | 32 | 'QQuickListView', | 32 | 'QQuickListView', |
56 | 33 | 'Slider', | ||
57 | 33 | 'TabBar', | 34 | 'TabBar', |
58 | 34 | 'Tabs', | 35 | 'Tabs', |
59 | 35 | 'TextField', | 36 | 'TextField', |
60 | @@ -58,6 +59,7 @@ | |||
61 | 58 | from ubuntuuitoolkit._custom_proxy_objects._qquicklistview import ( | 59 | from ubuntuuitoolkit._custom_proxy_objects._qquicklistview import ( |
62 | 59 | QQuickListView | 60 | QQuickListView |
63 | 60 | ) | 61 | ) |
64 | 62 | from ubuntuuitoolkit._custom_proxy_objects._slider import Slider | ||
65 | 61 | from ubuntuuitoolkit._custom_proxy_objects._tabbar import TabBar | 63 | from ubuntuuitoolkit._custom_proxy_objects._tabbar import TabBar |
66 | 62 | from ubuntuuitoolkit._custom_proxy_objects._tabs import Tabs | 64 | from ubuntuuitoolkit._custom_proxy_objects._tabs import Tabs |
67 | 63 | from ubuntuuitoolkit._custom_proxy_objects._textfield import TextField | 65 | from ubuntuuitoolkit._custom_proxy_objects._textfield import TextField |
68 | 64 | 66 | ||
69 | === added file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_slider.py' | |||
70 | --- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_slider.py 1970-01-01 00:00:00 +0000 | |||
71 | +++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_slider.py 2014-06-06 11:20:51 +0000 | |||
72 | @@ -0,0 +1,63 @@ | |||
73 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
74 | 2 | # | ||
75 | 3 | # Copyright (C) 2012, 2013, 2014 Canonical Ltd. | ||
76 | 4 | # | ||
77 | 5 | # This program is free software; you can redistribute it and/or modify | ||
78 | 6 | # it under the terms of the GNU Lesser General Public License as published by | ||
79 | 7 | # the Free Software Foundation; version 3. | ||
80 | 8 | # | ||
81 | 9 | # This program is distributed in the hope that it will be useful, | ||
82 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
83 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
84 | 12 | # GNU Lesser General Public License for more details. | ||
85 | 13 | # | ||
86 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
87 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
88 | 16 | |||
89 | 17 | from ubuntuuitoolkit._custom_proxy_objects import _common | ||
90 | 18 | |||
91 | 19 | |||
92 | 20 | class Slider(_common.UbuntuUIToolkitCustomProxyObjectBase): | ||
93 | 21 | """Autopilot helper for the Slider.""" | ||
94 | 22 | |||
95 | 23 | def set_value(self, value): | ||
96 | 24 | if value < self.minimumValue: | ||
97 | 25 | raise _common.ToolkitException( | ||
98 | 26 | 'The value is lower than the minimum permitted by the slider.') | ||
99 | 27 | elif value > self.maximumValue: | ||
100 | 28 | raise _common.ToolkitException( | ||
101 | 29 | 'The value is higher than the maximum permitted by the ' | ||
102 | 30 | 'slider.') | ||
103 | 31 | else: | ||
104 | 32 | self._set_valid_value(value) | ||
105 | 33 | |||
106 | 34 | def _set_valid_value(self, value): | ||
107 | 35 | x, y = self._get_value_point_in_bar(value) | ||
108 | 36 | self.pointing_device.move(x, y) | ||
109 | 37 | self.pointing_device.click() | ||
110 | 38 | |||
111 | 39 | def _get_value_point_in_bar(self, value): | ||
112 | 40 | bar_start, bar_end = self._get_bar_start_and_end() | ||
113 | 41 | # We have two points: (min, bar_start) and (max, bar_end). | ||
114 | 42 | # With that we can use linear interpolation to get the x coordinate to | ||
115 | 43 | # click. | ||
116 | 44 | p_x_from_slider = ( | ||
117 | 45 | bar_start + | ||
118 | 46 | (bar_end - bar_start) * | ||
119 | 47 | (value - self.minimumValue) / | ||
120 | 48 | (self.maximumValue - self.minimumValue)) | ||
121 | 49 | p_x = p_x_from_slider + self.globalRect.x | ||
122 | 50 | # The point to click on the y coordinate is the center of the slider. | ||
123 | 51 | p_y = self.globalRect.y + self.globalRect.height // 2 | ||
124 | 52 | return p_x, p_y | ||
125 | 53 | |||
126 | 54 | def _get_bar_start_and_end(self): | ||
127 | 55 | # We subtract from the bar width the width of the thumb because the | ||
128 | 56 | # center of the thumb never reaches the start or the end of the bar, | ||
129 | 57 | # so we have to scale down the range of values that we can select. | ||
130 | 58 | thumb = self.select_single(objectName='sliderThumb') | ||
131 | 59 | half_thumb_width = thumb.globalRect.width / 2 | ||
132 | 60 | bar = self.select_single(objectName='sliderBar') | ||
133 | 61 | bar_start = half_thumb_width | ||
134 | 62 | bar_end = bar.globalRect.width - half_thumb_width | ||
135 | 63 | return bar_start, bar_end | ||
136 | 0 | 64 | ||
137 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/__init__.py' | |||
138 | --- tests/autopilot/ubuntuuitoolkit/tests/__init__.py 2014-05-29 16:17:56 +0000 | |||
139 | +++ tests/autopilot/ubuntuuitoolkit/tests/__init__.py 2014-06-06 11:20:51 +0000 | |||
140 | @@ -1,6 +1,6 @@ | |||
141 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
142 | 2 | # | 2 | # |
144 | 3 | # Copyright (C) 2012, 2013 Canonical Ltd. | 3 | # Copyright (C) 2012, 2013, 2014 Canonical Ltd. |
145 | 4 | # | 4 | # |
146 | 5 | # This program is free software; you can redistribute it and/or modify | 5 | # This program is free software; you can redistribute it and/or modify |
147 | 6 | # it under the terms of the GNU Lesser General Public License as published by | 6 | # it under the terms of the GNU Lesser General Public License as published by |
148 | @@ -142,91 +142,6 @@ | |||
149 | 142 | def main_view(self): | 142 | def main_view(self): |
150 | 143 | return self.app.select_single(emulators.MainView) | 143 | return self.app.select_single(emulators.MainView) |
151 | 144 | 144 | ||
152 | 145 | def checkListItem(self, itemText): | ||
153 | 146 | item = self.getListItem(itemText) | ||
154 | 147 | self.assertThat(item, Not(Is(None))) | ||
155 | 148 | |||
156 | 149 | def getListItem(self, itemText): | ||
157 | 150 | # XXX We shouldn't access the elements by text, because that's likely | ||
158 | 151 | # to change often and might be translated. We should always use the | ||
159 | 152 | # objectName instead. --elopio - 2013-06-26216 | ||
160 | 153 | return self.main_view.select_single("Standard", text=itemText) | ||
161 | 154 | |||
162 | 155 | def getWidgetLoaderAndListView(self): | ||
163 | 156 | contentLoader = self.main_view.select_single( | ||
164 | 157 | "QQuickLoader", objectName="contentLoader") | ||
165 | 158 | listView = self.main_view.select_single( | ||
166 | 159 | "QQuickListView", objectName="widgetList") | ||
167 | 160 | self.assertThat(listView, Not(Is(None))) | ||
168 | 161 | self.assertThat(listView.visible, Eventually(Equals(True))) | ||
169 | 162 | return (contentLoader, listView) | ||
170 | 163 | |||
171 | 164 | def loadItem(self, item): | ||
172 | 165 | self.selectItem(item) | ||
173 | 166 | contentLoader = self.main_view.select_single( | ||
174 | 167 | "QQuickLoader", objectName="contentLoader") | ||
175 | 168 | self.assertThat(contentLoader.progress, Eventually(Equals(1.0))) | ||
176 | 169 | loadedPage = self.getListItem(item) | ||
177 | 170 | self.assertThat(loadedPage, Not(Is(None))) | ||
178 | 171 | #loadedPage is not a page, it is the list item which goes in | ||
179 | 172 | #background when the item is selected, which changes the visible | ||
180 | 173 | #property of item in list itself to False. So followin check | ||
181 | 174 | #fails on Nexus 4. Commenting it for now. | ||
182 | 175 | #self.assertThat(loadedPage.visible, Eventually(Equals(True))) | ||
183 | 176 | |||
184 | 177 | def drag(self, itemText, itemTextTo): | ||
185 | 178 | item = self.getListItem(itemText) | ||
186 | 179 | itemTo = self.getListItem(itemTextTo) | ||
187 | 180 | |||
188 | 181 | self.pointing_device.move_to_object(item) | ||
189 | 182 | self.pointing_device.press() | ||
190 | 183 | self.pointing_device.move_to_object(itemTo) | ||
191 | 184 | self.pointing_device.release() | ||
192 | 185 | |||
193 | 186 | def reveal_item_by_flick(self, item, flickable, direction): | ||
194 | 187 | x1, y1, w1, h1 = item.globalRect | ||
195 | 188 | x2, y2, w2, h2 = flickable.globalRect | ||
196 | 189 | if direction is FlickDirection.UP: | ||
197 | 190 | while y1 + h1 > y2 + h2: | ||
198 | 191 | self.flick(flickable, direction) | ||
199 | 192 | x1, y1, w1, h1 = item.globalRect | ||
200 | 193 | elif direction is FlickDirection.DOWN: | ||
201 | 194 | while y1 < y2: | ||
202 | 195 | self.flick(flickable, direction) | ||
203 | 196 | x1, y1, w1, h1 = item.globalRect | ||
204 | 197 | |||
205 | 198 | def flick(self, flickable, direction, delta=40): | ||
206 | 199 | """This funcito flicks the page from middle to the given direction.""" | ||
207 | 200 | x, y, w, h = flickable.globalRect | ||
208 | 201 | if direction == FlickDirection.UP: | ||
209 | 202 | self.pointing_device.drag(x + w / 2, y + h / 2, x + w / 2, | ||
210 | 203 | y + h / 2 - delta) | ||
211 | 204 | flickable.flicking.wait_for(False) | ||
212 | 205 | elif direction == FlickDirection.DOWN: | ||
213 | 206 | self.pointing_device.drag(x + w / 2, y + h / 2, x + w / 2, | ||
214 | 207 | y + h / 2 + delta) | ||
215 | 208 | flickable.flicking.wait_for(False) | ||
216 | 209 | else: | ||
217 | 210 | raise ValueError("Invalid direction or not implementd yet") | ||
218 | 211 | |||
219 | 212 | def selectItem(self, itemText): | ||
220 | 213 | item = self.getListItem(itemText) | ||
221 | 214 | x1, y1, w1, h1 = item.globalRect | ||
222 | 215 | x2, y2, w2, h2 = self.main_view.globalRect | ||
223 | 216 | |||
224 | 217 | orientationHelper = self.getOrientationHelper() | ||
225 | 218 | rot = orientationHelper.rotation | ||
226 | 219 | scrollTo = h2 / 2 - (y1 - h2 - h1) | ||
227 | 220 | if rot == 0.0 and y1 > h2: | ||
228 | 221 | self.pointing_device.drag(w2 / 2, h2 / 2, w2 / 2, scrollTo) | ||
229 | 222 | |||
230 | 223 | self.assertThat(item.selected, Eventually(Equals(False))) | ||
231 | 224 | |||
232 | 225 | self.pointing_device.move_to_object(item) | ||
233 | 226 | self.pointing_device.click() | ||
234 | 227 | |||
235 | 228 | self.assertThat(item.selected, Eventually(Equals(True))) | ||
236 | 229 | |||
237 | 230 | def getOrientationHelper(self): | 145 | def getOrientationHelper(self): |
238 | 231 | orientationHelper = self.main_view.select_many( | 146 | orientationHelper = self.main_view.select_many( |
239 | 232 | "OrientationHelper")[0] | 147 | "OrientationHelper")[0] |
240 | @@ -249,29 +164,3 @@ | |||
241 | 249 | obj = self.getObject(objectName) | 164 | obj = self.getObject(objectName) |
242 | 250 | self.pointing_device.move_to_object(obj) | 165 | self.pointing_device.move_to_object(obj) |
243 | 251 | self.pointing_device.click() | 166 | self.pointing_device.click() |
244 | 252 | |||
245 | 253 | def mousePress(self, objectName): | ||
246 | 254 | obj = self.getObject(objectName) | ||
247 | 255 | self.pointing_device.move_to_object(obj) | ||
248 | 256 | self.pointing_device.press() | ||
249 | 257 | |||
250 | 258 | def mouseRelease(self): | ||
251 | 259 | self.pointing_device.release() | ||
252 | 260 | |||
253 | 261 | def type_string(self, string): | ||
254 | 262 | self.keyboard.type(string) | ||
255 | 263 | |||
256 | 264 | def type_key(self, key): | ||
257 | 265 | self.keyboard.key(key) | ||
258 | 266 | |||
259 | 267 | def tap_clearButton(self, objectName): | ||
260 | 268 | textField = self.getObject(objectName) | ||
261 | 269 | self.assertIsNotNone(textField) | ||
262 | 270 | self.pointing_device.click_object(textField) | ||
263 | 271 | self.assertThat(textField.focus, Eventually(Equals(True))) | ||
264 | 272 | self.assertThat(textField.hasClearButton, Eventually(Equals(True))) | ||
265 | 273 | btn = textField.select_single("AbstractButton") | ||
266 | 274 | self.assertIsNotNone(btn) | ||
267 | 275 | self.assertThat(btn.visible, Eventually(Equals(True))) | ||
268 | 276 | self.pointing_device.click_object(btn) | ||
269 | 277 | self.assertThat(btn.pressed, Eventually(Equals(False))) | ||
270 | 278 | 167 | ||
271 | === added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.SliderTestCase.qml' | |||
272 | --- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.SliderTestCase.qml 1970-01-01 00:00:00 +0000 | |||
273 | +++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.SliderTestCase.qml 2014-06-06 11:20:51 +0000 | |||
274 | @@ -0,0 +1,32 @@ | |||
275 | 1 | /* | ||
276 | 2 | * Copyright 2014 Canonical Ltd. | ||
277 | 3 | * | ||
278 | 4 | * This program is free software; you can redistribute it and/or modify | ||
279 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
280 | 6 | * the Free Software Foundation; version 3. | ||
281 | 7 | * | ||
282 | 8 | * This program is distributed in the hope that it will be useful, | ||
283 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
284 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
285 | 11 | * GNU Lesser General Public License for more details. | ||
286 | 12 | * | ||
287 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
288 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
289 | 15 | */ | ||
290 | 16 | |||
291 | 17 | import QtQuick 2.0 | ||
292 | 18 | import Ubuntu.Components 1.1 | ||
293 | 19 | |||
294 | 20 | MainView { | ||
295 | 21 | |||
296 | 22 | width: units.gu(48) | ||
297 | 23 | height: units.gu(60) | ||
298 | 24 | |||
299 | 25 | Slider { | ||
300 | 26 | objectName: 'testSlider' | ||
301 | 27 | |||
302 | 28 | minimumValue: -10 | ||
303 | 29 | maximumValue: 10 | ||
304 | 30 | value: 0.0 | ||
305 | 31 | } | ||
306 | 32 | } | ||
307 | 0 | 33 | ||
308 | === added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.py' | |||
309 | --- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.py 1970-01-01 00:00:00 +0000 | |||
310 | +++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_slider.py 2014-06-06 11:20:51 +0000 | |||
311 | @@ -0,0 +1,95 @@ | |||
312 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
313 | 2 | # | ||
314 | 3 | # Copyright (C) 2014 Canonical Ltd. | ||
315 | 4 | # | ||
316 | 5 | # This program is free software; you can redistribute it and/or modify | ||
317 | 6 | # it under the terms of the GNU Lesser General Public License as published by | ||
318 | 7 | # the Free Software Foundation; version 3. | ||
319 | 8 | # | ||
320 | 9 | # This program is distributed in the hope that it will be useful, | ||
321 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
322 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
323 | 12 | # GNU Lesser General Public License for more details. | ||
324 | 13 | # | ||
325 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
326 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
327 | 16 | |||
328 | 17 | import os | ||
329 | 18 | |||
330 | 19 | try: | ||
331 | 20 | from unittest import mock | ||
332 | 21 | except ImportError: | ||
333 | 22 | import mock | ||
334 | 23 | |||
335 | 24 | import ubuntuuitoolkit | ||
336 | 25 | |||
337 | 26 | |||
338 | 27 | class SliderTestCase(ubuntuuitoolkit.tests.QMLFileAppTestCase): | ||
339 | 28 | |||
340 | 29 | path = os.path.abspath(__file__) | ||
341 | 30 | dir_path = os.path.dirname(path) | ||
342 | 31 | test_qml_file_path = os.path.join( | ||
343 | 32 | dir_path, 'test_slider.SliderTestCase.qml') | ||
344 | 33 | |||
345 | 34 | def setUp(self): | ||
346 | 35 | super(SliderTestCase, self).setUp() | ||
347 | 36 | # The test slider has a minimum value = -10, maximum value = 10 and | ||
348 | 37 | # starts with value = 0. | ||
349 | 38 | self.slider = self.main_view.select_single( | ||
350 | 39 | ubuntuuitoolkit.Slider, objectName='testSlider') | ||
351 | 40 | |||
352 | 41 | def test_get_slider_must_return_custom_proxy_object(self): | ||
353 | 42 | """Test the type of the returned object after selecting the slider. | ||
354 | 43 | |||
355 | 44 | It must be the custom proxy object for the Slider. | ||
356 | 45 | |||
357 | 46 | """ | ||
358 | 47 | self.assertIsInstance(self.slider, ubuntuuitoolkit.Slider) | ||
359 | 48 | |||
360 | 49 | def test_set_value_below_minimum_must_raise_exception(self): | ||
361 | 50 | """Test to set a value that is below the slider minimum. | ||
362 | 51 | |||
363 | 52 | It must raise a ToolkitException. | ||
364 | 53 | |||
365 | 54 | """ | ||
366 | 55 | error = self.assertRaises( | ||
367 | 56 | ubuntuuitoolkit.ToolkitException, self.slider.set_value, -15) | ||
368 | 57 | self.assertEqual( | ||
369 | 58 | 'The value is lower than the minimum permitted by the slider.', | ||
370 | 59 | str(error)) | ||
371 | 60 | |||
372 | 61 | def test_set_value_above_maximum_must_raise_exception(self): | ||
373 | 62 | """Test to set a value that is above the slider maximum. | ||
374 | 63 | |||
375 | 64 | It must raise a ToolkitException. | ||
376 | 65 | |||
377 | 66 | """ | ||
378 | 67 | error = self.assertRaises( | ||
379 | 68 | ubuntuuitoolkit.ToolkitException, self.slider.set_value, 15) | ||
380 | 69 | self.assertEqual( | ||
381 | 70 | 'The value is higher than the maximum permitted by the slider.', | ||
382 | 71 | str(error)) | ||
383 | 72 | |||
384 | 73 | def test_set_current_value_must_do_nothing(self): | ||
385 | 74 | """Test setting the current value on the slider. | ||
386 | 75 | |||
387 | 76 | The value must be kept the same and the slider should not be touched. | ||
388 | 77 | |||
389 | 78 | """ | ||
390 | 79 | with mock.patch.object(self.slider, 'pointing_device') as mock_device: | ||
391 | 80 | self.slider.set_value(0) | ||
392 | 81 | |||
393 | 82 | self.assertFalse(mock_device.called) | ||
394 | 83 | self.assertEqual(self.slider.value, 0) | ||
395 | 84 | |||
396 | 85 | def test_set_valid_value_must_update_slider_value(self): | ||
397 | 86 | """Test that setting a valid value on the slider must update it.""" | ||
398 | 87 | self.slider.set_value(5) | ||
399 | 88 | self.assertEqual(self.slider.value, 5) | ||
400 | 89 | |||
401 | 90 | # TODO test set minimum. | ||
402 | 91 | # TODO test set maximum. | ||
403 | 92 | # TODO file a bug because the docs doesn't say if min and max are | ||
404 | 93 | # exclusive or inclusive. | ||
405 | 94 | # TODO test set a value that's not selectable with the mouse | ||
406 | 95 | # TODO send Julia the test double post. | ||
407 | 0 | 96 | ||
408 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py' | |||
409 | --- tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py 2013-10-24 11:01:03 +0000 | |||
410 | +++ tests/autopilot/ubuntuuitoolkit/tests/gallery/__init__.py 2014-06-06 11:20:51 +0000 | |||
411 | @@ -1,6 +1,6 @@ | |||
412 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
413 | 2 | # | 2 | # |
415 | 3 | # Copyright (C) 2012, 2013 Canonical Ltd. | 3 | # Copyright (C) 2012, 2013, 2014 Canonical Ltd. |
416 | 4 | # | 4 | # |
417 | 5 | # This program is free software; you can redistribute it and/or modify | 5 | # This program is free software; you can redistribute it and/or modify |
418 | 6 | # it under the terms of the GNU Lesser General Public License as published by | 6 | # it under the terms of the GNU Lesser General Public License as published by |
419 | @@ -19,10 +19,10 @@ | |||
420 | 19 | import os | 19 | import os |
421 | 20 | import shutil | 20 | import shutil |
422 | 21 | 21 | ||
427 | 22 | from ubuntuuitoolkit import tests | 22 | import ubuntuuitoolkit |
428 | 23 | 23 | ||
429 | 24 | 24 | ||
430 | 25 | class GalleryTestCase(tests.QMLFileAppTestCase): | 25 | class GalleryTestCase(ubuntuuitoolkit.tests.QMLFileAppTestCase): |
431 | 26 | """Base class for gallery test cases.""" | 26 | """Base class for gallery test cases.""" |
432 | 27 | 27 | ||
433 | 28 | local_desktop_file_path = None | 28 | local_desktop_file_path = None |
434 | @@ -39,7 +39,7 @@ | |||
435 | 39 | 39 | ||
436 | 40 | def _get_path_to_gallery_source(self): | 40 | def _get_path_to_gallery_source(self): |
437 | 41 | return os.path.join( | 41 | return os.path.join( |
439 | 42 | tests.get_path_to_source_root(), 'examples', | 42 | ubuntuuitoolkit.tests.get_path_to_source_root(), 'examples', |
440 | 43 | 'ubuntu-ui-toolkit-gallery') | 43 | 'ubuntu-ui-toolkit-gallery') |
441 | 44 | 44 | ||
442 | 45 | def _application_source_exists(self): | 45 | def _application_source_exists(self): |
443 | @@ -58,7 +58,8 @@ | |||
444 | 58 | self.test_source_path, | 58 | self.test_source_path, |
445 | 59 | 'ubuntu-ui-toolkit-gallery.desktop') | 59 | 'ubuntu-ui-toolkit-gallery.desktop') |
446 | 60 | if self._application_source_exists(): | 60 | if self._application_source_exists(): |
448 | 61 | local_desktop_file_dir = tests.get_local_desktop_file_directory() | 61 | local_desktop_file_dir = ( |
449 | 62 | ubuntuuitoolkit.tests.get_local_desktop_file_directory()) | ||
450 | 62 | if not os.path.exists(local_desktop_file_dir): | 63 | if not os.path.exists(local_desktop_file_dir): |
451 | 63 | os.makedirs(local_desktop_file_dir) | 64 | os.makedirs(local_desktop_file_dir) |
452 | 64 | local_desktop_file_path = os.path.join( | 65 | local_desktop_file_path = os.path.join( |
453 | @@ -71,6 +72,19 @@ | |||
454 | 71 | else: | 72 | else: |
455 | 72 | return desktop_file_path | 73 | return desktop_file_path |
456 | 73 | 74 | ||
457 | 75 | def open_page(self, page): | ||
458 | 76 | """Open a page of the widget gallery. | ||
459 | 77 | |||
460 | 78 | :param page: The objectName of the element in the index list that opens | ||
461 | 79 | the page. | ||
462 | 80 | |||
463 | 81 | """ | ||
464 | 82 | list_view = self.main_view.select_single( | ||
465 | 83 | ubuntuuitoolkit.QQuickListView, objectName="widgetList") | ||
466 | 84 | list_view.click_element(page) | ||
467 | 85 | element = self.main_view.select_single('Standard', objectName=page) | ||
468 | 86 | element.selected.wait_for(True) | ||
469 | 87 | |||
470 | 74 | def tearDown(self): | 88 | def tearDown(self): |
471 | 75 | super(GalleryTestCase, self).tearDown() | 89 | super(GalleryTestCase, self).tearDown() |
472 | 76 | # We can't delete the desktop file before we close the application, | 90 | # We can't delete the desktop file before we close the application, |
473 | 77 | 91 | ||
474 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/test_buttons.py' | |||
475 | --- tests/autopilot/ubuntuuitoolkit/tests/gallery/test_buttons.py 2014-02-11 01:55:49 +0000 | |||
476 | +++ tests/autopilot/ubuntuuitoolkit/tests/gallery/test_buttons.py 2014-06-06 11:20:51 +0000 | |||
477 | @@ -45,9 +45,7 @@ | |||
478 | 45 | ] | 45 | ] |
479 | 46 | 46 | ||
480 | 47 | def test_buttons(self): | 47 | def test_buttons(self): |
484 | 48 | item = "Buttons" | 48 | self.open_page('buttonsElement') |
482 | 49 | self.loadItem(item) | ||
483 | 50 | self.checkPageHeader(item) | ||
485 | 51 | 49 | ||
486 | 52 | button = self.app.select_single(objectName=self.button_name) | 50 | button = self.app.select_single(objectName=self.button_name) |
487 | 53 | self.assertIsNot(button, None) | 51 | self.assertIsNot(button, None) |
488 | 54 | 52 | ||
489 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/test_gallery.py' | |||
490 | --- tests/autopilot/ubuntuuitoolkit/tests/gallery/test_gallery.py 2014-05-26 12:37:32 +0000 | |||
491 | +++ tests/autopilot/ubuntuuitoolkit/tests/gallery/test_gallery.py 2014-06-06 11:20:51 +0000 | |||
492 | @@ -1,6 +1,6 @@ | |||
493 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
494 | 2 | # | 2 | # |
496 | 3 | # Copyright (C) 2012, 2013 Canonical Ltd. | 3 | # Copyright (C) 2012, 2013, 2014 Canonical Ltd. |
497 | 4 | # | 4 | # |
498 | 5 | # This program is free software; you can redistribute it and/or modify | 5 | # This program is free software; you can redistribute it and/or modify |
499 | 6 | # it under the terms of the GNU Lesser General Public License as published by | 6 | # it under the terms of the GNU Lesser General Public License as published by |
500 | @@ -16,32 +16,19 @@ | |||
501 | 16 | 16 | ||
502 | 17 | """Tests for the Ubuntu UI Toolkit Gallery""" | 17 | """Tests for the Ubuntu UI Toolkit Gallery""" |
503 | 18 | 18 | ||
508 | 19 | from autopilot.matchers import Eventually | 19 | import ubuntuuitoolkit |
505 | 20 | from testtools.matchers import Is, Not, Equals | ||
506 | 21 | |||
507 | 22 | from ubuntuuitoolkit import emulators | ||
509 | 23 | from ubuntuuitoolkit.tests import gallery | 20 | from ubuntuuitoolkit.tests import gallery |
510 | 24 | 21 | ||
511 | 25 | 22 | ||
513 | 26 | class GenericTests(gallery.GalleryTestCase): | 23 | class GalleryAppTestCase(gallery.GalleryTestCase): |
514 | 27 | """Generic tests for the Gallery""" | 24 | """Generic tests for the Gallery""" |
515 | 28 | 25 | ||
527 | 29 | def test_0_can_select_mainwindow(self): | 26 | def test_select_main_view_must_return_main_window_emulator(self): |
528 | 30 | """Must be able to select the main window.""" | 27 | main_view = self.main_view |
529 | 31 | 28 | self.assertIsInstance(main_view, ubuntuuitoolkit.MainView) | |
519 | 32 | rootItem = self.main_view | ||
520 | 33 | self.assertThat(rootItem, Not(Is(None))) | ||
521 | 34 | self.assertThat(rootItem.visible, Eventually(Equals(True))) | ||
522 | 35 | |||
523 | 36 | def test_navigation(self): | ||
524 | 37 | item = "Navigation" | ||
525 | 38 | self.loadItem(item) | ||
526 | 39 | self.checkPageHeader(item) | ||
530 | 40 | 29 | ||
531 | 41 | def test_slider(self): | 30 | def test_slider(self): |
535 | 42 | item = "Slider" | 31 | self.open_page('slidersElement') |
533 | 43 | self.loadItem(item) | ||
534 | 44 | self.checkPageHeader(item) | ||
536 | 45 | 32 | ||
537 | 46 | item_data = [ | 33 | item_data = [ |
538 | 47 | ["slider_standard"], | 34 | ["slider_standard"], |
539 | @@ -57,9 +44,7 @@ | |||
540 | 57 | # TODO: move slider value | 44 | # TODO: move slider value |
541 | 58 | 45 | ||
542 | 59 | def test_progress_and_activity(self): | 46 | def test_progress_and_activity(self): |
546 | 60 | item = "Progress and activity" | 47 | self.open_page('progressBarsElement') |
544 | 61 | self.loadItem(item) | ||
545 | 62 | self.checkPageHeader(item) | ||
547 | 63 | 48 | ||
548 | 64 | item_data = [ | 49 | item_data = [ |
549 | 65 | ["progressbar_standard"], | 50 | ["progressbar_standard"], |
550 | @@ -79,9 +64,7 @@ | |||
551 | 79 | # FIXME: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1308979 | 64 | # FIXME: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1308979 |
552 | 80 | return | 65 | return |
553 | 81 | 66 | ||
557 | 82 | item = "Ubuntu Shape" | 67 | self.open_page('ubuntuShapesElement') |
555 | 83 | self.loadItem(item) | ||
556 | 84 | self.checkPageHeader(item) | ||
558 | 85 | 68 | ||
559 | 86 | item_data = [ | 69 | item_data = [ |
560 | 87 | ["ubuntushape_color_hex"], | 70 | ["ubuntushape_color_hex"], |
561 | @@ -115,12 +98,9 @@ | |||
562 | 115 | ] | 98 | ] |
563 | 116 | 99 | ||
564 | 117 | def test_open_page(self): | 100 | def test_open_page(self): |
568 | 118 | list_view = self.main_view.select_single( | 101 | self.open_page(self.element_name) |
566 | 119 | emulators.QQuickListView, objectName="widgetList") | ||
567 | 120 | list_view.click_element(self.element_name) | ||
569 | 121 | element = self.main_view.select_single( | 102 | element = self.main_view.select_single( |
570 | 122 | 'Standard', objectName=self.element_name) | 103 | 'Standard', objectName=self.element_name) |
571 | 123 | element.selected.wait_for(True) | ||
572 | 124 | self.checkPageHeader(element.text) | 104 | self.checkPageHeader(element.text) |
573 | 125 | if self.template_name == 'textinputsTemplate': | 105 | if self.template_name == 'textinputsTemplate': |
574 | 126 | page_type = 'TextInputs' | 106 | page_type = 'TextInputs' |
575 | 127 | 107 | ||
576 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/test_optionselector.py' | |||
577 | --- tests/autopilot/ubuntuuitoolkit/tests/gallery/test_optionselector.py 2014-05-23 09:50:42 +0000 | |||
578 | +++ tests/autopilot/ubuntuuitoolkit/tests/gallery/test_optionselector.py 2014-06-06 11:20:51 +0000 | |||
579 | @@ -24,9 +24,7 @@ | |||
580 | 24 | 24 | ||
581 | 25 | def setUp(self): | 25 | def setUp(self): |
582 | 26 | super(OptionSelectorTestCase, self).setUp() | 26 | super(OptionSelectorTestCase, self).setUp() |
586 | 27 | item = "Option Selector" | 27 | self.open_page('optionSelectorsElement') |
584 | 28 | self.loadItem(item) | ||
585 | 29 | self.checkPageHeader(item) | ||
587 | 30 | 28 | ||
588 | 31 | def test_select_option_from_collapsed_optionselector(self): | 29 | def test_select_option_from_collapsed_optionselector(self): |
589 | 32 | collapsed_option_selector = self.main_view.select_single( | 30 | collapsed_option_selector = self.main_view.select_single( |
590 | 33 | 31 | ||
591 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/test_textinput.py' | |||
592 | --- tests/autopilot/ubuntuuitoolkit/tests/gallery/test_textinput.py 2014-04-30 09:40:17 +0000 | |||
593 | +++ tests/autopilot/ubuntuuitoolkit/tests/gallery/test_textinput.py 2014-06-06 11:20:51 +0000 | |||
594 | @@ -54,9 +54,7 @@ | |||
595 | 54 | # Apply the user locale from the environment | 54 | # Apply the user locale from the environment |
596 | 55 | # The UITK does the same, so the test must be localized | 55 | # The UITK does the same, so the test must be localized |
597 | 56 | locale.setlocale(locale.LC_ALL, "") | 56 | locale.setlocale(locale.LC_ALL, "") |
601 | 57 | item = 'Text Field' | 57 | self.open_page('textinputsElement') |
599 | 58 | self.loadItem(item) | ||
600 | 59 | self.checkPageHeader(item) | ||
602 | 60 | 58 | ||
603 | 61 | def test_write_on_textfield_must_update_text(self): | 59 | def test_write_on_textfield_must_update_text(self): |
604 | 62 | textfield = self.main_view.select_single( | 60 | textfield = self.main_view.select_single( |
605 | @@ -78,9 +76,7 @@ | |||
606 | 78 | 76 | ||
607 | 79 | def setUp(self): | 77 | def setUp(self): |
608 | 80 | super(DisabledTextInputTestCase, self).setUp() | 78 | super(DisabledTextInputTestCase, self).setUp() |
612 | 81 | item = 'Text Field' | 79 | self.open_page('textinputsElement') |
610 | 82 | self.loadItem(item) | ||
611 | 83 | self.checkPageHeader(item) | ||
613 | 84 | 80 | ||
614 | 85 | def test_textfield_disabled(self): | 81 | def test_textfield_disabled(self): |
615 | 86 | textfield_disabled = self.main_view.select_single( | 82 | textfield_disabled = self.main_view.select_single( |
616 | 87 | 83 | ||
617 | === modified file 'tests/autopilot/ubuntuuitoolkit/tests/gallery/test_toggles.py' | |||
618 | --- tests/autopilot/ubuntuuitoolkit/tests/gallery/test_toggles.py 2013-11-01 15:15:30 +0000 | |||
619 | +++ tests/autopilot/ubuntuuitoolkit/tests/gallery/test_toggles.py 2014-06-06 11:20:51 +0000 | |||
620 | @@ -35,10 +35,7 @@ | |||
621 | 35 | 35 | ||
622 | 36 | def setUp(self): | 36 | def setUp(self): |
623 | 37 | super(EnabledTogglesTestCase, self).setUp() | 37 | super(EnabledTogglesTestCase, self).setUp() |
628 | 38 | item = "Toggles" | 38 | self.open_page('togglesElement') |
625 | 39 | self.checkListItem(item) | ||
626 | 40 | self.loadItem(item) | ||
627 | 41 | self.checkPageHeader(item) | ||
629 | 42 | 39 | ||
630 | 43 | def test_change_toggles_state(self): | 40 | def test_change_toggles_state(self): |
631 | 44 | toggle = self.main_view.select_single( | 41 | toggle = self.main_view.select_single( |
632 | @@ -65,10 +62,7 @@ | |||
633 | 65 | 62 | ||
634 | 66 | def setUp(self): | 63 | def setUp(self): |
635 | 67 | super(DisabledTogglesTestCase, self).setUp() | 64 | super(DisabledTogglesTestCase, self).setUp() |
640 | 68 | item = "Toggles" | 65 | self.open_page('togglesElement') |
637 | 69 | self.checkListItem(item) | ||
638 | 70 | self.loadItem(item) | ||
639 | 71 | self.checkPageHeader(item) | ||
641 | 72 | 66 | ||
642 | 73 | def test_change_toggles_state(self): | 67 | def test_change_toggles_state(self): |
643 | 74 | toggle = self.main_view.select_single( | 68 | toggle = self.main_view.select_single( |