Skip to content

Commit efc3f4a

Browse files
amosshiGoeLin
authored andcommitted
8041447: Test javax/swing/dnd/7171812/bug7171812.java fails with java.lang.RuntimeException: Test failed, scroll on drag doesn't work
Backport-of: 2c52cf07469970f730aa7397f9f6b98534af3a44
1 parent 4780287 commit efc3f4a

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion.java 8060176
128128
java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion_1.java 8060176 windows-all,macosx-all
129129
java/awt/dnd/MissingEventsOnModalDialog/MissingEventsOnModalDialogTest.java 8164464 linux-all,macosx-all
130130
java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java 8171510 macosx-all
131-
javax/swing/dnd/7171812/bug7171812.java 8041447 macosx-all
132131
java/awt/Focus/ChoiceFocus/ChoiceFocus.java 8169103 windows-all,macosx-all
133132
java/awt/Focus/ClearLwQueueBreakTest/ClearLwQueueBreakTest.java 8198618 macosx-all
134133
java/awt/Focus/ConsumeNextKeyTypedOnModalShowTest/ConsumeNextKeyTypedOnModalShowTest.java 6986252 macosx-all

test/jdk/javax/swing/dnd/7171812/bug7171812.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,45 +26,62 @@
2626
* @key headful
2727
* @bug 7171812
2828
* @summary [macosx] Views keep scrolling back to the drag position after DnD
29-
* @author Alexander Zuev
3029
* @run main bug7171812
3130
*/
3231

33-
import java.awt.*;
34-
import java.awt.dnd.*;
32+
import java.awt.BorderLayout;
33+
import java.awt.Point;
34+
import java.awt.Robot;
35+
import java.awt.dnd.DnDConstants;
36+
import java.awt.dnd.DropTarget;
37+
import java.awt.dnd.DropTargetDragEvent;
38+
import java.awt.dnd.DropTargetDropEvent;
39+
import java.awt.dnd.DropTargetEvent;
40+
import java.awt.dnd.DropTargetListener;
3541
import java.awt.event.InputEvent;
36-
import javax.swing.*;
42+
import javax.swing.JFrame;
43+
import javax.swing.JScrollPane;
44+
import javax.swing.SwingUtilities;
3745

3846
public class bug7171812 {
3947
static JFrame mainFrame;
4048
static String listData[];
4149
static JListWithScroll<String> list;
4250
static JScrollPane scrollPane;
51+
static volatile Point pt;
52+
static volatile int height;
4353

4454
/**
4555
* @param args the command line arguments
4656
*/
4757
public static void main(String[] args) throws Exception{
4858

59+
Robot robot = new Robot();
60+
robot.setAutoDelay(100);
61+
robot.setAutoWaitForIdle(true);
62+
4963
SwingUtilities.invokeAndWait(new Runnable() {
5064
@Override
5165
public void run() {
5266
setupGUI();
5367
}
5468
});
5569

56-
Robot robot = new Robot();
57-
robot.setAutoDelay(10);
5870
robot.waitForIdle();
59-
robot.mouseMove(scrollPane.getLocationOnScreen().x + 5, scrollPane.getLocationOnScreen().y + 5);
60-
robot.mousePress(InputEvent.BUTTON1_MASK);
61-
for(int offset = 5; offset < scrollPane.getHeight()-20; offset++) {
62-
robot.mouseMove(scrollPane.getLocationOnScreen().x+5, scrollPane.getLocationOnScreen().y+offset);
71+
robot.delay(1000);
72+
SwingUtilities.invokeAndWait(() -> {
73+
pt = scrollPane.getLocationOnScreen();
74+
height = scrollPane.getHeight();
75+
});
76+
robot.mouseMove(pt.x + 5, pt.y + 5);
77+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
78+
for(int offset = 5; offset < height - 20; offset++) {
79+
robot.mouseMove(pt.x + 5, pt.y + offset);
6380
}
6481
for(int offset = 5; offset < 195; offset++) {
65-
robot.mouseMove(scrollPane.getLocationOnScreen().x+offset, scrollPane.getLocationOnScreen().y+scrollPane.getHeight()-20);
82+
robot.mouseMove(pt.x + offset, pt.y + height - 20);
6683
}
67-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
84+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
6885
try {
6986
SwingUtilities.invokeAndWait(new Runnable() {
7087
@Override

0 commit comments

Comments
 (0)