|
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 t_uirobot.alert; |
|
18 |
|
19 import j2meunit.framework.*; |
|
20 |
|
21 import java.io.IOException; |
|
22 |
|
23 import javax.microedition.lcdui.*; |
|
24 |
|
25 import spede.SpedeRunner; |
|
26 import t_uirobot.UITestBase; |
|
27 |
|
28 import com.nokia.mj.impl.uitestutils.Key; |
|
29 |
|
30 /** |
|
31 * TEST CASE SPECIFICATION <br> |
|
32 * <br> |
|
33 * Short description of the module test: |
|
34 * <li> UI-robot based tests to test Alert's functionality. <br> |
|
35 * <br> |
|
36 * |
|
37 * @created 2008-07-01 |
|
38 */ |
|
39 public class AlertUITest extends UITestBase { |
|
40 |
|
41 private static final int SETCURRENT_TIMEOUT = 6000; |
|
42 private static final int TEXBOX_LENGTH = 100; |
|
43 |
|
44 private static String shortString = "Lorem ipsum"; |
|
45 |
|
46 private static String longString = "Lorem ipsum dolor sit amet, " |
|
47 + "consectetuer adipiscing elit. Cras turpis ligula, " |
|
48 + "condimentum nec, rhoncus quis, molestie in, arcu. " |
|
49 + "Curabitur id lacus. Quisque dictum nulla id odio. " |
|
50 + "Nullam nec urna. Cras ac lacus nec lacus iaculis aliquet." |
|
51 + " Integer ut eros. Proin laoreet justo et augue. " |
|
52 + "Praesent dui. Proin vel leo a eros auctor convallis. " |
|
53 + "Aenean urna nunc, sagittis vel, pellentesque a, " |
|
54 + "luctus a, metus. Phasellus posuere lacus nec augue." |
|
55 + "Nullam nec urna. Cras ac lacus nec lacus iaculis aliquet." |
|
56 + " Integer ut eros. Proin laoreet justo et augue. " |
|
57 + "Praesent dui. Proin vel leo a eros auctor convallis. " |
|
58 + "Aenean urna nunc, sagittis vel, pellentesque a, " |
|
59 + "luctus a, metus. Phasellus posuere lacus nec augue."; |
|
60 |
|
61 private TextBox textBox; |
|
62 private Command exitCmd; |
|
63 |
|
64 /** |
|
65 * Constructor. |
|
66 */ |
|
67 public AlertUITest() { |
|
68 super(); |
|
69 } |
|
70 |
|
71 /** |
|
72 * Constructor. |
|
73 * |
|
74 * @param sTestName Test name. |
|
75 * @param rTestMethod Test method. |
|
76 */ |
|
77 public AlertUITest(String sTestName, TestMethod rTestMethod) { |
|
78 super(sTestName, rTestMethod); |
|
79 } |
|
80 |
|
81 /** |
|
82 * Any pre-test setup can be done here |
|
83 */ |
|
84 protected void setUp() throws Exception { |
|
85 super.setUp(); |
|
86 exitCmd = new Command("exit", "exit", Command.EXIT, 0); |
|
87 textBox = new TextBox("textBox", "", TEXBOX_LENGTH, TextField.ANY); |
|
88 textBox.addCommand(exitCmd); |
|
89 } |
|
90 |
|
91 /** |
|
92 * Creates the test suite. You need to add a new aSuite.addTest entry for |
|
93 * any new test methods, otherwise they won't be run. |
|
94 * |
|
95 * @return New testsuite. |
|
96 */ |
|
97 public Test suite() { |
|
98 TestSuite aSuite = new TestSuite(); |
|
99 |
|
100 aSuite.addTest(new AlertUITest("testShowTimedAlert", new TestMethod() { |
|
101 public void run(TestCase tc) { |
|
102 ((AlertUITest) tc).testShowTimedAlert(); |
|
103 } |
|
104 })); |
|
105 |
|
106 aSuite.addTest(new AlertUITest("testCustomListener", new TestMethod() { |
|
107 public void run(TestCase tc) { |
|
108 ((AlertUITest) tc).testCustomListener(); |
|
109 } |
|
110 })); |
|
111 |
|
112 aSuite.addTest(new AlertUITest("testCustomListenerCustomCommand", |
|
113 new TestMethod() { |
|
114 public void run(TestCase tc) { |
|
115 ((AlertUITest) tc).testCustomListenerCustomCommand(); |
|
116 } |
|
117 })); |
|
118 |
|
119 aSuite.addTest(new AlertUITest("testKeypressOnCustomCommands", |
|
120 new TestMethod() { |
|
121 public void run(TestCase tc) { |
|
122 ((AlertUITest) tc).testKeypressOnCustomCommands(); |
|
123 } |
|
124 })); |
|
125 |
|
126 aSuite.addTest(new AlertUITest("testLongTextScrolling", |
|
127 new TestMethod() { |
|
128 public void run(TestCase tc) { |
|
129 ((AlertUITest) tc).testLongTextScrolling(); |
|
130 } |
|
131 })); |
|
132 |
|
133 aSuite.addTest(new AlertUITest("testImageAndTextCombinations", |
|
134 new TestMethod() { |
|
135 public void run(TestCase tc) { |
|
136 ((AlertUITest) tc).testImageAndTextCombinations(); |
|
137 } |
|
138 })); |
|
139 |
|
140 return aSuite; |
|
141 } |
|
142 |
|
143 /** |
|
144 * Tests showing a timed alert with default values. |
|
145 */ |
|
146 public void testShowTimedAlert() { |
|
147 setCurrent(textBox); |
|
148 |
|
149 Alert alert = new Alert("timedAlert"); |
|
150 int timeout = alert.getTimeout(); |
|
151 assertTrue("Alert should be timed", timeout != Alert.FOREVER); |
|
152 |
|
153 // LSK should be empty - should just dismiss Alert |
|
154 setCurrent(alert); |
|
155 key(Key.CBA1); |
|
156 assertEquals("LSK should dismiss", textBox, display.getCurrent()); |
|
157 |
|
158 // RSK should be empty - should just dismiss Alert |
|
159 setCurrent(alert); |
|
160 key(Key.CBA2); |
|
161 assertEquals("RSK should dismiss", textBox, display.getCurrent()); |
|
162 |
|
163 // Select should just dismiss Alert |
|
164 setCurrent(alert); |
|
165 key(Key.Select); |
|
166 assertEquals("Select should dismiss", textBox, display.getCurrent()); |
|
167 |
|
168 // Default listener should dismisses the Alert |
|
169 setCurrent(alert); |
|
170 block(timeout + CHANGE_DISPLAYABLE_DELAY); |
|
171 assertEquals("Textbox should be current", |
|
172 textBox, display.getCurrent()); |
|
173 } |
|
174 |
|
175 /** |
|
176 * Tests showing a timed alert with custom command listener. |
|
177 */ |
|
178 public void testCustomListener() { |
|
179 setCurrent(textBox); |
|
180 |
|
181 Alert alert = new Alert("customListenerAlert"); |
|
182 assertTrue("Alert should be timed", |
|
183 alert.getTimeout() != Alert.FOREVER); |
|
184 alert.setCommandListener(this); |
|
185 setCurrent(alert); |
|
186 // wait for max 10sec to get command listener callback |
|
187 assertTrue("Textbox isShown() should be false", !textBox.isShown()); |
|
188 assertCmdListener("", Alert.DISMISS_COMMAND, alert); |
|
189 } |
|
190 |
|
191 /** |
|
192 * Tests showing a timed alert with custom command listener and custom |
|
193 * command. |
|
194 */ |
|
195 public void testCustomListenerCustomCommand() { |
|
196 setCurrent(textBox); |
|
197 |
|
198 Alert alert = new Alert("customCmdAlert"); |
|
199 assertTrue("Alert should be timed", |
|
200 alert.getTimeout() != Alert.FOREVER); |
|
201 alert.setCommandListener(this); |
|
202 Command testCmd = new Command("test", "test", Command.ITEM, 0); |
|
203 alert.addCommand(testCmd); |
|
204 setCurrent(alert); |
|
205 // wait for max 10sec to get command listener callback |
|
206 assertTrue("Textbox isShown() should be false", !textBox.isShown()); |
|
207 assertCmdListener("", testCmd, alert); |
|
208 } |
|
209 |
|
210 /** |
|
211 * Tests pressing keys on Alert's custom commands. |
|
212 */ |
|
213 public void testKeypressOnCustomCommands() { |
|
214 setCurrent(textBox); |
|
215 |
|
216 Alert alert = new Alert("keypressAlert"); |
|
217 assertTrue("Alert should be timed", |
|
218 alert.getTimeout() != Alert.FOREVER); |
|
219 alert.setCommandListener(this); |
|
220 Command testCmd1 = new Command("Cmd1", "Command 1", Command.SCREEN, 0); |
|
221 Command testCmd2 = new Command("Cmd2", "Command 2", Command.SCREEN, 1); |
|
222 alert.addCommand(testCmd1); |
|
223 alert.addCommand(testCmd2); |
|
224 assertTrue("Alert should be modal", |
|
225 alert.getTimeout() == Alert.FOREVER); |
|
226 |
|
227 setCurrent(alert); |
|
228 key(Key.CBA1, 0); |
|
229 key(Key.Select); |
|
230 assertCmdListener("", testCmd1, alert); |
|
231 setCurrent(textBox); |
|
232 |
|
233 setCurrent(alert); |
|
234 key(Key.CBA1, 0); |
|
235 key(Key.DownArrow, 0); |
|
236 key(Key.Select); |
|
237 assertCmdListener("", testCmd2, alert); |
|
238 } |
|
239 |
|
240 /** |
|
241 * Tests scrolling a long text. |
|
242 */ |
|
243 public void testLongTextScrolling() { |
|
244 setCurrent(textBox); |
|
245 |
|
246 Alert alert = new Alert("scrollingAlert"); |
|
247 alert.setString(longString); |
|
248 alert.setCommandListener(this); |
|
249 assertTrue("Alert should be modal", |
|
250 alert.getTimeout() == Alert.FOREVER); |
|
251 |
|
252 setCurrent(alert); |
|
253 for (int i = 0; i < 10; i++) { |
|
254 key((i < 5 ? Key.DownArrow : Key.UpArrow)); |
|
255 } |
|
256 |
|
257 key(Key.CBA1); |
|
258 assertCmdListener("", Alert.DISMISS_COMMAND, alert); |
|
259 } |
|
260 |
|
261 /** |
|
262 * Tests different text and image setting combinations. |
|
263 */ |
|
264 public void testImageAndTextCombinations() { |
|
265 setCurrent(textBox); |
|
266 |
|
267 Image smallImg = null; |
|
268 Image largeImg = null; |
|
269 try { |
|
270 smallImg = Image.createImage("100x100.png"); |
|
271 } |
|
272 catch (IOException e) { |
|
273 fail("Cannot load image 100x100.png"); |
|
274 } |
|
275 try { |
|
276 largeImg = Image.createImage("200x200.png"); |
|
277 } |
|
278 catch (IOException e) { |
|
279 fail("Cannot load image 200x200.png"); |
|
280 } |
|
281 |
|
282 Alert alert = new Alert("varyingAlert"); |
|
283 alert.setTimeout(Alert.FOREVER); |
|
284 alert.setCommandListener(this); |
|
285 assertTrue("Alert should be modal", |
|
286 alert.getTimeout() == Alert.FOREVER); |
|
287 |
|
288 setCurrent(alert); |
|
289 for (int textIndex = 0; textIndex < 3; textIndex++) { |
|
290 switch (textIndex) { |
|
291 case 0: |
|
292 alert.setString(null); |
|
293 break; |
|
294 case 1: |
|
295 alert.setString(shortString); |
|
296 break; |
|
297 case 2: |
|
298 alert.setString(longString); |
|
299 break; |
|
300 default: |
|
301 break; |
|
302 } |
|
303 for (int imgIndex = 0; imgIndex < 3; imgIndex++) { |
|
304 switch (imgIndex) { |
|
305 case 0: |
|
306 alert.setImage(null); |
|
307 break; |
|
308 case 1: |
|
309 alert.setImage(smallImg); |
|
310 break; |
|
311 case 2: |
|
312 alert.setImage(largeImg); |
|
313 break; |
|
314 default: |
|
315 break; |
|
316 } |
|
317 block(CHANGE_DISPLAYABLE_DELAY); // 0.3 sec |
|
318 } |
|
319 } |
|
320 block(1000); // 1sec |
|
321 |
|
322 key(Key.CBA1); |
|
323 assertCmdListener("", Alert.DISMISS_COMMAND, alert); |
|
324 } |
|
325 |
|
326 } |