on xenial help sign in
Fix some tests; add a mock SessionManager plugin to avoid actually switching sessions during a test
commit5a1e855dfe1e7cd25f7011a5bb68438ae7204cbc authorMichael Terry <michael.terry@canonical.com> dateFri 30 Aug 2013, 18:06 (13 years ago) parentb288715
13 files changed+181−63
CMakeLists.txt+1−3 debian/rules+2−1 tests/autopilot/unity8/shell/tests/test_notifications.py−20 tests/mocks/CMakeLists.txt+1 tests/mocks/SessionManager/CMakeLists.txt+19 tests/mocks/SessionManager/SessionManager.cpp+33 tests/mocks/SessionManager/SessionManager.h+41 tests/mocks/SessionManager/plugin.cpp+35 tests/mocks/SessionManager/plugin.h+34 tests/mocks/SessionManager/qmldir+2 tests/plugins/SessionBroadcast/CMakeLists.txt+3−3 tests/plugins/SessionManager/CMakeLists.txt+7−7 tests/qmltests/tst_Shell.qml+3−29
CMakeLists.txt+1−3
@@ -187,10 +187,8 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SHELL_APP}.desktop
187187install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${GREETER_APP}.desktop
188188 DESTINATION ${CMAKE_INSTALL_DATADIR}/lightdm/greeters
189189 )
190−# This next rule should use ${CMAKE_INSTALL_SYSCONFDIR}, but until Debian bug
191−# 719148 is fixed, we need to manually specify /etc
192190install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/51-${GREETER_APP}.conf
193− DESTINATION /etc/lightdm/lightdm.conf.d
191+ DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/lightdm/lightdm.conf.d
194192 )
195193
196194#
debian/rules+2−1
@@ -19,7 +19,8 @@ override_dh_auto_clean:
1919override_dh_auto_configure:
2020 # Debian defines CMAKE_INSTALL_LOCALSTATEDIR as /usr/var, which is wrong.
2121 # So until Debian bug 719148 is fixed, do it ourselves.
22− dh_auto_configure -- -DCMAKE_INSTALL_LOCALSTATEDIR="/var"
22+ dh_auto_configure -- -DCMAKE_INSTALL_LOCALSTATEDIR="/var" \
23+ -DCMAKE_INSTALL_SYSCONFDIR="/etc"
2324
2425override_dh_install:
2526 # install autopilot tests
tests/autopilot/unity8/shell/tests/test_notifications.py−20
@@ -119,8 +119,6 @@ class InteractiveNotificationBase(NotificationsBase):
119119 def test_interactive(self):
120120 """Interactive notification must react upon click on itself."""
121121 self.launch_unity()
122− greeter = self.main_window.get_greeter()
123− greeter.swipe()
124122
125123 notify_list = self._get_notifications_list()
126124
@@ -158,8 +156,6 @@ class InteractiveNotificationBase(NotificationsBase):
158156 def test_sd_incoming_call(self):
159157 """Rejecting a call should make notification expand and offer more options."""
160158 self.launch_unity()
161− greeter = self.main_window.get_greeter()
162− greeter.swipe()
163159
164160 notify_list = self._get_notifications_list()
165161
@@ -334,8 +330,6 @@ class EphemeralNotificationsTests(NotificationsBase):
334330 def test_icon_summary_body(self):
335331 """Notification must display the expected summary and body text."""
336332 self.launch_unity()
337− greeter = self.main_window.get_greeter()
338− greeter.swipe()
339333
340334 notify_list = self._get_notifications_list()
341335
@@ -368,8 +362,6 @@ class EphemeralNotificationsTests(NotificationsBase):
368362 def test_icon_summary(self):
369363 """Notification must display the expected summary and secondary icon."""
370364 self.launch_unity()
371− greeter = self.main_window.get_greeter()
372− greeter.swipe()
373365
374366 notify_list = self._get_notifications_list()
375367
@@ -406,8 +398,6 @@ class EphemeralNotificationsTests(NotificationsBase):
406398 def test_urgency_order(self):
407399 """Notifications must be displayed in order according to their urgency."""
408400 self.launch_unity()
409− greeter = self.main_window.get_greeter()
410− greeter.swipe()
411401
412402 notify_list = self._get_notifications_list()
413403
@@ -497,8 +487,6 @@ class EphemeralNotificationsTests(NotificationsBase):
497487 def test_summary_and_body(self):
498488 """Notification must display the expected summary- and body-text."""
499489 self.launch_unity()
500− greeter = self.main_window.get_greeter()
501− greeter.swipe()
502490
503491 notify_list = self._get_notifications_list()
504492
@@ -523,8 +511,6 @@ class EphemeralNotificationsTests(NotificationsBase):
523511 def test_summary_only(self):
524512 """Notification must display only the expected summary-text."""
525513 self.launch_unity()
526− greeter = self.main_window.get_greeter()
527− greeter.swipe()
528514
529515 notify_list = self._get_notifications_list()
530516
@@ -542,8 +528,6 @@ class EphemeralNotificationsTests(NotificationsBase):
542528 def test_update_notification_same_layout(self):
543529 """Notification must allow updating its contents while being displayed."""
544530 self.launch_unity()
545− greeter = self.main_window.get_greeter()
546− greeter.swipe()
547531
548532 notify_list = self._get_notifications_list()
549533
@@ -581,8 +565,6 @@ class EphemeralNotificationsTests(NotificationsBase):
581565 def test_update_notification_layout_change(self):
582566 """Notification must allow updating its contents and layout while being displayed."""
583567 self.launch_unity()
584− greeter = self.main_window.get_greeter()
585− greeter.swipe()
586568
587569 notify_list = self._get_notifications_list()
588570
@@ -627,8 +609,6 @@ class EphemeralNotificationsTests(NotificationsBase):
627609 def test_append_hint(self):
628610 """Notification has to accumulate body-text using append-hint."""
629611 self.launch_unity()
630− greeter = self.main_window.get_greeter()
631− greeter.swipe()
632612
633613 notify_list = self._get_notifications_list()
634614
tests/mocks/CMakeLists.txt+1
@@ -5,5 +5,6 @@ add_subdirectory(liblightdm)
55add_subdirectory(libusermetrics)
66add_subdirectory(Powerd)
77add_subdirectory(QMenuModel)
8+add_subdirectory(SessionManager)
89add_subdirectory(Ubuntu)
910add_subdirectory(Unity)
tests/mocks/SessionManager/CMakeLists.txtnew file+19
@@ -0,0 +1,19 @@
1+add_library(MockSessionManager-qml MODULE
2+ plugin.cpp
3+ SessionManager.cpp
4+ )
5+
6+qt5_use_modules(MockSessionManager-qml Qml)
7+
8+# copy qmldir file into build directory for shadow builds
9+file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
10+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
11+ )
12+
13+install(TARGETS MockSessionManager-qml
14+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/SessionManager
15+ )
16+
17+install(FILES qmldir
18+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/SessionManager
19+ )
tests/mocks/SessionManager/SessionManager.cppnew file+33
@@ -0,0 +1,33 @@
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 "SessionManager.h"
20+
21+SessionManager::SessionManager(QObject* parent)
22+ : QObject(parent)
23+{
24+}
25+
26+bool SessionManager::active() const
27+{
28+ return true;
29+}
30+
31+void SessionManager::lock()
32+{
33+}
tests/mocks/SessionManager/SessionManager.hnew file+41
@@ -0,0 +1,41 @@
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+ * Authors: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#ifndef UNITY_MOCK_SESSIONMANAGER_H
20+#define UNITY_MOCK_SESSIONMANAGER_H
21+
22+#include <QObject>
23+
24+class SessionManager: public QObject
25+{
26+ Q_OBJECT
27+ Q_PROPERTY(bool active READ active NOTIFY activeChanged FINAL)
28+
29+public:
30+ explicit SessionManager(QObject *parent = 0);
31+
32+ bool active() const;
33+
34+public Q_SLOTS:
35+ void lock();
36+
37+Q_SIGNALS:
38+ void activeChanged();
39+};
40+
41+#endif
tests/mocks/SessionManager/plugin.cppnew file+35
@@ -0,0 +1,35 @@
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+ * Authors: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#include "plugin.h"
20+#include "SessionManager.h"
21+
22+#include <QtQml>
23+
24+static QObject *sessionmanager_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
25+{
26+ Q_UNUSED(engine)
27+ Q_UNUSED(scriptEngine)
28+ return new SessionManager();
29+}
30+
31+void SessionManagerPlugin::registerTypes(const char *uri)
32+{
33+ Q_ASSERT(uri == QLatin1String("SessionManager"));
34+ qmlRegisterSingletonType<SessionManager>(uri, 0, 1, "SessionManager", sessionmanager_provider);
35+}
tests/mocks/SessionManager/plugin.hnew file+34
@@ -0,0 +1,34 @@
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+ * Authors: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#ifndef MOCK_SESSIONMANAGER_PLUGIN_H
20+#define MOCK_SESSIONMANAGER_PLUGIN_H
21+
22+#include <QQmlEngine>
23+#include <QQmlExtensionPlugin>
24+
25+class SessionManagerPlugin : 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/SessionManager/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module SessionManager
2+plugin MockSessionManager-qml
tests/plugins/SessionBroadcast/CMakeLists.txt+3−3
@@ -13,12 +13,12 @@ include_directories(
1313
1414add_definitions(-DSM_BUSNAME=sessionBus)
1515
16−add_executable(mock-server
16+add_executable(sessionbroadcastmock
1717 ${CMAKE_CURRENT_BINARY_DIR}/BroadcastAdaptor.cpp
1818 server.cpp
1919 BroadcastServer.cpp
2020 )
21−qt5_use_modules(mock-server Core DBus)
21+qt5_use_modules(sessionbroadcastmock Core DBus)
2222
2323add_executable(sessionbroadcasttest
2424 ${CMAKE_SOURCE_DIR}/plugins/SessionBroadcast/SessionBroadcast.cpp
@@ -28,7 +28,7 @@ qt5_use_modules(sessionbroadcasttest Core DBus Test)
2828
2929add_test(NAME sessionbroadcasttest
3030 COMMAND dbus-test-runner
31− --task ${CMAKE_CURRENT_BINARY_DIR}/mock-server
31+ --task ${CMAKE_CURRENT_BINARY_DIR}/sessionbroadcastmock
3232 --task-name server
3333 --ignore-return
3434 --task ${CMAKE_CURRENT_BINARY_DIR}/sessionbroadcasttest
tests/plugins/SessionManager/CMakeLists.txt+7−7
@@ -16,7 +16,7 @@ include_directories(
1616
1717add_definitions(-DSM_BUSNAME=sessionBus)
1818
19−add_executable(mock-server
19+add_executable(sessionmanagermock
2020 ${CMAKE_CURRENT_BINARY_DIR}/LightDMSessionAdaptor.cpp
2121 ${CMAKE_CURRENT_BINARY_DIR}/LoginManagerAdaptor.cpp
2222 ${CMAKE_CURRENT_BINARY_DIR}/LoginPropertiesAdaptor.cpp
@@ -26,23 +26,23 @@ add_executable(mock-server
2626 LoginManagerServer.cpp
2727 LoginSessionServer.cpp
2828 )
29−qt5_use_modules(mock-server Core DBus)
29+qt5_use_modules(sessionmanagermock Core DBus)
3030
31−add_executable(test-sessionmanager
31+add_executable(sessionmanagertest
3232 ${CMAKE_SOURCE_DIR}/plugins/SessionManager/SessionManager.cpp
3333 client.cpp
3434 )
35−qt5_use_modules(test-sessionmanager Core DBus Test)
35+qt5_use_modules(sessionmanagertest Core DBus Test)
3636
37−add_test(NAME test-sessionmanager
37+add_test(NAME sessionmanagertest
3838 COMMAND env
3939 XDG_SESSION_ID=sessionid
4040 XDG_SESSION_PATH=/mocksession/lightdm
4141 dbus-test-runner
42− --task ${CMAKE_CURRENT_BINARY_DIR}/mock-server
42+ --task ${CMAKE_CURRENT_BINARY_DIR}/sessionmanagermock
4343 --task-name server
4444 --ignore-return
45− --task ${CMAKE_CURRENT_BINARY_DIR}/test-sessionmanager
45+ --task ${CMAKE_CURRENT_BINARY_DIR}/sessionmanagertest
4646 --task-name client
4747 --wait-for org.freedesktop.login1
4848 )
tests/qmltests/tst_Shell.qml+3−29
@@ -54,17 +54,7 @@ Item {
5454 name: "Shell"
5555 when: windowShown
5656
57− function initTestCase() {
58− swipeAwayGreeter();
59− }
60−
6157 function cleanup() {
62− // If a test invoked the greeter, make sure we swipe it away again
63− var greeter = findChild(shell, "greeter");
64− if (greeter.shown) {
65− swipeAwayGreeter();
66− }
67−
6858 // kill all (fake) running apps
6959 killApps(ApplicationManager.mainStageApplications);
7060 killApps(ApplicationManager.sideStageApplications);
@@ -115,8 +105,6 @@ Item {
115105 }
116106
117107 function test_suspend() {
118− var greeter = findChild(shell, "greeter");
119−
120108 // Launch an app from the launcher
121109 dragLauncherIntoView();
122110 tapOnAppIconInLauncher();
@@ -127,29 +115,15 @@ Item {
127115
128116 // Try to suspend while proximity is engaged...
129117 Powerd.displayPowerStateChange(Powerd.Off, Powerd.UseProximity);
130− tryCompare(greeter, "showProgress", 0);
118+ tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
131119
132120 // Now really suspend
133121 Powerd.displayPowerStateChange(Powerd.Off, 0);
134− tryCompare(greeter, "showProgress", 1);
135122 tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
136123
137124 // And wake up
138125 Powerd.displayPowerStateChange(Powerd.On, 0);
139126 tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
140− tryCompare(greeter, "showProgress", 1);
141− }
142−
143− function swipeAwayGreeter() {
144− var greeter = findChild(shell, "greeter");
145− tryCompare(greeter, "showProgress", 1);
146−
147− var touchX = shell.width - (shell.edgeSize / 2);
148− var touchY = shell.height / 2;
149− touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY);
150−
151− // wait until the animation has finished
152− tryCompare(greeter, "showProgress", 0);
153127 }
154128
155129 /*
@@ -323,8 +297,8 @@ Item {
323297
324298 function test_wallpaper_data() {
325299 return [
326− {tag: "red", url: "tests/data/unity/backgrounds/red.png", expectedUrl: "tests/data/unity/backgrounds/red.png"},
327− {tag: "blue", url: "tests/data/unity/backgrounds/blue.png", expectedUrl: "tests/data/unity/backgrounds/blue.png"},
300+ {tag: "red", url: "../tests/data/unity/backgrounds/red.png", expectedUrl: "tests/data/unity/backgrounds/red.png"},
301+ {tag: "blue", url: "../tests/data/unity/backgrounds/blue.png", expectedUrl: "tests/data/unity/backgrounds/blue.png"},
328302 {tag: "invalid", url: "invalid", expectedUrl: shell.defaultBackground},
329303 {tag: "empty", url: "", expectedUrl: shell.defaultBackground}
330304 ]