Debian Codegraph @

tests/reproducers/simple/JavawsAWTRobotUsageSample/testcases/JavawsAWTRobotUsageSampleTest.java

raw
1 /* JavawsAWTRobotUsageSampleTest.java
2 Copyright (C) 2012 Red Hat, Inc.
3
4 This file is part of IcedTea.
5
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library. Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module. An independent module is a module which is not derived from
32 or based on this library. If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so. If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37
38 import java.awt.Color;
39 import java.awt.event.InputEvent;
40 import java.awt.image.BufferedImage;
41 import java.io.File;
42 import java.io.IOException;
43
44 import javax.imageio.ImageIO;
45
46 import net.sourceforge.jnlp.ProcessResult;
47 import net.sourceforge.jnlp.ServerAccess;
48 import net.sourceforge.jnlp.annotations.NeedsDisplay;
49 import net.sourceforge.jnlp.awt.AWTFrameworkException;
50 import net.sourceforge.jnlp.awt.AWTHelper;
51 import net.sourceforge.jnlp.awt.imagesearch.ComponentNotFoundException;
52 import net.sourceforge.jnlp.browsertesting.BrowserTest;
53 import net.sourceforge.jnlp.closinglisteners.Rule;
54
55 import org.junit.Assert;
56 import org.junit.Test;
57
58 public class JavawsAWTRobotUsageSampleTest {
59
60 public static final ServerAccess server = new ServerAccess();
61
62 private final String initStr = "JavawsAWTRobotUsageSample is ready for awt tests!";
63 private static final Color APPLET_COLOR = new Color(230, 230, 250); // lavender
64 private static final Color BUTTON_COLOR1 = new Color(32, 178, 170); // light sea green
65
66 private abstract class AWTHelperImpl extends AWTHelper{
67
68 public AWTHelperImpl() {
69 super(initStr, 400, 400);
70
71 this.setAppletColor(APPLET_COLOR);
72 }
73
74 }
75
76 private class AWTHelperImpl_EnterExit extends AWTHelperImpl {
77
78 @Override
79 public void run() {
80 // move mouse into the button area and out
81 try {
82 moveToMiddleOfColoredRectangle(BUTTON_COLOR1);
83 moveOutsideColoredRectangle(BUTTON_COLOR1);
84 } catch (ComponentNotFoundException e) {
85 Assert.fail("Button not found: "+e.getMessage());
86 } catch (AWTFrameworkException e2){
87 Assert.fail("AWTFrameworkException: "+e2.getMessage());
88 }
89 }
90 }
91
92 private class AWTHelperImpl_MouseClick1 extends AWTHelperImpl{
93
94 @Override
95 public void run() {
96 // click in the middle of the button
97
98 try {
99 clickOnColoredRectangle(BUTTON_COLOR1, InputEvent.BUTTON1_MASK);
100 } catch (ComponentNotFoundException e) {
101 Assert.fail("Button not found: "+e.getMessage());
102 } catch (AWTFrameworkException e2){
103 Assert.fail("AWTFrameworkException: "+e2.getMessage());
104 }
105 }
106 }
107
108 private class AWTHelperImpl_MouseClick2 extends AWTHelperImpl{
109 @Override
110 public void run() {
111 // move mouse in the middle of the button and click 2nd
112 // button
113 try {
114 clickOnColoredRectangle(BUTTON_COLOR1, InputEvent.BUTTON2_MASK);
115 } catch (ComponentNotFoundException e) {
116 Assert.fail("Button not found: "+e.getMessage());
117 } catch (AWTFrameworkException e2){
118 Assert.fail("AWTFrameworkException: "+e2.getMessage());
119 }
120 }
121 }
122
123 private class AWTHelperImpl_MouseClick3 extends AWTHelperImpl{
124 @Override
125 public void run() {
126 // move mouse in the middle of the button and click 3rd
127 // button
128 try {
129 clickOnColoredRectangle(BUTTON_COLOR1, InputEvent.BUTTON3_MASK);
130 } catch (ComponentNotFoundException e) {
131 Assert.fail("Button not found: "+e.getMessage());
132 } catch (AWTFrameworkException e2){
133 Assert.fail("AWTFrameworkException: "+e2.getMessage());
134 }
135 }
136 }
137
138 private class AWTHelperImpl_MouseDrag extends AWTHelperImpl{
139 @Override
140 public void run() {
141 // move into the rectangle, press 1st button, drag out
142 try {
143 dragFromColoredRectangle(BUTTON_COLOR1);
144 } catch (ComponentNotFoundException e) {
145 Assert.fail("Button not found: "+e.getMessage());
146 } catch (AWTFrameworkException e2){
147 Assert.fail("AWTFrameworkException: "+e2.getMessage());
148 }
149 }
150 }
151
152 private class AWTHelperImpl_MouseMove extends AWTHelperImpl{
153 @Override
154 public void run() {
155 clickInTheMiddleOfApplet();
156 try {
157 moveInsideColoredRectangle(BUTTON_COLOR1);
158 } catch (ComponentNotFoundException e) {
159 Assert.fail("Button not found: "+e.getMessage());
160 } catch (AWTFrameworkException e2){
161 Assert.fail("AWTFrameworkException: "+e2.getMessage());
162 }
163 }
164 }
165
166
167 private void evaluateStdoutContents(ProcessResult pr, AWTHelper helper) {
168
169 // Assert that the applet was initialized.
170 Rule i = helper.getInitStrAsRule();
171 Assert.assertTrue(i.toPassingString(), i.evaluate(initStr));
172
173 // Assert there are all the test messages from applet
174 for (Rule r : helper.getRules() ) {
175 Assert.assertTrue(r.toPassingString(), r.evaluate(pr.stdout));
176 }
177
178 }
179
180
181 private void appletAWTMouseTest(String url, AWTHelper helper)
182 throws Exception {
183
184 String strURL = "/" + url;
185
186 try {
187 ServerAccess.PROCESS_TIMEOUT = 40 * 1000;// ms
188 ProcessResult pr = server.executeJavaws(strURL, helper, helper);
189 evaluateStdoutContents(pr, helper);
190 } finally {
191 ServerAccess.PROCESS_TIMEOUT = 20 * 1000;// ms
192 }
193 }
194
195 @Test
196 @NeedsDisplay
197 public void AppletAWTMouse_EnterAndExit_Test() throws Exception {
198 // display the page, activate applet, move over the button
199 AWTHelper helper = new AWTHelperImpl_EnterExit();
200 helper.addClosingRulesFromStringArray(new String[] { "mouseEntered", "mouseExited"});
201 appletAWTMouseTest("javaws-awtrobot-usage-sample.jnlp", helper);
202 }
203
204 @Test
205 @NeedsDisplay
206 public void AppletAWTMouse_ClickButton1_Test() throws Exception {
207 // display the page, activate applet, click on button
208 AWTHelper helper = new AWTHelperImpl_MouseClick1();
209 helper.addClosingRulesFromStringArray(new String[] { "mousePressedButton1", "mouseReleasedButton1", "mouseClickedButton1" });
210 appletAWTMouseTest("javaws-awtrobot-usage-sample.jnlp", helper);
211 }
212
213 @Test
214 @NeedsDisplay
215 public void AppletAWTMouse_ClickButton2_Test() throws Exception {
216 // display the page, activate applet, click on button
217 AWTHelper helper = new AWTHelperImpl_MouseClick2();
218 helper.addClosingRulesFromStringArray(new String[] { "mousePressedButton2", "mouseReleasedButton2", "mouseClickedButton2" });
219 appletAWTMouseTest("javaws-awtrobot-usage-sample.jnlp", helper);
220 }
221
222 @Test
223 @NeedsDisplay
224 public void AppletAWTMouse_ClickButton3_Test() throws Exception {
225 // display the page, activate applet, click on button
226 AWTHelper helper = new AWTHelperImpl_MouseClick3();
227 helper.addClosingRulesFromStringArray(new String[] { "mousePressedButton3", "mouseReleasedButton3", "mouseClickedButton3" });
228 appletAWTMouseTest("javaws-awtrobot-usage-sample.jnlp", helper);
229 }
230
231 @Test
232 @NeedsDisplay
233 public void AppletAWTMouse_Drag_Test() throws Exception {
234
235 // display the page, activate applet, click on button
236 AWTHelper helper = new AWTHelperImpl_MouseDrag();
237 helper.addClosingRulesFromStringArray(new String[] { "mouseDragged" });
238 appletAWTMouseTest("javaws-awtrobot-usage-sample.jnlp", helper);
239 }
240
241 @Test
242 @NeedsDisplay
243 public void AppletAWTMouse_Move_Test() throws Exception {
244 // display the page, activate applet, click on button
245 AWTHelper helper = new AWTHelperImpl_MouseMove();
246 helper.addClosingRulesFromStringArray(new String[] { "mouseMoved" });
247 appletAWTMouseTest("javaws-awtrobot-usage-sample.jnlp", helper);
248 }
249 }