1 /*
   2  * Copyright (c) 2013, 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 8029565
  27   @summary Conversion of a URI list to File list fails
  28   @author Petr Pchelko <petr.pchelko@oracle.com>
  29   @library ../../regtesthelpers
  30   @library ../../regtesthelpers/process
  31   @build Util
  32   @build ProcessResults ProcessCommunicator
  33   @run applet/othervm URIListToFileListBetweenJVMsTest.html
  34  */
  35 
  36 /**
  37  * URIListToFileListBetweenJVMsTest.java
  38  *
  39  * summary: DnD of File-List across JVM adds two empty items to the list
  40  */
  41 
  42 import test.java.awt.regtesthelpers.Util;
  43 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
  44 import test.java.awt.regtesthelpers.process.ProcessResults;
  45 
  46 import java.applet.Applet;
  47 import java.awt.*;
  48 import java.awt.event.InputEvent;
  49 
  50 import static java.lang.Thread.sleep;
  51 
  52 public class URIListToFileListBetweenJVMsTest extends Applet {
  53 
  54     // information related to the test in common
  55     static int VISIBLE_RAWS_IN_LIST=15;
  56 
  57     public void init() {
  58         setLayout(new BorderLayout());
  59     }
  60 
  61     public void start() {
  62 
  63         SourceFileListFrame sourceFrame = new SourceFileListFrame();
  64 
  65         Util.waitForIdle(null);
  66 
  67         String [] args = new String [] {
  68                 String.valueOf(sourceFrame.getNextLocationX()),
  69                 String.valueOf(sourceFrame.getNextLocationY()),
  70                 String.valueOf(sourceFrame.getDragSourcePointX()),
  71                 String.valueOf(sourceFrame.getDragSourcePointY()),
  72                 String.valueOf(sourceFrame.getSourceFilesNumber())
  73         };
  74 
  75         ProcessResults processResults = ProcessCommunicator.executeChildProcess(this.getClass(), args);
  76 
  77         verifyTestResults(processResults);
  78 
  79     }
  80 
  81     private static void verifyTestResults(ProcessResults processResults) {
  82         if ( InterprocessMessages.WRONG_FILES_NUMBER_ON_TARGET == processResults.getExitValue()) {
  83             processResults.printProcessErrorOutput(System.err);
  84             throw new RuntimeException("TEST IS FAILED: Target has recieved wrong number of files.");
  85         }
  86         processResults.verifyStdErr(System.err);
  87         processResults.verifyProcessExitValue(System.err);
  88         processResults.printProcessStandartOutput(System.out);
  89     }
  90 
  91     //We cannot make an instance of the applet without the default constructor
  92     public URIListToFileListBetweenJVMsTest() {
  93         super();
  94     }
  95 
  96     //We need in this constructor to pass frame position between JVMs
  97     public URIListToFileListBetweenJVMsTest(Point targetFrameLocation,
  98                                             Point dragSourcePoint,
  99                                             int transferredFilesNumber) throws InterruptedException
 100     {
 101         TargetFileListFrame targetFrame = new TargetFileListFrame(targetFrameLocation, transferredFilesNumber);
 102 
 103         Util.waitForIdle(null);
 104 
 105         final Robot robot = Util.createRobot();
 106 
 107         robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY());
 108         sleep(100);
 109         robot.mousePress(InputEvent.BUTTON1_MASK);
 110         sleep(100);
 111         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 112         sleep(100);
 113 
 114         Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(), InputEvent.BUTTON1_MASK);
 115 
 116     }
 117 
 118     enum InterprocessArguments {
 119         TARGET_FRAME_X_POSITION_ARGUMENT,
 120         TARGET_FRAME_Y_POSITION_ARGUMENT,
 121         DRAG_SOURCE_POINT_X_ARGUMENT,
 122         DRAG_SOURCE_POINT_Y_ARGUMENT,
 123         FILES_IN_THE_LIST_NUMBER_ARGUMENT;
 124 
 125         int extract (String [] args) {
 126             return Integer.parseInt(args[this.ordinal()]);
 127         }
 128     }
 129 
 130     public static void main (String [] args) throws Exception {
 131         Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extract(args),
 132                 InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extract(args));
 133         Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extract(args),
 134                 InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extract(args));
 135         int transferredFilesNumber = InterprocessArguments.FILES_IN_THE_LIST_NUMBER_ARGUMENT.extract(args);
 136 
 137         new URIListToFileListBetweenJVMsTest(targetFrameLocation, dragSourcePoint, transferredFilesNumber);
 138     }
 139 }