|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.openlcdui.mt_uirobot.form; |
|
18 |
|
19 import junit.framework.*; |
|
20 |
|
21 import javax.microedition.lcdui.*; |
|
22 |
|
23 import com.nokia.openlcdui.mt_uirobot.ItemUITestBase; |
|
24 |
|
25 import com.nokia.mj.impl.uitestutils.Key; |
|
26 |
|
27 /** |
|
28 * TEST CASE SPECIFICATION <br> |
|
29 * <br> |
|
30 * Short description of the module test: |
|
31 * <li> UI-robot based test to test item-related form functionality, |
|
32 * for example adding and removing items to form. <br> |
|
33 * <br> |
|
34 * Created: 2008-11-12 |
|
35 */ |
|
36 public class FormItemTest extends ItemUITestBase { |
|
37 |
|
38 /** |
|
39 * Constructor. |
|
40 */ |
|
41 public FormItemTest() { |
|
42 super(); |
|
43 } |
|
44 |
|
45 /** |
|
46 * Constructor. |
|
47 * |
|
48 * @param sTestName Test name. |
|
49 * @param rTestMethod Test method. |
|
50 */ |
|
51 public FormItemTest(String sTestName) { |
|
52 super(sTestName); |
|
53 } |
|
54 |
|
55 public static Test suite() { |
|
56 TestSuite suite = new TestSuite(); |
|
57 |
|
58 java.util.Vector methodNames; |
|
59 java.util.Enumeration e; |
|
60 |
|
61 // Add widget tests |
|
62 methodNames = FormItemTest.methodNames(); |
|
63 e = methodNames.elements(); |
|
64 while (e.hasMoreElements()) { |
|
65 suite.addTest(new FormItemTest((String)e.nextElement())); |
|
66 } |
|
67 |
|
68 return suite; |
|
69 } |
|
70 |
|
71 public static java.util.Vector methodNames() { |
|
72 java.util.Vector methodNames = new java.util.Vector(); |
|
73 methodNames.addElement("testAppendItemAfterSetCurrent"); |
|
74 methodNames.addElement("testRemoveCommandFromLabeledFocusedItem"); |
|
75 methodNames.addElement("testAddRemoveItems"); |
|
76 methodNames.addElement("testRemoveItemsWhenBackground"); |
|
77 return methodNames; |
|
78 } |
|
79 |
|
80 public void runTest() throws Throwable { |
|
81 if (getName().equals("testAppendItemAfterSetCurrent")) testAppendItemAfterSetCurrent(); |
|
82 else if (getName().equals("testRemoveCommandFromLabeledFocusedItem")) testRemoveCommandFromLabeledFocusedItem(); |
|
83 else if (getName().equals("testAddRemoveItems")) testAddRemoveItems(); |
|
84 else if (getName().equals("testRemoveItemsWhenBackground")) testRemoveItemsWhenBackground(); |
|
85 else super.runTest(); |
|
86 } |
|
87 |
|
88 |
|
89 /** |
|
90 * Tests to remove command from focused item which has label and |
|
91 * verifies that focus is moved to next/previous focusable item. |
|
92 */ |
|
93 public void testRemoveCommandFromLabeledFocusedItem() { |
|
94 StringItem button1 = new StringItem("label", "click!", Item.BUTTON); |
|
95 StringItem button2 = new StringItem("label", "click2!", Item.BUTTON); |
|
96 |
|
97 Command c1 = new Command("Ok1", "", Command.ITEM, 0); |
|
98 Command c2 = new Command("Ok2", "", Command.ITEM, 0); |
|
99 |
|
100 button1.addCommand(c1); |
|
101 button1.setItemCommandListener(this); |
|
102 button2.addCommand(c2); |
|
103 button2.setItemCommandListener(this); |
|
104 |
|
105 form.append(button1); |
|
106 form.append(button2); |
|
107 |
|
108 setCurrent(form); |
|
109 |
|
110 // First item should be focused. Remove command from it, and |
|
111 // make sure the focus is transfered to second button: |
|
112 button1.removeCommand(c1); |
|
113 block(CHANGE_DISPLAYABLE_DELAY); |
|
114 |
|
115 key(Key.CBA1); |
|
116 assertItemCmdListener("case1", c2, button2); |
|
117 |
|
118 // Add command back to first item and remove command from second one. |
|
119 // Verify that the focus is moved to first one: |
|
120 button1.addCommand(c1); |
|
121 button2.removeCommand(c2); |
|
122 //block(CHANGE_DISPLAYABLE_DELAY); |
|
123 block(CHANGE_DISPLAYABLE_DELAY); |
|
124 |
|
125 key(Key.CBA1); |
|
126 assertItemCmdListener("case2", c1, button1); |
|
127 } |
|
128 |
|
129 /** |
|
130 * Tests to add and remove items to/from form. |
|
131 */ |
|
132 public void testAddRemoveItems() { |
|
133 Command ok1 = new Command("Ok1", "", Command.ITEM, 0); |
|
134 Command ok2 = new Command("Ok2", "", Command.ITEM, 0); |
|
135 |
|
136 Form form2 = new Form("form2"); |
|
137 StringItem button1 = new StringItem(null, "button1", StringItem.BUTTON); |
|
138 StringItem button2 = new StringItem(null, "button2", StringItem.BUTTON); |
|
139 button1.addCommand(ok1); |
|
140 button2.addCommand(ok2); |
|
141 button1.setItemCommandListener(this); |
|
142 button2.setItemCommandListener(this); |
|
143 form.append(button1); |
|
144 form.append(button2); |
|
145 |
|
146 setCurrent(form); |
|
147 |
|
148 // Move to second button, hide form, remove second button, show |
|
149 // form and verify that the first button is selected: |
|
150 key(Key.RightArrow); |
|
151 |
|
152 setCurrent(form2); |
|
153 |
|
154 form.delete(1); |
|
155 |
|
156 setCurrent(form); |
|
157 key(Key.CBA1); |
|
158 assertItemCmdListener("case1", ok1, button1); |
|
159 |
|
160 // Add second button again and move to it and verify the command |
|
161 // works: |
|
162 form.append(button2); |
|
163 block(CHANGE_DISPLAYABLE_DELAY); |
|
164 key(Key.RightArrow); |
|
165 |
|
166 key(Key.CBA1); |
|
167 assertItemCmdListener("case2", ok2, button2); |
|
168 } |
|
169 |
|
170 /** |
|
171 * Tests to append item to form after form is set current. Then |
|
172 * verifies the focus transfer works. |
|
173 */ |
|
174 public void testAppendItemAfterSetCurrent() { |
|
175 StringItem hyperlink = new StringItem("label", "url", |
|
176 StringItem.HYPERLINK); |
|
177 StringItem button1 = new StringItem(null, "button1", |
|
178 StringItem.BUTTON); |
|
179 |
|
180 Command dummyCommand = new Command("dummy", "", Command.ITEM, 0); |
|
181 button1.addCommand(dummyCommand); |
|
182 |
|
183 Command ok = new Command("Ok", "", Command.ITEM, 0); |
|
184 |
|
185 setCurrent(form); |
|
186 |
|
187 form.append(button1); |
|
188 form.append(hyperlink); |
|
189 |
|
190 hyperlink.setItemCommandListener(this); |
|
191 hyperlink.addCommand(ok); |
|
192 |
|
193 // Give some time for layouter because adding command to hyperlink |
|
194 // means relayouting: |
|
195 block(CHANGE_DISPLAYABLE_DELAY); |
|
196 |
|
197 // Move to hyperlink, click command and verify it works: |
|
198 key(Key.RightArrow); |
|
199 key(Key.CBA1); |
|
200 assertItemCmdListener("case1", ok, hyperlink); |
|
201 |
|
202 // Click command by using MSK and verify it works: |
|
203 key(Key.Select); |
|
204 assertItemCmdListener("case2", ok, hyperlink); |
|
205 } |
|
206 |
|
207 /** |
|
208 * Test that command are working properly in case of |
|
209 */ |
|
210 public void testRemoveItemsWhenBackground() { |
|
211 Form forma = new Form ("Form A"); |
|
212 Form formb = new Form ("Form B"); |
|
213 Command dummyCommand1 = new Command("dummy1", "", Command.ITEM, 0); |
|
214 Command dummyCommand2 = new Command("dummy2", "", Command.ITEM, 0); |
|
215 Command dummyCommand3 = new Command("dummy3", "", Command.ITEM, 0); |
|
216 Command dummyCommand4 = new Command("dummy4", "", Command.ITEM, 0); |
|
217 Gauge g1 = new Gauge("Gauge1", true, 10, 0); |
|
218 Gauge g2 = new Gauge("Gauge2", true, 10, 0); |
|
219 Gauge g3 = new Gauge("Gauge3", true, 10, 0); |
|
220 Gauge g4 = new Gauge("Gauge4", true, 10, 0); |
|
221 setCurrent(forma); |
|
222 |
|
223 forma.append(g1); |
|
224 forma.append(g2); |
|
225 forma.append(g3); |
|
226 forma.append(g4); |
|
227 g1.addCommand(dummyCommand1); |
|
228 g1.setItemCommandListener(this); |
|
229 g2.addCommand(dummyCommand2); |
|
230 g2.setItemCommandListener(this); |
|
231 g3.addCommand(dummyCommand3); |
|
232 g3.setItemCommandListener(this); |
|
233 g4.addCommand(dummyCommand4); |
|
234 g4.setItemCommandListener(this); |
|
235 block(CHANGE_DISPLAYABLE_DELAY); |
|
236 key(Key.DownArrow); |
|
237 key(Key.DownArrow); |
|
238 key(Key.DownArrow); |
|
239 key(Key.Select); |
|
240 assertItemCmdListener("case1", dummyCommand4, g4); |
|
241 |
|
242 setCurrent(formb); |
|
243 |
|
244 //delete 3 list items from Form A |
|
245 forma.delete(1); |
|
246 forma.delete(1); |
|
247 forma.delete(1); |
|
248 formb.append(g2); |
|
249 block(CHANGE_DISPLAYABLE_DELAY); |
|
250 key(Key.Select); |
|
251 assertItemCmdListener("case2", dummyCommand2, g2); |
|
252 |
|
253 //check the focus was not changed when another item is added. |
|
254 formb.append(g3); |
|
255 block(CHANGE_DISPLAYABLE_DELAY); |
|
256 key(Key.Select); |
|
257 assertItemCmdListener("case3", dummyCommand2, g2); |
|
258 |
|
259 //switch displayble back to Form a |
|
260 setCurrent(forma); |
|
261 key(Key.Select); |
|
262 assertItemCmdListener("case4", dummyCommand1, g1); |
|
263 |
|
264 //delete first item from From B |
|
265 formb.delete(0); |
|
266 //add it to Form A |
|
267 forma.append(g2); |
|
268 block(CHANGE_DISPLAYABLE_DELAY); |
|
269 key(Key.DownArrow); |
|
270 key(Key.Select); |
|
271 assertItemCmdListener("case5", dummyCommand2, g2); |
|
272 } |
|
273 |
|
274 } |