Merge lp:~elopio/ubuntu-filemanager-app/ubuntusdk_emulator into lp:ubuntu-filemanager-app

Proposed by Leo Arias on 2013-06-14
Status: Work in progress
Proposed branch: lp:~elopio/ubuntu-filemanager-app/ubuntusdk_emulator
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~elopio/ubuntu-filemanager-app/fix1188732-test_open_directory
Diff against target: 337 lines (+78/-164)
4 files modified
tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py (+9/-11)
tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py (+55/-134)
tests/autopilot/ubuntu_filemanager_app/tests/__init__.py (+7/-13)
tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py (+7/-6)
To merge this branch: bzr merge lp:~elopio/ubuntu-filemanager-app/ubuntusdk_emulator
Reviewer Review Type Date Requested Status
Ubuntu File Manager Developers 2013-06-14 Pending
Review via email: mp+169542@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

43. By Leo Arias on 2013-06-14

Make a custom emulator for sdk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py'
2--- tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py 2013-06-14 21:14:28 +0000
3+++ tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py 2013-06-14 21:14:28 +0000
4@@ -8,23 +8,21 @@
5 """File Manager app autopilot emulators."""
6
7
8-class MainWindow(object):
9- """An emulator class that makes it easy to interact with the
10- filemanager-app.
11-
12- """
13- def __init__(self, app):
14- self.app = app
15-
16+from ubuntu_filemanager_app.emulators import ubuntusdk
17+
18+
19+class QQuickView(ubuntusdk.QQuickView):
20+ """Emulator for the main window of the filemanager-app."""
21+
22 def get_folder(self, index):
23 """Returns the list view folder with index number."""
24- return self.app.select_many("Subtitled")[index]
25+ return self.select_many("Subtitled")[index]
26
27 def get_action_popover(self):
28- return self.app.select_single("ActionSelectionPopover")
29+ return self.select_single("ActionSelectionPopover")
30
31 def get_current_folder_name(self):
32 # XXX the label with the folder name doesn't have an objectName.
33 # See bug #1190855.
34- return self.app.select_single('FolderListView').select_many(
35+ return self.select_single("FolderListView").select_many(
36 'Label')[0].text
37
38=== modified file 'tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py'
39--- tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py 2013-06-14 21:14:28 +0000
40+++ tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py 2013-06-14 21:14:28 +0000
41@@ -16,139 +16,60 @@
42 #
43 # Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
44
45-from testtools.matchers import Equals, NotEquals, Not, Is
46-from autopilot.matchers import Eventually
47-
48-class ubuntusdk(object):
49- """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
50-
51- def __init__(self, autopilot, app):
52- self.app = app
53- self.autopilot = autopilot
54-
55- def get_qml_view(self):
56- """Get the main QML view"""
57- return self.app.select_single("QQuickView")
58-
59- def get_object(self, typeName, name):
60- """Get a specific object"""
61- return self.app.select_single(typeName, objectName=name)
62-
63- def get_objects(self, typeName, name):
64- """Get more than one object"""
65- return self.app.select_many(typeName, objectName=name)
66-
67- def switch_to_tab(self, tab):
68- """Switch to the specified tab number"""
69- tabs = self.get_tabs()
70- currentTab = tabs.selectedTabIndex
71-
72- #perform operations until tab == currentTab
73- while tab != currentTab:
74- if tab > currentTab:
75- self._previous_tab()
76- if tab < currentTab:
77- self._next_tab()
78- currentTab = tabs.selectedTabIndex
79-
80- def toggle_toolbar(self):
81- """Toggle the toolbar between revealed and hidden"""
82- #check and see if the toolbar is open or not
83- if self.get_toolbar().opened:
84- self.hide_toolbar()
85- else:
86- self.open_toolbar()
87-
88- def get_toolbar(self):
89- """Returns the toolbar in the main events view."""
90- return self.app.select_single("Toolbar")
91-
92- def get_toolbar_button(self, buttonLabel):
93- """Returns the toolbar button at position index"""
94- toolbar = self.get_toolbar()
95- if not toolbar.opened:
96- self.open_toolbar()
97- row = toolbar.select_single("QQuickRow")
98- loaderList = row.select_many("QQuickLoader")
99- for loader in loaderList:
100- buttonList = loader.select_many("Button")
101- for button in buttonList:
102- if button.text == buttonLabel:
103+from autopilot import input, platform
104+from autopilot.introspection import dbus
105+
106+
107+def get_pointing_device():
108+ if platform.model == 'Desktop':
109+ input_device_class = input.Mouse
110+ else:
111+ input_device_class = input.Touch
112+ return input.Pointer(input_device_class.create())
113+
114+
115+class UbuntuSDKEmulatorBase(dbus.CustomEmulatorBase):
116+ """A base class for all Ubuntu SDK emulators."""
117+
118+
119+class QQuickView(UbuntuSDKEmulatorBase):
120+
121+ def __init__(self, *args):
122+ super(QQuickView, self).__init__(*args)
123+ self.pointing_device = get_pointing_device()
124+
125+ @property
126+ def toolbar(self):
127+ return self.select_single(Toolbar)
128+
129+ def open_toolbar(self):
130+ """Open the toolbar."""
131+ if not self.toolbar.opened:
132+ line_x = self.x + self.width * 0.50
133+ start_y = self.y + self.height - 1
134+ stop_y = self.y + self.height * 0.95
135+
136+ self.pointing_device.drag(line_x, start_y, line_x, stop_y)
137+
138+
139+class Toolbar(UbuntuSDKEmulatorBase):
140+
141+ def __init__(self, *args):
142+ super(Toolbar, self).__init__(*args)
143+ self.pointing_device = get_pointing_device()
144+
145+ def _get_button(self, text):
146+ """Return the toolbar button at position index."""
147+ # XXX we should receive the objectName, not the text.
148+ row = self.select_single("QQuickRow")
149+ loader_list = row.select_many("QQuickLoader")
150+ for loader in loader_list:
151+ button_list = loader.select_many("Button")
152+ for button in button_list:
153+ if button.text == text:
154 return button
155
156- def click_toolbar_button(self, buttonLabel):
157- """Clicks the toolbar button with buttonLabel"""
158- #The toolbar button is assumed to be the following format
159- #ToolbarActions {
160- # Action {
161- # objectName: "name"
162- # text: value
163- button = self.get_toolbar_button(buttonLabel)
164- self.autopilot.pointing_device.click_object(button)
165-
166- def open_toolbar(self):
167- """Open the toolbar"""
168- qmlView = self.get_qml_view()
169-
170- lineX = qmlView.x + qmlView.width * 0.50
171- startY = qmlView.y + qmlView.height - 1
172- stopY = qmlView.y + qmlView.height * 0.95
173-
174- self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
175-
176- def hide_toolbar(self):
177- """Hide the toolbar"""
178- qmlView = self.get_qml_view()
179-
180- lineX = qmlView.x + qmlView.width * 0.50
181- startY = qmlView.y + qmlView.height * 0.95
182- stopY = qmlView.y + qmlView.height - 1
183-
184- self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
185-
186- def set_popup_value(self, popover, button, value):
187- """Changes the given popover selector to the request value
188- At the moment this only works for values that are currently visible. To
189- access the remaining items, a help method to drag and recheck is needed."""
190- #The popover is assumed to be the following format
191- # Popover {
192- # Column {
193- # ListView {
194- # delegate: Standard {
195- # objectName: "name"
196- # text: value
197-
198- self.autopilot.pointing_device.click_object(button)
199- #we'll get all matching objects, incase the popover is reused between buttons
200- itemList = lambda: self.get_objects("Standard", popover)
201-
202- for item in itemList():
203- if item.get_properties()['text'] == value:
204- self.autopilot.pointing_device.click_object(item)
205-
206- def get_tabs(self):
207- """Return all tabs"""
208- return self.get_object("Tabs", "rootTabs")
209-
210- def _previous_tab(self):
211- """Switch to the previous tab"""
212- qmlView = self.get_qml_view()
213-
214- startX = qmlView.x + qmlView.width * 0.35
215- stopX = qmlView.x + qmlView.width * 0.50
216- lineY = qmlView.y + qmlView.height * 0.05
217-
218- self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
219- self.autopilot.pointing_device.click()
220- self.autopilot.pointing_device.click()
221-
222- def _next_tab(self):
223- """Switch to the next tab"""
224- qmlView = self.get_qml_view()
225-
226- startX = qmlView.x + qmlView.width * 0.50
227- stopX = qmlView.x + qmlView.width * 0.35
228- lineY = qmlView.y + qmlView.height * 0.05
229-
230- self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
231- self.autopilot.pointing_device.click()
232+ def click_button(self, object_name):
233+ """Click a toolbar button."""
234+ button = self._get_button(object_name)
235+ self.pointing_device.click_object(button)
236
237=== modified file 'tests/autopilot/ubuntu_filemanager_app/tests/__init__.py'
238--- tests/autopilot/ubuntu_filemanager_app/tests/__init__.py 2013-06-14 21:14:28 +0000
239+++ tests/autopilot/ubuntu_filemanager_app/tests/__init__.py 2013-06-14 21:14:28 +0000
240@@ -15,8 +15,7 @@
241
242 from time import sleep
243
244-from ubuntu_filemanager_app.emulators.main_window import MainWindow
245-from ubuntu_filemanager_app.emulators.ubuntusdk import ubuntusdk
246+from ubuntu_filemanager_app.emulators import main_window, ubuntusdk
247
248
249 class FileManagerTestCase(AutopilotTestCase):
250@@ -33,18 +32,17 @@
251 local_location = "../../ubuntu-filemanager-app.qml"
252
253 def setUp(self):
254- self.pointing_device = Pointer(self.input_device_class.create())
255 super(FileManagerTestCase, self).setUp()
256 if os.path.exists(self.local_location):
257 self.launch_test_local()
258 else:
259 self.launch_test_installed()
260+ self.pointing_device = Pointer(self.input_device_class.create())
261
262 def launch_test_local(self):
263 self.app = self.launch_test_application(
264- "qmlscene",
265- self.local_location,
266- app_type='qt')
267+ "qmlscene", self.local_location, app_type='qt',
268+ emulator_base=ubuntusdk.UbuntuSDKEmulatorBase)
269
270 def launch_test_installed(self):
271 self.app = self.launch_test_application(
272@@ -52,7 +50,7 @@
273 "/usr/share/ubuntu-filemanager-app/ubuntu-filemanager-app.qml",
274 "--desktop_file_hint="
275 "/usr/share/applications/ubuntu-filemanager-app.desktop",
276- app_type='qt')
277+ app_type='qt', emulator_base=ubuntusdk.UbuntuSDKEmulatorBase)
278
279 def tap_item(self, item):
280 self.pointing_device.move_to_object(item)
281@@ -61,9 +59,5 @@
282 self.pointing_device.release()
283
284 @property
285- def main_window(self):
286- return MainWindow(self.app)
287-
288- @property
289- def ubuntusdk(self):
290- return ubuntusdk(self, self.app)
291+ def main_view(self):
292+ return self.app.select_single(main_window.QQuickView)
293
294=== modified file 'tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py'
295--- tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py 2013-06-14 21:14:28 +0000
296+++ tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py 2013-06-14 21:14:28 +0000
297@@ -27,7 +27,8 @@
298 self._patch_home()
299 super(TestMainWindow, self).setUp()
300 self.assertThat(
301- self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))
302+ self.main_view.visible,
303+ Eventually(Equals(True)))
304
305 def _patch_home(self):
306 temp_dir = tempfile.mkdtemp()
307@@ -40,10 +41,10 @@
308 """Dragging from the bottom reveals the hidden toolbar."""
309 self._make_directory_in_home()
310
311- first_folder = self.main_window.get_folder(0)
312+ first_folder = self.main_view.get_folder(0)
313 self.tap_item(first_folder)
314
315- action_popover = self.main_window.get_action_popover()
316+ action_popover = self.main_view.get_action_popover()
317 self.assertThat(lambda: action_popover.opacity, Eventually(Equals(1)))
318
319 def _make_directory_in_home(self):
320@@ -51,14 +52,14 @@
321 # Currently, we need to open again the home folder to show the newly
322 # created one. See bug #1190676.
323 # TODO when the bug is fixed, remove the next line.
324- self.ubuntusdk.click_toolbar_button('Home')
325+ self.main_view.toolbar.click_button('Home')
326 return path
327
328 def test_open_directory(self):
329 sub_dir = self._make_directory_in_home()
330
331- first_folder = self.main_window.get_folder(0)
332+ first_folder = self.main_view.get_folder(0)
333 self.pointing_device.click_object(first_folder)
334 self.assertThat(
335- self.main_window.get_current_folder_name,
336+ self.main_view.get_current_folder_name,
337 Eventually(Equals(sub_dir)))

Subscribers

People subscribed via source and target branches