test/jdk/java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     1
/*
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 40128
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     4
 *
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     8
 *
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    13
 * accompanied this code).
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    14
 *
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    18
 *
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    21
 * questions.
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    22
 */
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    23
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    24
/**
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    25
 * @test
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    26
 * @summary JVM crash if the frame is disposed in DropTargetListener
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 37704
diff changeset
    27
 * @key headful
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    28
 * @author Petr Pchelko
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    29
 * @library ../../regtesthelpers
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    30
 * @build Util
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    31
 * @compile DisposeFrameOnDragTest.java
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    32
 * @run main/othervm DisposeFrameOnDragTest
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    33
 */
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    34
import java.awt.AWTException;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    35
import java.awt.Point;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    36
import java.awt.Robot;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    37
import java.awt.dnd.DropTargetAdapter;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    38
import java.awt.dnd.DropTargetDragEvent;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    39
import java.awt.dnd.DropTargetDropEvent;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    40
import java.awt.event.InputEvent;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    41
import java.lang.reflect.InvocationTargetException;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    42
import java.util.TooManyListenersException;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    43
import javax.swing.JFrame;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    44
import javax.swing.JTextArea;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    45
import javax.swing.SwingUtilities;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    46
import test.java.awt.regtesthelpers.Util;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    47
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    48
public class DisposeFrameOnDragTest {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    49
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    50
    private static JTextArea textArea;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    51
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    52
    public static void main(String[] args) throws Throwable {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    53
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    54
        SwingUtilities.invokeAndWait(new Runnable() {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    55
            @Override
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    56
            public void run() {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    57
                constructTestUI();
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    58
            }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    59
        });
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    60
37704
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    61
        Robot testRobot = null;
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    62
        try {
37704
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    63
            testRobot = new Robot();
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    64
        } catch(AWTException ex) {
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    65
            throw new RuntimeException("Error while creating Robot");
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    66
        }
37704
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    67
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    68
        Util.waitForIdle(testRobot);
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    69
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    70
        Point loc = textArea.getLocationOnScreen();
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    71
        Util.drag(testRobot,
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    72
                new Point((int) loc.x + 3, (int) loc.y + 3),
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    73
                new Point((int) loc.x + 40, (int) loc.y + 40),
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    74
                InputEvent.BUTTON1_MASK);
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    75
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    76
        Util.waitForIdle(testRobot);
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    77
20f112179039 8031423: Test java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java fails by Timeout on Windows
aghaisas
parents: 16710
diff changeset
    78
        testRobot.delay(200);
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    79
    }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    80
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    81
    private static void constructTestUI() {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    82
        final JFrame frame = new JFrame("Test frame");
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    83
        textArea = new JTextArea("Drag Me!");
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    84
        try {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    85
            textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    86
                @Override
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    87
                public void drop(DropTargetDropEvent dtde) {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    88
                    //IGNORE
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    89
                }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    90
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    91
                @Override
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    92
                public void dragOver(DropTargetDragEvent dtde) {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    93
                    frame.dispose();
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    94
                }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    95
            });
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    96
        } catch (TooManyListenersException ex) {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    97
            throw new RuntimeException(ex);
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    98
        }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
    99
        textArea.setSize(100, 100);
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   100
        textArea.setDragEnabled(true);
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   101
        textArea.select(0, textArea.getText().length());
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   102
        frame.add(textArea);
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   103
        frame.setBounds(100, 100, 100, 100);
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   104
        frame.setVisible(true);
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   105
    }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents:
diff changeset
   106
}