on xenial help sign in
Some improvements:

- Make ApplicationManagaer.availableApplications a property instead of a function, so it fits better with declarative (QML) code - List all available applications tst_DesktopStage - Refactor some function naming

commit8d372d5d89318377c1b53e42d9cd737c59ccfd1b authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 16 Mar 2015, 11:11 (12 years ago) parentc33d3d2
4 files changed+47−22
tests/mocks/Unity/Application/ApplicationManager.h+3−1 tests/qmltests/Stages/ApplicationCheckBox.qml+20−1 tests/qmltests/Stages/tst_DesktopStage.qml+23−19 tests/qmltests/Stages/tst_PhoneStage.qml+1−1
tests/mocks/Unity/Application/ApplicationManager.h+3−1
@@ -34,6 +34,7 @@ class ApplicationManager : public ApplicationManagerInterface {
3434 Q_FLAGS(ExecFlags)
3535
3636 Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
37+ Q_PROPERTY(QStringList availableApplications READ availableApplications NOTIFY availableApplicationsChanged)
3738
3839 public:
3940 ApplicationManager(QObject *parent = nullptr);
@@ -75,7 +76,7 @@ class ApplicationManager : public ApplicationManagerInterface {
7576 void setForceDashActive(bool forceDashActive) override;
7677
7778 // Only for testing
78− Q_INVOKABLE QStringList availableApplications();
79+ QStringList availableApplications();
7980 Q_INVOKABLE ApplicationInfo* add(QString appId);
8081
8182 QModelIndex findIndex(ApplicationInfo* application);
@@ -85,6 +86,7 @@ class ApplicationManager : public ApplicationManagerInterface {
8586 Q_SIGNALS:
8687 void focusRequested(const QString &appId);
8788 void emptyChanged(bool empty);
89+ void availableApplicationsChanged(QStringList list);
8890
8991 private Q_SLOTS:
9092 void onWindowCreatedTimerTimeout();
tests/qmltests/Stages/ApplicationCheckBox.qml+20−1
@@ -24,15 +24,23 @@ RowLayout {
2424 property string appId
2525 property alias checked: checkbox.checked
2626
27+ enabled: appId !== "unity8-dash"
28+
2729 Layout.fillWidth: true
2830 CheckBox {
2931 id: checkbox
3032 checked: false
3133 activeFocusOnPress: false
34+ property bool noop: false
3235 onCheckedChanged: {
36+ if (noop) {
37+ return;
38+ }
3339 if (checked) {
34− ApplicationManager.startApplication(root.appId);
40+ var application = ApplicationManager.startApplication(root.appId);
41+ appConnections.target = application;
3542 } else {
43+ appConnections.target = null;
3644 ApplicationManager.stopApplication(root.appId);
3745 }
3846 }
@@ -42,4 +50,15 @@ RowLayout {
4250 color: "white"
4351 anchors.verticalCenter: parent.verticalCenter
4452 }
53+
54+ Connections {
55+ id: appConnections
56+ onStateChanged: {
57+ if (target.state == ApplicationInfoInterface.Stopped) {
58+ checkbox.noop = true;
59+ checkbox.checked = false;
60+ checkbox.noop = false;
61+ }
62+ }
63+ }
4564}
tests/qmltests/Stages/tst_DesktopStage.qml+23−19
@@ -92,13 +92,11 @@ Rectangle {
9292 Column {
9393 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
9494 spacing: units.gu(1)
95− ApplicationCheckBox {
96− id: webbrowserCheckBox
97− appId: "webbrowser-app"
98− }
99− ApplicationCheckBox {
100− id: dialerCheckBox
101− appId: "dialer-app"
95+ Repeater {
96+ model: ApplicationManager.availableApplications
97+ ApplicationCheckBox {
98+ appId: modelData
99+ }
102100 }
103101 }
104102 }
@@ -125,14 +123,20 @@ Rectangle {
125123 // Shell instance gets destroyed.
126124 tryCompare(desktopStageLoader, "itemDestroyed", true);
127125
128− // kill all (fake) running apps
129− webbrowserCheckBox.checked = false;
130− dialerCheckBox.checked = false;
126+ killAllRunningApps();
131127
132128 desktopStageLoader.active = true;
133129 tryCompare(desktopStageLoader, "status", Loader.Ready);
134130 }
135131
132+ function killAllRunningApps() {
133+ while (ApplicationManager.count > 1) {
134+ var appIndex = ApplicationManager.get(0).appId == "unity8-dash" ? 1 : 0
135+ ApplicationManager.stopApplication(ApplicationManager.get(appIndex).appId);
136+ }
137+ compare(ApplicationManager.count, 1)
138+ }
139+
136140 function waitUntilAppSurfaceShowsUp(appId) {
137141 var appWindow = findChild(desktopStage, "appWindow_" + appId);
138142 verify(appWindow);
@@ -141,7 +145,7 @@ Rectangle {
141145 tryCompare(appWindowStates, "state", "surface");
142146 }
143147
144− function rectsOverlap(aLocal, bLocal) {
148+ function rectsIntersect(aLocal, bLocal) {
145149
146150 var a = aLocal.mapToItem(null, 0, 0, aLocal.width, aLocal.height);
147151 var b = bLocal.mapToItem(null, 0, 0, bLocal.width, bLocal.height);
@@ -153,16 +157,16 @@ Rectangle {
153157 }
154158
155159 function test_tappingOnWindowChangesFocusedApp() {
156− webbrowserCheckBox.checked = true;
157− waitUntilAppSurfaceShowsUp(webbrowserCheckBox.appId);
160+ ApplicationManager.startApplication("webbrowser-app");
161+ waitUntilAppSurfaceShowsUp("webbrowser-app");
158162
159− var webbrowserWindow = findChild(desktopStage, "appWindow_" + webbrowserCheckBox.appId);
163+ var webbrowserWindow = findChild(desktopStage, "appWindow_webbrowser-app");
160164 verify(webbrowserWindow);
161165 var dashWindow = findChild(desktopStage, "appWindow_unity8-dash");
162166 verify(dashWindow);
163167
164168 // some sanity check
165− compare(rectsOverlap(dashWindow, webbrowserWindow), false);
169+ compare(rectsIntersect(dashWindow, webbrowserWindow), false);
166170
167171 tap(dashWindow);
168172 compare(dashWindow.application.session.surface.activeFocus, true);
@@ -172,10 +176,10 @@ Rectangle {
172176 }
173177
174178 function test_tappingOnWindowTitleChangesFocusedApp() {
175− webbrowserCheckBox.checked = true;
176− waitUntilAppSurfaceShowsUp(webbrowserCheckBox.appId);
179+ ApplicationManager.startApplication("webbrowser-app");
180+ waitUntilAppSurfaceShowsUp("webbrowser-app");
177181
178− var webbrowserWindow = findChild(desktopStage, "decoratedWindow_" + webbrowserCheckBox.appId);
182+ var webbrowserWindow = findChild(desktopStage, "decoratedWindow_webbrowser-app");
179183 verify(webbrowserWindow);
180184 var webbrowserWindowTitle = findChild(webbrowserWindow, "windowDecorationTitle");
181185 verify(webbrowserWindowTitle);
@@ -185,7 +189,7 @@ Rectangle {
185189 verify(dashWindowTitle);
186190
187191 // some sanity check
188− compare(rectsOverlap(dashWindow, webbrowserWindow), false);
192+ compare(rectsIntersect(dashWindow, webbrowserWindow), false);
189193
190194 tap(dashWindowTitle);
191195 compare(dashWindow.application.session.surface.activeFocus, true);
tests/qmltests/Stages/tst_PhoneStage.qml+1−1
@@ -116,7 +116,7 @@ Item {
116116 function addApps(count) {
117117 if (count == undefined) count = 1;
118118 for (var i = 0; i < count; i++) {
119− var app = ApplicationManager.startApplication(ApplicationManager.availableApplications()[ApplicationManager.count])
119+ var app = ApplicationManager.startApplication(ApplicationManager.availableApplications[ApplicationManager.count])
120120 tryCompare(app, "state", ApplicationInfoInterface.Running)
121121 var spreadView = findChild(phoneStage, "spreadView");
122122 tryCompare(spreadView, "contentX", -spreadView.shift);