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(new GUIXDnDJava(), new ExtendedRobot()).runTask();
  48         System.exit(0);
  49     }
  50 
  51     /**
  52      * Initializes the GUI. Adds listeners to the GUI.
  53      */
  54     public TaskXDragDrop(GUIXDnDJava gui, ExtendedRobot robot) {
  55         super(gui, robot);
  56 
  57         this.gui.dragDropEnd = false;
  58         this.gui.dropSuccess = false;
  59         this.gui.dropAction = 0;
  60         this.gui.dropData = new String("");
  61         this.gui.requestFocus();
  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         robot.waitForIdle(1000);
  70 
  71         javaPoint = new Point(6, 200);
  72         Dimension d = gui.getSize();
  73         javaPoint.translate(d.width / 2, d.height / 2);
  74 
  75         nativePoint = new Point(650, javaPoint.y);
  76 
  77         robot.dragAndDrop(javaPoint, nativePoint);
  78         robot.waitForIdle(1000);
  79         robot.dragAndDrop(nativePoint, javaPoint);
  80         robot.waitForIdle(1000);
  81 
  82         if (!(GUIXDnDJava.data + GUIXDnDJava.data).equals(((String) (gui.dropData)).trim()))
  83             throw new RuntimeException("Incorrect drop data: " + gui.dropData);
  84 
  85         if (!gui.dragDropEnd)
  86             throw new RuntimeException("TEST FAIL: dragDropEnd() method is not called");
  87 
  88         gui.destroyProcess();
  89         gui.dispose();
  90     }
  91 
  92     public void verifyFailed() {
  93         if (gui.dropSuccess == false)
  94             throw new RuntimeException("Drop is NOT successful");
  95 
  96         if (gui.dropAction != DnDConstants.ACTION_MOVE)
  97             throw new RuntimeException("Drop Action is wrong");
  98     }
  99 }
 100