Skip to content

Commit

Permalink
8239801: [macos] java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTe…
Browse files Browse the repository at this point in the history
…st.java fails

Backport-of: b6dddf4ce6072416e17cadefbd8280f959fd93ca
  • Loading branch information
GoeLin committed Oct 25, 2023
1 parent 5eeb41a commit 8bde7d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ java/awt/Focus/FocusOwnerFrameOnClick/FocusOwnerFrameOnClick.java 8081489 generi
java/awt/Focus/IconifiedFrameFocusChangeTest/IconifiedFrameFocusChangeTest.java 6849364 generic-all
java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusToFrontTest.java 6848406 generic-all
java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java 6848407 generic-all
java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTest.java 8239801 macosx-all
java/awt/Frame/MaximizedUndecorated/MaximizedUndecorated.java 8022302 generic-all
java/awt/Frame/FrameLocation/FrameLocation.java 8233703 linux-all
java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java 8160558 windows-all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, 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
Expand All @@ -25,16 +25,23 @@
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Window;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.imageio.ImageIO;

/**
* @test
* @bug 4478780
Expand All @@ -49,12 +56,12 @@ public class AccessibleChoiceTest {
Button def = new Button("default owner");
CountDownLatch go = new CountDownLatch(1);

public static void main(final String[] args) {
public static void main(final String[] args) throws IOException {
AccessibleChoiceTest app = new AccessibleChoiceTest();
app.test();
}

private void test() {
private void test() throws IOException {
try {
init();
start();
Expand All @@ -77,7 +84,7 @@ public void focusGained(FocusEvent e) {
win.add(choice);
}

public void start () {
public void start () throws IOException {
frame.setVisible(true);
win.pack();
win.setLocation(100, 200);
Expand All @@ -89,15 +96,16 @@ public void start () {
} catch (Exception ex) {
throw new RuntimeException("Can't create robot");
}
robot.delay(2000);
robot.waitForIdle();
robot.delay(1000);
robot.setAutoDelay(150);
robot.setAutoWaitForIdle(true);

// Focus default button and wait till it gets focus
Point loc = def.getLocationOnScreen();
robot.mouseMove(loc.x+2, loc.y+2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

try {
go.await(1, TimeUnit.SECONDS);
Expand All @@ -120,10 +128,13 @@ public void start () {
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);

robot.delay(500);

String osName = System.getProperty("os.name").toLowerCase();
if (osName.startsWith("mac")) {
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.delay(500);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
Expand All @@ -132,6 +143,16 @@ public void start () {

// On success second item should be selected
if (choice.getSelectedItem() != choice.getItem(1)) {
// Print out os name to check if mac conditional is relevant
System.err.println("Failed on os: " + osName);

// Save image to better debug the status of test when failing
GraphicsConfiguration ge = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
BufferedImage failImage = robot.createScreenCapture(ge.getBounds());
ImageIO.write(failImage, "png", new File("failImage.png"));

throw new RuntimeException("Choice can't be controlled by keyboard");
}
}
Expand Down

1 comment on commit 8bde7d4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.