on xenial help sign in
Add a test for the Powerd plugin shell support.

Approved by Nick Dedekind, PS Jenkins bot.

commitf4fead7cf8722751351b8bc038a248e409da6193 authorMichael Terry <michael.terry@canonical.com> dateWed 14 Aug 2013, 15:53 (13 years ago) parentaf1b5626ee8d3c
10 files changed+221−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+36 tests/mocks/Powerd/plugin.cpp+35 tests/mocks/Powerd/plugin.h+34 tests/mocks/Powerd/qmldir+2 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+10−10 tests/qmltests/tst_Shell.qml+56−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+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: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#ifndef UNITY_MOCK_POWERD_H
20+#define UNITY_MOCK_POWERD_H
21+
22+#include <QtCore/QObject>
23+#include <QtDBus/QDBusInterface>
24+
25+class Powerd: public QObject
26+{
27+ Q_OBJECT
28+
29+public:
30+ explicit Powerd(QObject *parent = 0);
31+
32+Q_SIGNALS:
33+ void powerStateChange(int state);
34+};
35+
36+#endif
tests/mocks/Powerd/plugin.cppnew 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: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#include "plugin.h"
20+#include "Powerd.h"
21+
22+#include <QtQml/QtQml>
23+
24+static QObject *powerd_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
25+{
26+ Q_UNUSED(engine)
27+ Q_UNUSED(scriptEngine)
28+ return new Powerd();
29+}
30+
31+void PowerdPlugin::registerTypes(const char *uri)
32+{
33+ Q_ASSERT(uri == QLatin1String("Powerd"));
34+ qmlRegisterSingletonType<Powerd>(uri, 0, 1, "Powerd", powerd_provider);
35+}
tests/mocks/Powerd/plugin.hnew file+34
@@ -0,0 +1,34 @@
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: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#ifndef MOCK_POWER_PLUGIN_H
20+#define MOCK_POWER_PLUGIN_H
21+
22+#include <QtQml/QQmlEngine>
23+#include <QtQml/QQmlExtensionPlugin>
24+
25+class PowerdPlugin : public QQmlExtensionPlugin
26+{
27+ Q_OBJECT
28+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29+
30+public:
31+ void registerTypes(const char *uri);
32+};
33+
34+#endif
tests/mocks/Powerd/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Powerd
2+plugin MockPowerd-qml
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+56−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,30 @@ 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+ }
66+
6867 // kill all (fake) running apps
69− ApplicationManager.mainStageApplications.clear();
70− ApplicationManager.sideStageApplications.clear();
68+ killApps(ApplicationManager.mainStageApplications);
69+ killApps(ApplicationManager.sideStageApplications);
7170
7271 var dashHome = findChild(shell, "DashHome");
7372 swipeUntilScopeViewIsReached(dashHome);
7473 }
7574
75+ function killApps(apps) {
76+ while (apps.count > 0) {
77+ ApplicationManager.stopProcess(apps.get(0));
78+ }
79+ }
80+
7681 /*
7782 Test the effect of a right-edge drag on the dash in 3 situations:
7883 1 - when no application has been launched yet
@@ -100,15 +105,48 @@ Item {
100105 // Minimize that application once again
101106 swipeFromLeftEdge();
102107
103− // kill it
104− ApplicationManager.mainStageApplications.clear();
105−
108+ // Right edge behavior should now be the same as before that app,
109+ // was launched. Manually cleanup beforehand to get to initial
110+ // state.
111+ cleanup();
106112 waitForUIToSettle();
107−
108− // Right edge behavior should now be the same as before that app was launched
109113 checkRightEdgeDragWithNoRunningApps();
110114 }
111115
116+ function test_suspend() {
117+ var greeter = findChild(shell, "greeter");
118+
119+ // Launch an app from the launcher
120+ dragLauncherIntoView();
121+ tapOnAppIconInLauncher();
122+ waitUntilApplicationWindowIsFullyVisible();
123+
124+ var mainApp = ApplicationManager.mainStageFocusedApplication;
125+ tryCompareFunction(function() { return mainApp != null; }, true);
126+
127+ // Now suspend
128+ Powerd.powerStateChange(0);
129+ tryCompare(greeter, "showProgress", 1);
130+ tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
131+
132+ // And wake up
133+ Powerd.powerStateChange(1);
134+ tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
135+ tryCompare(greeter, "showProgress", 1);
136+ }
137+
138+ function swipeAwayGreeter() {
139+ var greeter = findChild(shell, "greeter");
140+ tryCompare(greeter, "showProgress", 1);
141+
142+ var touchX = shell.width - (shell.edgeSize / 2);
143+ var touchY = shell.height / 2;
144+ touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
145+
146+ // wait until the animation has finished
147+ tryCompare(greeter, "showProgress", 0);
148+ }
149+
112150 /*
113151 Perform a right-edge drag when the Dash is being show and there are
114152 no running/minimized apps to be restored.
@@ -123,8 +161,8 @@ Item {
123161
124162 var dash = findChild(shell, "dash");
125163 // check that dash has normal scale and opacity
126− compare(dash.contentScale, 1.0);
127− compare(dash.opacity, 1.0);
164+ tryCompare(dash.contentScale, 1.0);
165+ tryCompare(dash.opacity, 1.0);
128166
129167 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
130168 true /* beginTouch */, false /* endTouch */);