jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java
author yan
Mon, 10 Nov 2014 16:23:30 +0300
changeset 27763 1fba965925e8
parent 14856 92a1bcf46888
permissions -rw-r--r--
8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1 Reviewed-by: pchelko, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     1
/*
14856
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 12285
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     4
 *
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     7
 * published by the Free Software Foundation.
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     8
 *
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    13
 * accompanied this code).
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    14
 *
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    18
 *
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    21
 * questions.
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    22
 */
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    23
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    24
/*
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    25
 * Portions Copyright (c) 2012 IBM Corporation
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    26
 */
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    27
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    28
/* @test
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    29
 * @bug 7155298
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    30
 * @run main/othervm/timeout=60 TestDispose
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    31
 * @summary Editable TextArea blocks GUI application from exit.
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    32
 * @author Sean Chou
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    33
 */
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    34
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    35
import java.awt.FlowLayout;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    36
import java.awt.Frame;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    37
import java.awt.TextArea;
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    38
import java.awt.Robot;
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    39
import java.lang.reflect.InvocationTargetException;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    40
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    41
import javax.swing.JFrame;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    42
import javax.swing.SwingUtilities;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    43
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    44
public class TestDispose {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    45
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    46
    public static Frame frame = null;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    47
    public static TextArea textArea = null;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    48
    public static volatile Process worker = null;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    49
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    50
    public void testDispose() throws InvocationTargetException,
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    51
            InterruptedException {
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    52
        Robot robot;
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    53
        try {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    54
            robot = new Robot();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    55
        }catch(Exception ex) {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    56
            ex.printStackTrace();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    57
            throw new RuntimeException("Unexpected failure");
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    58
        }
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    59
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    60
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    61
        SwingUtilities.invokeAndWait(new Runnable() {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    62
            @Override
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    63
            public void run() {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    64
                frame = new JFrame("Test");
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    65
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    66
                textArea = new TextArea("editable textArea");
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    67
                textArea.setEditable(true);
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    68
                // textArea.setEditable(false); // this testcase passes if textArea is non-editable
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    69
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    70
                frame.setLayout(new FlowLayout());
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    71
                frame.add(textArea);
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    72
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    73
                frame.pack();
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    74
                frame.setVisible(true);
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    75
            }
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    76
        });
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    77
        robot.waitForIdle();
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    78
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    79
        SwingUtilities.invokeAndWait(new Runnable() {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    80
            @Override
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    81
            public void run() {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    82
                frame.dispose();
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    83
            }
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    84
        });
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 14856
diff changeset
    85
        robot.waitForIdle();
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    86
    }
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    87
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    88
    public static void main(String[] args) throws Exception{
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    89
        if(args.length == 0) {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    90
            Runtime.getRuntime().addShutdownHook(new Thread(){
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    91
                public void run() {
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    92
                    worker.destroy();
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    93
                }
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    94
            });
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    95
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    96
            System.out.println(System.getProperty("java.home")+"/bin/java TestDispose workprocess");
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    97
            worker = Runtime.getRuntime().exec(System.getProperty("java.home")+"/bin/java TestDispose workprocess");
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    98
            worker.waitFor();
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
    99
            return;
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   100
        }
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   101
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   102
        TestDispose app = new TestDispose();
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   103
        app.testDispose();
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   104
    }
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   105
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
diff changeset
   106
}