Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8065097: [macosx] javax/swing/Popup/TaskbarPositionTest.java fails because Popup is one pixel off #990

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -730,7 +730,6 @@ javax/swing/JInternalFrame/Test6325652.java 8224977 macosx-all
javax/swing/JPopupMenu/4870644/bug4870644.java 8194130 macosx-all,linux-all
javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java 8065099,8208565 macosx-all,linux-all
javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all
javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
javax/swing/JRootPane/4670486/bug4670486.java 8042381 macosx-all
javax/swing/JButton/8151303/PressedIconTest.java 8266246 macosx-aarch64
Expand Down
220 changes: 127 additions & 93 deletions test/jdk/javax/swing/Popup/TaskbarPositionTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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 @@ -21,27 +21,51 @@
* questions.
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import javax.swing.AbstractAction;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.PopupMenuListener;
import javax.swing.event.PopupMenuEvent;

/**
* @test
* @bug 4245587 4474813 4425878 4767478 8015599
* @key headful
* @author Mark Davidson
* @summary Tests the location of the heavy weight popup portion of JComboBox,
* JMenu and JPopupMenu.
* @library ../regtesthelpers
* @build Util
* @run main TaskbarPositionTest
*/
public class TaskbarPositionTest extends JFrame implements ActionListener {
public class TaskbarPositionTest implements ActionListener {

private boolean done;
private Throwable error;
private static TaskbarPositionTest test;
private static JFrame frame;
private static JPopupMenu popupMenu;
private static JPanel panel;
private static JComboBox<String> combo1;
Expand All @@ -63,27 +87,25 @@ public class TaskbarPositionTest extends JFrame implements ActionListener {
};

public TaskbarPositionTest() {
super("Use CTRL-down to show a JPopupMenu");
setContentPane(panel = createContentPane());
setJMenuBar(createMenuBar("1 - First Menu", true));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame = new JFrame("Use CTRL-down to show a JPopupMenu");
frame.setContentPane(panel = createContentPane());
frame.setJMenuBar(createMenuBar("1 - First Menu", true));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// CTRL-down will show the popup.
panel.getInputMap().put(KeyStroke.getKeyStroke(
KeyEvent.VK_DOWN, InputEvent.CTRL_MASK), "OPEN_POPUP");
panel.getActionMap().put("OPEN_POPUP", new PopupHandler());

pack();
frame.pack();

Toolkit toolkit = Toolkit.getDefaultToolkit();
fullScreenBounds = new Rectangle(new Point(), toolkit.getScreenSize());
screenBounds = new Rectangle(new Point(), toolkit.getScreenSize());

// Place the frame near the bottom. This is a pretty wild guess.
this.setLocation(0, (int) screenBounds.getHeight() - 2 * this.getHeight());

// Reduce the screen bounds by the insets.
GraphicsConfiguration gc = this.getGraphicsConfiguration();
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
if (gc != null) {
Insets screenInsets = toolkit.getScreenInsets(gc);
screenBounds = gc.getBounds();
Expand All @@ -93,7 +115,9 @@ public TaskbarPositionTest() {
screenBounds.y += screenInsets.top;
}

setVisible(true);
// Place the frame near the bottom.
frame.setLocation(0, screenBounds.y + screenBounds.height - frame.getHeight());
frame.setVisible(true);
}

public static class ComboPopupCheckListener implements PopupMenuListener {
Expand All @@ -113,7 +137,8 @@ public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
if (pm != null) {
Point p = pm.getLocation();
SwingUtilities.convertPointToScreen(p, pm);
if (p.y < cpos.y) {
if (p.y+1 < cpos.y) {
System.out.println("p.y " + p.y + " cpos.y " + cpos.y);
throw new RuntimeException("ComboBox popup is wrongly aligned");
} // check that popup was opened down
}
Expand Down Expand Up @@ -261,81 +286,90 @@ public void actionPerformed(ActionEvent evt) {

public static void main(String[] args) throws Throwable {


SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
test = new TaskbarPositionTest();
}
});

// Use Robot to automate the test
Robot robot;
robot = new Robot();
robot.setAutoDelay(125);

// 1 - menu
Util.hitMnemonics(robot, KeyEvent.VK_1);

robot.waitForIdle();
isPopupOnScreen(menu1.getPopupMenu(), screenBounds);

// 2 menu with sub menu
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
Util.hitMnemonics(robot, KeyEvent.VK_S);

robot.waitForIdle();
isPopupOnScreen(menu2.getPopupMenu(), screenBounds);

robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

// Focus should go to non editable combo box
robot.waitForIdle();
Thread.sleep(500);

robot.keyPress(KeyEvent.VK_DOWN);

// How do we check combo boxes?

// Editable combo box
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);

// combo1.getUI();

// Popup from Text field
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_CONTROL);

// Popup from a mouse click.
Point pt = new Point(2, 2);
SwingUtilities.convertPointToScreen(pt, panel);
robot.mouseMove((int) pt.getX(), (int) pt.getY());
robot.mousePress(InputEvent.BUTTON3_MASK);
robot.mouseRelease(InputEvent.BUTTON3_MASK);

robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
test.setLocation(-30, 100);
combo1.addPopupMenuListener(new ComboPopupCheckListener());
combo1.requestFocus();
}
});

robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);

robot.waitForIdle();
Thread.sleep(500);
try {
// Use Robot to automate the test
Robot robot;
robot = new Robot();
robot.setAutoDelay(50);

SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
test = new TaskbarPositionTest();
}
});

robot.waitForIdle();
robot.delay(1000);

// 1 - menu
Util.hitMnemonics(robot, KeyEvent.VK_1);

robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> isPopupOnScreen(menu1.getPopupMenu(), screenBounds));

// 2 menu with sub menu
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
Util.hitMnemonics(robot, KeyEvent.VK_S);

robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> isPopupOnScreen(menu2.getPopupMenu(), screenBounds));

robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

// Focus should go to non editable combo box
robot.waitForIdle();
robot.delay(500);

robot.keyPress(KeyEvent.VK_DOWN);

// How do we check combo boxes?

// Editable combo box
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);

// combo1.getUI();

// Popup from Text field
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_CONTROL);

// Popup from a mouse click.
Point pt = new Point(2, 2);
SwingUtilities.convertPointToScreen(pt, panel);
robot.mouseMove(pt.x, pt.y);
robot.mousePress(InputEvent.BUTTON3_MASK);
robot.mouseRelease(InputEvent.BUTTON3_MASK);

robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
frame.setLocation(-30, 100);
combo1.addPopupMenuListener(new ComboPopupCheckListener());
combo1.requestFocus();
}
});

robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);

robot.waitForIdle();
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}