on xenial help sign in
Add tests for Shell+Dash interaction

Approved by: Michael Zanetti

commita566a03f0d1074603c3e3d2ef73a060f1de0d862 authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 31 Aug 2015, 10:24 (11 years ago) parentda2e6ab6e10511
6 files changed+166−5
qml/Dash/Dash.qml+3−1 tests/mocks/Unity/DashCommunicator/dashcommunicator.cpp+7−2 tests/mocks/Unity/DashCommunicator/dashcommunicatorservice.cpp+14−1 tests/mocks/Unity/DashCommunicator/dashcommunicatorservice.h+6−1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/tst_DashShell.qml+135
qml/Dash/Dash.qml+3−1
@@ -36,10 +36,12 @@ Showable {
3636 }
3737 }
3838
39+ property bool windowActive: window.active
40+
3941 DashCommunicatorService {
4042 objectName: "dashCommunicatorService"
4143 onSetCurrentScopeRequested: {
42− if (!isSwipe || !window.active || bottomEdgeController.progress != 0 || scopeItem.scope || dashContent.subPageShown) {
44+ if (!isSwipe || !windowActive || bottomEdgeController.progress != 0 || scopeItem.scope || dashContent.subPageShown) {
4345 if (bottomEdgeController.progress != 0 && window.active) animate = false;
4446 dashContent.setCurrentScopeAtIndex(index, animate, true)
4547 backToDashContent()
tests/mocks/Unity/DashCommunicator/dashcommunicator.cpp+7−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2014, 2015 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -16,6 +16,8 @@
1616
1717#include "dashcommunicator.h"
1818
19+#include "dashcommunicatorservice.h"
20+
1921#include <QObject>
2022#include <QDBusConnection>
2123#include <QDBusInterface>
@@ -30,8 +32,11 @@ DashCommunicator::~DashCommunicator()
3032{
3133}
3234
33−
3435void DashCommunicator::setCurrentScope(int index, bool animate, bool reset)
3536{
3637 Q_EMIT setCurrentScopeCalled(index, animate, reset);
38+
39+ if (DashCommunicatorService::theCommunicatorService()) {
40+ DashCommunicatorService::theCommunicatorService()->mockSetCurrentScope(index, animate, reset);
41+ }
3742}
tests/mocks/Unity/DashCommunicator/dashcommunicatorservice.cpp+14−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2014, 2015 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -16,9 +16,17 @@
1616
1717#include "dashcommunicatorservice.h"
1818
19+#include <QDebug>
20+
21+DashCommunicatorService *DashCommunicatorService::m_theCommunicatorService = nullptr;
22+
1923DashCommunicatorService::DashCommunicatorService(QObject *parent):
2024 QObject(parent)
2125{
26+ if (m_theCommunicatorService) {
27+ qFatal("There's already a communicator service, this should not happen!");
28+ }
29+ m_theCommunicatorService = this;
2230}
2331
2432
@@ -27,6 +35,11 @@ DashCommunicatorService::~DashCommunicatorService()
2735
2836}
2937
38+DashCommunicatorService *DashCommunicatorService::theCommunicatorService()
39+{
40+ return m_theCommunicatorService;
41+}
42+
3043void DashCommunicatorService::mockSetCurrentScope(int index, bool animate, bool isSwipe)
3144{
3245 Q_EMIT setCurrentScopeRequested(index, animate, isSwipe);
tests/mocks/Unity/DashCommunicator/dashcommunicatorservice.h+6−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2014, 2015 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -26,11 +26,16 @@ public:
2626 DashCommunicatorService(QObject *parent = 0);
2727 ~DashCommunicatorService();
2828
29+ static DashCommunicatorService *theCommunicatorService();
30+
2931Q_SIGNALS:
3032 void setCurrentScopeRequested(int index, bool animate, bool isSwipe);
3133
3234public Q_SLOTS:
3335 void mockSetCurrentScope(int index, bool animate, bool isSwipe);
36+
37+private:
38+ static DashCommunicatorService *m_theCommunicatorService;
3439};
3540
3641#endif // DBUSUNITYSESSIONSERVICE_H
tests/qmltests/CMakeLists.txt+1
@@ -18,6 +18,7 @@ add_unity8_qmltest(Components Showable)
1818add_unity8_qmltest(Components ZoomableImage)
1919add_unity8_qmltest(Dash Dash)
2020add_unity8_qmltest(Dash DashContent)
21+add_unity8_qmltest(Dash DashShell)
2122add_unity8_qmltest(Dash Card)
2223add_unity8_qmlbenchmark(Dash CardBenchmark 1000)
2324add_unity8_qmltest(Dash CardTool)
tests/qmltests/Dash/tst_DashShell.qmlnew file+135
@@ -0,0 +1,135 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import QtTest 1.0
19+import "../../../qml/Dash"
20+import "../../../qml/"
21+import Ubuntu.Components 1.3
22+import Unity.Test 0.1 as UT
23+
24+Item {
25+ id: root
26+ width: units.gu(80)
27+ height: units.gu(80)
28+
29+ Shell {
30+ id: shell
31+ width: parent.width / 2
32+ height: parent.height
33+ }
34+
35+ Dash {
36+ id: dash
37+ width: parent.width / 2
38+ height: parent.height
39+ x: width
40+ clip: true
41+ }
42+
43+ UT.UnityTestCase {
44+ name: "DashShell"
45+ when: windowShown
46+
47+ readonly property Item dashContent: findChild(dash, "dashContent");
48+ readonly property var scopes: dashContent.scopes
49+
50+ function init() {
51+ dash.windowActive = true;
52+
53+ var greeter = findChild(shell, "greeter");
54+ greeter.forceShow();
55+
56+ // clear and reload the scopes.
57+ scopes.clear();
58+ var dashContentList = findChild(dash, "dashContentList");
59+ verify(dashContentList != undefined);
60+ tryCompare(dashContentList, "count", 0);
61+ scopes.load();
62+ tryCompare(dashContentList, "currentIndex", 0);
63+ tryCompare(dashContentList, "count", 6);
64+ tryCompare(scopes, "loaded", true);
65+ tryCompareFunction(function() {
66+ var mockScope1Loader = findChild(dash, "scopeLoader0");
67+ return mockScope1Loader && mockScope1Loader.item != null; },
68+ true, 15000);
69+ tryCompareFunction(function() {
70+ var mockScope1Loader = findChild(dash, "scopeLoader0");
71+ return mockScope1Loader && mockScope1Loader.status === Loader.Ready; },
72+ true, 15000);
73+ waitForRendering(findChild(dash, "scopeLoader0").item);
74+ }
75+
76+ function test_setShellHome() {
77+ var dashContentList = findChild(dash, "dashContentList");
78+ var startX = dash.width - units.gu(1);
79+ var startY = dash.height / 2;
80+ var stopX = units.gu(1)
81+ var stopY = startY;
82+ waitForRendering(dashContentList);
83+ touchFlick(dash, startX, startY, stopX, stopY);
84+ touchFlick(dash, startX, startY, stopX, stopY);
85+ compare(dashContentList.currentIndex, 2, "Could not flick to scope id 2");
86+
87+ // Flick the greeter away
88+ var startX = shell.width - units.gu(1);
89+ var startY = shell.height / 2;
90+ var stopX = units.gu(1)
91+ var stopY = startY;
92+ touchFlick(shell, startX, startY, stopX, stopY);
93+
94+ // Now do a long launcher movement
95+ touchFlick(shell, stopX, startY, startX, stopY);
96+
97+ var launcher = findChild(shell, "launcher");
98+ var buttonShowDashHome = findChild(launcher, "buttonShowDashHome");
99+ tryCompare(buttonShowDashHome, "enabled", true);
100+ tryCompare(launcher, "visibleWidth", launcher.panelWidth);
101+
102+ // Make sure that opening the launcher doesn't change the scope
103+ compare(dashContentList.currentIndex, 2, "Opening the launcher changed the current scope");
104+
105+ mouseClick(buttonShowDashHome);
106+ tryCompare(dashContentList, "currentIndex", 0);
107+ }
108+
109+ function test_setShortLauncherMoveResetNonActiveDash() {
110+ var dashContentList = findChild(dash, "dashContentList");
111+ var startX = dash.width - units.gu(1);
112+ var startY = dash.height / 2;
113+ var stopX = units.gu(1)
114+ var stopY = startY;
115+ waitForRendering(dashContentList);
116+ touchFlick(dash, startX, startY, stopX, stopY);
117+ touchFlick(dash, startX, startY, stopX, stopY);
118+ compare(dashContentList.currentIndex, 2, "Could not flick to scope id 2");
119+
120+ // Pretend the dash is not active
121+ dash.windowActive = false;
122+
123+ // Flick the greeter away
124+ var startX = shell.width - units.gu(1);
125+ var startY = shell.height / 2;
126+ var stopX = units.gu(1)
127+ var stopY = startY;
128+ touchFlick(shell, startX, startY, stopX, stopY);
129+
130+ // Now do a small launcher movement
131+ touchFlick(shell, stopX, startY, startX, stopY);
132+ compare(dashContentList.currentIndex, 0, "Small launcher move did not reset dash on non active window");
133+ }
134+ }
135+}