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