jdk/test/java/awt/Focus/RestoreFocusOnDisabledComponentTest/RestoreFocusOnDisabledComponentTest.java
author herrick
Fri, 12 Jun 2009 14:56:32 -0400
changeset 3111 fefdeafb7ab9
parent 715 f16baef3a20e
child 5506 202f599c92aa
permissions -rw-r--r--
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7 6845973: Update JDK7 with deployment changes in 6u13, 6u14 4802695: Support 64-bit Java Plug-in and Java webstart on Windows/Linux on AMD64 6825019: DownloadManager should not be loaded and referenced for full JRE 6738770: REGRESSION:JSException throws when use LiveConnect javascript facility 6772884: plugin2 : java.lang.OutOfMemoryError or crash 6707535: Crossing domain hole affecting multiple sites/domains using plug-in 6728071: Non-verification of Update files may allow unintended updates 6704154: Code loaded from local filesystem should not get access to localhost 6727081: Web Start security restrictions bypass using special extension jnlp 6727079: Java Web Start Socket() restriction bypass 6727071: Cache location/user name information disclosure in SingleInstanceImpl. 6716217: AppletClassLoader adds permissions based on codebase regardless of CS 6694892: Java Webstart inclusion via system properties override [CVE-2008-2086] 6704074: localhost socket access due to cache location exposed 6703909: Java webstart arbitrary file creation using nativelib 6665315: browser crashes when deployment.properties has more slashes ( / ) 6660121: Encoding values in JNLP files can cause buffer overflow 6606110: URLConnection.setProxiedHost for resources that are loaded via proxy 6581221: SSV(VISTA): Redirection FAILS to work if user does a downgrade install 6609756: Buffer Overflow in Java ActiveX component 6608712: Bypassing the same origin policy in Java with crafted names 6534630: "gnumake clobber" doesn't 6849953: JDK7 - replacement of bufferoverflowU.lib on amd64 breaks build 6849029: Need some JDK7 merge clean-up after comments on the webrev 6847582: Build problem on JDK7 with isSecureProperty in merge 6827935: JDK 7 deployment merging - problem in Compiler-msvm.gmk 6823215: latest merge fixes from 6u12 -> JDK7 6816153: further mergers for JDK7 deployment integration 6807074: Fix Java Kernel and JQS in initial JDK7 builds Summary: Initial changeset for implementing 6uX Deployment Features into JDK7 Reviewed-by: dgu, billyh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
134
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 134
diff changeset
     2
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
134
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     4
 *
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     8
 *
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    13
 * accompanied this code).
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    14
 *
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    18
 *
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    21
 * have any questions.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    22
 */
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    23
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    24
/*
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    25
  @test      %W% %E%
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    26
  @bug       6598089
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    27
  @summary   Tests restoring focus on a single disabled coponent
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    28
  @author    Anton Tarasov: area=awt-focus
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    29
  @library   ../../regtesthelpers
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    30
  @build     Util
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    31
  @run       main RestoreFocusOnDisabledComponentTest
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    32
*/
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    33
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    34
import java.awt.*;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    35
import java.awt.event.*;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    36
import java.applet.Applet;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    37
import test.java.awt.regtesthelpers.Util;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    38
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    39
/*
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    40
 * The bug is not reproducible on Windows.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    41
 */
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    42
public class RestoreFocusOnDisabledComponentTest extends Applet {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    43
    Frame frame = new Frame("Frame") {public String toString() {return "FRAME";}};
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    44
    Button b0 = new Button("button0") {public String toString() {return "B-0";}};
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    45
    Button b1 = new Button("button1") {public String toString() {return "B-1";}};
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    46
    volatile int nFocused;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    47
    Robot robot;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    48
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    49
    public static void main(String[] args) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    50
        RestoreFocusOnDisabledComponentTest app = new RestoreFocusOnDisabledComponentTest();
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    51
        app.init();
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    52
        app.start();
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    53
    }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    54
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    55
    public void init() {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    56
        robot = Util.createRobot();
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    57
    }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    58
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    59
    public void start() {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    60
        frame.add(b0);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    61
        frame.add(b1);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    62
        frame.setLayout(new FlowLayout());
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    63
        frame.pack();
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    64
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    65
        frame.setVisible(true);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    66
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    67
        Util.waitForIdle(robot);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    68
        KeyboardFocusManager.setCurrentKeyboardFocusManager(new DefaultKeyboardFocusManager() {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    69
            public boolean dispatchEvent(AWTEvent e) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    70
                if (e.getID() == FocusEvent.FOCUS_GAINED) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    71
                    // Trying to emulate timings. b1 should be disabled just by the time it gets
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    72
                    // FOCUS_GAINED event. The latter is a result of disabling b0 that initiates
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    73
                    // focus auto transfer.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    74
                    if (e.getSource() == b1) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    75
                        b1.setEnabled(false);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    76
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    77
                    } else if (e.getSource() == b0) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    78
                        if (++nFocused > 10) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    79
                            nFocused = -1;
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    80
                            throw new TestFailedException("Focus went into busy loop!");
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    81
                        }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    82
                    }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    83
                }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    84
                return super.dispatchEvent(e);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    85
            }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    86
        });
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    87
        // Initiating focus auto transfer.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    88
        // Focus will be requested to b1. When FOCUS_GAINED is being dispatched to b1, it will
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    89
        // be disabled. This will trigger focus restoring. Focus will be requested to b0 (the
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    90
        // last opposite component). When FOCUS_GAINED is being dispatched to b0, it will
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    91
        // also be disabled. However, the last opposite component (and the most recent focus owner)
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    92
        // will still be b0. When DKFM initiates focus restoring it should detect restoring
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    93
        // on the same component and break.
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    94
        b0.setEnabled(false);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    95
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    96
        Util.waitForIdle(robot);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    97
        if (nFocused != -1) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    98
            System.out.println("Test passed.");
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
    99
        }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   100
    }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   101
}
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   102
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   103
class TestFailedException extends RuntimeException {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   104
    TestFailedException(String msg) {
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   105
        super("Test failed: " + msg);
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   106
    }
6c750e108213 6598089: JDK 7: AWT often goes into busy loop when showing dialog
ant
parents:
diff changeset
   107
}