Merge lp:~elopio/ubuntu-ui-toolkit/fix1324556-get_top_container into lp:~bzoltan/ubuntu-ui-toolkit/landing_28-05

Proposed by Leo Arias
Status: Superseded
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/fix1324556-get_top_container
Merge into: lp:~bzoltan/ubuntu-ui-toolkit/landing_28-05
Diff against target: 354 lines (+210/-27)
9 files modified
modules/Ubuntu/Components/PageStack.qml (+1/-0)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_common.py (+16/-0)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py (+0/-17)
tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_header.py (+2/-9)
tests/autopilot/ubuntuuitoolkit/fixture_setup.py (+45/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/CustomMainView.qml (+23/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.HeaderInCustomMainViewTestCase.qml (+24/-0)
tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.py (+27/-0)
tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py (+72/-1)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/fix1324556-get_top_container
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Pending
Ubuntu SDK team Pending
Review via email: mp+221491@code.launchpad.net

This proposal supersedes a proposal from 2014-05-29.

This proposal has been superseded by a proposal from 2014-05-30.

Commit message

On the autopilot Header helper, do not assume that the top container will be a MainView.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:1092
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/306/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/575
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/525
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/138
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/138
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/138/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/138
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1020
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1105
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1105/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7914
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/465
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/663
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/663/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/306/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:1096
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/307/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/578
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/528/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/139
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/139
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/139/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/139
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1022
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1113
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1113/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7920
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/468/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/667
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/667/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/307/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:1097
http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/308/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/581/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/530
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-amd64-ci/140
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/140
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-armhf-ci/140/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-utopic-i386-ci/140
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1026/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1119
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1119/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/7930
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/470
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/669
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/669/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-sdk-team-ubuntu-ui-toolkit-staging-ci/308/rebuild

review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/PageStack.qml'
2--- modules/Ubuntu/Components/PageStack.qml 2014-05-13 09:09:35 +0000
3+++ modules/Ubuntu/Components/PageStack.qml 2014-05-30 07:40:10 +0000
4@@ -192,6 +192,7 @@
5 */
6 default property alias data: inactiveNode.data
7 PageTreeNode {
8+ anchors.fill: parent
9 id: inactiveNode
10 active: false
11 }
12
13=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_common.py'
14--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_common.py 2014-04-29 23:03:58 +0000
15+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_common.py 2014-05-30 07:40:10 +0000
16@@ -111,3 +111,19 @@
17 raise ToolkitException(
18 "The element is not contained in a Flickable so it can't be "
19 "swiped into view.")
20+
21+ def _get_top_container(self):
22+ """Return the top-most container with a globalRect."""
23+ root = self.get_root_instance()
24+ parent = self.get_parent()
25+ top_container = None
26+ while parent.id != root.id:
27+ if hasattr(parent, 'globalRect'):
28+ top_container = parent
29+
30+ parent = parent.get_parent()
31+
32+ if top_container is None:
33+ raise ToolkitException('Could not find the top-most container.')
34+ else:
35+ return top_container
36
37=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py'
38--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py 2014-05-20 07:31:55 +0000
39+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_flickable.py 2014-05-30 07:40:10 +0000
40@@ -51,23 +51,6 @@
41 containers = [self._get_top_container(), self]
42 return containers
43
44- def _get_top_container(self):
45- """Return the top-most container with a globalRect."""
46- root = self.get_root_instance()
47- parent = self.get_parent()
48- top_container = None
49- while parent.id != root.id:
50- if hasattr(parent, 'globalRect'):
51- top_container = parent
52-
53- parent = parent.get_parent()
54-
55- if top_container is None:
56- raise _common.ToolkitException(
57- "Couldn't find the top-most container.")
58- else:
59- return top_container
60-
61 def _is_child_visible(self, child, containers):
62 """Check if the center of the child is visible.
63
64
65=== modified file 'tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_header.py'
66--- tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_header.py 2014-05-13 12:43:31 +0000
67+++ tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_header.py 2014-05-30 07:40:10 +0000
68@@ -21,7 +21,6 @@
69
70 from ubuntuuitoolkit._custom_proxy_objects import (
71 _common,
72- _mainview,
73 _tabbar
74 )
75
76@@ -35,13 +34,6 @@
77 class Header(_common.UbuntuUIToolkitCustomProxyObjectBase):
78 """Header Autopilot emulator."""
79
80- def __init__(self, *args):
81- super(Header, self).__init__(*args)
82- # XXX we need a better way to keep reference to the main view.
83- # --elopio - 2014-02-26
84- self.main_view = self.get_root_instance().select_single(
85- _mainview.MainView)
86-
87 def _show_if_not_visible(self):
88 if not self._is_visible():
89 self._show()
90@@ -53,8 +45,9 @@
91 # FIXME This will fail if the header is not linked to a flickable that
92 # fills the main view. The header has a flickable property but it
93 # can't be read by autopilot. See bug http://pad.lv/1318829
94+ top_container = self._get_top_container()
95 start_x = stop_x = (self.globalRect.x + self.globalRect.width) // 2
96- start_y = self.main_view.globalRect.y + 5
97+ start_y = top_container.globalRect.y + 5
98 stop_y = start_y + self.globalRect.height
99 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
100 self.y.wait_for(0)
101
102=== modified file 'tests/autopilot/ubuntuuitoolkit/fixture_setup.py'
103--- tests/autopilot/ubuntuuitoolkit/fixture_setup.py 2014-04-23 08:50:20 +0000
104+++ tests/autopilot/ubuntuuitoolkit/fixture_setup.py 2014-05-30 07:40:10 +0000
105@@ -16,6 +16,7 @@
106
107 import copy
108 import os
109+import shutil
110 import tempfile
111
112 import fixtures
113@@ -118,3 +119,47 @@
114 original_value)
115 else:
116 self.addCleanup(environment.unset_initctl_env_var, variable)
117+
118+
119+class FakeHome(fixtures.Fixture):
120+
121+ # We copy the Xauthority file to allow executions using XVFB. If it is not
122+ # on the user's HOME directory, nothing will happen.
123+ should_copy_xauthority_file = True
124+
125+ def __init__(self, directory=None):
126+ super(FakeHome, self).__init__()
127+ self.directory = directory
128+
129+ def setUp(self):
130+ super(FakeHome, self).setUp()
131+ self.directory = self._make_directory_if_not_specified()
132+ if self.should_copy_xauthority_file:
133+ self._copy_xauthority_file(self.directory)
134+ # We patch both environment variables so it works on the desktop and on
135+ # the phone.
136+ self.useFixture(
137+ InitctlEnvironmentVariable(HOME=self.directory))
138+ self.useFixture(
139+ fixtures.EnvironmentVariable('HOME', newvalue=self.directory))
140+
141+ def _make_directory_if_not_specified(self):
142+ if self.directory is None:
143+ parent_directory = os.path.join(
144+ os.environ.get('HOME'), 'autopilot', 'fakeenv')
145+ if not os.path.exists(parent_directory):
146+ os.makedirs(parent_directory)
147+ temp_dir_fixture = fixtures.TempDir(parent_directory)
148+ self.useFixture(temp_dir_fixture)
149+ return temp_dir_fixture.path
150+ else:
151+ return self.directory
152+
153+ def _copy_xauthority_file(self, directory):
154+ """Copy the .Xauthority file if it exists in the user's home."""
155+ xauthority_file_path = os.path.join(
156+ os.environ.get('HOME'), '.Xauthority')
157+ if os.path.isfile(xauthority_file_path):
158+ shutil.copyfile(
159+ xauthority_file_path,
160+ os.path.join(directory, '.Xauthority'))
161
162=== added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/CustomMainView.qml'
163--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/CustomMainView.qml 1970-01-01 00:00:00 +0000
164+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/CustomMainView.qml 2014-05-30 07:40:10 +0000
165@@ -0,0 +1,23 @@
166+/*
167+ * Copyright 2014 Canonical Ltd.
168+ *
169+ * This program is free software; you can redistribute it and/or modify
170+ * it under the terms of the GNU Lesser General Public License as published by
171+ * the Free Software Foundation; version 3.
172+ *
173+ * This program is distributed in the hope that it will be useful,
174+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
175+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
176+ * GNU Lesser General Public License for more details.
177+ *
178+ * You should have received a copy of the GNU Lesser General Public License
179+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
180+ */
181+
182+import QtQuick 2.0
183+import Ubuntu.Components 0.1
184+
185+MainView {
186+ objectName: "overview"
187+ property string test
188+}
189
190=== added file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.HeaderInCustomMainViewTestCase.qml'
191--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.HeaderInCustomMainViewTestCase.qml 1970-01-01 00:00:00 +0000
192+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.HeaderInCustomMainViewTestCase.qml 2014-05-30 07:40:10 +0000
193@@ -0,0 +1,24 @@
194+/*
195+ * Copyright 2014 Canonical Ltd.
196+ *
197+ * This program is free software; you can redistribute it and/or modify
198+ * it under the terms of the GNU Lesser General Public License as published by
199+ * the Free Software Foundation; version 3.
200+ *
201+ * This program is distributed in the hope that it will be useful,
202+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
203+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204+ * GNU Lesser General Public License for more details.
205+ *
206+ * You should have received a copy of the GNU Lesser General Public License
207+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
208+ */
209+
210+import QtQuick 2.0
211+import Ubuntu.Components 1.1
212+
213+CustomMainView {
214+
215+ objectName: 'mainView'
216+
217+}
218
219=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.py'
220--- tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.py 2014-05-20 08:56:28 +0000
221+++ tests/autopilot/ubuntuuitoolkit/tests/custom_proxy_objects/test_header.py 2014-05-30 07:40:10 +0000
222@@ -14,6 +14,8 @@
223 # You should have received a copy of the GNU Lesser General Public License
224 # along with this program. If not, see <http://www.gnu.org/licenses/>.
225
226+import os
227+
228 import ubuntuuitoolkit
229 from ubuntuuitoolkit import tests
230
231@@ -157,3 +159,28 @@
232
233 # only three actions are visible
234 self.assertEqual(overflow_button.visible, False)
235+
236+
237+class CustomMainView(ubuntuuitoolkit.MainView):
238+ """Autopilot helper for a custom main view."""
239+
240+
241+class HeaderInCustomMainViewTestCase(tests.QMLFileAppTestCase):
242+
243+ path = os.path.abspath(__file__)
244+ dir_path = os.path.dirname(path)
245+ test_qml_file_path = os.path.join(
246+ dir_path, 'test_header.HeaderInCustomMainViewTestCase.qml')
247+
248+ @property
249+ def main_view(self):
250+ return self.app.select_single(CustomMainView)
251+
252+ def test_get_header_from_custom_main_view(self):
253+ """Test that we can get the header from a custom main view.
254+
255+ This prevents a regression of http://pad.lv/1324556.
256+
257+ """
258+ header = self.main_view.get_header()
259+ self.assertIsInstance(header, ubuntuuitoolkit.Header)
260
261=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py'
262--- tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py 2014-03-10 16:51:01 +0000
263+++ tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py 2014-05-30 07:40:10 +0000
264@@ -15,6 +15,7 @@
265 # along with this program. If not, see <http://www.gnu.org/licenses/>.
266
267 import os
268+import tempfile
269
270 try:
271 # Python 3.
272@@ -24,7 +25,7 @@
273 import mock
274 import testtools
275 from autopilot import testcase as autopilot_testcase
276-from testtools.matchers import Contains, Not, FileExists
277+from testtools.matchers import Contains, FileExists, Not
278
279 from ubuntuuitoolkit import base, environment, fixture_setup
280
281@@ -233,3 +234,73 @@
282 self.assertEqual(
283 'original test value',
284 environment.get_initctl_env_var('testenvvarforfixture'))
285+
286+
287+class FakeHomeTestCase(testtools.TestCase):
288+
289+ def test_fake_home_fixture_patches_initctl_env_var(self):
290+ original_home = environment.get_initctl_env_var('HOME')
291+ fake_home = original_home + 'fake'
292+ result = testtools.TestResult()
293+
294+ def inner_test():
295+ class TestWithFakeHome(testtools.TestCase):
296+ def test_it(self):
297+ fake_home_fixture = fixture_setup.FakeHome(fake_home)
298+ fake_home_fixture.should_copy_xauthority_file = False
299+ self.useFixture(fake_home_fixture)
300+ self.assertEqual(
301+ fake_home, environment.get_initctl_env_var('HOME'))
302+ return TestWithFakeHome('test_it')
303+
304+ inner_test().run(result)
305+
306+ self.assertTrue(
307+ result.wasSuccessful(),
308+ 'Failed to fake the home: {}'.format(result.errors))
309+ self.assertEqual(
310+ original_home,
311+ environment.get_initctl_env_var('HOME'))
312+
313+ def test_fake_home_fixture_patches_env_var(self):
314+ original_home = os.environ.get('HOME')
315+ fake_home = tempfile.gettempdir()
316+ result = testtools.TestResult()
317+
318+ def inner_test():
319+ class TestWithFakeHome(testtools.TestCase):
320+ def test_it(self):
321+ fake_home_fixture = fixture_setup.FakeHome(fake_home)
322+ fake_home_fixture.should_copy_xauthority_file = False
323+ self.useFixture(fake_home_fixture)
324+ self.assertEqual(
325+ fake_home, os.environ.get('HOME'))
326+ return TestWithFakeHome('test_it')
327+
328+ inner_test().run(result)
329+
330+ self.assertTrue(
331+ result.wasSuccessful(),
332+ 'Failed to fake the home: {}'.format(result.failures))
333+ self.assertEqual(original_home, os.environ.get('HOME'))
334+
335+ def test_fake_home_fixture_must_create_default_directory(self):
336+ original_home = os.environ.get('HOME')
337+ self.useFixture(fixture_setup.FakeHome())
338+
339+ home_parent_directory, _ = os.path.split(os.environ.get('HOME'))
340+ self.assertEqual(
341+ home_parent_directory,
342+ os.path.join(original_home, 'autopilot', 'fakeenv'))
343+
344+ def test_fake_home_fixture_must_copy_xauthority(self):
345+ # Fake the home first so we don't write the xauthority on the real
346+ # home.
347+ self.useFixture(fixture_setup.FakeHome())
348+
349+ open(os.path.join(os.environ.get('HOME'), '.Xauthority')).close()
350+
351+ self.useFixture(fixture_setup.FakeHome())
352+ self.assertTrue(
353+ os.path.exists(
354+ os.path.join(os.environ.get('HOME'), '.Xauthority')))

Subscribers

People subscribed via source and target branches

to all changes: