/*
* 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.
*
* 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 6187066
@summary Tests the Window.autoRequestFocus property for the Window.setVisible() method.
@author anton.tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main AutoRequestFocusSetVisibleTest
*/
}
public void init() {
// Create instructions for the user here, as well as set up
// the environment -- set the layout manager, add buttons,
// etc.
this.setLayout (new BorderLayout ());
{"This is an automatic test. Simply wait until it is done."
});
}
void recreateGUI() {
if (focusedFrame != null) {
}
/*
* When 'frame' is shown along with the 'ownedWindow'
* (i.e. showWithParent==true) then it can appear
* that the 'ownedWindow' is shown too early and
* it can't be focused due to its owner can't be
* yet activated. So, to avoid this race, we pospone
* a little the showing of the 'ownedWindow'.
*/
public void show() {
super.show();
}
};
}
public void start() {
///////////////////////////////////////////////////////
// 1. Show Frame with owned modal Dialog without delay.
// Check that the Dialog takes focus.
///////////////////////////////////////////////////////
recreateGUI();
dialog.setAutoRequestFocus(false);
setVisible(focusedFrame, true);
public void run() {
dialog.setVisible(true);
}
}, robot);
if (focusOwner.hasFocus()) {
throw new TestFailedException("the modal dialog must gain focus but it didn't!");
}
setVisible(dialog, false);
//////////////////////////////////////////////////
// 2. Show Frame, activate, auto hide, auto show.
// Check that the Frame takes focus.
//////////////////////////////////////////////////
recreateGUI();
setVisible(focusedFrame, false);
focusedFrame.setAutoRequestFocus(false);
setVisible(focusedFrame, true);
if (!focusedFrame.isFocused()) {
throw new Error("Test error: the frame couldn't be focused.");
}
if (!focusedFrame.isFocused()) {
throw new TestFailedException("the restored frame must gain focus but it didn't!");
}
////////////////////////
// 3.1 Show Frame normal.
////////////////////////
recreateGUI();
// 3.2. Show Frame maximized both.
/////////////////////////////////
} else {
}
// 3.3. Show Frame maximized vertically.
///////////////////////////////////////
} else {
}
// 3.4. Show Frame maximized horizontally.
/////////////////////////////////////////
} else {
}
// 3.5. Show Frame iconified.
////////////////////////////
} else {
}
///////////////////
// 4.1 Show Window.
///////////////////
recreateGUI();
// 4.2 Show Dialog.
//////////////////
// 4.3. Show modal Dialog.
/////////////////////////
///////////////////////////////////
// 5.1 Show Frame with owned Window.
///////////////////////////////////
// On Windows, an owned Window will not be focused on its showing
// if the owner is not currently active.
} else {
setVisible(ownedWindow, true);
}
// 5.2 Show Frame with owned Dialog.
///////////////////////////////////
setVisible(ownedDialog, true);
///////////////////////////////////
// 6. Show unblocking modal Dialog.
///////////////////////////////////
} else {
// ---
// Testing the bug of activating invisible modal Dialog (awt_Window::SetAndActivateModalBlocker).
// Having some window not excluded from modality, so that it would be blocked.
setVisible(f, true);
// ---
setVisible(focusedFrame, true);
if (!focusOwner.hasFocus()) {
if (!focusOwner.hasFocus()) {
throw new Error("Test error: the frame couldn't be focused.");
}
}
dialog.setAutoRequestFocus(false);
public void run() {
dialog.setVisible(true);
}
}, robot);
throw new TestFailedException("the unblocking dialog shouldn't gain focus but it did!");
}
setVisible(dialog, false);
}
}
/*
* @param msg notifies test stage number
* @param clickButton a button of the window (owner or owned) expected to be on the top of stack order
* @param shouldFocusChange true the test window should gain focus
*/
void test(String msg, final Window showWindow, Window ownedWindow, final Button clickButton, boolean shouldFocusChange) {
if (showWindow.isVisible()) {
}
if (!focusedFrame.isVisible()) {
setVisible(focusedFrame, true);
}
if (!focusOwner.hasFocus()) {
if (!focusOwner.hasFocus()) {
throw new Error("Test error: the frame couldn't be focused.");
}
}
//////////////////////////////////////////
// Test focus change on showing the window
//////////////////////////////////////////
public void run() {
showWindow.setAutoRequestFocus(false);
showWindow.setVisible(true);
}
};
public void run() {
} else {
showAction.run();
}
}
};
if (shouldFocusChange) {
trackerAction.run();
if (!testWindow.isFocused()) {
throw new TestFailedException("the window must gain focus but it didn't!");
}
throw new TestFailedException("the window shouldn't gain focus but it did!");
}
////////////////////////////////////////////
// Test that the window was shown on the top.
// Test that it can be focused.
////////////////////////////////////////////
if (!(testWindow instanceof Frame) ||
{
public void run() {
/*
* If 'showWindow' is not on the top then
* 'focusOwner' button completely overlaps 'clickButton'
* and we won't catch the action.
*/
}
}, 1000, false);
if (!performed) {
// In case of loosing ACTION_PERFORMED, try once more.
public void run() {
}
}, 1000, false);
if (!performed) {
throw new TestFailedException("the window shown is not on the top!");
}
}
}
recreateGUI();
}
}
}
}
w.setVisible(b);
try {
}
}
}
super("Test failed: " + msg);
}
}
/****************************************************
Standard Test Machinery
DO NOT modify anything below -- it's a standard
chunk of code whose purpose is to make user
interaction uniform, and thereby make it simpler
to read and understand someone else's test.
****************************************************/
/**
This is part of the standard test machinery.
It creates a dialog (with the instructions), and is the interface
for sending text messages to the user.
To print the instructions, send an array of strings to Sysout.createDialog
WithInstructions method. Put one line of instructions per array entry.
To display a message for the tester to see, simply call Sysout.println
with the string to be displayed.
This mimics System.out.println but works within the test harness as well
as standalone.
*/
class Sysout
{
{
// dialog.setVisible(true);
println( "Any messages for the tester will display here." );
}
public static void createDialog( )
{
// dialog.setVisible(true);
println( "Any messages for the tester will display here." );
}
{
}
{
}
}// Sysout class
/**
This is part of the standard test machinery. It provides a place for the
test instructions to be displayed, and a place for interactive messages
to the user to be displayed.
To have the test instructions displayed, see Sysout.
To have a message to the user be displayed, see Sysout.
Do not call anything in this dialog directly.
*/
{
//DO NOT call this directly, go through Sysout
{
pack();
// setVisible(true);
}// TestDialog()
//DO NOT call this directly, go through Sysout
{
//Clear out any current instructions
//Go down array of instruction strings
{
//chop up each into pieces maxSringLength long
remainingStr = instructions[ i ];
{
//if longer than max then chop off first max chars to print
{
//Try to chop on a word boundary
int posOfSpace = remainingStr.
}
//else just print
else
{
remainingStr = "";
}
}// while
}// for
}//printInstructions()
//DO NOT call this directly, go through Sysout
{
}
}// TestDialog class