on xenial help sign in
Added autopilot helpers for the app scope and the app preview.

Install the fake scopes in order to use them on the tests. Fixes: https://bugs.launchpad.net/bugs/1269114. Approved by PS Jenkins bot, Albert Astals Cid, Alejandro J. Cura.

commitf8124452ee9c99cb283898a8feafd83c7952d89d authorLeo Arias <leo.arias@canonical.com> dateMon 20 Jan 2014, 12:56 (13 years ago) parentd3c71aa7df12b2
12 files changed+173−16
debian/control+1 debian/unity8-fake-env.install+1 qml/Dash/Apps/AppPreview.qml+1 tests/autopilot/unity8/shell/emulators/__init__.py+1−1 tests/autopilot/unity8/shell/emulators/dash.py+53−2 tests/autopilot/unity8/shell/tests/test_emulators.py+89−2 tests/mocks/Unity/CMakeLists.txt+9−2 tests/mocks/Unity/fake_applications_scope.cpp+2−1 tests/mocks/Unity/fake_preview.cpp+5−3 tests/mocks/Unity/fake_preview.h+5−2 tests/mocks/Unity/fake_scope.cpp+3−2 tests/mocks/Unity/fake_scope.h+3−1
debian/control+1
@@ -102,6 +102,7 @@ Depends: gir1.2-glib-2.0,
102102 libqt5test5,
103103 libqt5widgets5,
104104 python-evdev,
105+ python-fixtures,
105106 python-gi,
106107 python-mock,
107108 unity8 (>= ${source:Version}),
debian/unity8-fake-env.install+1
@@ -1,2 +1,3 @@
11usr/lib/*/unity8/qml/mocks
2+usr/lib/*/unity8/qml/scopefakes
23usr/share/unity8/mocks
qml/Dash/Apps/AppPreview.qml+1
@@ -97,6 +97,7 @@ GenericPreview {
9797 spacing: units.gu(1)
9898
9999 Label {
100+ objectName: "descriptionLabel"
100101 anchors { left: parent.left; right: parent.right }
101102 text: root.previewData.description
102103 fontSize: "medium"
tests/autopilot/unity8/shell/emulators/__init__.py+1−1
@@ -25,7 +25,7 @@ class UnityEmulatorBase(introspection.CustomEmulatorBase):
2525
2626 def __init__(self, *args):
2727 super(UnityEmulatorBase, self).__init__(*args)
28− self.pointing_device = input.Touch.create()
28+ self.pointing_device = input.Pointer(device=input.Touch.create())
2929
3030
3131class UnityEmulatorException(Exception):
tests/autopilot/unity8/shell/emulators/dash.py+53−2
@@ -138,8 +138,59 @@ class Dash(emulators.UnityEmulatorBase):
138138
139139
140140class GenericScopeView(emulators.UnityEmulatorBase):
141− """Autopilot emulators for generic scopes."""
141+ """Autopilot emulator for generic scopes."""
142142
143143
144144class DashApps(emulators.UnityEmulatorBase):
145− """Autopilot emulators for the applications scope."""
145+ """Autopilot emulator for the applications scope."""
146+
147+ def get_applications(self, category):
148+ """Return the list of applications on a category.
149+
150+ :parameter category: The name of the category.
151+
152+ """
153+ category_element = self._get_category_element(category)
154+ application_tiles = category_element.select_many('Tile')
155+ # TODO return them on the same order they are displayed.
156+ # --elopio - 2014-1-15
157+ return [tile.text for tile in application_tiles]
158+
159+ def _get_category_element(self, category):
160+ try:
161+ return self.select_single(
162+ 'Base', objectName='dashCategory{}'.format(category))
163+ except dbus.StateNotFoundError:
164+ raise emulators.UnityEmulatorException(
165+ 'No category found with name {}'.format(category))
166+
167+ @autopilot_logging.log_action(logger.info)
168+ def open_preview(self, category, app_name):
169+ """Open the preview of an application.
170+
171+ :parameter category: The name of the category where the application is.
172+ :app_name: The name of the application.
173+
174+ """
175+ category_element = self._get_category_element(category)
176+ icon = category_element.select_single('Tile', text=app_name)
177+ # FIXME some categories need a long press in order to see the preview.
178+ # Some categories do not show previews, like recent apps.
179+ # --elopio - 2014-1-14
180+ self.pointing_device.click_object(icon)
181+ return self.get_root_instance().wait_select_single(AppPreview)
182+
183+
184+class AppPreview(emulators.UnityEmulatorBase):
185+ """Autopilot emulator for the application preview."""
186+
187+ def get_details(self):
188+ """Return the details of the application showed in its preview."""
189+ title = self.select_single('Label', objectName='titleLabel').text
190+ publisher = self.select_single(
191+ 'Label', objectName='subtitleLabel').text
192+ description = self.select_single(
193+ 'Label', objectName='descriptionLabel').text
194+ # TODO return screenshots, icon, rating and reviews.
195+ # --elopio - 2014-1-15
196+ return dict(title=title, publisher=publisher, description=description)
tests/autopilot/unity8/shell/tests/test_emulators.py+89−2
@@ -17,23 +17,43 @@
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818#
1919
20+"""Tests for the Dash autopilot emulators.
21+
22+The autopilot emulators are helpers for tests that check a user journey that
23+involves the dash. The code for some of those tests will not be inside this
24+branch, but in projects that depend on unity or that test the whole system
25+integration. So, we need to test the helpers in order to make sure that we
26+don't break them for those external projects.
27+
28+"""
29+
30+import os
31+import sysconfig
32+
2033import mock
2134
35+import fixtures
36+from testtools.matchers import Contains, HasLength
37+
38+import unity8
2239from unity8 import process_helpers
2340from unity8.shell import emulators, tests
2441from unity8.shell.emulators import dash as dash_emulators
2542
2643
27−class DashEmulatorTestCase(tests.UnityTestCase):
44+class DashBaseTestCase(tests.UnityTestCase):
2845
2946 scenarios = tests._get_device_emulation_scenarios()
3047
3148 def setUp(self):
32− super(DashEmulatorTestCase, self).setUp()
49+ super(DashBaseTestCase, self).setUp()
3350 unity_proxy = self.launch_unity()
3451 process_helpers.unlock_unity(unity_proxy)
3552 self.dash = self.main_window.get_dash()
3653
54+
55+class DashEmulatorTestCase(DashBaseTestCase):
56+
3757 def test_open_unexisting_scope(self):
3858 scope_name = 'unexisting'
3959 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
@@ -118,3 +138,70 @@ class DashEmulatorTestCase(tests.UnityTestCase):
118138 scope = self.dash.open_scope(self._get_scope_name_from_id(scope_id))
119139 self._assert_scope_is_opened(scope, scope_id)
120140 self.assertIsInstance(scope, dash_emulators.DashApps)
141+
142+
143+class DashAppsEmulatorTestCase(DashBaseTestCase):
144+
145+ available_applications = [
146+ 'Title.1', 'Title.21', 'Title.41', 'Title.61', 'Title.81',
147+ 'Title.101', 'Title.121', 'Title.141', 'Title.161', 'Title.181',
148+ 'Title.201', 'Title.221', 'Title.241', 'Title.261', 'Title.281']
149+
150+ def setUp(self):
151+ self._use_scope_fakes()
152+ super(DashAppsEmulatorTestCase, self).setUp()
153+ self.applications_scope = self.dash.open_scope('applications')
154+
155+ def _use_scope_fakes(self):
156+ self.useFixture(
157+ fixtures.EnvironmentVariable(
158+ 'QML2_IMPORT_PATH',
159+ newvalue=self._get_fake_scopes_library_path()))
160+
161+ def _get_fake_scopes_library_path(self):
162+ if unity8.running_installed_tests():
163+ mock_path = 'qml/scopefakes/'
164+ else:
165+ mock_path = os.path.join(
166+ '../lib/', sysconfig.get_config_var('MULTIARCH'),
167+ 'unity8/qml/scopefakes/')
168+ lib_path = unity8.get_lib_path()
169+ ld_library_path = os.path.abspath(os.path.join(lib_path, mock_path))
170+
171+ if not os.path.exists(ld_library_path):
172+ raise RuntimeError(
173+ 'Expected library path does not exists: %s.' % (
174+ ld_library_path))
175+ return ld_library_path
176+
177+ def test_get_applications_with_unexisting_category(self):
178+ exception = self.assertRaises(
179+ emulators.UnityEmulatorException,
180+ self.applications_scope.get_applications,
181+ 'unexisting category')
182+
183+ self.assertEqual(
184+ 'No category found with name unexisting category', str(exception))
185+
186+ def test_get_applications_should_return_list_with_names(self):
187+ category = 'installed'
188+ expected_apps_count = self._get_number_of_application_slots(category)
189+ expected_applications = self.available_applications[
190+ :expected_apps_count]
191+
192+ applications = self.applications_scope.get_applications(category)
193+
194+ self.assertThat(applications, HasLength(expected_apps_count))
195+ for expected in expected_applications:
196+ self.assertThat(applications, Contains(expected))
197+
198+ def _get_number_of_application_slots(self, category):
199+ category_element = self.applications_scope._get_category_element(
200+ category)
201+ grid = category_element.select_single('GenericFilterGrid')
202+ return grid.columns * grid.rows
203+
204+ def test_open_preview(self):
205+ preview = self.applications_scope.open_preview('installed', 'Title.1')
206+ self.assertIsInstance(preview, dash_emulators.AppPreview)
207+ self.assertTrue(preview.isCurrent)
tests/mocks/Unity/CMakeLists.txt+9−2
@@ -1,5 +1,7 @@
11add_subdirectory(Application)
22add_subdirectory(Indicators)
3+add_subdirectory(Launcher)
4+add_subdirectory(Notifications)
35
46pkg_search_module(DEE dee-1.0 REQUIRED)
57pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
@@ -41,5 +43,10 @@ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
4143 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
4244 )
4345
44−add_subdirectory(Launcher)
45−add_subdirectory(Notifications)
46+install(TARGETS FakeUnityQml
47+ DESTINATION ${SHELL_INSTALL_QML}/scopefakes/Unity
48+ )
49+
50+install(FILES qmldir
51+ DESTINATION ${SHELL_INSTALL_QML}/scopefakes/Unity
52+ )
tests/mocks/Unity/fake_applications_scope.cpp+2−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@ ApplicationsScope::ApplicationsScope(bool visible, QObject* parent)
3030 m_id = "applications.scope";
3131 m_name = "Applications";
3232 m_visible = visible;
33+ m_previewRendererName = "preview-application";
3334 m_categories->setModel(createCategoriesModel());
3435}
3536
tests/mocks/Unity/fake_preview.cpp+5−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -16,13 +16,15 @@
1616
1717#include "fake_preview.h"
1818
19−Preview::Preview(QObject *parent): QObject(parent)
19+Preview::Preview(const QString &rendererName, QObject *parent):
20+ QObject(parent),
21+ m_rendererName(rendererName)
2022{
2123}
2224
2325QString Preview::rendererName() const
2426{
25− return "generic-preview";
27+ return m_rendererName;
2628}
2729
2830QString Preview::title() const
tests/mocks/Unity/fake_preview.h+5−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -38,7 +38,7 @@ class Q_DECL_EXPORT Preview : public QObject
3838 Q_PROPERTY(QString image READ image NOTIFY previewChanged)
3939
4040public:
41− explicit Preview(QObject *parent = 0);
41+ explicit Preview(const QString &rendererName, QObject *parent = 0);
4242
4343 QString rendererName() const;
4444 QString title() const;
@@ -55,6 +55,9 @@ public:
5555
5656Q_SIGNALS:
5757 void previewChanged();
58+
59+private:
60+ QString m_rendererName;
5861};
5962
6063Q_DECLARE_METATYPE(Preview *)
tests/mocks/Unity/fake_scope.cpp+3−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
3838 , m_isActive(false)
3939 , m_categories(new Categories(this))
4040 , m_results(new DeeListModel(this))
41+ , m_previewRendererName("preview-generic")
4142{
4243 DeeModel* results_model = create_results_model(20, 300);
4344 m_categories->setResultModel(results_model);
@@ -47,7 +48,7 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
4748 m_timer.setInterval(1000);
4849 m_timer.setSingleShot(true);
4950 connect(&m_timer, &QTimer::timeout, [this]() {
50− Preview *p = new Preview(this);
51+ Preview *p = new Preview(m_previewRendererName, this);
5152 Q_EMIT previewReady(p);
5253 });
5354}
tests/mocks/Unity/fake_scope.h+3−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -116,6 +116,8 @@ protected:
116116 bool m_searching;
117117 bool m_isActive;
118118
119+ QString m_previewRendererName;
120+
119121 Categories* m_categories;
120122 DeeListModel* m_results;
121123