on xenial help sign in
fix up mocks and add tests
commitd4f11db350dc2f9b1a944898a20cb6a6d566fe3d authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 23 Jun 2015, 19:40 (11 years ago) parenta54da5015d3b84
15 files changed+152−60
qml/Components/UnityInputInfo/UnityInputInfo.qml+3 qml/OrientedShell.qml+3−5 qml/Shell.qml+13−15 src/ApplicationArguments.h+5 src/main.cpp+2−1 tests/autopilot/unity8/greeter/tests/test_args.py+6−6 tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo.cpp+33 tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h+7−2 tests/mocks/Unity/InputInfo/mockqinputinfo.cpp+8−2 tests/mocks/Unity/InputInfo/mockqinputinfo.h+4−1 tests/mocks/Unity/InputInfo/plugin.cpp−1 tests/qmltests/Tutorial/tst_Tutorial.qml+3−10 tests/qmltests/tst_OrientedShell.qml+65−13 tests/qmltests/tst_Shell.qml−2 tests/qmltests/tst_ShellWithPin.qml−2
qml/Components/UnityInputInfo/UnityInputInfo.qml+3
@@ -8,6 +8,8 @@ Item {
88 readonly property alias mice: priv.miceCount
99 readonly property alias keyboards: priv.keyboardCount
1010
11+ property alias inputInfo: inputInfo
12+
1113 QtObject {
1214 id: priv
1315
@@ -45,6 +47,7 @@ Item {
4547
4648 InputDeviceInfo {
4749 id: inputInfo
50+ objectName: "inputDeviceInfo"
4851
4952 onNewDevice: {
5053 var device = inputInfo.get(inputInfo.indexOf(devicePath));
qml/OrientedShell.qml+3−5
@@ -41,14 +41,11 @@ Rectangle {
4141 name: applicationArguments.deviceName
4242 }
4343
44− GSettings {
45− id: oskSettings
46− schema.id: "com.canonical.keyboard.maliit"
47− }
48−
4944
5045 // to be overwritten by tests
5146 property var usageModeSettings: GSettings { schema.id: "com.canonical.Unity8" }
47+ property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
48+
5249 property int physicalOrientation: Screen.orientation
5350 property bool orientationLocked: OrientationLock.enabled
5451 property var orientationLock: OrientationLock
@@ -158,6 +155,7 @@ Rectangle {
158155 nativeOrientation: root.nativeOrientation
159156 nativeWidth: root.width
160157 nativeHeight: root.height
158+ mode: applicationArguments.mode
161159
162160 // TODO: Factor in the connected input devices (eg: physical keyboard, mouse, touchscreen),
163161 // what's the output device (eg: big TV, desktop monitor, phone display), etc.
qml/Shell.qml+13−15
@@ -55,6 +55,7 @@ Item {
5555 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
5656 property bool beingResized
5757 property string usageScenario: "phone" // supported values: "phone", "tablet" or "desktop"
58+ property string mode: "full-greeter"
5859 function updateFocusedAppOrientation() {
5960 applicationsDisplayLoader.item.updateFocusedAppOrientation();
6061 }
@@ -68,9 +69,9 @@ Item {
6869
6970 readonly property bool orientationChangesEnabled: panel.indicators.fullyClosed
7071 && (applicationsDisplayLoader.item && applicationsDisplayLoader.item.orientationChangesEnabled)
71− && !greeter.animating
72+ && (!greeter || !greeter.animating)
7273
73− readonly property bool showingGreeter: greeter.shown
74+ readonly property bool showingGreeter: greeter && greeter.shown
7475
7576 property bool startingUp: true
7677 Timer { id: finishStartUpTimer; interval: 500; onTriggered: startingUp = false }
@@ -79,7 +80,7 @@ Item {
7980 if (startingUp) {
8081 // Ensure we don't rotate during start up
8182 return Qt.PrimaryOrientation;
82− } else if (greeter.shown) {
83+ } else if (greeter && greeter.shown) {
8384 return Qt.PrimaryOrientation;
8485 } else if (mainApp) {
8586 return mainApp.supportedOrientations;
@@ -101,16 +102,13 @@ Item {
101102
102103 // Disable everything while greeter is waiting, so that the user can't swipe
103104 // the greeter or launcher until we know whether the session is locked.
104− enabled: !greeter.waiting
105+ enabled: greeter && !greeter.waiting
105106
106107 property real edgeSize: units.gu(2)
107108 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
108109 property url background: asImageTester.status == Image.Ready ? asImageTester.source
109110 : gsImageTester.status == Image.Ready ? gsImageTester.source : defaultBackground
110111
111− // This is _only_ used to expose the property to autopilot tests
112− readonly property string testShellMode: shellMode
113−
114112 readonly property alias greeter: greeterLoader.item
115113
116114 function activateApplication(appId) {
@@ -264,7 +262,7 @@ Item {
264262 ? "phone"
265263 : shell.usageScenario
266264 source: {
267− if(shellMode === "greeter") {
265+ if(shell.mode === "greeter") {
268266 return "Stages/ShimStage.qml"
269267 } else if (applicationsDisplayLoader.usageScenario === "phone") {
270268 return "Stages/PhoneStage.qml";
@@ -276,7 +274,7 @@ Item {
276274 }
277275
278276 property bool interactive: tutorial.spreadEnabled
279− && !greeter.shown
277+ && (!greeter || !greeter.shown)
280278 && panel.indicators.fullyClosed
281279 && launcher.progress == 0
282280 && !notifications.useModal
@@ -307,12 +305,12 @@ Item {
307305 Binding {
308306 target: applicationsDisplayLoader.item
309307 property: "spreadEnabled"
310− value: tutorial.spreadEnabled && !greeter.hasLockedApp
308+ value: tutorial.spreadEnabled && (!greeter || !greeter.hasLockedApp)
311309 }
312310 Binding {
313311 target: applicationsDisplayLoader.item
314312 property: "inverseProgress"
315− value: greeter.locked ? 0 : launcher.progress
313+ value: greeter && greeter.locked ? 0 : launcher.progress
316314 }
317315 Binding {
318316 target: applicationsDisplayLoader.item
@@ -422,7 +420,7 @@ Item {
422420 id: greeterLoader
423421 anchors.fill: parent
424422 anchors.topMargin: panel.panelHeight
425− sourceComponent: shellMode != "shell" ? integratedGreeter :
423+ sourceComponent: shell.mode != "shell" ? integratedGreeter :
426424 Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
427425 onLoaded: {
428426 item.objectName = "greeter"
@@ -434,7 +432,7 @@ Item {
434432 Greeter {
435433
436434 hides: [launcher, panel.indicators]
437− tabletMode: shell.sideStageEnabled
435+ tabletMode: shell.usageScenario != "phone"
438436 launcherOffset: launcher.progress
439437 forcedUnlock: tutorial.running
440438 background: shell.background
@@ -550,8 +548,8 @@ Item {
550548 indicators {
551549 hides: [launcher]
552550 available: tutorial.panelEnabled
553− && (!greeter.locked || AccountsService.enableIndicatorsWhileLocked)
554− && !greeter.hasLockedApp
551+ && ((!greeter || !greeter.locked) || AccountsService.enableIndicatorsWhileLocked)
552+ && (!greeter || !greeter.hasLockedApp)
555553 contentEnabled: tutorial.panelContentEnabled
556554 width: parent.width > units.gu(60) ? units.gu(40) : parent.width
557555
src/ApplicationArguments.h+5
@@ -27,14 +27,19 @@ class ApplicationArguments : public QObject
2727{
2828 Q_OBJECT
2929 Q_PROPERTY(QString deviceName READ deviceName CONSTANT)
30+ Q_PROPERTY(QString mode READ mode CONSTANT)
3031public:
3132 ApplicationArguments(QObject *parent = nullptr);
3233
3334 void setDeviceName(QString deviceName) { m_deviceName = deviceName; }
3435 QString deviceName() const { return m_deviceName; }
3536
37+ void setMode(QString mode) { m_mode = mode; }
38+ QString mode() const { return m_mode; }
39+
3640private:
3741 QString m_deviceName;
42+ QString m_mode;
3843};
3944
4045#endif // APPLICATION_ARGUMENTS_H
src/main.cpp+2−1
@@ -60,6 +60,8 @@ int main(int argc, const char *argv[])
6060 qmlArgs.setDeviceName(QString(buffer));
6161 }
6262
63+ qmlArgs.setMode(parser.mode());
64+
6365 // The testability driver is only loaded by QApplication but not by QGuiApplication.
6466 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
6567 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
@@ -92,7 +94,6 @@ int main(int argc, const char *argv[])
9294
9395 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
9496 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
95− view->rootContext()->setContextProperty("shellMode", parser.mode());
9697 if (parser.hasFrameless()) {
9798 view->setFlags(Qt::FramelessWindowHint);
9899 }
tests/autopilot/unity8/greeter/tests/test_args.py+6−6
@@ -28,27 +28,27 @@ class GreeterArgsTest(GreeterTestCase):
2828 def test_full_greeter_mode(self):
2929 unity_proxy = self.launch_unity(mode='full-greeter')
3030 shell = self.get_shell(unity_proxy)
31− self.assertTrue(shell.testShellMode == 'full-greeter')
31+ self.assertTrue(shell.mode == 'full-greeter')
3232
3333 def test_full_shell_mode(self):
3434 unity_proxy = self.launch_unity(mode='full-shell')
3535 shell = self.get_shell(unity_proxy)
36− self.assertTrue(shell.testShellMode == 'full-shell')
36+ self.assertTrue(shell.mode == 'full-shell')
3737
3838 def test_greeter_mode(self):
3939 unity_proxy = self.launch_unity(mode='greeter')
4040 shell = self.get_shell(unity_proxy)
41− self.assertTrue(shell.testShellMode == 'greeter')
41+ self.assertTrue(shell.mode == 'greeter')
4242
4343 def test_nonexistent_mode(self):
4444 unity_proxy = self.launch_unity(mode=self.NONEXISTENT_MODE)
4545 shell = self.get_shell(unity_proxy)
46− self.assertTrue(shell.testShellMode == self.DEFAULT_SHELL_MODE,
46+ self.assertTrue(shell.mode == self.DEFAULT_SHELL_MODE,
4747 "Shell mode was {} but should have been {}"
48− .format(shell.testShellMode,
48+ .format(shell.mode,
4949 self.DEFAULT_SHELL_MODE))
5050
5151 def test_shell_mode(self):
5252 unity_proxy = self.launch_unity(mode='shell')
5353 shell = self.get_shell(unity_proxy)
54− self.assertTrue(shell.testShellMode == 'shell')
54+ self.assertTrue(shell.mode == 'shell')
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo.cpp+33
@@ -1,6 +1,7 @@
11/****************************************************************************
22**
33** Copyright (C) 2015 Jolla.
4+** Copyright (C) 2015 Canonical Ltd.
45** Contact: http://www.qt-project.org/legal
56**
67** This file is part of the QtSystems module of the Qt Toolkit.
@@ -44,6 +45,8 @@ QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
4445 QAbstractListModel(parent),
4546 deviceInfo(new QInputDeviceInfo)
4647{
48+ connect(deviceInfo, &QInputDeviceInfo::deviceAdded,this,&QDeclarativeInputDeviceInfo::addedDevice);
49+ connect(deviceInfo, &QInputDeviceInfo::deviceRemoved,this,&QDeclarativeInputDeviceInfo::removedDevice);
4750}
4851
4952QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
@@ -86,6 +89,36 @@ QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
8689 return inputDevices.value(index);
8790}
8891
92+void QDeclarativeInputDeviceInfo::addMockMouse()
93+{
94+ deviceInfo->addMockDevice(QInputDeviceInfo::Mouse);
95+}
96+
97+void QDeclarativeInputDeviceInfo::addMockKeyboard()
98+{
99+ deviceInfo->addMockDevice(QInputDeviceInfo::Keyboard);
100+}
101+
102+void QDeclarativeInputDeviceInfo::removeMockMouse()
103+{
104+ for (int i = 0; i < inputDevices.count(); i++) {
105+ if (inputDevices.at(i)->types().testFlag(QInputDeviceInfo::Mouse)) {
106+ deviceInfo->removeMockDevice(i);
107+ return;
108+ }
109+ }
110+}
111+
112+void QDeclarativeInputDeviceInfo::removeMockKeyboard()
113+{
114+ for (int i = 0; i < inputDevices.count(); i++) {
115+ if (inputDevices.at(i)->types().testFlag(QInputDeviceInfo::Keyboard)) {
116+ deviceInfo->removeMockDevice(i);
117+ return;
118+ }
119+ }
120+}
121+
89122void QDeclarativeInputDeviceInfo::updateDeviceList()
90123{
91124 QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h+7−2
@@ -1,6 +1,7 @@
11/****************************************************************************
22**
33** Copyright (C) 2015 Jolla.
4+** Copyright (C) 2015 Canoncal Ltd.
45** Contact: http://www.qt-project.org/legal
56**
67** This file is part of the QtSystems module of the Qt Toolkit.
@@ -68,6 +69,12 @@ public:
6869
6970 Q_INVOKABLE QInputDevice *get(int index) const;
7071
72+ // For testing
73+ Q_INVOKABLE void addMockMouse();
74+ Q_INVOKABLE void addMockKeyboard();
75+ Q_INVOKABLE void removeMockMouse();
76+ Q_INVOKABLE void removeMockKeyboard();
77+
7178Q_SIGNALS:
7279 void newDevice(const QString &devicePath);
7380 void deviceRemoved(const QString &devicePath);
@@ -75,8 +82,6 @@ Q_SIGNALS:
7582public Q_SLOTS:
7683 void updateDeviceList();
7784
78−
79−
8085private:
8186 QInputDeviceInfo *deviceInfo;
8287 QVector<QInputDevice *> inputDevices;
tests/mocks/Unity/InputInfo/mockqinputinfo.cpp+8−2
@@ -1,6 +1,6 @@
11/****************************************************************************
22**
3−** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
3+** Copyright (C) 2015 Canonical, Ltd. and/or its subsidiary(-ies).
44** Contact: http://www.qt-project.org/legal
55**
66** This file is part of the QtSystems module of the Qt Toolkit.
@@ -59,7 +59,12 @@ void QInputDevice::setName(const QString &name)
5959
6060QString QInputDevice::devicePath() const
6161{
62− return "/mock/device/path";
62+ return m_devicePath;
63+}
64+
65+void QInputDevice::setDevicePath(const QString &path)
66+{
67+ m_devicePath = path;
6368}
6469
6570QList <int> QInputDevice::buttons() const
@@ -112,6 +117,7 @@ void QInputDeviceInfo::removeMockDevice(int index)
112117void QInputDeviceInfo::addMockDevice(QInputDeviceInfo::InputType inputType)
113118{
114119 QInputDevice *device = new QInputDevice(this);
120+ device->setDevicePath("/mock/device/" + QString::number(m_counter++));
115121 device->setTypes({inputType});
116122 m_list.append(device);
117123 Q_EMIT deviceAdded(device->devicePath());
tests/mocks/Unity/InputInfo/mockqinputinfo.h+4−1
@@ -1,6 +1,6 @@
11/****************************************************************************
22**
3−** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
3+** Copyright (C) 2015 Canonical, Ltd. and/or its subsidiary(-ies).
44** Contact: http://www.qt-project.org/legal
55**
66** This file is part of the QtSystems module of the Qt Toolkit.
@@ -87,6 +87,8 @@ Q_SIGNALS:
8787
8888private:
8989 QVector<QInputDevice*> m_list;
90+
91+ int m_counter = 0;
9092};
9193
9294class QInputDevice : public QObject
@@ -125,6 +127,7 @@ Q_SIGNALS:
125127private:
126128 void setName(const QString &name);
127129 void setTypes(QInputDeviceInfo::InputTypes types);
130+ void setDevicePath(const QString &path);
128131
129132 QString m_name;
130133 QInputDeviceInfo::InputTypes m_types;
tests/mocks/Unity/InputInfo/plugin.cpp−1
@@ -27,7 +27,6 @@ void InputInfoPlugin::registerTypes(const char *uri)
2727{
2828 int major = 0;
2929 int minor = 1;
30− qDebug() << "****************** creating inputplugin";
3130 qmlRegisterType<QDeclarativeInputDeviceInfo>(uri, major, minor, "InputDeviceInfo");
3231 qmlRegisterType<QInputDevice>(uri, major, minor, "InputInfo");
3332}
tests/qmltests/Tutorial/tst_Tutorial.qml+3−10
@@ -17,7 +17,6 @@
1717import QtQuick 2.0
1818import QtTest 1.0
1919import AccountsService 0.1
20−import GSettings 1.0
2120import LightDM 0.1 as LightDM
2221import Ubuntu.Components 1.1
2322import Unity.Application 0.1
@@ -46,11 +45,6 @@ Item {
4645 }
4746 }
4847
49− GSettings {
50− id: unity8Settings
51− schema.id: "com.canonical.Unity8"
52− }
53−
5448 Component.onCompleted: {
5549 // must set the mock mode before loading the Shell
5650 LightDM.Greeter.mockMode = "single-pin";
@@ -73,7 +67,6 @@ Item {
7367 sourceComponent: Component {
7468 Shell {
7569 property string indicatorProfile: "phone"
76− property string shellMode: "full-greeter" /* default */
7770
7871 Component.onDestruction: {
7972 shellLoader.itemDestroyed = true;
@@ -119,7 +112,7 @@ Item {
119112
120113 function init() {
121114 tryCompare(shell, "enabled", true); // enabled by greeter when ready
122− unity8Settings.usageMode = "Staged";
115+
123116 AccountsService.demoEdges = false;
124117 AccountsService.demoEdges = true;
125118 swipeAwayGreeter();
@@ -193,7 +186,7 @@ Item {
193186 }
194187
195188 function checkRightEdge() {
196− if (unity8Settings.usageMode === "Staged") {
189+ if (shell.usageScenario === "phone") {
197190 touchFlick(shell, shell.width, halfHeight, halfWidth, halfHeight);
198191
199192 var stage = findChild(shell, "stage");
@@ -271,7 +264,7 @@ Item {
271264 }
272265
273266 function test_walkthroughOnDesktop() {
274− unity8Settings.usageMode = "Windowed";
267+ shell.usageScenario = "desktop";
275268 var page = goToPage("tutorialLeftFinish");
276269 var tick = findChild(page, "tick");
277270 tap(tick);
tests/qmltests/tst_OrientedShell.qml+65−13
@@ -23,8 +23,10 @@ import Unity.Application 0.1
2323import Unity.Test 0.1
2424import LightDM 0.1 as LightDM
2525import Powerd 0.1
26+import Unity.InputInfo 0.1
2627
2728import "../../qml"
29+import "../../qml/Components/UnityInputInfo"
2830
2931Rectangle {
3032 id: root
@@ -34,19 +36,8 @@ Rectangle {
3436
3537 QtObject {
3638 id: applicationArguments
37−
38− function hasGeometry() {
39− return false;
40− }
41−
42− function width() {
43− return 0;
44− }
45−
46− function height() {
47− return 0;
48− }
4939 property string deviceName: "mako"
40+ property string mode: "full-greeter"
5041 }
5142
5243 QtObject {
@@ -59,6 +50,11 @@ Rectangle {
5950 property string usageMode: usageModeSelector.model[usageModeSelector.selectedIndex]
6051 }
6152
53+ QtObject{
54+ id: mockOskSettings
55+ property bool stayHidden: false;
56+ }
57+
6258 property int physicalOrientation0
6359 property int physicalOrientation90
6460 property int physicalOrientation180
@@ -130,6 +126,7 @@ Rectangle {
130126 OrientedShell {
131127 anchors.fill: parent
132128 usageModeSettings: mockUsageModeSettings
129+ oskSettings: mockOskSettings
133130 physicalOrientation: root.physicalOrientation0
134131 orientationLocked: orientationLockedCheckBox.checked
135132 orientationLock: mockOrientationLock
@@ -305,6 +302,35 @@ Rectangle {
305302 }
306303 }
307304 }
305+
306+ Row {
307+ Button {
308+ text: "Add mouse"
309+ onClicked: {
310+ UnityInputInfo.inputInfo.addMockMouse()
311+ }
312+ }
313+ Button {
314+ text: "Remove mouse"
315+ onClicked: {
316+ UnityInputInfo.inputInfo.removeMockMouse()
317+ }
318+ }
319+ }
320+ Row {
321+ Button {
322+ text: "Add kbd"
323+ onClicked: {
324+ UnityInputInfo.inputInfo.addMockKeyboard()
325+ }
326+ }
327+ Button {
328+ text: "Remove kbd"
329+ onClicked: {
330+ UnityInputInfo.inputInfo.removeMockKeyboard()
331+ }
332+ }
333+ }
308334 }
309335 }
310336
@@ -898,6 +924,33 @@ Rectangle {
898924 tryCompare(shell, "transformRotationAngle", 0);
899925 }
900926
927+ function test_attachRemoveInputDevices() {
928+ usageModeSelector.selectedIndex = 2;
929+ tryCompare(mockUsageModeSettings, "usageMode", "Automatic")
930+
931+ loadShell("mako")
932+ var shell = findChild(orientedShell, "shell");
933+
934+ tryCompare(shell, "usageScenario", "phone");
935+ tryCompare(mockOskSettings, "stayHidden", false);
936+
937+ UnityInputInfo.inputInfo.addMockKeyboard();
938+ tryCompare(shell, "usageScenario", "phone");
939+ tryCompare(mockOskSettings, "stayHidden", true);
940+
941+ UnityInputInfo.inputInfo.addMockMouse();
942+ tryCompare(shell, "usageScenario", "desktop");
943+ tryCompare(mockOskSettings, "stayHidden", true);
944+
945+ UnityInputInfo.inputInfo.removeMockKeyboard();
946+ tryCompare(shell, "usageScenario", "desktop");
947+ tryCompare(mockOskSettings, "stayHidden", false);
948+
949+ UnityInputInfo.inputInfo.removeMockMouse();
950+ tryCompare(shell, "usageScenario", "phone");
951+ tryCompare(mockOskSettings, "stayHidden", false);
952+ }
953+
901954 // angle - rotation angle in degrees clockwise, relative to the primary orientation.
902955 function rotateTo(angle) {
903956 switch (angle) {
@@ -1147,5 +1200,4 @@ Rectangle {
11471200 return found;
11481201 }
11491202 }
1150−
11511203}
tests/qmltests/tst_Shell.qml−2
@@ -81,8 +81,6 @@ Rectangle {
8181 property bool itemDestroyed: false
8282 sourceComponent: Component {
8383 Shell {
84− property string shellMode: "full-greeter" /* default */
85−
8684 usageScenario: usageScenarioSelector.model[usageScenarioSelector.selectedIndex]
8785 orientation: Qt.PortraitOrientation
8886 primaryOrientation: Qt.PortraitOrientation
tests/qmltests/tst_ShellWithPin.qml−2
@@ -69,8 +69,6 @@ Item {
6969 property bool itemDestroyed: false
7070 sourceComponent: Component {
7171 Shell {
72− property string shellMode: "full-greeter" /* default */
73−
7472 Component.onDestruction: {
7573 shellLoader.itemDestroyed = true
7674 }