1 /*
   2  * Copyright (c) 2009, 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 /*
  25   test
  26   @bug 4899516
  27   @summary Transferable has no DataFlavors when dragging from Gnome window to Swing
  28   @author : area=dnd
  29   @run applet URIListBetweenJVMsTest.html
  30 */
  31 
  32 /**
  33  * URIListBetweenJVMsTest.java
  34  *
  35  * summary: Transferable has no DataFlavors when dragging from Gnome window to Swing
  36  */
  37 
  38 import static java.lang.Thread.sleep;
  39 
  40 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
  41 import test.java.awt.regtesthelpers.process.ProcessResults;
  42 import test.java.awt.regtesthelpers.Util;
  43 import java.applet.Applet;
  44 import java.awt.*;
  45 import java.awt.event.InputEvent;
  46 import java.io.*;
  47 
  48 public class URIListBetweenJVMsTest extends Applet {
  49 
  50     // information related to the test in common
  51     static int VISIBLE_RAWS_IN_LIST=15;
  52 
  53     public void init() {
  54         setLayout(new BorderLayout());
  55 
  56     }//End  init()
  57 
  58     public void start() {
  59 
  60     String toolkit = Toolkit.getDefaultToolkit().getClass().getName();
  61     if (toolkit.equals("sun.awt.windows.WToolkit")){
  62         System.out.println("This test is not for the Windows platform. Passed.");
  63         return;
  64     } else {
  65         System.out.println("Toolkit = " + toolkit);
  66     }
  67 
  68         SourceFileListFrame sourceFrame = new SourceFileListFrame();
  69 
  70         Util.waitForIdle(null);
  71 
  72         String [] args = new String [] {
  73                 String.valueOf(sourceFrame.getNextLocationX()),
  74                 String.valueOf(sourceFrame.getNextLocationY()),
  75                 String.valueOf(sourceFrame.getDragSourcePointX()),
  76                 String.valueOf(sourceFrame.getDragSourcePointY()),
  77                 String.valueOf(sourceFrame.getSourceFilesNumber())
  78         };
  79 
  80         String classpath = System.getProperty("java.class.path");
  81         ProcessResults processResults =
  82                 ProcessCommunicator.executeChildProcess(this.getClass(), classpath, args);
  83 
  84         verifyTestResults(processResults);
  85 
  86     }// start()
  87 
  88     private static void verifyTestResults(ProcessResults processResults) {
  89         if ( InterprocessMessages.WRONG_FILES_NUMBER_ON_TARGET ==
  90                 processResults.getExitValue())
  91         {
  92             processResults.printProcessErrorOutput(System.err);
  93             throw new RuntimeException("TEST IS FAILED: Target has recieved" +
  94                     " wrong number of files.");
  95         }
  96         processResults.verifyStdErr(System.err);
  97         processResults.verifyProcessExitValue(System.err);
  98         processResults.printProcessStandartOutput(System.out);
  99     }
 100 
 101     //We cannot make an instance of the applet without the default constructor
 102     public URIListBetweenJVMsTest () {
 103         super();
 104     }
 105 
 106     //We need in this constructor to pass frame position between JVMs
 107     public URIListBetweenJVMsTest (Point targetFrameLocation, Point dragSourcePoint,
 108             int transferredFilesNumber)
 109             throws InterruptedException
 110     {
 111         TargetFileListFrame targetFrame = new TargetFileListFrame(targetFrameLocation,
 112                 transferredFilesNumber);
 113 
 114         Util.waitForIdle(null);
 115 
 116         final Robot robot = Util.createRobot();
 117 
 118         robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY());
 119         sleep(100);
 120         robot.mousePress(InputEvent.BUTTON1_MASK);
 121         sleep(100);
 122         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 123         sleep(100);
 124 
 125         Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(),
 126                 InputEvent.BUTTON1_MASK);
 127 
 128     }
 129 
 130     enum InterprocessArguments {
 131         TARGET_FRAME_X_POSITION_ARGUMENT,
 132         TARGET_FRAME_Y_POSITION_ARGUMENT,
 133         DRAG_SOURCE_POINT_X_ARGUMENT,
 134         DRAG_SOURCE_POINT_Y_ARGUMENT,
 135         FILES_IN_THE_LIST_NUMBER_ARGUMENT;
 136 
 137         int extract (String [] args) {
 138             return Integer.parseInt(args[this.ordinal()]);
 139         }
 140     }
 141 
 142     public static void main (String [] args) {
 143         Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extract(args),
 144                 InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extract(args));
 145         Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extract(args),
 146                 InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extract(args));
 147         int transferredFilesNumber = InterprocessArguments.FILES_IN_THE_LIST_NUMBER_ARGUMENT.extract(args);
 148 
 149         try {
 150             new URIListBetweenJVMsTest(targetFrameLocation, dragSourcePoint, transferredFilesNumber);
 151         } catch (InterruptedException e) {
 152             e.printStackTrace();
 153         }
 154 
 155     }
 156 
 157 
 158 }// class URIListBetweenJVMsTest