5751N/A/*
5751N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5751N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5751N/A *
5751N/A * This code is free software; you can redistribute it and/or modify it
5751N/A * under the terms of the GNU General Public License version 2 only, as
5751N/A * published by the Free Software Foundation.
5751N/A *
5751N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5751N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5751N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5751N/A * version 2 for more details (a copy is included in the LICENSE file that
5751N/A * accompanied this code).
5751N/A *
5751N/A * You should have received a copy of the GNU General Public License version
5751N/A * 2 along with this work; if not, write to the Free Software Foundation,
5751N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5751N/A *
5751N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5751N/A * or visit www.oracle.com if you need additional information or have any
5751N/A * questions.
5751N/A */
5751N/A
5751N/A/*
6415N/A This is a part of MissedHtmlAndRtfBug.html test. Do not add any JTREG tags here
6415N/A bug 8005932
6415N/A summary Java 7 on mac os x only provides text clipboard formats
6415N/A author mikhail.cherkasov@oracle.com
5751N/A*/
5751N/Aimport java.awt.*;
5751N/Aimport java.awt.datatransfer.DataFlavor;
5751N/Aimport java.awt.event.*;
5751N/Aimport java.applet.Applet;
5751N/Aimport java.io.File;
5751N/Aimport java.util.ArrayList;
5751N/A
5751N/Aimport test.java.awt.regtesthelpers.process.ProcessCommunicator;
5751N/Aimport test.java.awt.regtesthelpers.process.ProcessResults;
5751N/Aimport test.java.awt.regtesthelpers.Util;
5751N/Aimport sun.awt.OSInfo;
5751N/A
5751N/Aimport static java.lang.Thread.sleep;
5751N/A
5751N/Apublic class MissedHtmlAndRtfBug extends Applet {
5751N/A public void init() {
5751N/A setLayout(new BorderLayout());
5751N/A }//End init()
5751N/A
5751N/A public void start() {
5751N/A if (OSInfo.getOSType() != OSInfo.OSType.MACOSX
5751N/A && OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
5751N/A System.out.println("This test is for Windows and Mac only. Passed.");
5751N/A return;
5751N/A }
5751N/A
5751N/A final Frame sourceFrame = new Frame("Source frame");
5751N/A final SourcePanel sourcePanel = new SourcePanel();
5751N/A sourceFrame.add(sourcePanel);
5751N/A sourceFrame.pack();
5751N/A sourceFrame.addWindowListener(new WindowAdapter() {
5751N/A @Override
5751N/A public void windowClosing(WindowEvent e) {
5751N/A sourceFrame.dispose();
5751N/A }
5751N/A });
5751N/A sourceFrame.setVisible(true);
5751N/A
5751N/A Util.waitForIdle(null);
5751N/A
5751N/A NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame);
5751N/A
5751N/A ArrayList<String> args = new ArrayList<String>(5);
5751N/A args.add(String.valueOf(positionCalculator.getNextLocationX()));
5751N/A args.add(String.valueOf(positionCalculator.getNextLocationY()));
5751N/A args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)));
5751N/A args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)));
5751N/A args.add(concatStrings(DataFlavorSearcher.RICH_TEXT_NAMES));
5751N/A
5751N/A ProcessResults processResults =
5751N/A// ProcessCommunicator.executeChildProcess(this.getClass(), "/Users/mcherkasov/ws/clipboard/DataFlover/out/production/DataFlover" +
5751N/A// " -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 ",
5751N/A// args.toArray(new String[0]));
5751N/A ProcessCommunicator.executeChildProcess(this.getClass(),
5751N/A "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
5751N/A
5751N/A verifyTestResults(processResults);
5751N/A
5751N/A args.set(args.size() - 1, concatStrings(DataFlavorSearcher.HTML_NAMES));
5751N/A
5751N/A ProcessCommunicator.executeChildProcess(this.getClass(),
5751N/A "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
5751N/A verifyTestResults(processResults);
5751N/A
5751N/A
5751N/A }// start()
5751N/A
5751N/A private String concatStrings(String[] strings) {
5751N/A StringBuffer result = new StringBuffer("\"");
5751N/A for (int i = 0; i < strings.length; i++) {
5751N/A result.append(strings[i]);
5751N/A result.append(",");
5751N/A }
5751N/A result.append("\"");
5751N/A return result.toString();
5751N/A }
5751N/A
5751N/A
5751N/A private static void verifyTestResults(ProcessResults processResults) {
5751N/A if (InterprocessMessages.DATA_IS_CORRUPTED ==
5751N/A processResults.getExitValue()) {
5751N/A processResults.printProcessErrorOutput(System.err);
5751N/A throw new RuntimeException("TEST IS FAILED: Target has received" +
5751N/A " corrupted data.");
5751N/A }
5751N/A processResults.verifyStdErr(System.err);
5751N/A processResults.verifyProcessExitValue(System.err);
5751N/A processResults.printProcessStandartOutput(System.out);
5751N/A }
5751N/A
5751N/A //We cannot make an instance of the applet without the default constructor
5751N/A public MissedHtmlAndRtfBug() {
5751N/A super();
5751N/A }
5751N/A
5751N/A //We need in this constructor to pass frame position between JVMs
5751N/A public MissedHtmlAndRtfBug(Point targetFrameLocation, Point dragSourcePoint, DataFlavor df)
5751N/A throws InterruptedException {
5751N/A final Frame targetFrame = new Frame("Target frame");
5751N/A final TargetPanel targetPanel = new TargetPanel(targetFrame, df);
5751N/A targetFrame.add(targetPanel);
5751N/A targetFrame.addWindowListener(new WindowAdapter() {
5751N/A @Override
5751N/A public void windowClosing(WindowEvent e) {
5751N/A targetFrame.dispose();
5751N/A }
5751N/A });
5751N/A targetFrame.setLocation(targetFrameLocation);
5751N/A targetFrame.pack();
5751N/A targetFrame.setVisible(true);
5751N/A
5751N/A doTest(dragSourcePoint, targetPanel);
5751N/A }
5751N/A
5751N/A private void doTest(Point dragSourcePoint, TargetPanel targetPanel) {
5751N/A Util.waitForIdle(null);
5751N/A
5751N/A final Robot robot = Util.createRobot();
5751N/A
5751N/A robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
5751N/A try {
5751N/A sleep(100);
5751N/A robot.mousePress(InputEvent.BUTTON1_MASK);
5751N/A sleep(100);
5751N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
5751N/A sleep(100);
5751N/A } catch (InterruptedException e) {
5751N/A e.printStackTrace();
5751N/A }
5751N/A
5751N/A Util.drag(robot, dragSourcePoint, new Point(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel),
5751N/A AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)),
5751N/A InputEvent.BUTTON1_MASK);
5751N/A }
5751N/A
5751N/A
5751N/A enum InterprocessArguments {
5751N/A TARGET_FRAME_X_POSITION_ARGUMENT,
5751N/A TARGET_FRAME_Y_POSITION_ARGUMENT,
5751N/A DRAG_SOURCE_POINT_X_ARGUMENT,
5751N/A DRAG_SOURCE_POINT_Y_ARGUMENT,
5751N/A DATA_FLAVOR_NAMES;
5751N/A
5751N/A int extractInt(String[] args) {
5751N/A return Integer.parseInt(args[this.ordinal()]);
5751N/A }
5751N/A
5751N/A String[] extractStringArray(String[] args) {
5751N/A return args[this.ordinal()].replaceAll("\"", "").split(",");
5751N/A }
5751N/A }
5751N/A
5751N/A public static void main(String[] args) {
5751N/A Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extractInt(args),
5751N/A InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extractInt(args));
5751N/A Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extractInt(args),
5751N/A InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extractInt(args));
5751N/A String[] names = InterprocessArguments.DATA_FLAVOR_NAMES.extractStringArray(args);
5751N/A
5751N/A DataFlavor df = DataFlavorSearcher.getByteDataFlavorForNative(names);
5751N/A try {
5751N/A new MissedHtmlAndRtfBug(targetFrameLocation, dragSourcePoint, df);
5751N/A } catch (InterruptedException e) {
5751N/A e.printStackTrace();
5751N/A }
5751N/A }
5751N/A
5751N/A
5751N/A}