Debian Codegraph @

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

raw
1 /* AppletAWTRobotUsageSampleTest.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.AWTException;
39 import java.awt.Color;
40 import java.awt.event.InputEvent;
41 import java.awt.image.BufferedImage;
42 import java.io.File;
43 import java.io.IOException;
44
45 import javax.imageio.ImageIO;
46
47 import net.sourceforge.jnlp.ProcessResult;
48 import net.sourceforge.jnlp.annotations.NeedsDisplay;
49 import net.sourceforge.jnlp.annotations.TestInBrowsers;
50 import net.sourceforge.jnlp.awt.AWTFrameworkException;
51 import net.sourceforge.jnlp.awt.AWTHelper;
52 import net.sourceforge.jnlp.awt.imagesearch.ComponentNotFoundException;
53 import net.sourceforge.jnlp.browsertesting.BrowserTest;
54 import net.sourceforge.jnlp.browsertesting.Browsers;
55 import net.sourceforge.jnlp.closinglisteners.Rule;
56
57 import org.junit.Assert;
58 import org.junit.Test;
59
60 public class AppletAWTRobotUsageSampleTest extends BrowserTest {
61
62 private final String initStr = "JavawsAWTRobotUsageSample is ready for awt tests!";
63
64 private static final Color APPLET_COLOR = new Color(230, 230, 250); // lavender
65 private static final Color BUTTON_COLOR1 = new Color(32, 178, 170); // light sea green
66
67 private abstract class AWTHelperImpl extends AWTHelper{
68
69 public AWTHelperImpl() {
70 super(initStr, 400, 400);
71
72 this.setAppletColor(APPLET_COLOR);
73 }
74
75 }
76
77 private class AWTHelperImpl_EnterExit extends AWTHelperImpl {
78
79 @Override
80 public void run() {
81 // move mouse into the button area and out
82 try {
83 moveToMiddleOfColoredRectangle(BUTTON_COLOR1);
84 moveOutsideColoredRectangle(BUTTON_COLOR1);
85 } catch (ComponentNotFoundException e) {
86 Assert.fail("Button not found: "+e.getMessage());
87 } catch (AWTFrameworkException e2){
88 Assert.fail("AWTFrameworkException: "+e2.getMessage());
89 }
90 }
91 }
92
93 private class AWTHelperImpl_MouseClick1 extends AWTHelperImpl{
94
95 @Override
96 public void run() {
97 // click in the middle of the button
98
99 try {
100 clickOnColoredRectangle(BUTTON_COLOR1, InputEvent.BUTTON1_MASK);
101 } catch (ComponentNotFoundException e) {
102 Assert.fail("Button not found: "+e.getMessage());
103 } catch (AWTFrameworkException e2){
104 Assert.fail("AWTFrameworkException: "+e2.getMessage());
105 }
106 }
107 }
108
109 private class AWTHelperImpl_MouseClick2 extends AWTHelperImpl{
110 @Override
111 public void run() {
112 // move mouse in the middle of the button and click 2nd
113 // button
114 try {
115 clickOnColoredRectangle(BUTTON_COLOR1, InputEvent.BUTTON2_MASK);
116 } catch (ComponentNotFoundException e) {
117 Assert.fail("Button not found: "+e.getMessage());
118 } catch (AWTFrameworkException e2){
119 Assert.fail("AWTFrameworkException: "+e2.getMessage());
120 }
121 }
122 }
123
124 private class AWTHelperImpl_MouseClick3 extends AWTHelperImpl{
125 @Override
126 public void run() {
127 // move mouse in the middle of the button and click 3rd
128 // button
129 try {
130 clickOnColoredRectangle(BUTTON_COLOR1, InputEvent.BUTTON3_MASK);
131 } catch (ComponentNotFoundException e) {
132 Assert.fail("Button not found: "+e.getMessage());
133 } catch (AWTFrameworkException e2){
134 Assert.fail("AWTFrameworkException: "+e2.getMessage());
135 }
136 }
137 }
138
139 private class AWTHelperImpl_MouseDrag extends AWTHelperImpl{
140 @Override
141 public void run() {
142 // move into the rectangle, press 1st button, drag out
143 try {
144 dragFromColoredRectangle(BUTTON_COLOR1);
145 } catch (ComponentNotFoundException e) {
146 Assert.fail("Button not found: "+e.getMessage());
147 } catch (AWTFrameworkException e2){
148 Assert.fail("AWTFrameworkException: "+e2.getMessage());
149 }
150 }
151 }
152
153 private class AWTHelperImpl_MouseMove extends AWTHelperImpl{
154 @Override
155 public void run() {
156 clickInTheMiddleOfApplet();
157 try {
158 moveInsideColoredRectangle(BUTTON_COLOR1);
159 } catch (ComponentNotFoundException e) {
160 Assert.fail("Button not found: "+e.getMessage());
161 } catch (AWTFrameworkException e2){
162 Assert.fail("AWTFrameworkException: "+e2.getMessage());
163 }
164 }
165 }
166
167
168 private void evaluateStdoutContents(ProcessResult pr, AWTHelper helper) {
169
170 // Assert that the applet was initialized.
171 Rule i = helper.getInitStrAsRule();
172 Assert.assertTrue(i.toPassingString(), i.evaluate(initStr));
173
174 // Assert there are all the test messages from applet
175 for (Rule r : helper.getRules() ) {
176 Assert.assertTrue(r.toPassingString(), r.evaluate(pr.stdout));
177 }
178
179 }
180
181
182 private void appletAWTMouseTest(String url, AWTHelper helper)
183 throws Exception {
184
185 String strURL = "/" + url;
186
187 ProcessResult pr = server.executeBrowser(strURL, helper, helper);
188 evaluateStdoutContents(pr, helper);
189 }
190
191 @Test
192 @TestInBrowsers(testIn = { Browsers.one })
193 @NeedsDisplay
194 public void AppletAWTMouse_EnterAndExit_Test() throws Exception {
195
196 // display the page, activate applet, move over the button
197 AWTHelper helper = new AWTHelperImpl_EnterExit();
198 helper.addClosingRulesFromStringArray(new String[] { "mouseEntered", "mouseExited"});
199 appletAWTMouseTest("AppletAWTRobotUsageSample.html", helper);
200 }
201
202 @Test
203 @TestInBrowsers(testIn = { Browsers.one })
204 @NeedsDisplay
205 public void AppletAWTMouse_ClickButton1_Test() throws Exception {
206
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("AppletAWTRobotUsageSample.html", helper);
211 }
212
213 @Test
214 @TestInBrowsers(testIn = { Browsers.one })
215 @NeedsDisplay
216 public void AppletAWTMouse_ClickButton2_Test() throws Exception {
217
218 // display the page, activate applet, click on button
219 AWTHelper helper = new AWTHelperImpl_MouseClick2();
220 helper.addClosingRulesFromStringArray(new String[] { "mousePressedButton2", "mouseReleasedButton2", "mouseClickedButton2" });
221 appletAWTMouseTest("AppletAWTRobotUsageSample.html", helper);
222 }
223
224 @Test
225 @TestInBrowsers(testIn = { Browsers.one })
226 @NeedsDisplay
227 public void AppletAWTMouse_ClickButton3_Test() throws Exception {
228
229 // display the page, activate applet, click on button
230 AWTHelper helper = new AWTHelperImpl_MouseClick3();
231 helper.addClosingRulesFromStringArray(new String[] { "mousePressedButton3", "mouseReleasedButton3", "mouseClickedButton3" });
232 appletAWTMouseTest("AppletAWTRobotUsageSample.html", helper);
233 }
234
235 @Test
236 @TestInBrowsers(testIn = { Browsers.one })
237 @NeedsDisplay
238 public void AppletAWTMouse_Drag_Test() throws Exception {
239
240 // display the page, activate applet, click on button
241 AWTHelper helper = new AWTHelperImpl_MouseDrag();
242 helper.addClosingRulesFromStringArray(new String[] { "mouseDragged" });
243 appletAWTMouseTest("AppletAWTRobotUsageSample.html", helper);
244 }
245
246 @Test
247 @TestInBrowsers(testIn = { Browsers.one })
248 @NeedsDisplay
249 public void AppletAWTMouse_Move_Test() throws Exception {
250
251 // display the page, activate applet, click on button
252 AWTHelper helper = new AWTHelperImpl_MouseMove();
253 helper.addClosingRulesFromStringArray(new String[] { "mouseMoved" });
254 appletAWTMouseTest("AppletAWTRobotUsageSample.html", helper);
255 }
256 }