on xenial help sign in
Add 'light' property to IndicatorsModel for tests

The qmltests spend a significant amount of time creating the mock indicators on slower hardware. This can take up to 3 seconds per test function on my (2018) laptop, for example. In large test cases like the Shell, it adds up to 35 minutes to complete the test battery... This commit allows returning less data from the mock indicators model, greatly reducing the object creation time for each test function.

commiteba99afd435da916a84278737fcecdfa1dc10597 authorDalton Durst <dalton@ubports.com> dateSun 17 Jan 2021, 10:09 (6 years ago) parentd456639
6 files changed+59−12
plugins/Unity/Indicators/indicatorsmodel.cpp+13 plugins/Unity/Indicators/indicatorsmodel.h+9 qml/OrientedShell.qml+2 qml/Shell.qml+4 tests/mocks/Unity/Indicators/IndicatorsModel.qml+30−12 tests/qmltests/tst_OrientedShell.qml+1
plugins/Unity/Indicators/indicatorsmodel.cpp+13
@@ -103,6 +103,19 @@ void IndicatorsModel::setProfile(const QString &profile)
103103 m_manager->setProfile(profile);
104104}
105105
106+bool IndicatorsModel::light() const
107+{
108+ return m_light;
109+}
110+
111+void IndicatorsModel::setLight(const bool &light)
112+{
113+ if (m_light != light) {
114+ m_light = light;
115+ Q_EMIT lightChanged();
116+ }
117+}
118+
106119/*!
107120 \qmlmethod IndicatorsModel::unload()
108121
plugins/Unity/Indicators/indicatorsmodel.h+9
@@ -35,6 +35,9 @@ class UNITYINDICATORS_EXPORT IndicatorsModel : public QAbstractListModel
3535 Q_PROPERTY(int count READ count NOTIFY countChanged)
3636 Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
3737
38+ // Used for tests
39+ Q_PROPERTY(bool light READ light WRITE setLight NOTIFY lightChanged)
40+
3841public:
3942
4043 IndicatorsModel(QObject *parent=nullptr);
@@ -48,6 +51,9 @@ public:
4851 QString profile() const;
4952 void setProfile(const QString& profile);
5053
54+ bool light() const;
55+ void setLight(const bool &light);
56+
5157 /* QAbstractItemModel */
5258 QHash<int, QByteArray> roleNames() const override;
5359 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -60,6 +66,7 @@ Q_SIGNALS:
6066 void countChanged();
6167 void profileChanged();
6268 void indicatorDataChanged(const QVariant& data);
69+ void lightChanged();
6370
6471private Q_SLOTS:
6572 void onIdentifierChanged();
@@ -74,6 +81,8 @@ private:
7481
7582 void notifyDataChanged(QObject *sender, int role);
7683 int count() const;
84+
85+ bool m_light;
7786};
7887
7988#endif // INDICATORSMODEL_H
qml/OrientedShell.qml+2
@@ -40,6 +40,7 @@ Item {
4040 }
4141
4242 property alias orientations: d.orientations
43+ property bool lightIndicators: false
4344
4445 Item {
4546 id: d
@@ -276,6 +277,7 @@ Item {
276277 hasKeyboard: keyboardsModel.count > 0
277278 hasTouchscreen: touchScreensModel.count > 0
278279 supportsMultiColorLed: deviceConfiguration.supportsMultiColorLed
280+ lightIndicators: root.lightIndicators
279281
280282 // Since we dont have proper multiscreen support yet
281283 // hardcode screen count to only show osk on this screen
qml/Shell.qml+4
@@ -71,6 +71,9 @@ StyledItem {
7171 property bool hasTouchscreen: false
7272 property bool supportsMultiColorLed: true
7373
74+ // Used by tests
75+ property bool lightIndicators: false
76+
7477 // to be read from outside
7578 readonly property int mainAppWindowOrientationAngle: stage.mainAppWindowOrientationAngle
7679
@@ -539,6 +542,7 @@ StyledItem {
539542 // involve taking the url-dispatcher dbus name and using
540543 // SessionBroadcast to tell the session.
541544 profile: shell.mode === "greeter" ? "desktop_greeter" : "phone"
545+ light: root.lightIndicators
542546 Component.onCompleted: load();
543547 }
544548 }
tests/mocks/Unity/Indicators/IndicatorsModel.qml+30−12
@@ -23,6 +23,10 @@ import "fakeindicatorsmodeldata.js" as FakeIndicators
2323Indicators.FakeIndicatorsModel {
2424 id: root
2525
26+ property var light: false
27+
28+ onLightChanged: load()
29+
2630 property var originalModelData: [
2731 {
2832 "identifier": "indicator-keyboard",
@@ -126,51 +130,65 @@ Indicators.FakeIndicatorsModel {
126130 getUnityMenuModelData("indicator-keyboard",
127131 "English (F)",
128132 "",
129− [ "image://theme/input-keyboard-symbolic" ]));
133+ [ "image://theme/input-keyboard-symbolic" ],
134+ root.light));
130135 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake1",
131136 getUnityMenuModelData("fake-indicator-bluetooth",
132137 "Bluetooth (F)",
133138 "",
134− [ "image://theme/bluetooth-active" ]));
139+ [ "image://theme/bluetooth-active" ],
140+ root.light));
135141 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake2",
136142 getUnityMenuModelData("fake-indicator-network",
137143 "Network (F)",
138144 "",
139− [ "image://theme/simcard-error", "image://theme/wifi-high" ]));
145+ [ "image://theme/simcard-error", "image://theme/wifi-high" ],
146+ root.light));
140147 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake3",
141148 getUnityMenuModelData("fake-indicator-messages",
142149 "Messages (F)",
143150 "",
144− [ "image://theme/messages-new" ]));
151+ [ "image://theme/messages-new" ],
152+ root.light));
145153 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake4",
146154 getUnityMenuModelData("fake-indicator-files",
147155 "Files (F)",
148156 "",
149− [ "image://theme/transfer-progress" ]));
157+ [ "image://theme/transfer-progress" ],
158+ root.light));
150159 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake5",
151160 getUnityMenuModelData("fake-indicator-sound",
152161 "Sound (F)",
153162 "",
154− [ "image://theme/audio-volume-high" ]));
163+ [ "image://theme/audio-volume-high" ],
164+ root.light));
155165 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake6",
156166 getUnityMenuModelData("fake-indicator-power",
157167 "Battery (F)",
158168 "",
159− [ "image://theme/battery-020" ]));
169+ [ "image://theme/battery-020" ],
170+ root.light));
160171 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake7",
161172 getUnityMenuModelData("fake-indicator-datetime",
162173 "Upcoming Events (F)",
163174 "12:04",
164− []));
175+ [],
176+ root.light));
165177 Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicators/fake8",
166178 getUnityMenuModelData("fake-indicator-session",
167179 "System (F)",
168180 "",
169− ["image://theme/system-devices-panel"]));
181+ ["image://theme/system-devices-panel"],
182+ root.light));
170183 }
171184
172− function getUnityMenuModelData(identifier, title, label, icons) {
173− var menudata = FakeIndicators.fakeMenuData[identifier];
185+ function getUnityMenuModelData(identifier, title, label, icons, light) {
186+ var menudata = undefined;
187+ var maxItems = 1;
188+ if (!light) {
189+ var menudata = FakeIndicators.fakeMenuData[identifier];
190+ maxItems = 8;
191+ }
174192
175193 if (menudata !== undefined) {
176194 var rootState = menudata[0]["rowData"].actionState;
@@ -203,7 +221,7 @@ Indicators.FakeIndicatorsModel {
203221 }];
204222
205223 var submenus = [];
206− for (var i = 0; i < 8; i++) {
224+ for (var i = 0; i < maxItems; i++) {
207225 var submenu = {
208226 "rowData": { // 1.1
209227 "label": identifier,
tests/qmltests/tst_OrientedShell.qml+1
@@ -165,6 +165,7 @@ Rectangle {
165165 physicalOrientation: root.physicalOrientation0
166166 orientationLocked: orientationLockedCheckBox.checked
167167 orientationLock: mockOrientationLock
168+ lightIndicators: true
168169 }
169170 }
170171