author | vagarwal |
Wed, 12 Sep 2018 11:51:39 +0530 | |
changeset 51921 | 372cbac1a862 |
parent 49218 | 3f825ec26b01 |
child 52128 | 1e0cdaf980f3 |
permissions | -rw-r--r-- |
36744 | 1 |
/* |
51921
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
2 |
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
36744 | 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 |
|
51921
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
39 |
import javax.swing.UIManager; |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
40 |
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
|
41 |
import static org.jemmy2ext.JemmyExt.*; |
36744 | 42 |
|
43 |
/* |
|
44 |
* @test |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
45 |
* @key headful screenshots intermittent |
36744 | 46 |
* @summary Verifies buttons on SwingSet3 ButtonDemo page by clicking each |
47 |
* button, taking its screenshots and checking that pressed button |
|
48 |
* image is different from initial button image. |
|
49 |
* |
|
50 |
* @library /sanity/client/lib/jemmy/src |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
51 |
* @library /sanity/client/lib/Extensions/src |
36744 | 52 |
* @library /sanity/client/lib/SwingSet3/src |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
53 |
* @modules java.desktop |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
54 |
* java.logging |
36744 | 55 |
* @build org.jemmy2ext.JemmyExt |
56 |
* @build com.sun.swingset3.demos.button.ButtonDemo |
|
57 |
* @run testng ButtonDemoScreenshotTest |
|
58 |
*/ |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
59 |
@Listeners(GuiTestListener.class) |
36744 | 60 |
public class ButtonDemoScreenshotTest { |
61 |
||
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
62 |
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
|
63 |
private static StrictImageComparator sComparator = null; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
64 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
65 |
@BeforeClass |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
66 |
public void init() { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
67 |
sComparator = new StrictImageComparator(); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
68 |
} |
36744 | 69 |
|
51921
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
70 |
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class) |
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
71 |
public void test(String lookAndFeel) throws Exception { |
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
72 |
UIManager.setLookAndFeel(lookAndFeel); |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
73 |
Robot rob = new Robot(); |
36744 | 74 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
75 |
new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication(); |
36744 | 76 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
77 |
JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
78 |
waitImageIsStill(rob, mainFrame); |
36744 | 79 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
80 |
// Check all the buttons |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
81 |
for (int i : BUTTONS) { |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
82 |
checkButton(mainFrame, i, rob); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
83 |
} |
36744 | 84 |
} |
85 |
||
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
86 |
private void checkButton(JFrameOperator jfo, int i, Robot rob) { |
36744 | 87 |
JButtonOperator button = new JButtonOperator(jfo, i); |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
88 |
|
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
89 |
//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
|
90 |
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
|
91 |
button.addActionListener(e -> actionListenerCalled.set(true)); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
92 |
//end of instrumentation for JDK-8198920 |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
93 |
|
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
94 |
button.moveMouse(button.getCenterX(), button.getCenterY()); |
36744 | 95 |
|
96 |
BufferedImage initialButtonImage = capture(rob, button); |
|
97 |
assertNotBlack(initialButtonImage); |
|
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
98 |
save(initialButtonImage, "button" + i + ".png"); |
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 |
BufferedImage[] pressedImage = new BufferedImage[1]; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
101 |
|
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
102 |
button.pressMouse(); |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
103 |
//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
|
104 |
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
|
105 |
//end of instrumentation for JDK-8198920 |
36744 | 106 |
try { |
107 |
waitPressed(button); |
|
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
108 |
//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
|
109 |
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
|
110 |
//end of instrumentation for JDK-8198920 |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
111 |
button.waitState(new ComponentChooser() { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
112 |
public boolean checkComponent(Component c) { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
113 |
pressedImage[0] = capture(rob, button); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
114 |
assertNotBlack(pressedImage[0]); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
115 |
return !sComparator.compare(initialButtonImage, pressedImage[0]); |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
116 |
} |
51921
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
117 |
|
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
118 |
public String getDescription() { |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
119 |
return "Button with new image"; |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
120 |
} |
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
121 |
}); |
36744 | 122 |
} finally { |
51921
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
123 |
if (pressedImage[0] != null) { |
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
124 |
save(pressedImage[0], "button" + i + "_pressed.png"); |
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
125 |
} |
47841
3b6fc119b32b
8157338: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java is unstable
shurailine
parents:
47216
diff
changeset
|
126 |
button.releaseMouse(); |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
127 |
//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
|
128 |
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
|
129 |
try { |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
130 |
button.waitState(comp -> actionListenerCalled.get()); |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
131 |
button.getOutput().printTrace("JDK-8198920: Action listener was called by " + System.currentTimeMillis()); |
51921
372cbac1a862
8210052: Enable testing for all the available look and feels in SwingSet3 demo tests
vagarwal
parents:
49218
diff
changeset
|
132 |
} catch (org.netbeans.jemmy.TimeoutExpiredException e) { |
49218
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
133 |
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
|
134 |
} |
3f825ec26b01
8198922: Provide instrumentation for sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
shurailine
parents:
47841
diff
changeset
|
135 |
//end of instrumentation for JDK-8198920 |
36744 | 136 |
} |
137 |
} |
|
138 |
} |