author | shurailine |
Fri, 02 Mar 2018 14:25:39 -0800 | |
changeset 49218 | 3f825ec26b01 |
parent 47841 | 3b6fc119b32b |
child 51921 | 372cbac1a862 |
permissions | -rw-r--r-- |
36744 | 1 |
/* |
2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
24 |
import com.sun.swingset3.demos.button.ButtonDemo; |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
25 |
import org.jtregext.GuiTestListener; |
36744 | 26 |
import org.netbeans.jemmy.ClassReference; |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
27 |
import org.netbeans.jemmy.ComponentChooser; |
36744 | 28 |
import org.netbeans.jemmy.image.StrictImageComparator; |
29 |
import org.netbeans.jemmy.operators.JButtonOperator; |
|
30 |
import org.netbeans.jemmy.operators.JFrameOperator; |
|
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
31 |
import org.testng.annotations.BeforeClass; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
32 |
import org.testng.annotations.Listeners; |
36744 | 33 |
import org.testng.annotations.Test; |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
34 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
35 |
import java.awt.Component; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
36 |
import java.awt.Robot; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
37 |
import java.awt.image.BufferedImage; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
38 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
39 |
import static com.sun.swingset3.demos.button.ButtonDemo.DEMO_TITLE; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
40 |
import static org.jemmy2ext.JemmyExt.*; |
36744 | 41 |
|
42 |
/* |
|
43 |
* @test |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
44 |
* @key headful screenshots intermittent |
36744 | 45 |
* @summary Verifies buttons on SwingSet3 ButtonDemo page by clicking each |
46 |
* button, taking its screenshots and checking that pressed button |
|
47 |
* image is different from initial button image. |
|
48 |
* |
|
49 |
* @library /sanity/client/lib/jemmy/src |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
50 |
* @library /sanity/client/lib/Extensions/src |
36744 | 51 |
* @library /sanity/client/lib/SwingSet3/src |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
52 |
* @modules java.desktop |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
53 |
* java.logging |
36744 | 54 |
* @build org.jemmy2ext.JemmyExt |
55 |
* @build com.sun.swingset3.demos.button.ButtonDemo |
|
56 |
* @run testng ButtonDemoScreenshotTest |
|
57 |
*/ |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
58 |
@Listeners(GuiTestListener.class) |
36744 | 59 |
public class ButtonDemoScreenshotTest { |
60 |
||
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
61 |
private static final int[] BUTTONS = {0, 1, 2, 3, 4, 5}; // "open browser" buttons (6, 7) open a browser, so ignore |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
62 |
private static StrictImageComparator sComparator = null; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
63 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
64 |
@BeforeClass |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
65 |
public void init() { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
66 |
sComparator = new StrictImageComparator(); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
67 |
} |
36744 | 68 |
|
69 |
@Test |
|
70 |
public void test() throws Exception { |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
71 |
Robot rob = new Robot(); |
36744 | 72 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
73 |
new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication(); |
36744 | 74 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
75 |
JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
76 |
waitImageIsStill(rob, mainFrame); |
36744 | 77 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
78 |
// Check all the buttons |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
79 |
for (int i : BUTTONS) { |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
80 |
checkButton(mainFrame, i, rob); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
81 |
} |
36744 | 82 |
} |
83 |
||
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
84 |
private void checkButton(JFrameOperator jfo, int i, Robot rob) { |
36744 | 85 |
JButtonOperator button = new JButtonOperator(jfo, i); |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
86 |
|
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
87 |
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
88 |
java.util.concurrent.atomic.AtomicBoolean actionListenerCalled = new java.util.concurrent.atomic.AtomicBoolean(false); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
89 |
button.addActionListener(e -> actionListenerCalled.set(true)); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
90 |
//end of instrumentation for JDK-8198920 |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
91 |
|
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
92 |
button.moveMouse(button.getCenterX(), button.getCenterY()); |
36744 | 93 |
|
94 |
BufferedImage initialButtonImage = capture(rob, button); |
|
95 |
assertNotBlack(initialButtonImage); |
|
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
96 |
save(initialButtonImage, "button" + i + ".png"); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
97 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
98 |
BufferedImage[] pressedImage = new BufferedImage[1]; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
99 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
100 |
button.pressMouse(); |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
101 |
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
102 |
button.getOutput().printTrace("JDK-8198920: Button pressed at " + System.currentTimeMillis()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
103 |
//end of instrumentation for JDK-8198920 |
36744 | 104 |
try { |
105 |
waitPressed(button); |
|
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
106 |
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
107 |
button.getOutput().printTrace("JDK-8198920: Button press confirmed by " + System.currentTimeMillis()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
108 |
//end of instrumentation for JDK-8198920 |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
109 |
button.waitState(new ComponentChooser() { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
110 |
public boolean checkComponent(Component c) { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
111 |
pressedImage[0] = capture(rob, button); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
112 |
assertNotBlack(pressedImage[0]); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
113 |
return !sComparator.compare(initialButtonImage, pressedImage[0]); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
114 |
} |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
115 |
public String getDescription() { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
116 |
return "Button with new image"; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
117 |
} |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
118 |
}); |
36744 | 119 |
} finally { |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
120 |
if(pressedImage[0] != null) save(pressedImage[0], "button" + i + "_pressed.png"); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
121 |
button.releaseMouse(); |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
122 |
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
123 |
button.getOutput().printTrace("JDK-8198920: Button released at " + System.currentTimeMillis()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
124 |
try { |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
125 |
button.waitState(comp -> actionListenerCalled.get()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
126 |
button.getOutput().printTrace("JDK-8198920: Action listener was called by " + System.currentTimeMillis()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
127 |
} catch(org.netbeans.jemmy.TimeoutExpiredException e) { |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
128 |
button.getOutput().printTrace("JDK-8198920: Action listener was not called by " + System.currentTimeMillis()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
129 |
} |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
130 |
//end of instrumentation for JDK-8198920 |
36744 | 131 |
} |
132 |
} |
|
133 |
} |