1 /* 2 * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.*; 25 import java.awt.dnd.DnDConstants; 26 27 /* 28 * @test 29 * @summary Testcase to test the reliability of XDnD implementation. Opens a 30 * native window and drags and drops between java and the native 31 * windows. Checks if the events are properly triggered and the drag 32 * and drop occurs successfully. Tries to drag large amount of data 33 * and checks if there is any memory leak issue. This testcase has 34 * been taken from XDnD Tiger testsuite. 35 * @author Girish R (girish.ramachandran@sun.com), AWT-SQE 36 * @library ../../../lib/testlibrary 37 * @build ExtendedRobot 38 * @run shell TaskXDragDrop.sh 39 */ 40 41 public class TaskXDragDrop extends Task<GUIXDnDJava> { 42 43 Point javaPoint; 44 Point nativePoint; 45 46 public static void main (String[] args) throws Exception { 47 new TaskXDragDrop(GUIXDnDJava.class, new ExtendedRobot()).runTask(); 48 System.exit(0); 49 } 50 51 /** 52 * Initializes the GUI. Adds listeners to the GUI. 53 */ 54 public TaskXDragDrop(Class guiClass, ExtendedRobot robot) throws Exception { 55 super(guiClass, robot); 56 57 gui.startChild(); 58 gui.dragDropEnd = false; 59 gui.dropSuccess = false; 60 gui.dropAction = 0; 61 gui.dropData = new String(""); 62 } 63 64 /** 65 * Took the test from XDnD tests. 66 * Open the native window and wait for the test to complete. 67 */ 68 public void task() throws Exception { 69 //EventQueue.invokeAndWait(gui::requestFocus); 70 //robot.waitForIdle(1000); 71 72 javaPoint = new Point(6, 200); 73 Dimension d = gui.getSize(); 74 javaPoint.translate(d.width / 2, d.height / 2); 75 76 nativePoint = new Point(650, javaPoint.y); 77 78 robot.dragAndDrop(javaPoint, nativePoint); 79 //robot.waitForIdle(1000); 80 robot.dragAndDrop(nativePoint, javaPoint); 81 //robot.waitForIdle(1000); 82 83 if (!(GUIXDnDJava.data + GUIXDnDJava.data).equals(((String) (gui.dropData)).trim())) 84 throw new RuntimeException("Incorrect drop data: " + gui.dropData); 85 86 if (!gui.dragDropEnd) 87 throw new RuntimeException("TEST FAIL: dragDropEnd() method is not called"); 88 89 gui.destroyProcess(); 90 EventQueue.invokeAndWait(gui::dispose); 91 } 92 93 public void verifyFailed() { 94 if (gui.dropSuccess == false) 95 throw new RuntimeException("Drop is NOT successful"); 96 97 if (gui.dropAction != DnDConstants.ACTION_MOVE) 98 throw new RuntimeException("Drop Action is wrong"); 99 } 100 } 101