Skip to content

Commit 8bde7d4

Browse files
committed
8239801: [macos] java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTest.java fails
Backport-of: b6dddf4ce6072416e17cadefbd8280f959fd93ca
1 parent 5eeb41a commit 8bde7d4

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ java/awt/Focus/FocusOwnerFrameOnClick/FocusOwnerFrameOnClick.java 8081489 generi
119119
java/awt/Focus/IconifiedFrameFocusChangeTest/IconifiedFrameFocusChangeTest.java 6849364 generic-all
120120
java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusToFrontTest.java 6848406 generic-all
121121
java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java 6848407 generic-all
122-
java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTest.java 8239801 macosx-all
123122
java/awt/Frame/MaximizedUndecorated/MaximizedUndecorated.java 8022302 generic-all
124123
java/awt/Frame/FrameLocation/FrameLocation.java 8233703 linux-all
125124
java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java 8160558 windows-all

test/jdk/java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTest.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2022, 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
@@ -25,16 +25,23 @@
2525
import java.awt.Choice;
2626
import java.awt.FlowLayout;
2727
import java.awt.Frame;
28+
import java.awt.GraphicsConfiguration;
29+
import java.awt.GraphicsEnvironment;
2830
import java.awt.Point;
2931
import java.awt.Robot;
3032
import java.awt.Window;
3133
import java.awt.event.FocusAdapter;
3234
import java.awt.event.FocusEvent;
3335
import java.awt.event.InputEvent;
3436
import java.awt.event.KeyEvent;
37+
import java.awt.image.BufferedImage;
38+
import java.io.File;
39+
import java.io.IOException;
3540
import java.util.concurrent.CountDownLatch;
3641
import java.util.concurrent.TimeUnit;
3742

43+
import javax.imageio.ImageIO;
44+
3845
/**
3946
* @test
4047
* @bug 4478780
@@ -49,12 +56,12 @@ public class AccessibleChoiceTest {
4956
Button def = new Button("default owner");
5057
CountDownLatch go = new CountDownLatch(1);
5158

52-
public static void main(final String[] args) {
59+
public static void main(final String[] args) throws IOException {
5360
AccessibleChoiceTest app = new AccessibleChoiceTest();
5461
app.test();
5562
}
5663

57-
private void test() {
64+
private void test() throws IOException {
5865
try {
5966
init();
6067
start();
@@ -77,7 +84,7 @@ public void focusGained(FocusEvent e) {
7784
win.add(choice);
7885
}
7986

80-
public void start () {
87+
public void start () throws IOException {
8188
frame.setVisible(true);
8289
win.pack();
8390
win.setLocation(100, 200);
@@ -89,15 +96,16 @@ public void start () {
8996
} catch (Exception ex) {
9097
throw new RuntimeException("Can't create robot");
9198
}
92-
robot.delay(2000);
99+
robot.waitForIdle();
100+
robot.delay(1000);
93101
robot.setAutoDelay(150);
94102
robot.setAutoWaitForIdle(true);
95103

96104
// Focus default button and wait till it gets focus
97105
Point loc = def.getLocationOnScreen();
98106
robot.mouseMove(loc.x+2, loc.y+2);
99-
robot.mousePress(InputEvent.BUTTON1_MASK);
100-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
107+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
108+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
101109

102110
try {
103111
go.await(1, TimeUnit.SECONDS);
@@ -120,10 +128,13 @@ public void start () {
120128
robot.keyPress(KeyEvent.VK_DOWN);
121129
robot.keyRelease(KeyEvent.VK_DOWN);
122130

131+
robot.delay(500);
132+
123133
String osName = System.getProperty("os.name").toLowerCase();
124134
if (osName.startsWith("mac")) {
125135
robot.keyPress(KeyEvent.VK_DOWN);
126136
robot.keyRelease(KeyEvent.VK_DOWN);
137+
robot.delay(500);
127138
robot.keyPress(KeyEvent.VK_ENTER);
128139
robot.keyRelease(KeyEvent.VK_ENTER);
129140
}
@@ -132,6 +143,16 @@ public void start () {
132143

133144
// On success second item should be selected
134145
if (choice.getSelectedItem() != choice.getItem(1)) {
146+
// Print out os name to check if mac conditional is relevant
147+
System.err.println("Failed on os: " + osName);
148+
149+
// Save image to better debug the status of test when failing
150+
GraphicsConfiguration ge = GraphicsEnvironment
151+
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
152+
.getDefaultConfiguration();
153+
BufferedImage failImage = robot.createScreenCapture(ge.getBounds());
154+
ImageIO.write(failImage, "png", new File("failImage.png"));
155+
135156
throw new RuntimeException("Choice can't be controlled by keyboard");
136157
}
137158
}

0 commit comments

Comments
 (0)