@@ -0,0 +1,523 @@
1+/*
2+ * Copyright 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+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import QMenuModel 0.1
21+import Unity.Indicators 0.1 as Indicators
22+
23+Item {
24+ id: testView
25+ width: units.gu(40)
26+ height: units.gu(70)
27+
28+ Indicators.MenuItemFactory {
29+ id: factory
30+ menuModel: UnityMenuModel {}
31+ }
32+
33+ Loader {
34+ id: loader
35+ property int modelIndex: 0
36+ property var data
37+
38+ onLoaded: {
39+ if (item.hasOwnProperty("menuData")) {
40+ item.menuData = data;
41+ }
42+ }
43+ }
44+
45+ UT.UnityTestCase {
46+ name: "IndicatorPage"
47+
48+ property QtObject menuData: QtObject {
49+ property string label: "root"
50+ property bool sensitive: true
51+ property bool isSeparator: false
52+ property string icon: ""
53+ property string type: ""
54+ property var ext: undefined
55+ property string action: ""
56+ property var actionState: undefined
57+ property bool isCheck: false
58+ property bool isRadio: false
59+ property bool isToggled: false
60+ }
61+
62+ function init() {
63+ menuData.label = "";
64+ menuData.sensitive = true;
65+ menuData.isSeparator = false;
66+ menuData.icon = "";
67+ menuData.type = "";
68+ menuData.ext = undefined;
69+ menuData.action = "";
70+ menuData.actionState = undefined;
71+ menuData.isCheck = false;
72+ menuData.isRadio = false;
73+ menuData.isToggled = false;
74+
75+ loader.sourceComponent = null;
76+ loader.data = undefined;
77+
78+ verify(loader.item == null);
79+ }
80+
81+ function test_createTypes_data() {
82+ return [
83+ { tag: 'volume', type: "unity.widgets.systemsettings.tablet.volumecontrol", objectName: "sliderMenu" },
84+ { tag: 'switch1', type: "unity.widgets.systemsettings.tablet.switch", objectName: "switchMenu" },
85+
86+ { tag: 'button', type: "com.canonical.indicator.button", objectName: "buttonMenu" },
87+ { tag: 'separator', type: "com.canonical.indicator.div", objectName: "divMenu" },
88+ { tag: 'section', type: "com.canonical.indicator.section", objectName: "sectionMenu" },
89+ { tag: 'progress', type: "com.canonical.indicator.progress", objectName: "progressMenu" },
90+ { tag: 'slider1', type: "com.canonical.indicator.slider", objectName: "sliderMenu" },
91+ { tag: 'switch2', type: "com.canonical.indicator.switch", objectName: "switchMenu" },
92+
93+ { tag: 'messageItem', type: "com.canonical.indicator.messages.messageitem", objectName: "messageItem" },
94+ { tag: 'sourceItem', type: "com.canonical.indicator.messages.sourceitem", objectName: "groupedMessage" },
95+
96+ { tag: 'slider2', type: "com.canonical.unity.slider", objectName: "sliderMenu" },
97+ { tag: 'switch3', type: "com.canonical.unity.switch", objectName: "switchMenu" },
98+
99+ { tag: 'mediaplayer', type: "com.canonical.unity.media-player", objectName: "standardMenu" },
100+ { tag: 'playbackitem', type: "com.canonical.unity.playback-item", objectName: "standardMenu" },
101+
102+ { tag: 'wifisection', type: "unity.widgets.systemsettings.tablet.wifisection", objectName: "wifiSection" },
103+ { tag: 'accesspoint', type: "unity.widgets.systemsettings.tablet.accesspoint", objectName: "accessPoint" },
104+
105+ { tag: 'unknown', type: "", objectName: "standardMenu"}
106+ ];
107+ }
108+
109+ function test_createTypes(data) {
110+ menuData.type = data.type;
111+
112+ loader.data = menuData;
113+ loader.sourceComponent = factory.load(menuData);
114+ tryCompareFunction(function() { return loader.item != undefined; }, true);
115+ compare(loader.item.objectName, data.objectName, "Created object name does not match intended object (" + loader.item.objectName + " != " + data.objectName + ")");
116+ }
117+
118+// function test_create_checkable() {
119+// var tmpData = menuData;
120+// tmpData.isCheck = true;
121+
122+// loader.data = tmpData;
123+// loader.sourceComponent = factory.load(tmpData);
124+// tryCompareFunction(function() { return loader.item != undefined; }, true);
125+// compare(loader.item.objectName, "checkableMenu", "Should have created a checkable menu");
126+// }
127+
128+ function test_create_radio() {
129+ skip("No radio component");
130+ menuData.isRadio = true;
131+
132+ loader.data = menuData;
133+ loader.sourceComponent = factory.load(menuData);
134+ tryCompareFunction(function() { return loader.item != undefined; }, true);
135+ compare(loader.item.objectName, "checkableMenu", "Should have created a checkable menu");
136+ }
137+
138+ function test_create_separator() {
139+ menuData.isSeparator = true;
140+
141+ loader.data = menuData;
142+ loader.sourceComponent = factory.load(menuData);
143+ tryCompareFunction(function() { return loader.item != undefined; }, true);
144+ compare(loader.item.objectName, "divMenu", "Should have created a separator menu");
145+ }
146+
147+ function test_create_sliderMenu_data() {
148+ return [
149+ {label: "testLabel1", enabled: false, minValue: 0, maxValue: 100, value: 10.5 },
150+ {label: "testLabel2", enabled: true, minValue: 0, maxValue: 100, value: 100 },
151+ ];
152+ }
153+
154+ function test_create_sliderMenu(data) {
155+ menuData.type = "com.canonical.indicator.slider"
156+ menuData.label = data.label;
157+ menuData.sensitive = data.enabled;
158+ menuData.actionState = data.value;
159+ menuData.ext = {
160+ 'minIcon': "file:///testMinIcon",
161+ 'maxIcon': "file:///testMaxIcon",
162+ 'minValue': data.minValue,
163+ 'maxValue': data.maxValue
164+ };
165+
166+ loader.data = menuData;
167+ loader.sourceComponent = factory.load(menuData);
168+ tryCompareFunction(function() { return loader.item != undefined; }, true);
169+ compare(loader.item.objectName, "sliderMenu", "Should have created a slider menu");
170+
171+ compare(loader.item.text, data.label, "Label does not match data");
172+ compare(loader.item.minIcon, "file:///testMinIcon", "MinIcon does not match data");
173+ compare(loader.item.maxIcon, "file:///testMaxIcon", "MaxIcon does not match data");
174+ compare(loader.item.minimumValue, data.minValue, "MinValue does not match data");
175+ compare(loader.item.maximumValue, data.maxValue, "MaxValue does not match data");
176+ compare(loader.item.value, data.value, "Calue does not match data");
177+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
178+ }
179+
180+ function test_create_buttonMenu_data() {
181+ return [
182+ {label: "testLabel1", enabled: false },
183+ {label: "testLabel2", enabled: true },
184+ ];
185+ }
186+
187+ function test_create_buttonMenu(data) {
188+ menuData.type = "com.canonical.indicator.button"
189+ menuData.label = data.label;
190+ menuData.sensitive = data.enabled;
191+
192+ loader.data = menuData;
193+ loader.sourceComponent = factory.load(menuData);
194+ tryCompareFunction(function() { return loader.item != undefined; }, true);
195+ compare(loader.item.objectName, "buttonMenu", "Should have created a button menu");
196+
197+ compare(loader.item.buttonText, data.label, "Label does not match data");
198+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
199+ }
200+
201+ function test_create_sectionMenu_data() {
202+ return [
203+ {label: "testLabel1" },
204+ {label: "testLabel2" },
205+ ];
206+ }
207+
208+ function test_create_sectionMenu(data) {
209+ menuData.type = "com.canonical.indicator.section"
210+ menuData.label = data.label;
211+
212+ loader.data = menuData;
213+ loader.sourceComponent = factory.load(menuData);
214+ tryCompareFunction(function() { return loader.item != undefined; }, true);
215+ compare(loader.item.objectName, "sectionMenu", "Should have created a section menu");
216+
217+ compare(loader.item.text, data.label, "Label does not match data");
218+ }
219+
220+ function test_create_progressMenu_data() {
221+ return [
222+ {label: "testLabel1", enabled: true, value: 10 },
223+ {label: "testLabel2", enabled: false, value: 55 },
224+ ];
225+ }
226+
227+ function test_create_progressMenu(data) {
228+ menuData.type = "com.canonical.indicator.progress"
229+ menuData.label = data.label;
230+ menuData.sensitive = data.enabled;
231+ menuData.actionState = data.value;
232+
233+ loader.data = menuData;
234+ loader.sourceComponent = factory.load(menuData);
235+ tryCompareFunction(function() { return loader.item != undefined; }, true);
236+ compare(loader.item.objectName, "progressMenu", "Should have created a progress menu");
237+
238+ compare(loader.item.text, data.label, "Label does not match data");
239+ compare(loader.item.value, data.value, "Value does not match data");
240+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
241+ }
242+
243+ function test_create_standardMenu_data() {
244+ return [
245+ {label: "testLabel1", enabled: true, icon: "file:///testIcon" },
246+ {label: "testLabel2", enabled: false, icon: "file:///testIcon2"},
247+ ];
248+ }
249+
250+ function test_create_standardMenu(data) {
251+ menuData.type = ""
252+ menuData.label = data.label;
253+ menuData.sensitive = data.enabled;
254+ menuData.icon = data.icon;
255+
256+ loader.data = menuData;
257+ loader.sourceComponent = factory.load(menuData);
258+ tryCompareFunction(function() { return loader.item != undefined; }, true);
259+ compare(loader.item.objectName, "standardMenu", "Should have created a standard menu");
260+
261+ compare(loader.item.text, data.label, "Label does not match data");
262+ compare(loader.item.iconSource, data.icon, "MaxIcon does not match data");
263+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
264+ }
265+
266+// function test_create_checkableMenu_data() {
267+// return [
268+// {label: "testLabel1", enabled: true, checked: false },
269+// {label: "testLabel2", enabled: false, checked: true },
270+// ];
271+// }
272+
273+// function test_create_checkableMenu(data) {
274+// var menuData = {
275+// 'label': data.label,
276+// 'sensitive': data.enabled,
277+// 'isSeparator': false,
278+// 'icon': "",
279+// 'type': undefined,
280+// 'ext': {},
281+// 'action': "",
282+// 'actionState': undefined,
283+// 'isCheck': true,
284+// 'isRadio': false,
285+// 'isToggled': data.checked,
286+// };
287+
288+// loader.data = menuData;
289+// loader.sourceComponent = factory.load(menuData);
290+// tryCompareFunction(function() { return loader.item != undefined; }, true);
291+// compare(loader.item.objectName, "checkableMenu", "Should have created a standard menu");
292+
293+// compare(loader.item.text, data.label, "Label does not match data");
294+// compare(loader.item.checked, data.checked, "Checked does not match data");
295+// compare(loader.item.enabled, data.enabled, "Enabled does not match data");
296+// }
297+
298+ function test_create_switchMenu_data() {
299+ return [
300+ {label: "testLabel1", enabled: true, checked: false },
301+ {label: "testLabel2", enabled: false, checked: true },
302+ ];
303+ }
304+
305+ function test_create_switchMenu(data) {
306+ menuData.type = "com.canonical.indicator.switch";
307+ menuData.label = data.label;
308+ menuData.sensitive = data.enabled;
309+ menuData.icon = "file:///testIcon";
310+ menuData.isToggled = data.checked;
311+
312+ loader.data = menuData;
313+ loader.sourceComponent = factory.load(menuData);
314+ tryCompareFunction(function() { return loader.item != undefined; }, true);
315+ compare(loader.item.objectName, "switchMenu", "Should have created a standard menu");
316+
317+ compare(loader.item.text, data.label, "Label does not match data");
318+ compare(loader.item.icon, "file:///testIcon", "MaxIcon does not match data");
319+ compare(loader.item.checked, data.checked, "Checked does not match data");
320+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
321+ }
322+
323+ function test_create_wifiSection_data() {
324+ return [
325+ {label: "testLabel1", busy: false },
326+ {label: "testLabel2", busy: true },
327+ ];
328+ }
329+
330+ function test_create_wifiSection(data) {
331+ menuData.type = "unity.widgets.systemsettings.tablet.wifisection";
332+ menuData.label = data.label;
333+ menuData.ext = { 'xCanonicalBusyAction': data.busy }
334+
335+ loader.data = menuData;
336+ loader.sourceComponent = factory.load(menuData);
337+ tryCompareFunction(function() { return loader.item != undefined; }, true);
338+ compare(loader.item.objectName, "wifiSection", "Should have created a wifi section menu");
339+
340+ compare(loader.item.text, data.label, "Label does not match data");
341+ compare(loader.item.busy, data.busy, "Busy does not match data");
342+ }
343+
344+ function test_create_accessPoint_data() {
345+ return [
346+ {label: "testLabel1", enabled: true, checked: false, secure: true, adHoc: false },
347+ {label: "testLabel2", enabled: false, checked: true, secure: false, adHoc: true },
348+ ];
349+ }
350+
351+ function test_create_accessPoint(data) {
352+ menuData.type = "unity.widgets.systemsettings.tablet.accesspoint";
353+ menuData.label = data.label;
354+ menuData.sensitive = data.enabled;
355+ menuData.isToggled = data.checked;
356+ menuData.ext = {
357+ 'xCanonicalWifiApStrengthAction': "action::strength",
358+ 'xCanonicalWifiApIsSecure': data.secure,
359+ 'xCanonicalWifiApIsAdhoc': data.adHoc,
360+ };
361+
362+ loader.data = menuData;
363+ loader.sourceComponent = factory.load(menuData);
364+ tryCompareFunction(function() { return loader.item != undefined; }, true);
365+ compare(loader.item.objectName, "accessPoint", "Should have created a access point menu");
366+
367+ compare(loader.item.label, data.label, "Label does not match data");
368+ compare(loader.item.strengthAction.name, "action::strength", "Strength action incorrect");
369+ compare(loader.item.secure, data.secure, "Secure does not match data");
370+ compare(loader.item.adHoc, data.adHoc, "AdHoc does not match data");
371+ compare(loader.item.checked, data.checked, "Checked does not match data");
372+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
373+ }
374+
375+ function test_create_messageItem() {
376+ menuData.type = "com.canonical.indicator.messages.messageitem";
377+
378+ loader.data = menuData;
379+ loader.sourceComponent = factory.load(menuData);
380+ tryCompareFunction(function() { return loader.item != undefined; }, true);
381+ compare(loader.item.objectName, "messageItem", "Should have created a message menu");
382+ }
383+
384+ function test_create_groupedMessage_data() {
385+ return [
386+ {label: "testLabel1", enabled: true, count: "5", appIcon: "file:///testIcon" },
387+ {label: "testLabel2", enabled: false, count: "10", appIcon: "file:///testIcon2" },
388+ ];
389+ }
390+
391+ function test_create_groupedMessage(data) {
392+ menuData.type = "com.canonical.indicator.messages.sourceitem";
393+ menuData.label = data.label;
394+ menuData.sensitive = data.enabled;
395+ menuData.icon = data.appIcon;
396+ menuData.ext = { 'icon': data.appIcon };
397+ menuData.actionState = [data.count];
398+ menuData.isToggled = true;
399+
400+ loader.data = menuData;
401+ loader.sourceComponent = factory.load(menuData);
402+ tryCompareFunction(function() { return loader.item != undefined; }, true);
403+ compare(loader.item.objectName, "groupedMessage", "Should have created a group message menu");
404+
405+ compare(loader.item.title, data.label, "Label does not match data");
406+ compare(loader.item.count, data.count, "Count does not match data");
407+ compare(loader.item.appIcon, data.appIcon, "App Icon does not match data");
408+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
409+ }
410+
411+// function test_create_mediaPayerMenu_data() {
412+// return [{
413+// label: "player1",
414+// icon: "file:://icon1",
415+// albumArt: "file:://art1",
416+// song: "song1",
417+// artist: "artist1",
418+// album: "album1",
419+// running: true,
420+// state: "Playing",
421+// enabled: true
422+// },{
423+// label: "player2",
424+// icon: "file:://icon2",
425+// albumArt: "file:://art2",
426+// song: "song2",
427+// artist: "artist2",
428+// album: "album2",
429+// running: false,
430+// state: "Paused",
431+// enabled: false
432+// }
433+// ];
434+// }
435+
436+// function test_create_mediaPayerMenu(data) {
437+// var menuData = {
438+// 'label': data.label,
439+// 'sensitive': data.enabled,
440+// 'isSeparator': false,
441+// 'icon': data.icon,
442+// 'type': "com.canonical.unity.media-player",
443+// 'ext': {},
444+// 'action': "",
445+// 'actionState': {
446+// 'art-url': data.albumArt,
447+// 'title': data.song,
448+// 'artist': data.artist,
449+// 'album': data.album,
450+// 'running': data.running,
451+// 'state': data.state,
452+// },
453+// 'isCheck': false,
454+// 'isRadio': false,
455+// 'isToggled': false,
456+// };
457+
458+// loader.data = menuData;
459+// loader.sourceComponent = factory.load(menuData);
460+// tryCompareFunction(function() { return loader.item != undefined; }, true);
461+// compare(loader.item.objectName, "mediaPayerMenu", "Should have created a media player menu");
462+
463+// compare(loader.item.playerIcon, data.icon, "Album art does not match data");
464+// compare(loader.item.playerName, data.label, "Album art does not match data");
465+// compare(loader.item.albumArt, data.albumArt, "Album art does not match data");
466+// compare(loader.item.song, data.song, "Song does not match data");
467+// compare(loader.item.artist, data.artist, "Artist does not match data");
468+// compare(loader.item.album, data.album, "Album does not match data");
469+// compare(loader.item.running, data.running, "Running does not match data");
470+// compare(loader.item.state, data.state, "State does not match data");
471+// compare(loader.item.enabled, data.enabled, "Enabled does not match data");
472+// }
473+
474+// function test_create_playbackItemMenu_data() {
475+// return [{
476+// playAction: "action::play",
477+// nextAction: "action::next",
478+// previousAction: "action::previous",
479+// enabled: true
480+// },{
481+// playAction: "action::play2",
482+// nextAction: "action::next2",
483+// previousAction: "action::previous2",
484+// enabled: false
485+// }
486+// ];
487+// }
488+
489+// function test_create_playbackItemMenu(data) {
490+// var menuData = {
491+// 'label': "",
492+// 'sensitive': data.enabled,
493+// 'isSeparator': false,
494+// 'icon': "",
495+// 'type': "com.canonical.unity.playback-item",
496+// 'ext': {
497+// 'xCanonicalPlayAction': data.playAction,
498+// 'xCanonicalNextAction': data.nextAction,
499+// 'xCanonicalPreviousAction': data.previousAction
500+// },
501+// 'action': "",
502+// 'actionState': {},
503+// 'isCheck': false,
504+// 'isRadio': false,
505+// 'isToggled': false,
506+// };
507+
508+// loader.data = menuData;
509+// loader.sourceComponent = factory.load(menuData);
510+// tryCompareFunction(function() { return loader.item != undefined; }, true);
511+// compare(loader.item.objectName, "playbackItemMenu", "Should have created a playback menu");
512+
513+// compare(loader.item.playing, false, "Playing does not match data");
514+// compare(loader.item.playAction.name, data.playAction, "Play action incorrect");
515+// compare(loader.item.nextAction.name, data.nextAction, "Next action incorrect");
516+// compare(loader.item.previousAction.name, data.previousAction, "Previous action incorrect");
517+// compare(loader.item.canPlay, false, "CanPlay should be false");
518+// compare(loader.item.canGoNext, false, "CanGoNext should be false");
519+// compare(loader.item.canGoPrevious, false, "CanGoPrevious should be false");
520+// compare(loader.item.enabled, data.enabled, "Enabled does not match data");
521+// }
522+ }
523+}