Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
41153 views
1
/*
2
* Copyright (c) 2011, 2020, 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
24
import com.sun.swingset3.demos.button.ButtonDemo;
25
import org.jtregext.GuiTestListener;
26
import org.netbeans.jemmy.ClassReference;
27
import org.netbeans.jemmy.operators.JButtonOperator;
28
import org.netbeans.jemmy.operators.JFrameOperator;
29
import org.testng.annotations.Listeners;
30
import org.testng.annotations.Test;
31
32
import java.awt.Dimension;
33
import java.awt.Point;
34
import java.awt.Rectangle;
35
import java.awt.Toolkit;
36
import java.awt.image.BufferedImage;
37
38
import javax.swing.UIManager;
39
import static com.sun.swingset3.demos.button.ButtonDemo.DEMO_TITLE;
40
import static org.jemmy2ext.JemmyExt.*;
41
42
/*
43
* @test
44
* @key headful screenshots
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
50
* @library /sanity/client/lib/Extensions/src
51
* @library /sanity/client/lib/SwingSet3/src
52
* @modules java.desktop
53
* java.logging
54
* @build org.jemmy2ext.JemmyExt
55
* @build com.sun.swingset3.demos.button.ButtonDemo
56
* @run testng/othervm/timeout=600 -Dswing.disablevistaanimation=true ButtonDemoScreenshotTest
57
*/
58
@Listeners(GuiTestListener.class)
59
public class ButtonDemoScreenshotTest {
60
61
private static final int[] BUTTONS = {0, 1, 2, 3, 4, 5}; // "open browser" buttons (6, 7) open a browser, so ignore
62
63
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
64
public void test(String lookAndFeel) throws Exception {
65
UIManager.setLookAndFeel(lookAndFeel);
66
67
//capture some of the background
68
Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize();
69
Point screenCenter = new Point(screeSize.width / 2, screeSize.height / 2);
70
Rectangle center = new Rectangle(
71
screenCenter.x - 50, screenCenter.y - 50,
72
100, 100);
73
BufferedImage background = getRobot().createScreenCapture(center);
74
75
new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication();
76
77
JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
78
mainFrame.waitComponentShowing(true);
79
80
//make sure the frame is already painted
81
waitChangedImage(() -> getRobot().createScreenCapture(center),
82
background, mainFrame.getTimeouts(), "background");
83
//make sure the frame is painted completely
84
waitStillImage(mainFrame, "frame");
85
86
// Check all the buttons
87
for (int i : BUTTONS) {
88
checkButton(mainFrame, i);
89
}
90
}
91
92
private void checkButton(JFrameOperator jfo, int i) throws InterruptedException {
93
JButtonOperator button = new JButtonOperator(jfo, i);
94
95
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed
96
java.util.concurrent.atomic.AtomicBoolean actionListenerCalled = new java.util.concurrent.atomic.AtomicBoolean(false);
97
button.addActionListener(e -> actionListenerCalled.set(true));
98
//end of instrumentation for JDK-8198920
99
100
button.moveMouse(button.getCenterX(), button.getCenterY());
101
102
BufferedImage notPressed, pressed = null;
103
notPressed = waitStillImage(button, "not-pressed-" + i);
104
105
button.pressMouse();
106
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed
107
button.getOutput().printTrace("JDK-8198920: Button pressed at " + System.currentTimeMillis());
108
//end of instrumentation for JDK-8198920
109
try {
110
waitPressed(button);
111
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed
112
button.getOutput().printTrace("JDK-8198920: Button press confirmed by " + System.currentTimeMillis());
113
//end of instrumentation for JDK-8198920
114
waitChangedImage(() -> capture(button), notPressed,
115
button.getTimeouts(), "after-press-" + i);
116
pressed = waitStillImage(button, "pressed-" + i);
117
} finally {
118
button.releaseMouse();
119
if(pressed != null) {
120
waitChangedImage(() -> capture(button), pressed,
121
button.getTimeouts(), "released-" + i);
122
}
123
//additional instrumentation for JDK-8198920. To be removed after the bug is fixed
124
button.getOutput().printTrace("JDK-8198920: Button released at " + System.currentTimeMillis());
125
try {
126
button.waitState(comp -> actionListenerCalled.get());
127
button.getOutput().printTrace("JDK-8198920: Action listener was called by " + System.currentTimeMillis());
128
} catch (org.netbeans.jemmy.TimeoutExpiredException e) {
129
button.getOutput().printTrace("JDK-8198920: Action listener was not called by " + System.currentTimeMillis());
130
}
131
//end of instrumentation for JDK-8198920
132
}
133
}
134
}
135
136