@@ -0,0 +1,369 @@
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: "MenuItemFactory"
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_radio() {
119+ skip("No radio component");
120+ menuData.isRadio = true;
121+
122+ loader.data = menuData;
123+ loader.sourceComponent = factory.load(menuData);
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_separator() {
129+ menuData.isSeparator = true;
130+
131+ loader.data = menuData;
132+ loader.sourceComponent = factory.load(menuData);
133+ tryCompareFunction(function() { return loader.item != undefined; }, true);
134+ compare(loader.item.objectName, "divMenu", "Should have created a separator menu");
135+ }
136+
137+ function test_create_sliderMenu_data() {
138+ return [
139+ {label: "testLabel1", enabled: false, minValue: 0, maxValue: 100, value: 10.5 },
140+ {label: "testLabel2", enabled: true, minValue: 0, maxValue: 100, value: 100 },
141+ ];
142+ }
143+
144+ function test_create_sliderMenu(data) {
145+ menuData.type = "com.canonical.indicator.slider"
146+ menuData.label = data.label;
147+ menuData.sensitive = data.enabled;
148+ menuData.actionState = data.value;
149+ menuData.ext = {
150+ 'minIcon': "file:///testMinIcon",
151+ 'maxIcon': "file:///testMaxIcon",
152+ 'minValue': data.minValue,
153+ 'maxValue': data.maxValue
154+ };
155+
156+ loader.data = menuData;
157+ loader.sourceComponent = factory.load(menuData);
158+ tryCompareFunction(function() { return loader.item != undefined; }, true);
159+ compare(loader.item.objectName, "sliderMenu", "Should have created a slider menu");
160+
161+ compare(loader.item.text, data.label, "Label does not match data");
162+ compare(loader.item.minIcon, "file:///testMinIcon", "MinIcon does not match data");
163+ compare(loader.item.maxIcon, "file:///testMaxIcon", "MaxIcon does not match data");
164+ compare(loader.item.minimumValue, data.minValue, "MinValue does not match data");
165+ compare(loader.item.maximumValue, data.maxValue, "MaxValue does not match data");
166+ compare(loader.item.value, data.value, "Calue does not match data");
167+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
168+ }
169+
170+ function test_create_buttonMenu_data() {
171+ return [
172+ {label: "testLabel1", enabled: false },
173+ {label: "testLabel2", enabled: true },
174+ ];
175+ }
176+
177+ function test_create_buttonMenu(data) {
178+ menuData.type = "com.canonical.indicator.button"
179+ menuData.label = data.label;
180+ menuData.sensitive = data.enabled;
181+
182+ loader.data = menuData;
183+ loader.sourceComponent = factory.load(menuData);
184+ tryCompareFunction(function() { return loader.item != undefined; }, true);
185+ compare(loader.item.objectName, "buttonMenu", "Should have created a button menu");
186+
187+ compare(loader.item.buttonText, data.label, "Label does not match data");
188+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
189+ }
190+
191+ function test_create_sectionMenu_data() {
192+ return [
193+ {label: "testLabel1" },
194+ {label: "testLabel2" },
195+ ];
196+ }
197+
198+ function test_create_sectionMenu(data) {
199+ menuData.type = "com.canonical.indicator.section"
200+ menuData.label = data.label;
201+
202+ loader.data = menuData;
203+ loader.sourceComponent = factory.load(menuData);
204+ tryCompareFunction(function() { return loader.item != undefined; }, true);
205+ compare(loader.item.objectName, "sectionMenu", "Should have created a section menu");
206+
207+ compare(loader.item.text, data.label, "Label does not match data");
208+ }
209+
210+ function test_create_progressMenu_data() {
211+ return [
212+ {label: "testLabel1", enabled: true, value: 10 },
213+ {label: "testLabel2", enabled: false, value: 55 },
214+ ];
215+ }
216+
217+ function test_create_progressMenu(data) {
218+ menuData.type = "com.canonical.indicator.progress"
219+ menuData.label = data.label;
220+ menuData.sensitive = data.enabled;
221+ menuData.actionState = data.value;
222+
223+ loader.data = menuData;
224+ loader.sourceComponent = factory.load(menuData);
225+ tryCompareFunction(function() { return loader.item != undefined; }, true);
226+ compare(loader.item.objectName, "progressMenu", "Should have created a progress menu");
227+
228+ compare(loader.item.text, data.label, "Label does not match data");
229+ compare(loader.item.value, data.value, "Value does not match data");
230+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
231+ }
232+
233+ function test_create_standardMenu_data() {
234+ return [
235+ {label: "testLabel1", enabled: true, icon: "file:///testIcon" },
236+ {label: "testLabel2", enabled: false, icon: "file:///testIcon2"},
237+ ];
238+ }
239+
240+ function test_create_standardMenu(data) {
241+ menuData.type = ""
242+ menuData.label = data.label;
243+ menuData.sensitive = data.enabled;
244+ menuData.icon = data.icon;
245+
246+ loader.data = menuData;
247+ loader.sourceComponent = factory.load(menuData);
248+ tryCompareFunction(function() { return loader.item != undefined; }, true);
249+ compare(loader.item.objectName, "standardMenu", "Should have created a standard menu");
250+
251+ compare(loader.item.text, data.label, "Label does not match data");
252+ compare(loader.item.iconSource, data.icon, "MaxIcon does not match data");
253+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
254+ }
255+
256+ function test_create_switchMenu_data() {
257+ return [
258+ {label: "testLabel1", enabled: true, checked: false },
259+ {label: "testLabel2", enabled: false, checked: true },
260+ ];
261+ }
262+
263+ function test_create_switchMenu(data) {
264+ menuData.type = "com.canonical.indicator.switch";
265+ menuData.label = data.label;
266+ menuData.sensitive = data.enabled;
267+ menuData.icon = "file:///testIcon";
268+ menuData.isToggled = data.checked;
269+
270+ loader.data = menuData;
271+ loader.sourceComponent = factory.load(menuData);
272+ tryCompareFunction(function() { return loader.item != undefined; }, true);
273+ compare(loader.item.objectName, "switchMenu", "Should have created a standard menu");
274+
275+ compare(loader.item.text, data.label, "Label does not match data");
276+ compare(loader.item.icon, "file:///testIcon", "MaxIcon does not match data");
277+ compare(loader.item.checked, data.checked, "Checked does not match data");
278+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
279+ }
280+
281+ function test_create_wifiSection_data() {
282+ return [
283+ {label: "testLabel1", busy: false },
284+ {label: "testLabel2", busy: true },
285+ ];
286+ }
287+
288+ function test_create_wifiSection(data) {
289+ menuData.type = "unity.widgets.systemsettings.tablet.wifisection";
290+ menuData.label = data.label;
291+ menuData.ext = { 'xCanonicalBusyAction': data.busy }
292+
293+ loader.data = menuData;
294+ loader.sourceComponent = factory.load(menuData);
295+ tryCompareFunction(function() { return loader.item != undefined; }, true);
296+ compare(loader.item.objectName, "wifiSection", "Should have created a wifi section menu");
297+
298+ compare(loader.item.text, data.label, "Label does not match data");
299+ compare(loader.item.busy, data.busy, "Busy does not match data");
300+ }
301+
302+ function test_create_accessPoint_data() {
303+ return [
304+ {label: "testLabel1", enabled: true, checked: false, secure: true, adHoc: false },
305+ {label: "testLabel2", enabled: false, checked: true, secure: false, adHoc: true },
306+ ];
307+ }
308+
309+ function test_create_accessPoint(data) {
310+ menuData.type = "unity.widgets.systemsettings.tablet.accesspoint";
311+ menuData.label = data.label;
312+ menuData.sensitive = data.enabled;
313+ menuData.isToggled = data.checked;
314+ menuData.ext = {
315+ 'xCanonicalWifiApStrengthAction': "action::strength",
316+ 'xCanonicalWifiApIsSecure': data.secure,
317+ 'xCanonicalWifiApIsAdhoc': data.adHoc,
318+ };
319+
320+ loader.data = menuData;
321+ loader.sourceComponent = factory.load(menuData);
322+ tryCompareFunction(function() { return loader.item != undefined; }, true);
323+ compare(loader.item.objectName, "accessPoint", "Should have created a access point menu");
324+
325+ compare(loader.item.label, data.label, "Label does not match data");
326+ compare(loader.item.strengthAction.name, "action::strength", "Strength action incorrect");
327+ compare(loader.item.secure, data.secure, "Secure does not match data");
328+ compare(loader.item.adHoc, data.adHoc, "AdHoc does not match data");
329+ compare(loader.item.checked, data.checked, "Checked does not match data");
330+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
331+ }
332+
333+ function test_create_messageItem() {
334+ menuData.type = "com.canonical.indicator.messages.messageitem";
335+
336+ loader.data = menuData;
337+ loader.sourceComponent = factory.load(menuData);
338+ tryCompareFunction(function() { return loader.item != undefined; }, true);
339+ compare(loader.item.objectName, "messageItem", "Should have created a message menu");
340+ }
341+
342+ function test_create_groupedMessage_data() {
343+ return [
344+ {label: "testLabel1", enabled: true, count: "5", appIcon: "file:///testIcon" },
345+ {label: "testLabel2", enabled: false, count: "10", appIcon: "file:///testIcon2" },
346+ ];
347+ }
348+
349+ function test_create_groupedMessage(data) {
350+ menuData.type = "com.canonical.indicator.messages.sourceitem";
351+ menuData.label = data.label;
352+ menuData.sensitive = data.enabled;
353+ menuData.icon = data.appIcon;
354+ menuData.ext = { 'icon': data.appIcon };
355+ menuData.actionState = [data.count];
356+ menuData.isToggled = true;
357+
358+ loader.data = menuData;
359+ loader.sourceComponent = factory.load(menuData);
360+ tryCompareFunction(function() { return loader.item != undefined; }, true);
361+ compare(loader.item.objectName, "groupedMessage", "Should have created a group message menu");
362+
363+ compare(loader.item.title, data.label, "Label does not match data");
364+ compare(loader.item.count, data.count, "Count does not match data");
365+ compare(loader.item.appIcon, data.appIcon, "App Icon does not match data");
366+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
367+ }
368+ }
369+}