author | ihse |
Tue, 09 May 2017 12:57:30 +0200 | |
changeset 45028 | b0ea3c0bfb81 |
parent 44776 | 5fcc7728c117 |
permissions | -rw-r--r-- |
24539 | 1 |
/* |
45028
b0ea3c0bfb81
8179889: Fix typographic errors in copyright headers
ihse
parents:
44776
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
24539 | 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 java.awt.*; |
|
25 |
import java.awt.event.*; |
|
26 |
import javax.swing.*; |
|
25129
3961e8fcb668
8044157: [TEST_BUG] Improve recently submitted AWT_Mixing tests
yan
parents:
24539
diff
changeset
|
27 |
import test.java.awt.regtesthelpers.Util; |
24539 | 28 |
|
29 |
/** |
|
30 |
* Base class for testing overlapping of Swing and AWT component put into one frame. |
|
31 |
* Validates drawing and event delivery at the components intersection. |
|
32 |
* <p> See base class for usage |
|
33 |
* |
|
34 |
* @author Sergey Grinev |
|
35 |
*/ |
|
36 |
public abstract class SimpleOverlappingTestBase extends OverlappingTestBase { |
|
37 |
||
38 |
{ |
|
39 |
testEmbeddedFrame = true; |
|
40 |
} |
|
41 |
||
42 |
/** |
|
43 |
* Event delivery validation. If set to true (default) tested lightweight component will be provided |
|
44 |
* with mouse listener which should be called in order for test to pass. |
|
45 |
*/ |
|
46 |
protected final boolean useDefaultClickValidation; |
|
47 |
||
48 |
/** |
|
49 |
* Constructor which sets {@link SimpleOverlappingTestBase#useDefaultClickValidation } |
|
50 |
* @param defaultClickValidation |
|
51 |
*/ |
|
52 |
protected SimpleOverlappingTestBase(boolean defaultClickValidation) { |
|
53 |
super(); |
|
54 |
this.useDefaultClickValidation = defaultClickValidation; |
|
55 |
} |
|
56 |
||
57 |
public SimpleOverlappingTestBase() { |
|
58 |
this(true); |
|
59 |
} |
|
60 |
||
61 |
//overridables |
|
62 |
/** |
|
63 |
* Successors override this method providing swing component for testing |
|
64 |
* @return swing component to test |
|
65 |
*/ |
|
66 |
protected abstract JComponent getSwingComponent(); |
|
67 |
||
68 |
/** |
|
69 |
* For tests debugging. Please, ignore. |
|
70 |
*/ |
|
71 |
protected static final boolean debug = false; |
|
72 |
||
73 |
/** |
|
74 |
* Should be set to true if test isn't using {@link SimpleOverlappingTestBase#useDefaultClickValidation } |
|
75 |
*/ |
|
76 |
protected volatile boolean wasLWClicked = false; |
|
77 |
||
78 |
/** |
|
79 |
* Current tested lightweight component |
|
80 |
* @see SimpleOverlappingTestBase#getSwingComponent() |
|
81 |
*/ |
|
82 |
protected JComponent testedComponent; |
|
83 |
||
84 |
/** |
|
85 |
* Setups simple frame with lightweight component returned by {@link SimpleOverlappingTestBase#getSwingComponent() } |
|
86 |
* Called by base class. |
|
87 |
*/ |
|
88 |
protected void prepareControls() { |
|
89 |
wasLWClicked = false; |
|
90 |
||
91 |
final JFrame f = new JFrame("Mixing : Simple Overlapping test"); |
|
92 |
f.setLayout(new SpringLayout()); |
|
93 |
f.setSize(200, 200); |
|
94 |
||
95 |
testedComponent = getSwingComponent(); |
|
96 |
||
97 |
if (useDefaultClickValidation) { |
|
98 |
testedComponent.addMouseListener(new MouseAdapter() { |
|
99 |
||
100 |
@Override |
|
101 |
public void mouseClicked(MouseEvent e) { |
|
102 |
wasLWClicked = true; |
|
103 |
f.setVisible(false); |
|
104 |
} |
|
105 |
}); |
|
106 |
} |
|
107 |
||
108 |
if (!debug) { |
|
109 |
f.add(testedComponent); |
|
110 |
} else { |
|
111 |
System.err.println("Warning: DEBUG MODE"); |
|
112 |
} |
|
113 |
||
114 |
propagateAWTControls(f); |
|
115 |
||
116 |
f.setVisible(true); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* AWT Robot instance. Shouldn't be used in most cases. |
|
121 |
*/ |
|
122 |
protected Robot robot; |
|
123 |
||
124 |
/** |
|
125 |
* Run test by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } validation for current lightweight component. |
|
126 |
* <p>Called by base class. |
|
127 |
* @return true if test passed |
|
128 |
*/ |
|
129 |
protected boolean performTest() { |
|
130 |
testedComponent.requestFocus(); |
|
131 |
||
132 |
// run robot |
|
133 |
robot = Util.createRobot(); |
|
134 |
robot.setAutoDelay(20); |
|
135 |
||
136 |
// get coord |
|
137 |
Point lLoc = !debug ? testedComponent.getLocationOnScreen() : new Point(70, 30); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
25129
diff
changeset
|
138 |
Util.waitForIdle(robot); |
24539 | 139 |
/* this is a workaround for certain jtreg(?) focus issue: |
140 |
tests fail starting after failing mixing tests but always pass alone. |
|
141 |
*/ |
|
142 |
JFrame ancestor = (JFrame)(testedComponent.getTopLevelAncestor()); |
|
143 |
if( ancestor != null ) { |
|
144 |
Point ancestorLoc = ancestor.getLocationOnScreen(); |
|
44776
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
145 |
ancestorLoc.translate(isOel7() ? 5 : |
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
146 |
ancestor.getWidth() / 2 - 15, 2); |
24539 | 147 |
robot.mouseMove(ancestorLoc.x, ancestorLoc.y); |
148 |
Util.waitForIdle(robot); |
|
149 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
|
150 |
robot.delay(50); |
|
151 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
|
152 |
Util.waitForIdle(robot); |
|
153 |
} |
|
154 |
||
155 |
clickAndBlink(robot, lLoc); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
25129
diff
changeset
|
156 |
Util.waitForIdle(robot); |
24539 | 157 |
|
158 |
return wasLWClicked; |
|
159 |
} |
|
160 |
||
44776
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
161 |
public boolean isOel7() { |
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
162 |
return System.getProperty("os.name").toLowerCase() |
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
163 |
.contains("linux") && System.getProperty("os.version") |
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
164 |
.toLowerCase().contains("el7"); |
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
165 |
} |
5fcc7728c117
8081454: [TESTBUG]Some java/awt/Mixing tests fail in OEL 7 only
ssadetsky
parents:
28087
diff
changeset
|
166 |
|
24539 | 167 |
} |