Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/ToolTipDemoTest.java
41153 views
1
/*
2
* Copyright (c) 2018, 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 static com.sun.swingset3.demos.tooltip.ToolTipDemo.DEMO_TITLE;
25
import static com.sun.swingset3.demos.tooltip.ToolTipDemo.HTML_TOOLTIP_COMP_TITLE;
26
import static com.sun.swingset3.demos.tooltip.ToolTipDemo.HTML_TOOLTIP_TEXT;
27
import static com.sun.swingset3.demos.tooltip.ToolTipDemo.PLAIN_TOOLTIP_COMP_TITLE;
28
import static com.sun.swingset3.demos.tooltip.ToolTipDemo.PLAIN_TOOLTIP_TEXT;
29
import static com.sun.swingset3.demos.tooltip.ToolTipDemo.STYLE_TOOLTIP_COMP_TITLE;
30
import static com.sun.swingset3.demos.tooltip.ToolTipDemo.STYLE_TOOLTIP_TEXT;
31
import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR;
32
33
import java.awt.Dimension;
34
import java.awt.Point;
35
36
import javax.swing.ToolTipManager;
37
import javax.swing.UIManager;
38
39
import org.jtregext.GuiTestListener;
40
import org.netbeans.jemmy.ClassReference;
41
import org.netbeans.jemmy.operators.JComponentOperator;
42
import org.netbeans.jemmy.operators.JFrameOperator;
43
import org.netbeans.jemmy.operators.JLabelOperator;
44
import org.netbeans.jemmy.operators.JToolTipOperator;
45
import org.testng.annotations.Listeners;
46
import org.testng.annotations.Test;
47
48
import com.sun.swingset3.demos.tooltip.ToolTipDemo;
49
50
/*
51
* @test
52
* @key headful
53
* @summary Verifies SwingSet3 ToolTipDemo page by checking whether tooltip
54
* shown or removed on user actions, tooltip text, location, number of
55
* tooltips shown at a time, with different tooltip texts plain, html and
56
* styled.
57
*
58
* @library /sanity/client/lib/jemmy/src
59
* @library /sanity/client/lib/Extensions/src
60
* @library /sanity/client/lib/SwingSet3/src
61
* @modules java.desktop
62
* java.logging
63
* @build org.jemmy2ext.JemmyExt
64
* @build com.sun.swingset3.demos.tooltip.ToolTipDemo
65
* @run testng/timeout=600 ToolTipDemoTest
66
*/
67
@Listeners(GuiTestListener.class)
68
public class ToolTipDemoTest {
69
70
private static int TOOLTIP_DISMISS_DELAY = 60000;
71
72
/**
73
* Testing whether tooltip shown while keeping the mouse on label, removed
74
* on mouse press, tooltip text, location, number of tooltips shown at a
75
* time with different tooltip texts plain, html and styled.
76
*
77
* @throws Exception
78
*/
79
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
80
public void test(String lookAndFeel) throws Exception {
81
UIManager.setLookAndFeel(lookAndFeel);
82
new ClassReference(ToolTipDemo.class.getCanonicalName()).startApplication();
83
JFrameOperator frameOperator = new JFrameOperator(DEMO_TITLE);
84
frameOperator.setComparator(EXACT_STRING_COMPARATOR);
85
// Setting the tooltip dismiss delay
86
ToolTipManager.sharedInstance().setDismissDelay(TOOLTIP_DISMISS_DELAY);
87
88
// Verifying the plain tooltip properties
89
checkToolTip(frameOperator, PLAIN_TOOLTIP_COMP_TITLE,
90
PLAIN_TOOLTIP_TEXT);
91
// Verifying the html tooltip properties
92
checkToolTip(frameOperator, HTML_TOOLTIP_COMP_TITLE,
93
HTML_TOOLTIP_TEXT);
94
// Verifying the styled tooltip properties
95
checkToolTip(frameOperator, STYLE_TOOLTIP_COMP_TITLE,
96
STYLE_TOOLTIP_TEXT);
97
98
// Reducing the frame size to half and verifying that tooltip shown
99
// even it goes out of the window
100
Dimension newSize = new Dimension(frameOperator.getWidth() / 2,
101
frameOperator.getHeight() / 2);
102
frameOperator.resize(newSize.width, newSize.height);
103
frameOperator.waitComponentSize(newSize);
104
checkToolTip(frameOperator, HTML_TOOLTIP_COMP_TITLE,
105
HTML_TOOLTIP_TEXT);
106
}
107
108
/**
109
* Shows the tooltip on specified component and verifies the properties
110
* tooltip text, location. And dismisses thetooltip after verification of
111
* the properties.
112
*
113
* @param frameOperator
114
* @param compTitle
115
* @param toolTipText
116
*/
117
private void checkToolTip(JFrameOperator frameOperator, String compTitle,
118
String toolTipText) {
119
120
JLabelOperator toolTipHostComp =
121
new JLabelOperator(frameOperator, compTitle);
122
JToolTipOperator toolTipOperator =
123
new JToolTipOperator(toolTipHostComp.showToolTip());
124
toolTipOperator.waitTipText(toolTipText);
125
checkToolTipLocation(toolTipHostComp, toolTipOperator);
126
127
// Dismissing the tooltip by mouse click
128
toolTipHostComp.clickMouse();
129
toolTipOperator.waitComponentShowing(false);
130
131
}
132
133
private void checkToolTipLocation(JComponentOperator componentOpertor,
134
JToolTipOperator toolTipOperator) {
135
Point labelStartPoint = componentOpertor.getLocationOnScreen();
136
Dimension labelSize = componentOpertor.getSize();
137
Point labelEndPoint = new Point((labelStartPoint.x + labelSize.width),
138
(labelStartPoint.y + labelSize.height));
139
toolTipOperator.waitComponentLocationOnScreen(
140
labelStartPoint, labelEndPoint);
141
}
142
}
143
144