jdk/test/java/awt/dnd/Button2DragTest/Button2DragTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 38383 c76fffbf4ef5
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    24
import java.awt.Frame;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    25
import java.awt.Point;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    26
import java.awt.Robot;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    27
import java.awt.datatransfer.StringSelection;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    28
import java.awt.dnd.DnDConstants;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    29
import java.awt.dnd.DragGestureEvent;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    30
import java.awt.dnd.DragGestureListener;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    31
import java.awt.dnd.DragSource;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    32
import java.awt.dnd.DragSourceAdapter;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    33
import java.awt.dnd.DragSourceDropEvent;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    34
import java.awt.dnd.DragSourceListener;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    35
import java.awt.dnd.DropTarget;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    36
import java.awt.dnd.DropTargetAdapter;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    37
import java.awt.dnd.DropTargetDropEvent;
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    38
import java.awt.event.InputEvent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    40
import test.java.awt.regtesthelpers.Util;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    43
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 38383
diff changeset
    44
 * @key headful
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    45
 * @bug 4955110
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    46
 * @summary tests that DragSourceDragEvent.getDropAction() accords to its new
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    47
 *          spec (does not depend on the user drop action)
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    48
 * @library ../../regtesthelpers
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    49
 * @build Util
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    50
 * @run main/othervm Button2DragTest
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    51
 * @author Alexander.Gerasimov area=dnd
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    53
public final class Button2DragTest {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private volatile boolean dropSuccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    57
    private static Frame frame;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    59
    public static void main(final String[] args) {
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    60
        Button2DragTest test = new Button2DragTest();
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    61
        try {
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    62
            test.run();
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    63
        } finally {
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    64
            if (frame != null) {
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    65
                frame.dispose();
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    66
            }
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    67
        }
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    68
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    70
    public void run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        frame = new Frame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        final DragSourceListener dragSourceListener = new DragSourceAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            public void dragDropEnd(DragSourceDropEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                dropSuccess = e.getDropSuccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                System.err.println("Drop was successful: " + dropSuccess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        DragGestureListener dragGestureListener = new DragGestureListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            public void dragGestureRecognized(DragGestureEvent dge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                                            dragGestureListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            public void drop(DropTargetDropEvent dtde) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                dtde.acceptDrop(DnDConstants.ACTION_MOVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                dtde.dropComplete(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                System.err.println("Drop");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        new DropTarget(frame, dropTargetListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        //What would normally go into main() will probably go here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        //Use System.out.println for diagnostic messages that you want
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        //to read after the test is done.
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
    99
        frame.setUndecorated(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        frame.setBounds(100, 100, 200, 200);
38383
c76fffbf4ef5 7124381: DragSourceListener.dragDropEnd() never been called on completion of dnd operation
serb
parents: 23263
diff changeset
   101
        frame.setLocationRelativeTo(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        Robot robot = Util.createRobot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Point startPoint = frame.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Point endPoint = new Point(startPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        startPoint.translate(50, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        endPoint.translate(150, 150);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Util.waitForIdle(robot);
23263
dcf3b071fc36 8032058: [TEST_BUG] [macosx] java/awt/dnd/Button2DragTest sometimes fail
pchelko
parents: 5506
diff changeset
   116
        robot.delay(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (dropSuccess) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            System.err.println("test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new RuntimeException("test failed: drop was not successful");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}