Skip to content

Commit

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

Reviewed-by: honkar, azvegint
  • Loading branch information
Damon Nguyen authored and Alisen Chung committed Nov 22, 2022
1 parent 260e4dc commit b6dddf4
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
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/FileDialog/FileDialogIconTest/FileDialogIconTest.java 8160558 windows-all
java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion.java 8060176 windows-all,macosx-all
Expand Down
@@ -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

3 comments on commit b6dddf4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on b6dddf4 Oct 24, 2023

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on b6dddf4 Oct 24, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-b6dddf4c in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit b6dddf4c from the openjdk/jdk repository.

The commit being backported was authored by Damon Nguyen on 22 Nov 2022 and was reviewed by Harshitha Onkar and Alexander Zvegintsev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git GoeLin-backport-b6dddf4c:GoeLin-backport-b6dddf4c
$ git checkout GoeLin-backport-b6dddf4c
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git GoeLin-backport-b6dddf4c

Please sign in to comment.