on xenial help sign in
Test powerd plugin in tst_Shell.qml
commit3eb3738db49301a0a43942eb51d0a9aca266147d authorMichael Terry <michael.terry@canonical.com> dateThu 8 Aug 2013, 09:58 (13 years ago) parent2a526c6
10 files changed+224−29
Shell.qml+1 tests/mocks/CMakeLists.txt+2−1 tests/mocks/Powerd/CMakeLists.txt+21 tests/mocks/Powerd/Powerd.cpp+24 tests/mocks/Powerd/Powerd.h+37 tests/mocks/Powerd/plugin.cpp+36 tests/mocks/Powerd/plugin.h+35 tests/mocks/Powerd/qmldir+3 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+10−10 tests/qmltests/tst_Shell.qml+55−18
Shell.qml+1
@@ -404,6 +404,7 @@ FocusScope {
404404
405405 Greeter {
406406 id: greeter
407+ objectName: "greeter"
407408
408409 available: true
409410 hides: [launcher, panel.indicators, hud]
tests/mocks/CMakeLists.txt+2−1
@@ -1,6 +1,7 @@
1+add_subdirectory(HudClient)
12add_subdirectory(libusermetrics)
23add_subdirectory(LightDM)
4+add_subdirectory(Powerd)
35add_subdirectory(QMenuModel)
46add_subdirectory(Ubuntu)
57add_subdirectory(Unity)
6−add_subdirectory(HudClient)
tests/mocks/Powerd/CMakeLists.txtnew file+21
@@ -0,0 +1,21 @@
1+add_definitions(-DSM_BUSNAME=sessionBus)
2+
3+add_library(MockPowerd-qml MODULE
4+ plugin.cpp
5+ Powerd.cpp
6+ )
7+
8+qt5_use_modules(MockPowerd-qml Qml)
9+
10+# copy qmldir file into build directory for shadow builds
11+file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
12+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
13+ )
14+
15+install(TARGETS MockPowerd-qml
16+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/Powerd
17+ )
18+
19+install(FILES qmldir
20+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/Powerd
21+ )
tests/mocks/Powerd/Powerd.cppnew file+24
@@ -0,0 +1,24 @@
1+/*
2+ * Copyright (C) 2013 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+ * Author: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#include "Powerd.h"
20+
21+Powerd::Powerd(QObject* parent)
22+ : QObject(parent)
23+{
24+}
tests/mocks/Powerd/Powerd.hnew file+37
@@ -0,0 +1,37 @@
1+/*
2+ * Copyright (C) 2012,2013 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+ * Authors: Gerry Boland <gerry.boland@canonical.com>
17+ * Michael Terry <michael.terry@canonical.com>
18+ */
19+
20+#ifndef UNITY_MOCK_POWERD_H
21+#define UNITY_MOCK_POWERD_H
22+
23+#include <QtCore/QObject>
24+#include <QtDBus/QDBusInterface>
25+
26+class Powerd: public QObject
27+{
28+ Q_OBJECT
29+
30+public:
31+ explicit Powerd(QObject *parent = 0);
32+
33+Q_SIGNALS:
34+ void powerStateChange(int state);
35+};
36+
37+#endif
tests/mocks/Powerd/plugin.cppnew file+36
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright (C) 2012,2013 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+ * Authors: Gerry Boland <gerry.boland@canonical.com>
17+ * Michael Terry <michael.terry@canonical.com>
18+ */
19+
20+#include "plugin.h"
21+#include "Powerd.h"
22+
23+#include <QtQml/QtQml>
24+
25+static QObject *powerd_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
26+{
27+ Q_UNUSED(engine)
28+ Q_UNUSED(scriptEngine)
29+ return new Powerd();
30+}
31+
32+void PowerdPlugin::registerTypes(const char *uri)
33+{
34+ Q_ASSERT(uri == QLatin1String("Powerd"));
35+ qmlRegisterSingletonType<Powerd>(uri, 0, 1, "Powerd", powerd_provider);
36+}
tests/mocks/Powerd/plugin.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2012,2013 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+ * Authors: Gerry Boland <gerry.boland@canonical.com>
17+ * Michael Terry <michael.terry@canonical.com>
18+ */
19+
20+#ifndef MOCK_POWER_PLUGIN_H
21+#define MOCK_POWER_PLUGIN_H
22+
23+#include <QtQml/QQmlEngine>
24+#include <QtQml/QQmlExtensionPlugin>
25+
26+class PowerdPlugin : public QQmlExtensionPlugin
27+{
28+ Q_OBJECT
29+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
30+
31+public:
32+ void registerTypes(const char *uri);
33+};
34+
35+#endif
tests/mocks/Powerd/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Powerd
2+plugin MockPowerd-qml
3+typeinfo plugin.qmltypes
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+10−10
@@ -22,25 +22,25 @@
2222
2323MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
2424{
25− MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
25+ MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app", this);
2626 m_list.append(item);
27− item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera");
27+ item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
2828 m_list.append(item);
29− item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
29+ item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
3030 m_list.append(item);
31− item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
31+ item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook", this);
3232 m_list.append(item);
33− item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
33+ item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser", this);
3434 m_list.append(item);
35− item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
35+ item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
3636 m_list.append(item);
37− item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
37+ item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
3838 m_list.append(item);
39− item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
39+ item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather", this);
4040 m_list.append(item);
41− item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
41+ item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad", this);
4242 m_list.append(item);
43− item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar");
43+ item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
4444 m_list.append(item);
4545}
4646
tests/qmltests/tst_Shell.qml+55−18
@@ -21,6 +21,7 @@ import QtQuick 2.0
2121import QtTest 1.0
2222import Ubuntu.Application 0.1
2323import Unity.Test 0.1 as UT
24+import Powerd 0.1
2425
2526import "../.."
2627
@@ -53,26 +54,29 @@ Item {
5354 when: windowShown
5455
5556 function initTestCase() {
56− // swipe away the greeter/lockscreen
57− var touchX = shell.width - (shell.edgeSize / 2);
58− var touchY = shell.height / 2;
59− touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
60−
61− var dash = findChild(shell, "dash");
62− // wait until the animation has finished
63− tryCompare(dash, "contentScale", 1.0);
64− tryCompare(dash, "opacity", 1.0);
57+ swipeAwayGreeter();
6558 }
6659
6760 function cleanup() {
61+ // If a test invoked the greeter, make sure we swipe it away again
62+ var greeter = findChild(shell, "greeter");
63+ if (greeter.shown)
64+ swipeAwayGreeter();
65+
6866 // kill all (fake) running apps
69− ApplicationManager.mainStageApplications.clear();
70− ApplicationManager.sideStageApplications.clear();
67+ killApps(ApplicationManager.mainStageApplications);
68+ killApps(ApplicationManager.sideStageApplications);
7169
7270 var dashHome = findChild(shell, "DashHome");
7371 swipeUntilScopeViewIsReached(dashHome);
7472 }
7573
74+ function killApps(apps) {
75+ while (apps.count > 0) {
76+ ApplicationManager.stopProcess(apps.get(0));
77+ }
78+ }
79+
7680 /*
7781 Test the effect of a right-edge drag on the dash in 3 situations:
7882 1 - when no application has been launched yet
@@ -100,15 +104,48 @@ Item {
100104 // Minimize that application once again
101105 swipeFromLeftEdge();
102106
103− // kill it
104− ApplicationManager.mainStageApplications.clear();
105−
107+ // Right edge behavior should now be the same as before that app,
108+ // was launched. Manually cleanup beforehand to get to initial
109+ // state.
110+ cleanup();
106111 waitForUIToSettle();
107−
108− // Right edge behavior should now be the same as before that app was launched
109112 checkRightEdgeDragWithNoRunningApps();
110113 }
111114
115+ function test_suspend() {
116+ var greeter = findChild(shell, "greeter");
117+
118+ // Launch an app from the launcher
119+ dragLauncherIntoView();
120+ tapOnAppIconInLauncher();
121+ waitUntilApplicationWindowIsFullyVisible();
122+
123+ var mainApp = ApplicationManager.mainStageFocusedApplication;
124+ tryCompareFunction(function() { return mainApp != null; }, true);
125+
126+ // Now suspend
127+ Powerd.powerStateChange(0);
128+ tryCompare(greeter, "showProgress", 1);
129+ tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
130+
131+ // And wake up
132+ Powerd.powerStateChange(1);
133+ tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
134+ tryCompare(greeter, "showProgress", 1);
135+ }
136+
137+ function swipeAwayGreeter() {
138+ var greeter = findChild(shell, "greeter");
139+ tryCompare(greeter, "showProgress", 1);
140+
141+ var touchX = shell.width - (shell.edgeSize / 2);
142+ var touchY = shell.height / 2;
143+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
144+
145+ // wait until the animation has finished
146+ tryCompare(greeter, "showProgress", 0);
147+ }
148+
112149 /*
113150 Perform a right-edge drag when the Dash is being show and there are
114151 no running/minimized apps to be restored.
@@ -123,8 +160,8 @@ Item {
123160
124161 var dash = findChild(shell, "dash");
125162 // check that dash has normal scale and opacity
126− compare(dash.contentScale, 1.0);
127− compare(dash.opacity, 1.0);
163+ tryCompare(dash.contentScale, 1.0);
164+ tryCompare(dash.opacity, 1.0);
128165
129166 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
130167 true /* beginTouch */, false /* endTouch */);