8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu

Reviewed-by: yan, serb
This commit is contained in:
Semyon Sadetsky 2017-04-13 08:04:33 -07:00
parent 2fdd517464
commit 84dd5699d5

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -70,9 +70,14 @@ public class bug8024061 {
private static final DataFlavor DropObjectFlavor; private static final DataFlavor DropObjectFlavor;
private static final int DELAY = 1000; private static final int DELAY = 1000;
private final DnDPanel panel1 = new DnDPanel(Color.yellow); static final DnDPanel panel1 = new DnDPanel(Color.yellow);
private final DnDPanel panel2 = new DnDPanel(Color.pink); static final DnDPanel panel2 = new DnDPanel(Color.pink);
private final JFrame frame; private final JFrame frame;
static Point here;
static Point there;
static Dimension d;
private static final CountDownLatch lock = new CountDownLatch(1); private static final CountDownLatch lock = new CountDownLatch(1);
private static volatile Exception dragEnterException = null; private static volatile Exception dragEnterException = null;
@ -91,7 +96,7 @@ public class bug8024061 {
frame = new JFrame("DnDWithRobot"); frame = new JFrame("DnDWithRobot");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Dimension d = new Dimension(100, 100); d = new Dimension(100, 100);
panel1.setPreferredSize(d); panel1.setPreferredSize(d);
panel2.setPreferredSize(d); panel2.setPreferredSize(d);
@ -126,12 +131,15 @@ public class bug8024061 {
final Robot robot = new Robot(); final Robot robot = new Robot();
robot.setAutoDelay(10); robot.setAutoDelay(10);
robot.waitForIdle(); robot.waitForIdle();
robot.delay(200);
JFrame frame = dnd[0].frame; JFrame frame = dnd[0].frame;
Point point = frame.getLocationOnScreen(); SwingUtilities.invokeAndWait(() -> {
Point here = new Point(point.x + 35, point.y + 45); here = panel1.getLocationOnScreen();
Point there = new Point(point.x + 120, point.y + 45); there = panel2.getLocationOnScreen();
here.x += 25; });
here.translate(d.width / 2, d.height / 2);
there.translate(d.width / 2, d.height / 2);
robot.mouseMove(here.x, here.y); robot.mouseMove(here.x, here.y);
robot.mousePress(InputEvent.BUTTON1_MASK); robot.mousePress(InputEvent.BUTTON1_MASK);
while (here.x < there.x) { while (here.x < there.x) {
@ -159,7 +167,7 @@ public class bug8024061 {
throw new RuntimeException("Timed out waiting for dragEnter()"); throw new RuntimeException("Timed out waiting for dragEnter()");
} }
} finally { } finally {
frame.dispose(); SwingUtilities.invokeLater(frame::dispose);
} }
} }
@ -220,7 +228,7 @@ public class bug8024061 {
} }
} }
class DnDPanel extends JPanel { static class DnDPanel extends JPanel {
DropObject dropObject; DropObject dropObject;
final DragSource dragSource; final DragSource dragSource;
final DropTarget dropTarget; final DropTarget dropTarget;