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 // UITestUtils.java // // // |
|
18 |
|
19 package com.nokia.mj.impl.uitestutils; |
|
20 |
|
21 import java.lang.String; |
|
22 import org.eclipse.swt.internal.qt.OS; |
|
23 |
|
24 public class UITestUtils { |
|
25 |
|
26 private static final int RES_CHANGE_DEFAULT_DELAY = 5000; |
|
27 |
|
28 public UITestUtils() { |
|
29 // Always disable screensaver when running tests. |
|
30 S60Utils.S60DisableScreensaver(); |
|
31 } |
|
32 |
|
33 /** Init test and s. shot directory, make sure you use slashes to start and |
|
34 end it dir name */ |
|
35 public void startTest(String screenShotDir) { |
|
36 } |
|
37 |
|
38 /** Ends the test, prints a summary, etc */ |
|
39 public void endTest(boolean passed, String msg) { |
|
40 } |
|
41 |
|
42 /** Log a message */ |
|
43 public void log(String msg) { |
|
44 } |
|
45 |
|
46 /** Logs one of the two messages and either PASSED or FAILED according to |
|
47 value of passed parameter */ |
|
48 public void log(boolean passed, String msgPassed, String msgFailed) { |
|
49 } |
|
50 |
|
51 /** Sends a key event to the midlet using the specified key and scan code */ |
|
52 public void triggerKeyPressEvent(Key key) { |
|
53 int keycode = key.scanCode; |
|
54 int modifiers = key.modifiers; |
|
55 if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.PRESS) != 0) |
|
56 throw new RuntimeException("Emulating key press failed"); |
|
57 if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.RELEASE) != 0) |
|
58 throw new RuntimeException("Emulating key release failed"); |
|
59 } |
|
60 |
|
61 /** Sends a key down event to the application using the specified key */ |
|
62 public void triggerKeyDownEvent(Key key) { |
|
63 int keycode = key.scanCode; |
|
64 int modifiers = key.modifiers; |
|
65 if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.PRESS) != 0) |
|
66 throw new RuntimeException("Emulating key press failed"); |
|
67 } |
|
68 |
|
69 /** Sends a key up event to the application using the specified key */ |
|
70 public void triggerKeyUpEvent(Key key) { |
|
71 int keycode = key.scanCode; |
|
72 int modifiers = key.modifiers; |
|
73 if(S60Utils.S60SendKeyToFocusWindow(keycode, modifiers, S60Utils.RELEASE) != 0) |
|
74 throw new RuntimeException("Emulating key release failed"); |
|
75 } |
|
76 |
|
77 |
|
78 /** Triggers key repeat events using the specified key and scan code. |
|
79 Calling this method will trigger the following events to Canvas/CustomItem: |
|
80 1. keyPressed event |
|
81 2. keyRepeated events, the number of events is indicated by count parameter |
|
82 3. keyReleased events |
|
83 |
|
84 NOTE 1: This method returns right after triggering the keyPressed event. There should be enough delay |
|
85 after calling this so that all repeat events can be handled before the test result is checked. |
|
86 The delay before triggering first repeat event is 0.6 seconds and between sequential repeat |
|
87 events 0.2 seconds. |
|
88 |
|
89 NOTE 2: For triggering media key repeat events triggerMediaKeyRepeatEvents() |
|
90 must be used. |
|
91 */ |
|
92 public int triggerKeyRepeatEvents(Key key, int count) { |
|
93 return 0; |
|
94 } |
|
95 |
|
96 /** This method must be used when triggering repeat events for media keys. |
|
97 pressedTimeInMillis defines how long a key is kept pressed down. |
|
98 |
|
99 NOTE 1: This method returns right after triggering the keyDown event. There should be enough delay |
|
100 (> pressedTimeInMillis) after calling this so that all repeat events and key up can be handled before |
|
101 the test result is checked. |
|
102 */ |
|
103 public int triggerMediaKeyRepeatEvents(Key key, int pressedTimeInMillis) { |
|
104 return 0; |
|
105 } |
|
106 |
|
107 /** Sends pointer down event to the midlet */ |
|
108 public void triggerPointerDownEvent(int x, int y) { |
|
109 // Setting double click interval to 0 disables double clicks, making it possible |
|
110 // to click around in the test cases quickly without causing unwanted double click |
|
111 // events |
|
112 OS.QApplication_setDoubleClickInterval(0); |
|
113 if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON1, S60Utils.PRESS) != 0) |
|
114 throw new RuntimeException("Emulating pointer down failed"); |
|
115 } |
|
116 |
|
117 /** Sends pointer up event to the midlet */ |
|
118 public void triggerPointerUpEvent(int x, int y) { |
|
119 if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON1, S60Utils.RELEASE) != 0) |
|
120 throw new RuntimeException("Emulating pointer up failed"); |
|
121 } |
|
122 |
|
123 /** Sends pointer drag event to the midlet */ |
|
124 public void triggerPointerDragEvent(int x, int y) { |
|
125 if(S60Utils.S60SendPointerMoveEvent(x, y, S60Utils.BUTTON1) != 0 ) { |
|
126 throw new RuntimeException("Emulating pointer move failed"); |
|
127 } |
|
128 } |
|
129 |
|
130 /** |
|
131 * Sends a pointer event to open up a context menu. E.g. long-press, right-click |
|
132 * or such depending on the platform. |
|
133 */ |
|
134 public void triggerContextPointerEvent(int x, int y) { |
|
135 if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON3, S60Utils.PRESS) != 0) |
|
136 throw new RuntimeException("Emulating pointer down failed"); |
|
137 if(S60Utils.S60SendPointerEvent(x, y, S60Utils.BUTTON3, S60Utils.RELEASE) != 0) |
|
138 throw new RuntimeException("Emulating pointer up failed"); |
|
139 } |
|
140 |
|
141 /** Takes a screen shot and saves it into a .png file. Returns true if |
|
142 reference screen shot exists and is identical to the new screen shot*/ |
|
143 public boolean getScreenShot(String screenShotName) { |
|
144 return true; |
|
145 } |
|
146 |
|
147 /** Takes a screen shot and saves it into a .png file. Returns true if |
|
148 reference screen shot exists and compared area is identical in the reference and new screen shot. |
|
149 areaToCompare and displayableType define the area that is compared. See also SpedeRunner.java.*/ |
|
150 public boolean getScreenShot(String screenShotName, int areaToCompare, int displayableType) { |
|
151 return true; |
|
152 } |
|
153 |
|
154 /** Takes a screen shot and saves it into a .png file. Returns true if |
|
155 reference screen shot exists and compared area is identical in the reference and new screen shot. |
|
156 Four integer parameters define the rectangle area for screen shot comparison. */ |
|
157 public boolean getScreenShot(String screenShotName, int topLeftX, int topLeftY, |
|
158 int bottomRightX, int bottomRightY) { |
|
159 return true; |
|
160 } |
|
161 |
|
162 public void dispose() { |
|
163 } |
|
164 |
|
165 /** Enable or disable QWERTY input */ |
|
166 public void changeQwertyInput(boolean aOn) { |
|
167 } |
|
168 |
|
169 public int switchResolution() { |
|
170 return switchResolution(1); |
|
171 } |
|
172 |
|
173 /** Change the screen resolution - works only on the emulator */ |
|
174 public int switchResolution(int numTimes) { |
|
175 return 0; |
|
176 } |
|
177 |
|
178 /** Change the screen resolution - works only on the emulator */ |
|
179 public int switchResolutionWithDelay(int delayMillis) { |
|
180 return 0; |
|
181 } |
|
182 |
|
183 /** |
|
184 * Get the top left and bottom right coordinates of main pane, form rect, etc. |
|
185 * |
|
186 * @param coordinates The coordinates are returned in this array |
|
187 * @param type Defines for which area the coordinates are fetched |
|
188 */ |
|
189 public void getBoundsOf(int type, int[] coordinates) { |
|
190 } |
|
191 |
|
192 /** |
|
193 * Disable screen saver |
|
194 */ |
|
195 public void disableScreenSaver() { |
|
196 } |
|
197 |
|
198 /** |
|
199 * Enable screen saver |
|
200 */ |
|
201 public void enableScreenSaver() { |
|
202 } |
|
203 } |
|