/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 7124430
@summary Tests that SunToolkit.grab API works
@author anton.tarasov@oracle.com: area=awt.toolkit
@library ../../regtesthelpers
@build Util
@run main GrabTest
*/
public class GrabTest {
private static Frame f;
private static Window w;
private static Button b;
static volatile boolean ungrabbed;
static volatile boolean buttonPressed;
static volatile boolean windowPressed;
static volatile boolean framePressed;
static volatile boolean passed = true;
public void eventDispatched(AWTEvent e) {
ungrabbed = true;
}
}
f = new Frame("Frame");
f.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
framePressed = true;
}
});
w = new Window(f);
w.setLayout(new FlowLayout());
b = new Button("Press");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonPressed = true;
}
});
w.add(b);
w.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
windowPressed = true;
}
});
f.setVisible(true);
w.setVisible(true);
try {
} catch (AWTException ex) {
throw new RuntimeException(ex);
}
test();
}
public static void test() {
// 1. Check that button press doesn't cause ungrab
if (ungrabbed) {
passed = false;
}
// 2. Check that press on the window itself doesn't cause ungrab
if (ungrabbed) {
passed = false;
}
// 3. Check that press on the frame causes ungrab, event must be dispatched
if (!ungrabbed) {
passed = false;
}
ungrabbed = false;
// 4. Check that press on the frame's title causes ungrab
if (!ungrabbed) {
passed = false;
}
ungrabbed = false;
// 5. Check that press on the other frame's title causes ungrab
f1.setVisible(true);
if (!ungrabbed) {
passed = false;
}
f.requestFocus(); // restore focus
if (!f.hasFocus()) {
}
ungrabbed = false;
// 6. Check that press on the outside area causes ungrab
if (!ungrabbed) {
passed = false;
}
ungrabbed = false;
// 7. Check that disposing the window causes ungrab
w.dispose();
if (!ungrabbed) {
passed = false;
}
if (passed) {
} else {
throw new RuntimeException("Test failed.");
}
}
if (!condition) {
throw new RuntimeException(msg);
}
}
}