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
=== modified file 'tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py'
--- tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py 2013-06-14 21:14:28 +0000
+++ tests/autopilot/ubuntu_filemanager_app/emulators/main_window.py 2013-06-14 21:14:28 +0000
@@ -8,23 +8,21 @@
8"""File Manager app autopilot emulators."""8"""File Manager app autopilot emulators."""
99
1010
11class MainWindow(object):11from ubuntu_filemanager_app.emulators import ubuntusdk
12 """An emulator class that makes it easy to interact with the12
13 filemanager-app.13
1414class QQuickView(ubuntusdk.QQuickView):
15 """15 """Emulator for the main window of the filemanager-app."""
16 def __init__(self, app):16
17 self.app = app
18
19 def get_folder(self, index):17 def get_folder(self, index):
20 """Returns the list view folder with index number."""18 """Returns the list view folder with index number."""
21 return self.app.select_many("Subtitled")[index]19 return self.select_many("Subtitled")[index]
2220
23 def get_action_popover(self):21 def get_action_popover(self):
24 return self.app.select_single("ActionSelectionPopover")22 return self.select_single("ActionSelectionPopover")
2523
26 def get_current_folder_name(self):24 def get_current_folder_name(self):
27 # XXX the label with the folder name doesn't have an objectName.25 # XXX the label with the folder name doesn't have an objectName.
28 # See bug #1190855.26 # See bug #1190855.
29 return self.app.select_single('FolderListView').select_many(27 return self.select_single("FolderListView").select_many(
30 'Label')[0].text28 'Label')[0].text
3129
=== modified file 'tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py'
--- tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py 2013-06-14 21:14:28 +0000
+++ tests/autopilot/ubuntu_filemanager_app/emulators/ubuntusdk.py 2013-06-14 21:14:28 +0000
@@ -16,139 +16,60 @@
16#16#
17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
1818
19from testtools.matchers import Equals, NotEquals, Not, Is19from autopilot import input, platform
20from autopilot.matchers import Eventually20from autopilot.introspection import dbus
2121
22class ubuntusdk(object):22
23 """An emulator class that makes it easy to interact with the ubuntu sdk applications."""23def get_pointing_device():
2424 if platform.model == 'Desktop':
25 def __init__(self, autopilot, app):25 input_device_class = input.Mouse
26 self.app = app26 else:
27 self.autopilot = autopilot27 input_device_class = input.Touch
2828 return input.Pointer(input_device_class.create())
29 def get_qml_view(self):29
30 """Get the main QML view"""30
31 return self.app.select_single("QQuickView")31class UbuntuSDKEmulatorBase(dbus.CustomEmulatorBase):
3232 """A base class for all Ubuntu SDK emulators."""
33 def get_object(self, typeName, name):33
34 """Get a specific object"""34
35 return self.app.select_single(typeName, objectName=name)35class QQuickView(UbuntuSDKEmulatorBase):
3636
37 def get_objects(self, typeName, name):37 def __init__(self, *args):
38 """Get more than one object"""38 super(QQuickView, self).__init__(*args)
39 return self.app.select_many(typeName, objectName=name)39 self.pointing_device = get_pointing_device()
4040
41 def switch_to_tab(self, tab):41 @property
42 """Switch to the specified tab number"""42 def toolbar(self):
43 tabs = self.get_tabs()43 return self.select_single(Toolbar)
44 currentTab = tabs.selectedTabIndex44
4545 def open_toolbar(self):
46 #perform operations until tab == currentTab46 """Open the toolbar."""
47 while tab != currentTab:47 if not self.toolbar.opened:
48 if tab > currentTab:48 line_x = self.x + self.width * 0.50
49 self._previous_tab()49 start_y = self.y + self.height - 1
50 if tab < currentTab:50 stop_y = self.y + self.height * 0.95
51 self._next_tab()51
52 currentTab = tabs.selectedTabIndex52 self.pointing_device.drag(line_x, start_y, line_x, stop_y)
5353
54 def toggle_toolbar(self):54
55 """Toggle the toolbar between revealed and hidden"""55class Toolbar(UbuntuSDKEmulatorBase):
56 #check and see if the toolbar is open or not56
57 if self.get_toolbar().opened:57 def __init__(self, *args):
58 self.hide_toolbar()58 super(Toolbar, self).__init__(*args)
59 else:59 self.pointing_device = get_pointing_device()
60 self.open_toolbar()60
6161 def _get_button(self, text):
62 def get_toolbar(self):62 """Return the toolbar button at position index."""
63 """Returns the toolbar in the main events view."""63 # XXX we should receive the objectName, not the text.
64 return self.app.select_single("Toolbar")64 row = self.select_single("QQuickRow")
6565 loader_list = row.select_many("QQuickLoader")
66 def get_toolbar_button(self, buttonLabel):66 for loader in loader_list:
67 """Returns the toolbar button at position index"""67 button_list = loader.select_many("Button")
68 toolbar = self.get_toolbar()68 for button in button_list:
69 if not toolbar.opened:69 if button.text == text:
70 self.open_toolbar()
71 row = toolbar.select_single("QQuickRow")
72 loaderList = row.select_many("QQuickLoader")
73 for loader in loaderList:
74 buttonList = loader.select_many("Button")
75 for button in buttonList:
76 if button.text == buttonLabel:
77 return button70 return button
7871
79 def click_toolbar_button(self, buttonLabel):72 def click_button(self, object_name):
80 """Clicks the toolbar button with buttonLabel"""73 """Click a toolbar button."""
81 #The toolbar button is assumed to be the following format74 button = self._get_button(object_name)
82 #ToolbarActions {75 self.pointing_device.click_object(button)
83 # Action {
84 # objectName: "name"
85 # text: value
86 button = self.get_toolbar_button(buttonLabel)
87 self.autopilot.pointing_device.click_object(button)
88
89 def open_toolbar(self):
90 """Open the toolbar"""
91 qmlView = self.get_qml_view()
92
93 lineX = qmlView.x + qmlView.width * 0.50
94 startY = qmlView.y + qmlView.height - 1
95 stopY = qmlView.y + qmlView.height * 0.95
96
97 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
98
99 def hide_toolbar(self):
100 """Hide the toolbar"""
101 qmlView = self.get_qml_view()
102
103 lineX = qmlView.x + qmlView.width * 0.50
104 startY = qmlView.y + qmlView.height * 0.95
105 stopY = qmlView.y + qmlView.height - 1
106
107 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
108
109 def set_popup_value(self, popover, button, value):
110 """Changes the given popover selector to the request value
111 At the moment this only works for values that are currently visible. To
112 access the remaining items, a help method to drag and recheck is needed."""
113 #The popover is assumed to be the following format
114 # Popover {
115 # Column {
116 # ListView {
117 # delegate: Standard {
118 # objectName: "name"
119 # text: value
120
121 self.autopilot.pointing_device.click_object(button)
122 #we'll get all matching objects, incase the popover is reused between buttons
123 itemList = lambda: self.get_objects("Standard", popover)
124
125 for item in itemList():
126 if item.get_properties()['text'] == value:
127 self.autopilot.pointing_device.click_object(item)
128
129 def get_tabs(self):
130 """Return all tabs"""
131 return self.get_object("Tabs", "rootTabs")
132
133 def _previous_tab(self):
134 """Switch to the previous tab"""
135 qmlView = self.get_qml_view()
136
137 startX = qmlView.x + qmlView.width * 0.35
138 stopX = qmlView.x + qmlView.width * 0.50
139 lineY = qmlView.y + qmlView.height * 0.05
140
141 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
142 self.autopilot.pointing_device.click()
143 self.autopilot.pointing_device.click()
144
145 def _next_tab(self):
146 """Switch to the next tab"""
147 qmlView = self.get_qml_view()
148
149 startX = qmlView.x + qmlView.width * 0.50
150 stopX = qmlView.x + qmlView.width * 0.35
151 lineY = qmlView.y + qmlView.height * 0.05
152
153 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
154 self.autopilot.pointing_device.click()
15576
=== modified file 'tests/autopilot/ubuntu_filemanager_app/tests/__init__.py'
--- tests/autopilot/ubuntu_filemanager_app/tests/__init__.py 2013-06-14 21:14:28 +0000
+++ tests/autopilot/ubuntu_filemanager_app/tests/__init__.py 2013-06-14 21:14:28 +0000
@@ -15,8 +15,7 @@
1515
16from time import sleep16from time import sleep
1717
18from ubuntu_filemanager_app.emulators.main_window import MainWindow18from ubuntu_filemanager_app.emulators import main_window, ubuntusdk
19from ubuntu_filemanager_app.emulators.ubuntusdk import ubuntusdk
2019
2120
22class FileManagerTestCase(AutopilotTestCase):21class FileManagerTestCase(AutopilotTestCase):
@@ -33,18 +32,17 @@
33 local_location = "../../ubuntu-filemanager-app.qml"32 local_location = "../../ubuntu-filemanager-app.qml"
3433
35 def setUp(self):34 def setUp(self):
36 self.pointing_device = Pointer(self.input_device_class.create())
37 super(FileManagerTestCase, self).setUp()35 super(FileManagerTestCase, self).setUp()
38 if os.path.exists(self.local_location):36 if os.path.exists(self.local_location):
39 self.launch_test_local()37 self.launch_test_local()
40 else:38 else:
41 self.launch_test_installed()39 self.launch_test_installed()
40 self.pointing_device = Pointer(self.input_device_class.create())
4241
43 def launch_test_local(self):42 def launch_test_local(self):
44 self.app = self.launch_test_application(43 self.app = self.launch_test_application(
45 "qmlscene",44 "qmlscene", self.local_location, app_type='qt',
46 self.local_location,45 emulator_base=ubuntusdk.UbuntuSDKEmulatorBase)
47 app_type='qt')
4846
49 def launch_test_installed(self):47 def launch_test_installed(self):
50 self.app = self.launch_test_application(48 self.app = self.launch_test_application(
@@ -52,7 +50,7 @@
52 "/usr/share/ubuntu-filemanager-app/ubuntu-filemanager-app.qml",50 "/usr/share/ubuntu-filemanager-app/ubuntu-filemanager-app.qml",
53 "--desktop_file_hint="51 "--desktop_file_hint="
54 "/usr/share/applications/ubuntu-filemanager-app.desktop",52 "/usr/share/applications/ubuntu-filemanager-app.desktop",
55 app_type='qt')53 app_type='qt', emulator_base=ubuntusdk.UbuntuSDKEmulatorBase)
5654
57 def tap_item(self, item):55 def tap_item(self, item):
58 self.pointing_device.move_to_object(item)56 self.pointing_device.move_to_object(item)
@@ -61,9 +59,5 @@
61 self.pointing_device.release()59 self.pointing_device.release()
6260
63 @property61 @property
64 def main_window(self):62 def main_view(self):
65 return MainWindow(self.app)63 return self.app.select_single(main_window.QQuickView)
66
67 @property
68 def ubuntusdk(self):
69 return ubuntusdk(self, self.app)
7064
=== modified file 'tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py'
--- tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py 2013-06-14 21:14:28 +0000
+++ tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py 2013-06-14 21:14:28 +0000
@@ -27,7 +27,8 @@
27 self._patch_home()27 self._patch_home()
28 super(TestMainWindow, self).setUp()28 super(TestMainWindow, self).setUp()
29 self.assertThat(29 self.assertThat(
30 self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))30 self.main_view.visible,
31 Eventually(Equals(True)))
3132
32 def _patch_home(self):33 def _patch_home(self):
33 temp_dir = tempfile.mkdtemp()34 temp_dir = tempfile.mkdtemp()
@@ -40,10 +41,10 @@
40 """Dragging from the bottom reveals the hidden toolbar."""41 """Dragging from the bottom reveals the hidden toolbar."""
41 self._make_directory_in_home()42 self._make_directory_in_home()
4243
43 first_folder = self.main_window.get_folder(0)44 first_folder = self.main_view.get_folder(0)
44 self.tap_item(first_folder)45 self.tap_item(first_folder)
4546
46 action_popover = self.main_window.get_action_popover()47 action_popover = self.main_view.get_action_popover()
47 self.assertThat(lambda: action_popover.opacity, Eventually(Equals(1)))48 self.assertThat(lambda: action_popover.opacity, Eventually(Equals(1)))
4849
49 def _make_directory_in_home(self):50 def _make_directory_in_home(self):
@@ -51,14 +52,14 @@
51 # Currently, we need to open again the home folder to show the newly52 # Currently, we need to open again the home folder to show the newly
52 # created one. See bug #1190676.53 # created one. See bug #1190676.
53 # TODO when the bug is fixed, remove the next line.54 # TODO when the bug is fixed, remove the next line.
54 self.ubuntusdk.click_toolbar_button('Home')55 self.main_view.toolbar.click_button('Home')
55 return path56 return path
5657
57 def test_open_directory(self):58 def test_open_directory(self):
58 sub_dir = self._make_directory_in_home()59 sub_dir = self._make_directory_in_home()
5960
60 first_folder = self.main_window.get_folder(0)61 first_folder = self.main_view.get_folder(0)
61 self.pointing_device.click_object(first_folder)62 self.pointing_device.click_object(first_folder)
62 self.assertThat(63 self.assertThat(
63 self.main_window.get_current_folder_name,64 self.main_view.get_current_folder_name,
64 Eventually(Equals(sub_dir)))65 Eventually(Equals(sub_dir)))

Subscribers

People subscribed via source and target branches