changeset 14848:18a3b77136f6

8046221: [TEST_BUG] Cleanup datatransfer tests Reviewed-by: anthony, alexsch
author pchelko
date Mon, 16 Jun 2014 17:13:58 +0400
parents 425618a5301b
children 2239168b30f5
files test/java/awt/DataFlavor/MissedHtmlAndRtfBug/AbsoluteComponentCenterCalculator.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/DataFlavorSearcher.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/InterprocessMessages.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.html test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MyTransferable.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/NextFramePositionCalculator.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/SourcePanel.java test/java/awt/DataFlavor/MissedHtmlAndRtfBug/TargetPanel.java test/java/awt/datatransfer/DataFlavor/DataFlavorCloneTest/DataFlavorCloneTest.java test/java/awt/datatransfer/DataFlavor/DataFlavorEqualsNullTest.java test/java/awt/datatransfer/DataFlavor/DataFlavorEqualsTest.java test/java/awt/datatransfer/DataFlavor/DataFlavorFileListTest.java test/java/awt/datatransfer/DataFlavor/DataFlavorSerializedTest.java test/java/awt/datatransfer/DataFlavor/DefaultMatchTest.java test/java/awt/datatransfer/DataFlavor/EqualHashCodeTest.java test/java/awt/datatransfer/DataFlavor/ExternalizeTest.java test/java/awt/datatransfer/DataFlavor/GetReaderForTextIAEForStringSelectionTest.java test/java/awt/datatransfer/DataFlavor/GetReaderForTextNPETest.java test/java/awt/datatransfer/DataFlavor/MimeTypeSerializationTest.java test/java/awt/datatransfer/DataFlavor/NoClassParameterTest.java test/java/awt/datatransfer/DataFlavor/NormalizeMimeTypeParameter.java test/java/awt/datatransfer/DataFlavor/NullDataFlavorTest.java test/java/awt/datatransfer/DataFlavor/ReaderForUnicodeText.java test/java/awt/datatransfer/DataFlavor/SelectBestFlavorNPETest.java test/java/awt/datatransfer/DataFlavor/SelectBestTextFlavorBadArrayTest.java test/java/awt/datatransfer/DataFlavor/ToStringNullPointerTest.java test/java/awt/datatransfer/DuplicatedNativesTest/DuplicatedNativesTest.java test/java/awt/datatransfer/MappingGenerationTest/MappingGenerationTest.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/AbsoluteComponentCenterCalculator.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/DataFlavorSearcher.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/InterprocessMessages.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.html test/java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/MyTransferable.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/NextFramePositionCalculator.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/SourcePanel.java test/java/awt/datatransfer/MissedHtmlAndRtfBug/TargetPanel.java test/java/awt/datatransfer/SystemFlavorMap/DuplicateMappingTest.java test/java/awt/datatransfer/SystemFlavorMap/DuplicatedNativesTest.java test/java/awt/datatransfer/SystemFlavorMap/GetNativesForFlavorTest.java test/java/awt/datatransfer/SystemFlavorMap/MappingGenerationTest.java test/java/awt/datatransfer/SystemFlavorMap/SetNativesForFlavorTest.java
diffstat 43 files changed, 2385 insertions(+), 860 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/AbsoluteComponentCenterCalculator.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.*;
-
-class AbsoluteComponentCenterCalculator {
-    private AbsoluteComponentCenterCalculator() {
-    }
-
-    public static int calculateXCenterCoordinate(Component component) {
-        return (int) component.getLocationOnScreen().getX() + (component.getWidth() / 2);
-    }
-
-    public static int calculateYCenterCoordinate(Component component) {
-        return (int) component.getLocationOnScreen().getY() + (component.getHeight() / 2);
-    }
-}
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/DataFlavorSearcher.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.FlavorTable;
-import java.awt.datatransfer.SystemFlavorMap;
-import java.util.Arrays;
-
-public class DataFlavorSearcher {
-    static public String[] HTML_NAMES = new String[]{"HTML", "HTML Format"};
-    static public String[] RICH_TEXT_NAMES = new String[]{"RICH_TEXT", "Rich Text Format"};
-
-    static public DataFlavor getByteDataFlavorForNative(String[] nats) {
-        FlavorTable flavorTable = (FlavorTable) SystemFlavorMap.getDefaultFlavorMap();
-
-        for (String nat : nats) {
-            java.util.List<DataFlavor> flavors = flavorTable.getFlavorsForNative(nat);
-            for (DataFlavor flavor : flavors) {
-                if (flavor != null
-                        && flavor.getRepresentationClass().equals(byte[].class)) {
-                    return flavor;
-                }
-            }
-        }
-        throw new RuntimeException("No data flavor was found for natives: " + Arrays.toString(nats));
-    }
-}
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/InterprocessMessages.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-interface InterprocessMessages {
-    final static int EXECUTION_IS_SUCCESSFULL = 0;
-    final static int DATA_IS_CORRUPTED = 212;
-    final static int NO_DROP_HAPPENED = 112;
-}
-
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.html	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-<!--
- Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-
- This code is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License version 2 only, as
- published by the Free Software Foundation.
-
- This code is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- version 2 for more details (a copy is included in the LICENSE file that
- accompanied this code).
-
- You should have received a copy of the GNU General Public License version
- 2 along with this work; if not, write to the Free Software Foundation,
- Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
- Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- or visit www.oracle.com if you need additional information or have any
- questions.
--->
-
-<html>
-<!--  
-  @test
-  @bug 8005932 8017456
-  @summary Java 7 on mac os x only provides text clipboard formats
-  @author mikhail.cherkasov@oracle.com
-  @library ../../regtesthelpers
-  @library ../../regtesthelpers/process
-  @build Util
-  @build ProcessResults ProcessCommunicator
-  @run applet/othervm MissedHtmlAndRtfBug.html
--->
-
-<head>
-    <title>Java 7 on mac os x only provides text clipboard formats</title>
-</head>
-<body>
-
-<h1> MissedHtmlAndRtfBug <br>Bug ID: 8005932 </h1>
-
-<p> This is an AUTOMATIC test, simply wait for completion </p>
-
-<APPLET CODE="MissedHtmlAndRtfBug.class" WIDTH=200 HEIGHT=200></APPLET>
-</body>
-</html>
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-/*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.*;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.event.*;
-import java.applet.Applet;
-import java.io.File;
-import java.util.ArrayList;
-
-import test.java.awt.regtesthelpers.process.ProcessCommunicator;
-import test.java.awt.regtesthelpers.process.ProcessResults;
-import test.java.awt.regtesthelpers.Util;
-import sun.awt.OSInfo;
-
-import static java.lang.Thread.sleep;
-
-public class MissedHtmlAndRtfBug extends Applet {
-
-    public void init() {
-        setLayout(new BorderLayout());
-    }//End  init()
-
-    public void start() {
-        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX
-                && OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
-            System.out.println("This test is for Windows and Mac only. Passed.");
-            return;
-        }
-
-        final Frame sourceFrame = new Frame("Source frame");
-        final SourcePanel sourcePanel = new SourcePanel();
-        sourceFrame.add(sourcePanel);
-        sourceFrame.pack();
-        sourceFrame.addWindowListener(new WindowAdapter() {
-            @Override
-            public void windowClosing(WindowEvent e) {
-                sourceFrame.dispose();
-            }
-        });
-        sourceFrame.setVisible(true);
-
-        Util.waitForIdle(null);
-
-        NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame);
-
-        ArrayList<String> args = new ArrayList<String>(5);
-        args.add(String.valueOf(positionCalculator.getNextLocationX()));
-        args.add(String.valueOf(positionCalculator.getNextLocationY()));
-        args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)));
-        args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)));
-        args.add(concatStrings(DataFlavorSearcher.RICH_TEXT_NAMES));
-
-        ProcessResults processResults =
-                ProcessCommunicator.executeChildProcess(this.getClass(),
-                        "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
-
-        verifyTestResults(processResults);
-
-        args.set(args.size() - 1, concatStrings(DataFlavorSearcher.HTML_NAMES));
-
-        ProcessCommunicator.executeChildProcess(this.getClass(),
-                "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
-        verifyTestResults(processResults);
-
-
-    }// start()
-
-    private String concatStrings(String[] strings) {
-        StringBuffer result = new StringBuffer("\"");
-        for (int i = 0; i < strings.length; i++) {
-            result.append(strings[i]);
-            result.append(",");
-        }
-        result.append("\"");
-        return result.toString();
-    }
-
-
-    private static void verifyTestResults(ProcessResults processResults) {
-        if (InterprocessMessages.DATA_IS_CORRUPTED ==
-                processResults.getExitValue()) {
-            processResults.printProcessErrorOutput(System.err);
-            throw new RuntimeException("TEST IS FAILED: Target has received" +
-                    " corrupted data.");
-        }
-        if (InterprocessMessages.NO_DROP_HAPPENED ==
-                processResults.getExitValue()) {
-            processResults.printProcessErrorOutput(System.err);
-            throw new RuntimeException("Error. Drop did not happen." +
-                " Target frame is possibly covered by a window of other application." +
-                " Please, rerun the test with all windows minimized.");
-        }
-        processResults.verifyStdErr(System.err);
-        processResults.verifyProcessExitValue(System.err);
-        processResults.printProcessStandartOutput(System.out);
-    }
-
-    //We cannot make an instance of the applet without the default constructor
-    public MissedHtmlAndRtfBug() {
-        super();
-    }
-
-    //We need in this constructor to pass frame position between JVMs
-    public MissedHtmlAndRtfBug(Point targetFrameLocation, Point dragSourcePoint, DataFlavor df)
-            throws InterruptedException {
-        final Frame targetFrame = new Frame("Target frame");
-        final TargetPanel targetPanel = new TargetPanel(targetFrame, df);
-        targetFrame.add(targetPanel);
-        targetFrame.addWindowListener(new WindowAdapter() {
-            @Override
-            public void windowClosing(WindowEvent e) {
-                targetFrame.dispose();
-            }
-        });
-        targetFrame.setLocation(targetFrameLocation);
-        targetFrame.pack();
-        targetFrame.setVisible(true);
-
-        doTest(dragSourcePoint, targetPanel);
-    }
-
-    private void doTest(Point dragSourcePoint, TargetPanel targetPanel) {
-        Util.waitForIdle(null);
-
-        final Robot robot = Util.createRobot();
-
-        robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
-        try {
-            sleep(100);
-            robot.mousePress(InputEvent.BUTTON1_MASK);
-            sleep(100);
-            robot.mouseRelease(InputEvent.BUTTON1_MASK);
-            sleep(100);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-
-        Util.drag(robot, dragSourcePoint, new Point(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel),
-                AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)),
-                InputEvent.BUTTON1_MASK);
-    }
-
-
-    enum InterprocessArguments {
-        TARGET_FRAME_X_POSITION_ARGUMENT,
-        TARGET_FRAME_Y_POSITION_ARGUMENT,
-        DRAG_SOURCE_POINT_X_ARGUMENT,
-        DRAG_SOURCE_POINT_Y_ARGUMENT,
-        DATA_FLAVOR_NAMES;
-
-        int extractInt(String[] args) {
-            return Integer.parseInt(args[this.ordinal()]);
-        }
-
-        String[] extractStringArray(String[] args) {
-            return args[this.ordinal()].replaceAll("\"", "").split(",");
-        }
-    }
-
-    public static void main(String[] args) throws InterruptedException {
-        Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extractInt(args),
-                InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extractInt(args));
-        Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extractInt(args),
-                InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extractInt(args));
-        String[] names = InterprocessArguments.DATA_FLAVOR_NAMES.extractStringArray(args);
-
-        DataFlavor df = DataFlavorSearcher.getByteDataFlavorForNative(names);
-        try {
-            new MissedHtmlAndRtfBug(targetFrameLocation, dragSourcePoint, df);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        sleep(5000);
-        System.exit(InterprocessMessages.NO_DROP_HAPPENED);
-    }
-
-
-}
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MyTransferable.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.datatransfer.*;
-import java.io.IOException;
-
-class MyTransferable implements Transferable {
-
-    public static final String TEST_DATA = "<b>Test</b>";
-    private DataFlavor[] dataFlavors;
-
-    public MyTransferable() {
-        dataFlavors = new DataFlavor[]{DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.HTML_NAMES),
-                DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.RICH_TEXT_NAMES)};
-    }
-
-
-    @Override
-    public DataFlavor[] getTransferDataFlavors() {
-        return dataFlavors;
-    }
-
-    @Override
-    public boolean isDataFlavorSupported(DataFlavor flavor) {
-        for (DataFlavor f : dataFlavors) {
-            if (f.equals(flavor)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public Object getTransferData(DataFlavor flavor)
-            throws UnsupportedFlavorException, IOException {
-        if (isDataFlavorSupported(flavor)) {
-            return TEST_DATA.getBytes("UTF-16");
-        } else {
-            throw new UnsupportedFlavorException(flavor);
-        }
-    }
-}
\ No newline at end of file
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/NextFramePositionCalculator.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.*;
-
-
-class NextFramePositionCalculator {
-
-    private final Frame currentFrame;
-
-    public NextFramePositionCalculator(Frame currentFrame) {
-        this.currentFrame = currentFrame;
-    }
-
-    public int getNextLocationX() {
-        return currentFrame.getX() + currentFrame.getWidth();
-    }
-
-    public int getNextLocationY() {
-        return currentFrame.getY();
-    }
-
-}
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/SourcePanel.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.dnd.DragSource;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DragGestureEvent;
-import java.awt.dnd.DragGestureListener;
-import java.awt.*;
-
-public class SourcePanel extends Panel {
-
-    private final MyDragGestureListener dragGestureListener =
-            new MyDragGestureListener();
-
-    public SourcePanel() {
-        setPreferredSize(new Dimension(200, 200));
-        DragSource defaultDragSource =
-                DragSource.getDefaultDragSource();
-        defaultDragSource.createDefaultDragGestureRecognizer(this,
-                DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
-        setBackground(Color.RED);
-    }
-
-    private class MyDragGestureListener implements DragGestureListener {
-        public void dragGestureRecognized(DragGestureEvent dge) {
-            dge.startDrag(null, new MyTransferable());
-        }
-    }
-}
--- a/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/TargetPanel.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.datatransfer.Transferable;
-import java.awt.dnd.*;
-import java.awt.*;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class TargetPanel extends Panel implements DropTargetListener {
-
-
-    //private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener();
-
-    private Frame frame;
-    DataFlavor dataFlavor;
-
-    public TargetPanel(Frame frame, DataFlavor dataFlavor) {
-        this.dataFlavor = dataFlavor;
-        this.frame = frame;
-        setBackground(Color.DARK_GRAY);
-        setPreferredSize(new Dimension(200, 200));
-        setDropTarget(new DropTarget(this, this));
-    }
-
-    public void dragEnter(DropTargetDragEvent dtde) {
-        if (dtde.isDataFlavorSupported(dataFlavor)) {
-            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
-        }
-    }
-
-    public void dragOver(DropTargetDragEvent dtde) {
-        if (dtde.isDataFlavorSupported(dataFlavor)) {
-            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
-        }
-    }
-
-    public void dropActionChanged(DropTargetDragEvent dtde) {
-        if (dtde.isDataFlavorSupported(dataFlavor)) {
-            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
-        }
-    }
-
-    public void dragExit(DropTargetEvent dte) {
-
-    }
-
-    public void drop(DropTargetDropEvent dtde) {
-        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
-        if (dtde.isDataFlavorSupported(dataFlavor)) {
-            String result = null;
-            try {
-                Transferable t = dtde.getTransferable();
-                byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
-                result = new String(data, "UTF-16");
-                repaint();
-            } catch (UnsupportedFlavorException e) {
-                e.printStackTrace();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-            dtde.dropComplete(true);
-
-
-            if (result != null && result.contains(MyTransferable.TEST_DATA)) {
-                System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
-                Timer t = new Timer();
-                t.schedule(new TimerTask() {
-                    @Override
-                    public void run() {
-                        System.exit(0);
-                    }
-                }, 2000);
-                return;
-
-            }
-        }
-        dtde.rejectDrop();
-        System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
-        System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/DataFlavorCloneTest/DataFlavorCloneTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4181601
+  @summary tests that DataFlavor.clone method doesn't throw exception
+  @author xianfa: area=
+  @run main DataFlavorCloneTest
+*/
+
+
+import java.awt.datatransfer.DataFlavor;
+
+public class DataFlavorCloneTest {
+
+    public static void main(String[] args) throws Exception {
+        DataFlavor df1 = null;
+        Object df2 = null;
+        try {
+            df1 = new DataFlavor();
+            df2 = df1.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeException("FAILED: Unexpected exception: " + e);
+        } catch (NullPointerException e) {
+            throw new RuntimeException("FAILED: Got Null pointer exception");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/DataFlavorEqualsNullTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4175731
+  @summary DataFlavor.equals(null) throws NullPointerException
+  @author prs@sparc.spb.su: area=
+  @run main DataFlavorEqualsNullTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+
+public class DataFlavorEqualsNullTest {
+    public static boolean finished = false;
+    static boolean noexc = true;
+    static boolean eq = false;
+    static DataFlavor df = null;
+
+    public static void main(String[] args) throws Exception {
+
+        try {
+            df = new DataFlavor("application/postscript;class=java.awt.datatransfer.DataFlavor");
+        } catch (ClassNotFoundException e) {
+            // This should never happen
+        }
+        try {
+            eq = df.equals((Object) null);
+            if (eq) noexc = false;
+            eq = df.equals((DataFlavor) null);
+            if (eq) noexc = false;
+            eq = df.equals((String) null);
+            if (eq) noexc = false;
+        } catch (NullPointerException e1) {
+            noexc = false;
+        }
+        finished = true;
+        if (!noexc)
+            throw new RuntimeException("Test FAILED");
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/DataFlavorEqualsTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4175341
+  @summary DataFlavor.equals throws NullPointerException
+  @author prs@sparc.spb.su: area=
+  @run main DataFlavorEqualsTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+
+public class DataFlavorEqualsTest {
+     public static boolean finished = false;
+     static boolean noexc = true;
+     static boolean eq = false;
+     static DataFlavor df = null;
+
+     public static void main(String[] args) {
+         df = new DataFlavor();
+         try {
+             eq = df.equals((Object)new DataFlavor());
+             if (!eq) noexc = false;
+             eq = df.equals(new DataFlavor());
+             if (!eq) noexc = false;
+             eq = df.equals("application/postscript;class=java.awt.datatransfer.DataFlavor");
+             if (eq) noexc = false;
+         } catch (NullPointerException e1) {
+             noexc = false;
+         }
+         finished = true;
+         if (!noexc)
+             throw new RuntimeException("Test FAILED");
+
+     }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/DataFlavorFileListTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4172848
+  @summary DataFlavor.isFlavorJavaFileListType works wrong
+  @author prs@sparc.spb.su: area=
+  @run main DataFlavorFileListTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+
+public class DataFlavorFileListTest {
+     public static boolean finished = false;
+     static DataFlavor df = null;
+
+     public static void main(String[] args) throws Exception {
+         df = new DataFlavor("application/x-java-file-list;class=java.util.ArrayList");
+         boolean fl = df.isFlavorJavaFileListType();
+         finished = true;
+         if (!fl)
+             throw new RuntimeException("Test FAILED");
+     }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/DataFlavorSerializedTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4174020
+  @summary DataFlavor.isMimeTypeSerializedObject works wrong
+  @author prs@sparc.spb.su: area=
+  @run main DataFlavorSerializedTest
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+
+public class DataFlavorSerializedTest {
+     public static boolean finished = false;
+     static DataFlavor df = null;
+
+     public static void main(String[] args) throws Exception {
+         df = new DataFlavor("application/x-java-serialized-object;class=java.io.Serializable");
+         boolean fl = df.isMimeTypeSerializedObject();
+         finished = true;
+         if (!fl)
+             throw new RuntimeException("Test FAILED");
+     }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/DefaultMatchTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4250750
+  @summary tests that DataFlavor.match() does not throw NPE.
+  @author prs@sparc.spb.su: area=
+  @run main DefaultMatchTest
+*/
+
+
+import java.awt.datatransfer.DataFlavor;
+
+public class DefaultMatchTest {
+
+    static DataFlavor df1, df2, df3;
+
+    public static void main(String[] args) throws Exception {
+        boolean passed = true;
+        try {
+            df1 = new DataFlavor("application/postscript");
+            df2 = new DataFlavor();
+            df3 = new DataFlavor();
+        } catch (ClassNotFoundException e1) {
+            throw new RuntimeException("Could not create DataFlavors. This should never happen.");
+        } catch (IllegalArgumentException e2) {
+            passed = false;
+        }
+        try {
+            boolean b;
+            b = df1.match(df2);
+            b = df2.match(df1);
+            b = df2.match(df3);
+        } catch (NullPointerException e) {
+            throw new RuntimeException("The test FAILED: DataFlavor.match still throws NPE");
+        }
+        if (!passed) {
+            throw new RuntimeException("Test FAILED");
+        }
+        System.out.println("Test PASSED");
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/EqualHashCodeTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4157612
+  @summary tests that certain awt classes do not break basic hashCode() contract.
+  @author prs@sparc.spb.su: area=
+  @run main EqualHashCodeTest
+*/
+
+import java.awt.*;
+import java.awt.color.ColorSpace;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+
+public class EqualHashCodeTest {
+
+     static DataFlavor df1, df2;
+     static Insets insets1, insets2;
+     static Dimension dim1, dim2;
+     static ColorModel cm1, cm2;
+     static int[] ColorModelBits = { 8, 8, 8, 8 };
+
+     public static void main(String[] args) throws Exception {
+         boolean passed = true;
+         try {
+             df1 = new DataFlavor( "application/postscript" );
+             df2 = new DataFlavor( "application/*" );
+         } catch (ClassNotFoundException e1) {
+             throw new RuntimeException("Could not create DataFlavors. This should never happen.");
+         } catch (IllegalArgumentException e2) {
+             passed = false;
+         }
+         if (df1.hashCode() != df2.hashCode()) {
+             passed = false;
+         }
+         dim1 = new Dimension(3, 18);
+         dim2 = new Dimension(3, 18);
+         if (dim1.hashCode() != dim2.hashCode()) {
+             passed = false;
+         }
+         insets1 = new Insets(3, 4, 7, 11);
+         insets2 = new Insets(3, 4, 7, 11);
+         if (insets1.hashCode() != insets2.hashCode()) {
+             passed = false;
+         }
+         cm1 = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                       ColorModelBits, true, true,
+                                       Transparency.OPAQUE, 0);
+         cm2 = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                       ColorModelBits, true, true,
+                                       Transparency.OPAQUE, 0);
+         if (cm1.hashCode() != cm2.hashCode()) {
+             passed = false;
+         }
+         if (!passed)
+             throw new RuntimeException("Test FAILED");
+     }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/ExternalizeTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4274267
+  @summary Tests that externalized DataFlavor is restored properly
+  @author prs@sparc.spb.su: area=
+  @run main ExternalizeTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+public class ExternalizeTest {
+
+   public static void main(String[] args) {
+       DataFlavor df = new DataFlavor("text/enriched; charset=ascii", "Enrich Flavor");
+
+       storeDataFlavor(df);
+       DataFlavor df1 = retrieveDataFlavor();
+
+       if (!df.equals(df1)) {
+           throw new RuntimeException("FAILED: restored DataFlavor is not equal to externalized one");
+       }
+
+   }
+
+   public static void storeDataFlavor(DataFlavor dfs){
+       // To store the dataflavor into a file using writeExternal()
+       try {
+           FileOutputStream ostream = new FileOutputStream("t.tmp");
+           ObjectOutputStream p = new ObjectOutputStream(ostream);
+           dfs.writeExternal(p);
+           ostream.close();
+
+       } catch (Exception ex){
+           throw new RuntimeException("FAIL: problem occured while storing DataFlavor");
+       }
+   }
+
+
+   public static DataFlavor retrieveDataFlavor(){
+       DataFlavor df=DataFlavor.stringFlavor;
+       try {
+           FileInputStream istream = new FileInputStream("t.tmp");
+           ObjectInputStream p = new ObjectInputStream(istream);
+           df.readExternal(p);
+           istream.close();
+       } catch (Exception ex){
+           throw new RuntimeException("FAIL: problem occured while retrieving DataFlavor");
+       }
+
+       return df;
+   }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/GetReaderForTextIAEForStringSelectionTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4260874
+  @summary Tests that DataFlavor.getReaderForText do not throw NPE when transferObject is null
+  @author tdv@sparc.spb.su: area=
+  @run main GetReaderForTextIAEForStringSelectionTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.Reader;
+
+public class GetReaderForTextIAEForStringSelectionTest  {
+
+   public static void main(String[] args) throws Exception {
+      DataFlavor pt ;
+
+      try {
+          pt = DataFlavor.plainTextFlavor;
+          StringSelection ss = new StringSelection("ReaderExample");
+          Reader re = pt.getReaderForText(ss);
+          if(re == null) {
+              throw new RuntimeException("Test FAILED! reader==null");
+          }
+      } catch (Exception e) {
+          throw new RuntimeException("Test FAILED because of the exception: " + e);
+      }
+    }
+
+ }
+
+class FakeTransferable implements Transferable {
+    public DataFlavor[] getTransferDataFlavors() {
+        return null;
+    }
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        return false;
+    }
+    public Object getTransferData(DataFlavor flavor) throws
+        UnsupportedFlavorException, IOException {
+        return null;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/GetReaderForTextNPETest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4260874
+  @summary Tests that DataFlavor.getReaderForText do not throw NPE when transferObject is null
+  @author tdv@sparc.spb.su: area=
+  @run main GetReaderForTextNPETest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.Reader;
+
+public class GetReaderForTextNPETest {
+
+    public static void main(String[] args) {
+        DataFlavor df = new DataFlavor();
+        FakeTransferable t = new FakeTransferable();
+        Reader reader;
+        try {
+            reader = df.getReaderForText(null);
+        } catch (Exception e) {
+            if (!(e instanceof NullPointerException)) {
+                throw new RuntimeException("TEST FAILED: not a NPE thrown on a null argument.");
+            }
+        }
+        try {
+            reader = df.getReaderForText(t);
+        } catch (Exception e) {
+            if (!(e instanceof IllegalArgumentException)) {
+                throw new RuntimeException("FAILED: not an IllegalArgumentException thrown on a transferable with null transfer data .");
+            }
+        }
+    }
+}
+
+class FakeTransferable implements Transferable {
+    public DataFlavor[] getTransferDataFlavors() {
+        return null;
+    }
+
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        return false;
+    }
+
+    public Object getTransferData(DataFlavor flavor) throws
+            UnsupportedFlavorException, IOException {
+        return null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/MimeTypeSerializationTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4116781
+  @summary Tests that long (more than 64K) MimeType can be serialized
+           and deserialized.
+  @author gas@sparc.spb.su area=datatransfer
+  @run main MimeTypeSerializationTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Arrays;
+
+public class MimeTypeSerializationTest {
+
+    public static void main(String[] args) throws Exception {
+        boolean failed = false;
+
+        try {
+            int len = 70000;
+            char[] longValue = new char[len];
+            Arrays.fill(longValue, 'v');
+            DataFlavor longdf = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
+                "; class=java.lang.String; longParameter=" + new String(longValue));
+
+            DataFlavor shortdf = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
+                "; class=java.lang.String");
+
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(100000);
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(longdf);
+            oos.writeObject(shortdf);
+            oos.close();
+
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            DataFlavor longdf2 = (DataFlavor) ois.readObject();
+            DataFlavor shortdf2 = (DataFlavor) ois.readObject();
+            ois.close();
+
+            failed = !( longdf.getMimeType().equals(longdf2.getMimeType()) &&
+                shortdf.getMimeType().equals(shortdf2.getMimeType()) );
+            if (failed) {
+                System.err.println("deserialized MIME type does not match original one");
+            }
+        } catch (IOException e) {
+            failed = true;
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (failed) {
+            throw new RuntimeException("test failed: serialization attempt failed");
+        } else {
+            System.err.println("test passed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/NoClassParameterTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4212613
+  @summary tests that DataFlavor(String) doesn't through Exception if no "class=" specified.
+  @author prs@sparc.spb.su: area=
+  @run main NoClassParameterTest
+*/
+
+
+import java.awt.datatransfer.DataFlavor;
+
+public class NoClassParameterTest {
+     static DataFlavor df = null;
+
+     public static void main(String[] args) {
+         boolean passed = true;
+         try {
+             df = new DataFlavor("application/postscript");
+         } catch (ClassNotFoundException e1) {
+             throw new RuntimeException("This should never happen.");
+         } catch (IllegalArgumentException e2) {
+             passed = false;
+         }
+         if (!passed)
+             throw new RuntimeException("Test FAILED");
+     }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/NormalizeMimeTypeParameter.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /*
+  @test
+  @bug 4260860
+  @summary tests that DataFlavor.normalizeMimeTypeParameter() returns parm value
+  @author ssi@sparc.spb.su area=
+  @run main NormalizeMimeTypeParameter
+*/
+
+import java.awt.datatransfer.DataFlavor;
+
+public class NormalizeMimeTypeParameter {
+
+  static class TestFlavor extends DataFlavor {
+    public String normalizeMimeType(String mimeType) {
+      return super.normalizeMimeType(mimeType);
+    }
+    public String normalizeMimeTypeParameter(String parameterName,
+                                             String parameterValue) {
+      return super.normalizeMimeTypeParameter(parameterName, parameterValue);
+    }
+  }
+
+  static TestFlavor testFlavor;
+
+  public static void main(String[] args) {
+    testFlavor = new TestFlavor();
+
+    String type = "TestType";
+    String parameter = "TestParameter";
+
+    String retValue = testFlavor.normalizeMimeTypeParameter(type, parameter);
+    if(!retValue.equals(parameter)) {
+      throw new RuntimeException("Test FAILED: " + retValue);
+    }
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/NullDataFlavorTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4682039
+  @summary Tests that DataTransferer.getFormatsForFlavors() does not throw
+           NullPointerException if some of given as parameter data flavors
+           are null.
+  @author gas@sparc.spb.su area=datatransfer
+  @run main NullDataFlavorTest
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+
+public class NullDataFlavorTest {
+
+    private final static Clipboard clipboard =
+        Toolkit.getDefaultToolkit().getSystemClipboard();
+
+    public static void main(String[] args) throws Exception {
+        boolean failed = false;
+
+        try {
+            clipboard.setContents(new NullSelection("DATA1",
+                new DataFlavor[] { null, null, null }), null);
+            clipboard.setContents(new NullSelection("DATA2",
+                new DataFlavor[] { null, DataFlavor.stringFlavor, null }), null);
+            clipboard.setContents(new NullSelection("DATA3", null), null);
+        } catch (NullPointerException e) {
+            failed = true;
+            e.printStackTrace();
+        } catch (Throwable e) {
+            e.printStackTrace();
+        }
+
+        if (failed) {
+            throw new RuntimeException("test failed: NullPointerException " +
+            "has been thrown");
+        } else {
+            System.err.println("test passed");
+        }
+    }
+}
+
+class NullSelection implements Transferable {
+
+    private final DataFlavor[] flavors;
+
+    private final String data;
+
+    public NullSelection(String data, DataFlavor[] flavors) {
+        this.data = data;
+        this.flavors = flavors;
+    }
+
+    @Override
+    public DataFlavor[] getTransferDataFlavors() {
+        return flavors;
+    }
+
+    @Override
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        for (DataFlavor fl : flavors) {
+            if (flavor.equals(fl)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Object getTransferData(DataFlavor flavor)
+        throws UnsupportedFlavorException, java.io.IOException
+    {
+        for (DataFlavor fl : flavors) {
+            if (flavor.equals(fl)) {
+                return data;
+            }
+        }
+        throw new UnsupportedFlavorException(flavor);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/ReaderForUnicodeText.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4274234
+  @summary Tests that DataFlavor.getReaderForText() doesn't throw UnsupportedEncodingException for unicode text
+  @author prs@sparc.spb.su: area=
+  @run main ReaderForUnicodeText
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+public class ReaderForUnicodeText {
+
+   public static void main(String[] args) throws Exception {
+      DataFlavor df = DataFlavor.plainTextFlavor;
+      TextTransferable t = new TextTransferable();
+      Reader reader;
+      try {
+          reader = df.getReaderForText(t);
+      } catch (UnsupportedEncodingException e) {
+           throw new RuntimeException("FAILED: Exception thrown in getReaderForText()");
+      }
+    }
+}
+
+class TextTransferable implements Transferable {
+
+    String text = "Try to test me...";
+
+    @Override
+    public DataFlavor[] getTransferDataFlavors() {
+        DataFlavor flavors[] = {DataFlavor.plainTextFlavor};
+        return flavors;
+    }
+
+    @Override
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        if (flavor.match(DataFlavor.plainTextFlavor)) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public Object getTransferData(DataFlavor flavor) throws
+        UnsupportedFlavorException, IOException {
+
+        byte[] textBytes = null;
+
+        if (!isDataFlavorSupported(flavor)) {
+            throw new UnsupportedFlavorException(flavor);
+        }
+        String encoding = flavor.getParameter("charset");
+        if (encoding == null) {
+            textBytes = text.getBytes();
+        } else {
+            textBytes = text.getBytes(encoding);
+        }
+        return new ByteArrayInputStream(textBytes);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/SelectBestFlavorNPETest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4370469
+  @summary tests that selectBestTextFlavor doesn't throw NPE
+  @author prs@sparc.spb.su: area=
+  @run main SelectBestFlavorNPETest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+
+public class SelectBestFlavorNPETest {
+
+    public static void main(String[] args) {
+
+        DataFlavor flavor1 = new DataFlavor("text/plain; charset=unicode; class=java.io.InputStream",
+                "Flavor 1");
+        DataFlavor flavor2 = new DataFlavor("text/plain; class=java.io.InputStream", "Flavor 2");
+        DataFlavor[] flavors = new DataFlavor[]{flavor1, flavor2};
+        try {
+            DataFlavor best = DataFlavor.selectBestTextFlavor(flavors);
+            System.out.println("best=" + best);
+        } catch (NullPointerException e1) {
+            throw new RuntimeException("Test FAILED because of NPE in selectBestTextFlavor");
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/SelectBestTextFlavorBadArrayTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4386360
+  @summary tests that DataFlavor.selectBestTextFlavor() returns null when passed
+           is a null array or an empty array or an array which doesn't contain
+           a text flavor in a supported encoding.
+  @author das@sparc.spb.su area=datatransfer
+  @run main SelectBestTextFlavorBadArrayTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.util.Stack;
+import java.util.stream.Collectors;
+
+public class SelectBestTextFlavorBadArrayTest {
+
+    public static void main(String[] args) {
+        final String[] failureMessages = {
+            "DataFlavor.selectBestTextFlavor(null) doesn't return null.",
+            "DataFlavor.selectBestTextFlavor() doesn't return null for an empty array.",
+            "DataFlavor.selectBestTextFlavor() shouldn't return flavor in an unsupported encoding."
+        };
+        Stack<String> failures = new Stack<>();
+
+        DataFlavor flavor = DataFlavor.selectBestTextFlavor(null);
+        if (flavor != null) {
+            failures.push(failureMessages[0]);
+        }
+        flavor = DataFlavor.selectBestTextFlavor(new DataFlavor[0]);
+        if (flavor != null) {
+            failures.push(failureMessages[1]);
+        }
+
+        try {
+            flavor = DataFlavor.selectBestTextFlavor(new DataFlavor[]
+                { new DataFlavor("text/plain; charset=unsupported; class=java.io.InputStream") });
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+            failures.push("Exception thrown: " + e.toString());
+        }
+        if (flavor != null) {
+            failures.push(failureMessages[2]);
+        }
+
+        if (failures.size() > 0) {
+            String failureReport = failures.stream().collect(Collectors.joining("\n"));
+            throw new RuntimeException("TEST FAILED: \n" + failureReport);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/DataFlavor/ToStringNullPointerTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+ /*
+  @test
+  @bug 4250768
+  @summary tests that DataFlavor.toString() does not throw NPE
+  @author prs@sparc.spb.su: area=
+  @run main ToStringNullPointerTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+
+public class ToStringNullPointerTest {
+
+     static DataFlavor df1;
+
+     public static void main(String[] args) {
+         df1 = new DataFlavor();
+         try {
+             String thisDF = df1.toString();
+         } catch (NullPointerException e) {
+             throw new RuntimeException("Test FAILED: it still throws NPE!");
+         }
+     }
+}
+
--- a/test/java/awt/datatransfer/DuplicatedNativesTest/DuplicatedNativesTest.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.SystemFlavorMap;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-/* @test
- * @bug 8028230
- * @summary Checks that SystemFlavorMap.getNativesForFlavor returns a list without duplicates
- * @author Petr Pchelko
- * @run main DuplicatedNativesTest
- */
-public class DuplicatedNativesTest {
-
-    public static void main(String[] args) throws Exception {
-
-        // 1. Check that returned natives do not contain duplicates.
-        SystemFlavorMap flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
-        for (Map.Entry<DataFlavor, String> entry : flavorMap.getNativesForFlavors(null).entrySet()) {
-            List<String> natives = flavorMap.getNativesForFlavor(entry.getKey());
-            if (new HashSet<>(natives).size() != natives.size()) {
-                throw new RuntimeException("FAILED: returned natives contain duplicates: " + Arrays.toString(natives.toArray()));
-            }
-        }
-
-        // 2. Check that even if we set a duplicate it would be ignored.
-        flavorMap.setNativesForFlavor(DataFlavor.stringFlavor, new String[] {"test", "test", "test"});
-        List<String> natives = flavorMap.getNativesForFlavor(DataFlavor.stringFlavor);
-        if (new HashSet<>(natives).size() != natives.size()) {
-            throw new RuntimeException("FAILED: duplicates were not ignored: " + Arrays.toString(natives.toArray()));
-        }
-    }
-}
--- a/test/java/awt/datatransfer/MappingGenerationTest/MappingGenerationTest.java	Tue Apr 07 17:34:14 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,183 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.SystemFlavorMap;
-import java.util.List;
-
-/*
-  @test
-  @bug 4512530 8027148
-  @summary tests that mappings for text flavors are generated properly
-  @author das@sparc.spb.su area=datatransfer
-*/
-
-public class MappingGenerationTest {
-
-    private static final SystemFlavorMap fm =
-        (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
-
-    public static void main(String[] args)  {
-        test1();
-        test2();
-        test3();
-        test4();
-        test5();
-        test6();
-    }
-
-    /**
-     * Verifies that Lists returned from getNativesForFlavor() and
-     * getFlavorsForNative() are not modified with a subsequent call
-     * to addUnencodedNativeForFlavor() and addFlavorForUnencodedNative()
-     * respectively.
-     */
-    public static void test1() {
-        DataFlavor df = new DataFlavor("text/plain-test1", null);
-        String nat = "native1";
-
-        List<String> natives = fm.getNativesForFlavor(df);
-        fm.addUnencodedNativeForFlavor(df, nat);
-        List<String> nativesNew = fm.getNativesForFlavor(df);
-        if (natives.equals(nativesNew)) {
-            System.err.println("orig=" + natives);
-            System.err.println("new=" + nativesNew);
-            throw new RuntimeException("Test failed");
-        }
-
-        List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
-        fm.addFlavorForUnencodedNative(nat, df);
-        List<DataFlavor> flavorsNew = fm.getFlavorsForNative(nat);
-        if (flavors.equals(flavorsNew)) {
-            System.err.println("orig=" + flavors);
-            System.err.println("new=" + flavorsNew);
-            throw new RuntimeException("Test failed");
-        }
-    }
-
-    /**
-     * Verifies that SystemFlavorMap is not affected by modification of
-     * the Lists returned from getNativesForFlavor() and
-     * getFlavorsForNative().
-     */
-    public static void test2() {
-        DataFlavor df = new DataFlavor("text/plain-test2", null);
-        String nat = "native2";
-        DataFlavor extraDf = new DataFlavor("text/test", null);
-
-        List<String> natives = fm.getNativesForFlavor(df);
-        natives.add("Should not be here");
-        java.util.List nativesNew = fm.getNativesForFlavor(df);
-        if (natives.equals(nativesNew)) {
-            System.err.println("orig=" + natives);
-            System.err.println("new=" + nativesNew);
-            throw new RuntimeException("Test failed");
-        }
-
-        List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
-        flavors.add(extraDf);
-        java.util.List flavorsNew = fm.getFlavorsForNative(nat);
-        if (flavors.equals(flavorsNew)) {
-            System.err.println("orig=" + flavors);
-            System.err.println("new=" + flavorsNew);
-            throw new RuntimeException("Test failed");
-        }
-    }
-
-    /**
-     * Verifies that addUnencodedNativeForFlavor() for a particular text flavor
-     * doesn't affect mappings for other flavors.
-     */
-    public static void test3() {
-        DataFlavor df1 = new DataFlavor("text/plain-test3", null);
-        DataFlavor df2 = new DataFlavor("text/plain-test3; charset=Unicode; class=java.io.Reader", null);
-        String nat = "native3";
-        List<String> natives = fm.getNativesForFlavor(df2);
-        fm.addUnencodedNativeForFlavor(df1, nat);
-        List<String> nativesNew = fm.getNativesForFlavor(df2);
-        if (!natives.equals(nativesNew)) {
-            System.err.println("orig=" + natives);
-            System.err.println("new=" + nativesNew);
-            throw new RuntimeException("Test failed");
-        }
-    }
-
-    /**
-     * Verifies that addUnencodedNativeForFlavor() really adds the specified
-     * flavor-to-native mapping to the existing mappings.
-     */
-    public static void test4() {
-        DataFlavor df = new DataFlavor("text/plain-test4; charset=Unicode; class=java.io.Reader", null);
-        String nat = "native4";
-        List<String> natives = fm.getNativesForFlavor(df);
-        if (!natives.contains(nat)) {
-            fm.addUnencodedNativeForFlavor(df, nat);
-            List<String> nativesNew = fm.getNativesForFlavor(df);
-            natives.add(nat);
-            if (!natives.equals(nativesNew)) {
-                System.err.println("orig=" + natives);
-                System.err.println("new=" + nativesNew);
-                throw new RuntimeException("Test failed");
-            }
-        }
-    }
-
-    /**
-     * Verifies that a flavor doesn't have any flavor-to-native mappings after
-     * a call to setNativesForFlavor() with this flavor and an empty native
-     * array as arguments.
-     */
-    public static void test5() {
-        final DataFlavor flavor =
-            new DataFlavor("text/plain-TEST5; charset=Unicode", null);
-
-        fm.getNativesForFlavor(flavor);
-
-        fm.setNativesForFlavor(flavor, new String[0]);
-
-        List<String> natives = fm.getNativesForFlavor(flavor);
-
-        if (!natives.isEmpty()) {
-            System.err.println("natives=" + natives);
-            throw new RuntimeException("Test failed");
-        }
-    }
-
-    /**
-     * Verifies that a native doesn't have any native-to-flavor mappings after
-     * a call to setFlavorsForNative() with this native and an empty flavor
-     * array as arguments.
-     */
-    public static void test6() {
-        final String nat = "STRING";
-        fm.getFlavorsForNative(nat);
-        fm.setFlavorsForNative(nat, new DataFlavor[0]);
-
-        List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
-
-        if (!flavors.isEmpty()) {
-            System.err.println("flavors=" + flavors);
-            throw new RuntimeException("Test failed");
-        }
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/AbsoluteComponentCenterCalculator.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+
+class AbsoluteComponentCenterCalculator {
+    private AbsoluteComponentCenterCalculator() {
+    }
+
+    public static int calculateXCenterCoordinate(Component component) {
+        return (int) component.getLocationOnScreen().getX() + (component.getWidth() / 2);
+    }
+
+    public static int calculateYCenterCoordinate(Component component) {
+        return (int) component.getLocationOnScreen().getY() + (component.getHeight() / 2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/DataFlavorSearcher.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.FlavorTable;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+
+public class DataFlavorSearcher {
+    static public String[] HTML_NAMES = new String[]{"HTML", "HTML Format"};
+    static public String[] RICH_TEXT_NAMES = new String[]{"RICH_TEXT", "Rich Text Format"};
+
+    static public DataFlavor getByteDataFlavorForNative(String[] nats) {
+        FlavorTable flavorTable = (FlavorTable) SystemFlavorMap.getDefaultFlavorMap();
+
+        for (String nat : nats) {
+            java.util.List<DataFlavor> flavors = flavorTable.getFlavorsForNative(nat);
+            for (DataFlavor flavor : flavors) {
+                if (flavor != null
+                        && flavor.getRepresentationClass().equals(byte[].class)) {
+                    return flavor;
+                }
+            }
+        }
+        throw new RuntimeException("No data flavor was found for natives: " + Arrays.toString(nats));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/InterprocessMessages.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+interface InterprocessMessages {
+    final static int EXECUTION_IS_SUCCESSFULL = 0;
+    final static int DATA_IS_CORRUPTED = 212;
+    final static int NO_DROP_HAPPENED = 112;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.html	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,48 @@
+<!--
+ Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ or visit www.oracle.com if you need additional information or have any
+ questions.
+-->
+
+<html>
+<!--  
+  @test
+  @bug 8005932 8017456
+  @summary Java 7 on mac os x only provides text clipboard formats
+  @author mikhail.cherkasov@oracle.com
+  @library ../../regtesthelpers
+  @library ../../regtesthelpers/process
+  @build Util
+  @build ProcessResults ProcessCommunicator
+  @run applet/othervm MissedHtmlAndRtfBug.html
+-->
+
+<head>
+    <title>Java 7 on mac os x only provides text clipboard formats</title>
+</head>
+<body>
+
+<h1> MissedHtmlAndRtfBug <br>Bug ID: 8005932 </h1>
+
+<p> This is an AUTOMATIC test, simply wait for completion </p>
+
+<APPLET CODE="MissedHtmlAndRtfBug.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.event.*;
+import java.applet.Applet;
+import java.io.File;
+import java.util.ArrayList;
+
+import test.java.awt.regtesthelpers.process.ProcessCommunicator;
+import test.java.awt.regtesthelpers.process.ProcessResults;
+import test.java.awt.regtesthelpers.Util;
+import sun.awt.OSInfo;
+
+import static java.lang.Thread.sleep;
+
+public class MissedHtmlAndRtfBug extends Applet {
+
+    public void init() {
+        setLayout(new BorderLayout());
+    }//End  init()
+
+    public void start() {
+        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX
+                && OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
+            System.out.println("This test is for Windows and Mac only. Passed.");
+            return;
+        }
+
+        final Frame sourceFrame = new Frame("Source frame");
+        final SourcePanel sourcePanel = new SourcePanel();
+        sourceFrame.add(sourcePanel);
+        sourceFrame.pack();
+        sourceFrame.addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowClosing(WindowEvent e) {
+                sourceFrame.dispose();
+            }
+        });
+        sourceFrame.setVisible(true);
+
+        Util.waitForIdle(null);
+
+        NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame);
+
+        ArrayList<String> args = new ArrayList<String>(5);
+        args.add(String.valueOf(positionCalculator.getNextLocationX()));
+        args.add(String.valueOf(positionCalculator.getNextLocationY()));
+        args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)));
+        args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)));
+        args.add(concatStrings(DataFlavorSearcher.RICH_TEXT_NAMES));
+
+        ProcessResults processResults =
+                ProcessCommunicator.executeChildProcess(this.getClass(),
+                        "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
+
+        verifyTestResults(processResults);
+
+        args.set(args.size() - 1, concatStrings(DataFlavorSearcher.HTML_NAMES));
+
+        ProcessCommunicator.executeChildProcess(this.getClass(),
+                "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
+        verifyTestResults(processResults);
+
+
+    }// start()
+
+    private String concatStrings(String[] strings) {
+        StringBuffer result = new StringBuffer("\"");
+        for (int i = 0; i < strings.length; i++) {
+            result.append(strings[i]);
+            result.append(",");
+        }
+        result.append("\"");
+        return result.toString();
+    }
+
+
+    private static void verifyTestResults(ProcessResults processResults) {
+        if (InterprocessMessages.DATA_IS_CORRUPTED ==
+                processResults.getExitValue()) {
+            processResults.printProcessErrorOutput(System.err);
+            throw new RuntimeException("TEST IS FAILED: Target has received" +
+                    " corrupted data.");
+        }
+        if (InterprocessMessages.NO_DROP_HAPPENED ==
+                processResults.getExitValue()) {
+            processResults.printProcessErrorOutput(System.err);
+            throw new RuntimeException("Error. Drop did not happen." +
+                " Target frame is possibly covered by a window of other application." +
+                " Please, rerun the test with all windows minimized.");
+        }
+        processResults.verifyStdErr(System.err);
+        processResults.verifyProcessExitValue(System.err);
+        processResults.printProcessStandartOutput(System.out);
+    }
+
+    //We cannot make an instance of the applet without the default constructor
+    public MissedHtmlAndRtfBug() {
+        super();
+    }
+
+    //We need in this constructor to pass frame position between JVMs
+    public MissedHtmlAndRtfBug(Point targetFrameLocation, Point dragSourcePoint, DataFlavor df)
+            throws InterruptedException {
+        final Frame targetFrame = new Frame("Target frame");
+        final TargetPanel targetPanel = new TargetPanel(targetFrame, df);
+        targetFrame.add(targetPanel);
+        targetFrame.addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowClosing(WindowEvent e) {
+                targetFrame.dispose();
+            }
+        });
+        targetFrame.setLocation(targetFrameLocation);
+        targetFrame.pack();
+        targetFrame.setVisible(true);
+
+        doTest(dragSourcePoint, targetPanel);
+    }
+
+    private void doTest(Point dragSourcePoint, TargetPanel targetPanel) {
+        Util.waitForIdle(null);
+
+        final Robot robot = Util.createRobot();
+
+        robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
+        try {
+            sleep(100);
+            robot.mousePress(InputEvent.BUTTON1_MASK);
+            sleep(100);
+            robot.mouseRelease(InputEvent.BUTTON1_MASK);
+            sleep(100);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+        Util.drag(robot, dragSourcePoint, new Point(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel),
+                AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)),
+                InputEvent.BUTTON1_MASK);
+    }
+
+
+    enum InterprocessArguments {
+        TARGET_FRAME_X_POSITION_ARGUMENT,
+        TARGET_FRAME_Y_POSITION_ARGUMENT,
+        DRAG_SOURCE_POINT_X_ARGUMENT,
+        DRAG_SOURCE_POINT_Y_ARGUMENT,
+        DATA_FLAVOR_NAMES;
+
+        int extractInt(String[] args) {
+            return Integer.parseInt(args[this.ordinal()]);
+        }
+
+        String[] extractStringArray(String[] args) {
+            return args[this.ordinal()].replaceAll("\"", "").split(",");
+        }
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extractInt(args),
+                InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extractInt(args));
+        Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extractInt(args),
+                InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extractInt(args));
+        String[] names = InterprocessArguments.DATA_FLAVOR_NAMES.extractStringArray(args);
+
+        DataFlavor df = DataFlavorSearcher.getByteDataFlavorForNative(names);
+        try {
+            new MissedHtmlAndRtfBug(targetFrameLocation, dragSourcePoint, df);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        sleep(5000);
+        System.exit(InterprocessMessages.NO_DROP_HAPPENED);
+    }
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/MyTransferable.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.datatransfer.*;
+import java.io.IOException;
+
+class MyTransferable implements Transferable {
+
+    public static final String TEST_DATA = "<b>Test</b>";
+    private DataFlavor[] dataFlavors;
+
+    public MyTransferable() {
+        dataFlavors = new DataFlavor[]{DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.HTML_NAMES),
+                DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.RICH_TEXT_NAMES)};
+    }
+
+
+    @Override
+    public DataFlavor[] getTransferDataFlavors() {
+        return dataFlavors;
+    }
+
+    @Override
+    public boolean isDataFlavorSupported(DataFlavor flavor) {
+        for (DataFlavor f : dataFlavors) {
+            if (f.equals(flavor)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Object getTransferData(DataFlavor flavor)
+            throws UnsupportedFlavorException, IOException {
+        if (isDataFlavorSupported(flavor)) {
+            return TEST_DATA.getBytes("UTF-16");
+        } else {
+            throw new UnsupportedFlavorException(flavor);
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/NextFramePositionCalculator.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.*;
+
+
+class NextFramePositionCalculator {
+
+    private final Frame currentFrame;
+
+    public NextFramePositionCalculator(Frame currentFrame) {
+        this.currentFrame = currentFrame;
+    }
+
+    public int getNextLocationX() {
+        return currentFrame.getX() + currentFrame.getWidth();
+    }
+
+    public int getNextLocationY() {
+        return currentFrame.getY();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/SourcePanel.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.*;
+
+public class SourcePanel extends Panel {
+
+    private final MyDragGestureListener dragGestureListener =
+            new MyDragGestureListener();
+
+    public SourcePanel() {
+        setPreferredSize(new Dimension(200, 200));
+        DragSource defaultDragSource =
+                DragSource.getDefaultDragSource();
+        defaultDragSource.createDefaultDragGestureRecognizer(this,
+                DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
+        setBackground(Color.RED);
+    }
+
+    private class MyDragGestureListener implements DragGestureListener {
+        public void dragGestureRecognized(DragGestureEvent dge) {
+            dge.startDrag(null, new MyTransferable());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/MissedHtmlAndRtfBug/TargetPanel.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.*;
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class TargetPanel extends Panel implements DropTargetListener {
+
+
+    //private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener();
+
+    private Frame frame;
+    DataFlavor dataFlavor;
+
+    public TargetPanel(Frame frame, DataFlavor dataFlavor) {
+        this.dataFlavor = dataFlavor;
+        this.frame = frame;
+        setBackground(Color.DARK_GRAY);
+        setPreferredSize(new Dimension(200, 200));
+        setDropTarget(new DropTarget(this, this));
+    }
+
+    public void dragEnter(DropTargetDragEvent dtde) {
+        if (dtde.isDataFlavorSupported(dataFlavor)) {
+            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
+        }
+    }
+
+    public void dragOver(DropTargetDragEvent dtde) {
+        if (dtde.isDataFlavorSupported(dataFlavor)) {
+            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
+        }
+    }
+
+    public void dropActionChanged(DropTargetDragEvent dtde) {
+        if (dtde.isDataFlavorSupported(dataFlavor)) {
+            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
+        }
+    }
+
+    public void dragExit(DropTargetEvent dte) {
+
+    }
+
+    public void drop(DropTargetDropEvent dtde) {
+        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+        if (dtde.isDataFlavorSupported(dataFlavor)) {
+            String result = null;
+            try {
+                Transferable t = dtde.getTransferable();
+                byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
+                result = new String(data, "UTF-16");
+                repaint();
+            } catch (UnsupportedFlavorException e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            dtde.dropComplete(true);
+
+
+            if (result != null && result.contains(MyTransferable.TEST_DATA)) {
+                System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
+                Timer t = new Timer();
+                t.schedule(new TimerTask() {
+                    @Override
+                    public void run() {
+                        System.exit(0);
+                    }
+                }, 2000);
+                return;
+
+            }
+        }
+        dtde.rejectDrop();
+        System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
+        System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/DuplicateMappingTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4493189
+  @summary tests that addUnencodedNativeForFlavor()/addFlavorForUnencodedNative()
+           do not allow to duplicate mappings
+  @author das@sparc.spb.su area=datatransfer
+  @run main DuplicateMappingTest
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Iterator;
+
+public class DuplicateMappingTest {
+
+    public static void main(String[] args) throws Exception {
+
+        final String nativeString = "NATIVE";
+        final DataFlavor dataFlavor = new DataFlavor();
+
+        final SystemFlavorMap fm =
+                (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
+
+        fm.addUnencodedNativeForFlavor(dataFlavor, nativeString);
+        fm.addUnencodedNativeForFlavor(dataFlavor, nativeString);
+
+        final java.util.List natives =
+                fm.getNativesForFlavor(dataFlavor);
+        boolean found = false;
+
+        for (final Iterator i = natives.iterator(); i.hasNext(); ) {
+            if (nativeString.equals(i.next())) {
+                if (found) {
+                    throw new RuntimeException("getNativesForFlavor() returns:" +
+                            natives);
+                } else {
+                    found = true;
+                }
+            }
+        }
+
+        if (!found) {
+            throw new RuntimeException("getNativesForFlavor() returns:" +
+                    natives);
+        }
+
+        fm.addFlavorForUnencodedNative(nativeString, dataFlavor);
+        fm.addFlavorForUnencodedNative(nativeString, dataFlavor);
+
+        final java.util.List flavors =
+                fm.getFlavorsForNative(nativeString);
+        found = false;
+
+        for (final Iterator i = flavors.iterator(); i.hasNext(); ) {
+            if (dataFlavor.equals(i.next())) {
+                if (found) {
+                    throw new RuntimeException("getFlavorsForNative() returns:" +
+                            flavors);
+                } else {
+                    found = true;
+                }
+            }
+        }
+
+        if (!found) {
+            throw new RuntimeException("getFlavorsForNative() returns:" +
+                    natives);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/DuplicatedNativesTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+/* @test
+ * @bug 8028230
+ * @summary Checks that SystemFlavorMap.getNativesForFlavor returns a list without duplicates
+ * @author Petr Pchelko
+ * @run main DuplicatedNativesTest
+ */
+public class DuplicatedNativesTest {
+
+    public static void main(String[] args) throws Exception {
+
+        // 1. Check that returned natives do not contain duplicates.
+        SystemFlavorMap flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+        for (Map.Entry<DataFlavor, String> entry : flavorMap.getNativesForFlavors(null).entrySet()) {
+            List<String> natives = flavorMap.getNativesForFlavor(entry.getKey());
+            if (new HashSet<>(natives).size() != natives.size()) {
+                throw new RuntimeException("FAILED: returned natives contain duplicates: " + Arrays.toString(natives.toArray()));
+            }
+        }
+
+        // 2. Check that even if we set a duplicate it would be ignored.
+        flavorMap.setNativesForFlavor(DataFlavor.stringFlavor, new String[] {"test", "test", "test"});
+        List<String> natives = flavorMap.getNativesForFlavor(DataFlavor.stringFlavor);
+        if (new HashSet<>(natives).size() != natives.size()) {
+            throw new RuntimeException("FAILED: duplicates were not ignored: " + Arrays.toString(natives.toArray()));
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/GetNativesForFlavorTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4493178
+  @summary tests that getNativesForFlavor() synthesizes an encoded String native
+           only if there are no mappings for the DataFlavor and the mappings
+           were not explicitly removed
+  @author das@sparc.spb.su area=datatransfer
+  @run main GetNativesForFlavorTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Iterator;
+
+public class GetNativesForFlavorTest {
+
+    final static SystemFlavorMap fm =
+            (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
+
+    public static void main(String[] args) throws Exception {
+        // 1.Check that the encoded native is not added if there are other
+        // natives for this DataFlavor.
+        test1();
+
+        // 2.Check that the encoded native is not added if all mappings were
+        // explicitly removed for this DataFlavor.
+        test2();
+
+        // 3.Check that only the encoded native is added for text DataFlavors
+        // that has no mappings and that DataFlavor is properly encoded.
+        test3();
+
+        // 4.Verifies that the encoded native is added only for DataFlavors
+        // that has no mappings and that DataFlavor is properly encoded.
+        test4();
+    }
+
+    /**
+     * Verifies that the encoded native is not added if there are other
+     * natives mapped to this DataFlavor.
+     */
+    public static void test1() throws ClassNotFoundException {
+        final DataFlavor flavor =
+                new DataFlavor("text/plain-TEST; charset=Unicode");
+
+        final java.util.List natives = fm.getNativesForFlavor(flavor);
+
+        if (natives.size() > 1) {
+            for (final Iterator i = natives.iterator(); i.hasNext(); ) {
+                String element = (String) i.next();
+                if (SystemFlavorMap.isJavaMIMEType(element)) {
+                    throw new RuntimeException("getFlavorsForNative() returns: "
+                            + natives);
+                }
+            }
+        }
+    }
+
+    /**
+     * Verifies that the encoded native is not added if all mappings were
+     * explicitly removed for this DataFlavor.
+     */
+    public static void test2() throws ClassNotFoundException {
+        final DataFlavor flavor =
+                new DataFlavor("text/plain-TEST; charset=Unicode");
+
+        fm.setNativesForFlavor(flavor, new String[0]);
+
+        final java.util.List natives = fm.getNativesForFlavor(flavor);
+
+        if (!natives.isEmpty()) {
+            throw new RuntimeException("getFlavorsForNative() returns:" +
+                    natives);
+        }
+    }
+
+    /**
+     * Verifies that only the encoded native is added for text DataFlavors
+     * that has no mappings and that DataFlavor is properly encoded.
+     */
+    public static void test3() throws ClassNotFoundException {
+        //
+        final DataFlavor flavor =
+                new DataFlavor("text/plain-TEST-nocharset; class=java.nio.ByteBuffer");
+
+        final java.util.List natives = fm.getNativesForFlavor(flavor);
+        boolean encodedNativeFound = false;
+
+        if (natives.size() == 0) {
+            throw new RuntimeException("getFlavorsForNative() returns:" +
+                    natives);
+        }
+
+        if (natives.size() == 1) {
+            String element = (String) natives.get(0);
+            if (SystemFlavorMap.isJavaMIMEType(element)) {
+                final DataFlavor decodedFlavor =
+                        SystemFlavorMap.decodeDataFlavor(element);
+                if (!flavor.equals(decodedFlavor)) {
+                    System.err.println("DataFlavor is not properly incoded:");
+                    System.err.println("    encoded flavor: " + flavor);
+                    System.err.println("    decoded flavor: " + decodedFlavor);
+                    throw new RuntimeException("getFlavorsForNative() returns:"
+                            + natives);
+                }
+            }
+        } else {
+            for (final Iterator i = natives.iterator(); i.hasNext(); ) {
+                String element = (String) i.next();
+                if (SystemFlavorMap.isJavaMIMEType(element)) {
+                    throw new RuntimeException("getFlavorsForNative() returns:"
+                            + natives);
+                }
+            }
+        }
+    }
+
+    /**
+     * Verifies that the encoded native is added only for DataFlavors
+     * that has no mappings and that DataFlavor is properly encoded.
+     */
+    public static void test4() throws ClassNotFoundException {
+        final DataFlavor flavor =
+                new DataFlavor("unknown/unknown");
+
+        final java.util.List natives = fm.getNativesForFlavor(flavor);
+
+        if (natives.size() == 1) {
+            String element = (String) natives.get(0);
+            if (SystemFlavorMap.isJavaMIMEType(element)) {
+                final DataFlavor decodedFlavor =
+                        SystemFlavorMap.decodeDataFlavor(element);
+                if (!flavor.equals(decodedFlavor)) {
+                    System.err.println("DataFlavor is not properly incoded:");
+                    System.err.println("    encoded flavor: " + flavor);
+                    System.err.println("    decoded flavor: " + decodedFlavor);
+                    throw new RuntimeException("getFlavorsForNative() returns:"
+                            + natives);
+                }
+            }
+        } else {
+            throw new RuntimeException("getFlavorsForNative() returns:"
+                    + natives);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/MappingGenerationTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.List;
+
+/*
+  @test
+  @bug 4512530 8027148
+  @summary tests that mappings for text flavors are generated properly
+  @author das@sparc.spb.su area=datatransfer
+*/
+
+public class MappingGenerationTest {
+
+    private static final SystemFlavorMap fm =
+        (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+    public static void main(String[] args)  {
+        test1();
+        test2();
+        test3();
+        test4();
+        test5();
+        test6();
+    }
+
+    /**
+     * Verifies that Lists returned from getNativesForFlavor() and
+     * getFlavorsForNative() are not modified with a subsequent call
+     * to addUnencodedNativeForFlavor() and addFlavorForUnencodedNative()
+     * respectively.
+     */
+    public static void test1() {
+        DataFlavor df = new DataFlavor("text/plain-test1", null);
+        String nat = "native1";
+
+        List<String> natives = fm.getNativesForFlavor(df);
+        fm.addUnencodedNativeForFlavor(df, nat);
+        List<String> nativesNew = fm.getNativesForFlavor(df);
+        if (natives.equals(nativesNew)) {
+            System.err.println("orig=" + natives);
+            System.err.println("new=" + nativesNew);
+            throw new RuntimeException("Test failed");
+        }
+
+        List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
+        fm.addFlavorForUnencodedNative(nat, df);
+        List<DataFlavor> flavorsNew = fm.getFlavorsForNative(nat);
+        if (flavors.equals(flavorsNew)) {
+            System.err.println("orig=" + flavors);
+            System.err.println("new=" + flavorsNew);
+            throw new RuntimeException("Test failed");
+        }
+    }
+
+    /**
+     * Verifies that SystemFlavorMap is not affected by modification of
+     * the Lists returned from getNativesForFlavor() and
+     * getFlavorsForNative().
+     */
+    public static void test2() {
+        DataFlavor df = new DataFlavor("text/plain-test2", null);
+        String nat = "native2";
+        DataFlavor extraDf = new DataFlavor("text/test", null);
+
+        List<String> natives = fm.getNativesForFlavor(df);
+        natives.add("Should not be here");
+        java.util.List nativesNew = fm.getNativesForFlavor(df);
+        if (natives.equals(nativesNew)) {
+            System.err.println("orig=" + natives);
+            System.err.println("new=" + nativesNew);
+            throw new RuntimeException("Test failed");
+        }
+
+        List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
+        flavors.add(extraDf);
+        java.util.List flavorsNew = fm.getFlavorsForNative(nat);
+        if (flavors.equals(flavorsNew)) {
+            System.err.println("orig=" + flavors);
+            System.err.println("new=" + flavorsNew);
+            throw new RuntimeException("Test failed");
+        }
+    }
+
+    /**
+     * Verifies that addUnencodedNativeForFlavor() for a particular text flavor
+     * doesn't affect mappings for other flavors.
+     */
+    public static void test3() {
+        DataFlavor df1 = new DataFlavor("text/plain-test3", null);
+        DataFlavor df2 = new DataFlavor("text/plain-test3; charset=Unicode; class=java.io.Reader", null);
+        String nat = "native3";
+        List<String> natives = fm.getNativesForFlavor(df2);
+        fm.addUnencodedNativeForFlavor(df1, nat);
+        List<String> nativesNew = fm.getNativesForFlavor(df2);
+        if (!natives.equals(nativesNew)) {
+            System.err.println("orig=" + natives);
+            System.err.println("new=" + nativesNew);
+            throw new RuntimeException("Test failed");
+        }
+    }
+
+    /**
+     * Verifies that addUnencodedNativeForFlavor() really adds the specified
+     * flavor-to-native mapping to the existing mappings.
+     */
+    public static void test4() {
+        DataFlavor df = new DataFlavor("text/plain-test4; charset=Unicode; class=java.io.Reader", null);
+        String nat = "native4";
+        List<String> natives = fm.getNativesForFlavor(df);
+        if (!natives.contains(nat)) {
+            fm.addUnencodedNativeForFlavor(df, nat);
+            List<String> nativesNew = fm.getNativesForFlavor(df);
+            natives.add(nat);
+            if (!natives.equals(nativesNew)) {
+                System.err.println("orig=" + natives);
+                System.err.println("new=" + nativesNew);
+                throw new RuntimeException("Test failed");
+            }
+        }
+    }
+
+    /**
+     * Verifies that a flavor doesn't have any flavor-to-native mappings after
+     * a call to setNativesForFlavor() with this flavor and an empty native
+     * array as arguments.
+     */
+    public static void test5() {
+        final DataFlavor flavor =
+            new DataFlavor("text/plain-TEST5; charset=Unicode", null);
+
+        fm.getNativesForFlavor(flavor);
+
+        fm.setNativesForFlavor(flavor, new String[0]);
+
+        List<String> natives = fm.getNativesForFlavor(flavor);
+
+        if (!natives.isEmpty()) {
+            System.err.println("natives=" + natives);
+            throw new RuntimeException("Test failed");
+        }
+    }
+
+    /**
+     * Verifies that a native doesn't have any native-to-flavor mappings after
+     * a call to setFlavorsForNative() with this native and an empty flavor
+     * array as arguments.
+     */
+    public static void test6() {
+        final String nat = "STRING";
+        fm.getFlavorsForNative(nat);
+        fm.setFlavorsForNative(nat, new DataFlavor[0]);
+
+        List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
+
+        if (!flavors.isEmpty()) {
+            System.err.println("flavors=" + flavors);
+            throw new RuntimeException("Test failed");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/datatransfer/SystemFlavorMap/SetNativesForFlavorTest.java	Mon Jun 16 17:13:58 2014 +0400
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 4478912
+  @summary tests that getNativesForFlavor()/getFlavorsForNative() return the
+           same list as was set with setNativesForFlavor()/setFlavorsForNative()
+  @author das@sparc.spb.su area=datatransfer
+  @run main SetNativesForFlavorTest
+*/
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+
+public class SetNativesForFlavorTest  {
+
+    public static void main(String[] args) throws Exception {
+            final String nativeString = "NATIVE";
+
+            final SystemFlavorMap fm =
+                (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
+
+            fm.setNativesForFlavor(DataFlavor.plainTextFlavor,
+                                   new String[] { nativeString });
+
+            final java.util.List natives =
+                fm.getNativesForFlavor(DataFlavor.plainTextFlavor);
+
+            if (natives.size() != 1 || !natives.contains(nativeString)) {
+                throw new RuntimeException("getNativesForFlavor() returns:" +
+                                           natives);
+            }
+
+            final DataFlavor dataFlavor =
+                new DataFlavor("text/unknown; class=java.lang.String");
+
+            fm.setFlavorsForNative(nativeString, new DataFlavor[] { dataFlavor });
+
+            final java.util.List flavors = fm.getFlavorsForNative(nativeString);
+
+            if (flavors.size() != 1 || !flavors.contains(dataFlavor)) {
+                throw new RuntimeException("getFlavorsForNative() returns:" +
+                                           flavors);
+            }
+    }
+}