Merge lp:~elopio/ubuntu-ui-toolkit/toolbar_emulator into lp:ubuntu-ui-toolkit

Proposed by Leo Arias
Status: Merged
Approved by: Florian Boucault
Approved revision: 574
Merged at revision: 569
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/toolbar_emulator
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~elopio/ubuntu-ui-toolkit/custom_emulators
Diff against target: 247 lines (+188/-4)
3 files modified
debian/control (+1/-0)
tests/autopilot/UbuntuUiToolkit/emulators.py (+84/-0)
tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py (+103/-4)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/toolbar_emulator
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Juhapekka Piiroinen (community) Needs Information
Thomi Richards (community) Approve
Review via email: mp+171720@code.launchpad.net

Commit message

Added the Toolbar Autopilot emulator.

To post a comment you must log in.
571. By Leo Arias

Fixed pep8.

572. By Leo Arias

Typo.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM

review: Approve
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Check my +junk version again. If you don't force proper integers to click for say opening the toolbar it seems to fails when using gu units for window size.

So something like line_x = x + self.width * 0.50 I force to line_x = int(x + self.width * 0.50)

Otherwise this looks good!

Revision history for this message
Leo Arias (elopio) wrote :

Thanks for pointing that out Nicholas. With this change in autopilot, now we don't have to cast to int:
https://code.launchpad.net/~elopio/autopilot/fix1195499-move_non_int/+merge/171934

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Juhapekka Piiroinen (juhapekka-piiroinen) wrote :

> "Added the objectName property to ActionItem."

Could you justify the change to modules/Ubuntu/Components/ActionItem.qml. As in my opinion objectName should be set by the applications, not by the library. :)

review: Needs Information
Revision history for this message
Leo Arias (elopio) wrote :

Hi.

Do you mean that it should be defined on the test_qml?
If I just add it to the Action definition on the QML, it will not be present on the ActionItem object accessed by autopilot. I'm not close to be a QML expert thought, so I might be missing something.

I might have also misunderstood your question. I'm not close to be an english expert either :)

573. By Leo Arias

If we define the objectName on the ToolbarButton, we don't need to have the objectName property on the ActionItem.

574. By Leo Arias

Removed pdb.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-06-27 02:42:26 +0000
3+++ debian/control 2013-06-28 18:16:24 +0000
4@@ -105,6 +105,7 @@
5 libqt5test5,
6 libqt5widgets5,
7 python-autopilot (>= 1.3),
8+ python-mock,
9 ubuntu-ui-toolkit-examples (>= ${source:Version}),
10 Description: Test package for Ubuntu UI Toolkit
11 Autopilot tests for the ubuntu-ui-toolkit package
12
13=== modified file 'tests/autopilot/UbuntuUiToolkit/emulators.py'
14--- tests/autopilot/UbuntuUiToolkit/emulators.py 2013-06-27 02:31:46 +0000
15+++ tests/autopilot/UbuntuUiToolkit/emulators.py 2013-06-28 18:16:24 +0000
16@@ -14,9 +14,24 @@
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20+from autopilot import input, platform
21 from autopilot.introspection import dbus
22
23
24+def get_pointing_device():
25+ """Get the pointing device depending on the platform.
26+
27+ If the platform is `Desktop`, the pointing device will be a `Mouse`.
28+ If not, the pointing device will be `Touch`.
29+
30+ """
31+ if platform.model == 'Desktop':
32+ input_device_class = input.Mouse
33+ else:
34+ input_device_class = input.Touch
35+ return input.Pointer(input_device_class.create())
36+
37+
38 class UbuntuUIToolkitEmulatorBase(dbus.CustomEmulatorBase):
39 """A base class for all the Ubuntu UI Toolkit emulators."""
40
41@@ -24,6 +39,75 @@
42 class MainView(UbuntuUIToolkitEmulatorBase):
43 """MainView Autopilot emulator."""
44
45+ def __init__(self, *args):
46+ super(MainView, self).__init__(*args)
47+ self.pointing_device = get_pointing_device()
48+
49 def get_header(self):
50 """Get the Header emulator of the MainView."""
51 return self.select_single('Header')
52+
53+ def get_toolbar(self):
54+ """Get the Toolbar emulator of the MainView."""
55+ return self.select_single(Toolbar)
56+
57+ def open_toolbar(self):
58+ """Open the toolbar if it's not already opened.
59+
60+ :return: the toolbar.
61+
62+ """
63+ toolbar = self.get_toolbar()
64+ if not toolbar.opened:
65+ self._drag_to_open_toolbar()
66+ toolbar.opened.wait_for(True)
67+
68+ return toolbar
69+
70+ def _drag_to_open_toolbar(self):
71+ x = self.globalRect[0]
72+ y = self.globalRect[1]
73+ line_x = x + self.width * 0.50
74+ start_y = y + self.height - 1
75+ stop_y = y + self.height * 0.95
76+
77+ self.pointing_device.drag(line_x, start_y, line_x, stop_y)
78+
79+ def close_toolbar(self):
80+ """Close the toolbar if it's opened."""
81+ toolbar = self.get_toolbar()
82+ if toolbar.opened:
83+ self._drag_to_close_toolbar()
84+ toolbar.opened.wait_for(False)
85+
86+ def _drag_to_close_toolbar(self):
87+ x = self.globalRect[0]
88+ y = self.globalRect[1]
89+ line_x = x + self.width * 0.50
90+ start_y = y + self.height * 0.95
91+ stop_y = y + self.height - 1
92+
93+ self.pointing_device.drag(line_x, start_y, line_x, stop_y)
94+
95+
96+class Toolbar(UbuntuUIToolkitEmulatorBase):
97+ """Toolbar Autopilot emulator."""
98+
99+ def __init__(self, *args):
100+ super(Toolbar, self).__init__(*args)
101+ self.pointing_device = get_pointing_device()
102+
103+ def click_button(self, object_name):
104+ """Click a button of the toolbar.
105+
106+ :param object_name: The QML objectName property of the button.
107+
108+ """
109+ button = self._get_button(object_name)
110+ not_found_error = 'Button with objectName "{0}" not found.'.format(
111+ object_name)
112+ assert button is not None, not_found_error
113+ self.pointing_device.click_object(button)
114+
115+ def _get_button(self, object_name):
116+ return self.select_single('ActionItem', objectName=object_name)
117
118=== modified file 'tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py'
119--- tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py 2013-06-27 02:29:35 +0000
120+++ tests/autopilot/UbuntuUiToolkit/tests/test_emulators.py 2013-06-28 18:16:24 +0000
121@@ -14,6 +14,7 @@
122 # You should have received a copy of the GNU Lesser General Public License
123 # along with this program. If not, see <http://www.gnu.org/licenses/>.
124
125+import mock
126
127 from UbuntuUiToolkit import tests
128 from UbuntuUiToolkit import emulators
129@@ -28,16 +29,114 @@
130 MainView {
131 width: units.gu(48)
132 height: units.gu(60)
133-
134- Page {
135- title: "Test title"
136- }
137 }
138 """)
139
140 def test_main_view_custom_emulator(self):
141 self.assertIsInstance(self.main_view, emulators.MainView)
142
143+ def test_get_header_without_header(self):
144+ header = self.main_view.get_header()
145+ self.assertFalse(header.visible)
146+
147+ def test_toolbar_custom_emulator(self):
148+ toolbar = self.main_view.get_toolbar()
149+ self.assertIsInstance(toolbar, emulators.Toolbar)
150+ self.assertFalse(toolbar.opened)
151+
152+
153+class PageTestCase(tests.UbuntuUiToolkitTestCase):
154+
155+ test_qml = ("""
156+import QtQuick 2.0
157+import Ubuntu.Components 0.1
158+
159+MainView {
160+ width: units.gu(48)
161+ height: units.gu(60)
162+
163+ Page {
164+ title: "Test title"
165+ }
166+}
167+""")
168+
169 def test_get_header(self):
170 header = self.main_view.get_header()
171+ self.assertTrue(header.visible)
172 self.assertEqual(header.title, "Test title")
173+
174+
175+class ToolbarTestCase(tests.UbuntuUiToolkitTestCase):
176+
177+ test_qml = ("""
178+import QtQuick 2.0
179+import Ubuntu.Components 0.1
180+
181+MainView {
182+ width: units.gu(50)
183+ height: units.gu(50)
184+
185+ Page {
186+
187+ Label {
188+ id: "label"
189+ objectName: "clicked_label"
190+ anchors.centerIn: parent
191+ text: "Button not clicked."
192+ }
193+
194+ tools: ToolbarItems {
195+ ToolbarButton {
196+ objectName: "buttonName"
197+ action: Action {
198+ text: "buttonText"
199+ onTriggered: label.text = "Button clicked."
200+ }
201+ }
202+ locked: false
203+ opened: false
204+ }
205+ }
206+}
207+""")
208+
209+ def test_open_toolbar(self):
210+ toolbar = self.main_view.open_toolbar()
211+ self.assertTrue(toolbar.opened)
212+
213+ def test_opened_toolbar_is_not_opened_again(self):
214+ toolbar = self.main_view.open_toolbar()
215+ with mock.patch.object(
216+ self.main_view.pointing_device, 'drag') as mock_drag:
217+ self.main_view.open_toolbar()
218+
219+ self.assertFalse(mock_drag.called)
220+ self.assertTrue(toolbar.opened)
221+
222+ def test_close_toolbar(self):
223+ toolbar = self.main_view.open_toolbar()
224+ self.main_view.close_toolbar()
225+ self.assertFalse(toolbar.opened)
226+
227+ def test_closed_toolbar_is_not_closed_again(self):
228+ with mock.patch.object(
229+ self.main_view.pointing_device, 'drag') as mock_drag:
230+ self.main_view.close_toolbar()
231+
232+ self.assertFalse(mock_drag.called)
233+ self.assertFalse(self.main_view.get_toolbar().opened)
234+
235+ def test_click_toolbar_button(self):
236+ label = self.app.select_single('Label', objectName='clicked_label')
237+ self.assertNotEqual(label.text, 'Button clicked.')
238+ toolbar = self.main_view.open_toolbar()
239+ toolbar.click_button('buttonName')
240+ self.assertEqual(label.text, 'Button clicked.')
241+
242+ def test_click_unexisting_button(self):
243+ toolbar = self.main_view.open_toolbar()
244+ error = self.assertRaises(
245+ AssertionError, toolbar.click_button, 'unexisting')
246+ self.assertEqual(
247+ error.message, 'Button with objectName "unexisting" not found.')

Subscribers

People subscribed via source and target branches

to status/vote changes: