Skip to content
Permalink
Browse files
8214469: [macos] PIT: java/awt/Choice/ChoiceKeyEventReaction/ChoiceKe…
…yEventReaction.java fails

Reviewed-by: mdoerr
Backport-of: c282453
  • Loading branch information
GoeLin committed Sep 23, 2021
1 parent 86cf496 commit b9307bdf45b09ad2ad0cd31fe35317de3c561a64
Showing 2 changed files with 22 additions and 23 deletions.
@@ -511,7 +511,6 @@ java/awt/event/MouseEvent/ClickDuringKeypress/ClickDuringKeypress.java 8233568 m
java/awt/event/KeyEvent/DeadKey/DeadKeyMacOSXInputText.java 8233568 macosx-all
java/awt/event/KeyEvent/DeadKey/deadKeyMacOSX.java 8233568 macosx-all
com/apple/eawt/DefaultMenuBar/DefaultMenuBarTest.java 8233648 macosx-all
java/awt/Choice/ChoiceKeyEventReaction/ChoiceKeyEventReaction.java 7185258 macosx-all
java/awt/TrayIcon/RightClickWhenBalloonDisplayed/RightClickWhenBalloonDisplayed.java 8238720 windows-all
java/awt/PopupMenu/PopupMenuLocation.java 8238720 windows-all
java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java 8238720 windows-all
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2019, 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
@@ -30,18 +30,18 @@
* @run main ChoiceKeyEventReaction
*/

import java.awt.Robot;
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Robot;
import java.awt.TextField;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ItemEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.ItemListener;
import java.awt.Frame;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class ChoiceKeyEventReaction
{
@@ -60,6 +60,7 @@ public static void main(String[] args) {
try {
robot = new Robot();
robot.setAutoDelay(100);
robot.waitForIdle();

moveFocusToTextField();
testKeyOnChoice(InputEvent.BUTTON1_MASK, KeyEvent.VK_UP);
@@ -99,6 +100,7 @@ public void itemStateChanged(ItemEvent e) {
frame.add(choice1);
frame.setLayout (new FlowLayout());
frame.setSize (200,200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

@@ -108,33 +110,31 @@ private static void testKeyOnChoice(int button, int key) {

robot.mousePress(button);
robot.mouseRelease(button);
robot.waitForIdle();

robot.keyPress(key);
robot.keyRelease(key);
robot.waitForIdle();

System.out.println("keyTypedOnTextField = "+keyTypedOnTextField +": itemChanged = " + itemChanged);
if (itemChanged) {
throw new RuntimeException("Test failed. ItemChanged event occur on Choice.");
}

// We may just write
// if (toolkit.equals("sun.awt.windows.WToolkit") == keyTypedOnTextField) {fail;}
// but must report differently in these cases so put two separate if statements for simplicity.
if (toolkit.equals("sun.awt.windows.WToolkit") &&
!keyTypedOnTextField) {
throw new RuntimeException("Test failed. (Win32) KeyEvent wasn't addressed to TextField. ");
}

if (!toolkit.equals("sun.awt.windows.WToolkit") &&
keyTypedOnTextField) {
throw new RuntimeException("Test failed. (XToolkit/MToolkit). KeyEvent was addressed to TextField.");
// We may just write
// if (toolkit.equals("sun.awt.windows.WToolkit") == keyTypedOnTextField) {fail;}
// but must report differently in these cases so put two separate if statements for simplicity.
if (!toolkit.equals("sun.awt.X11.XToolkit") &&
!keyTypedOnTextField) {
throw new RuntimeException("Test failed. (Win32/MacOS) KeyEvent wasn't addressed to TextField. ");
}

System.out.println("Test passed. Unfocusable Choice doesn't react on keys.");
if (toolkit.equals("sun.awt.X11.XToolkit") &&
keyTypedOnTextField) {
throw new RuntimeException("Test failed. (XToolkit/MToolkit). KeyEvent was addressed to TextField.");
}

//close opened choice
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
System.out.println("Test passed. Unfocusable Choice doesn't react on keys.");
}

public static void moveFocusToTextField() {

1 comment on commit b9307bd

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on b9307bd Sep 23, 2021

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.