Skip to content

Commit

Permalink
8213126: java/awt/Window/MainKeyWindow/TestMainKeyWindow.java time-ou…
Browse files Browse the repository at this point in the history
…t on mac10.13

Reviewed-by: psadhukhan
  • Loading branch information
mrserb committed Jan 7, 2021
1 parent 8530ef0 commit 2e99e28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ java/awt/im/memoryleak/InputContextMemoryLeakTest.java 8023814 linux-all
java/awt/Frame/DisposeParentGC/DisposeParentGC.java 8079786 macosx-all
java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java 8169468 macosx-all
java/awt/TextArea/AutoScrollOnSelectAndAppend/AutoScrollOnSelectAndAppend.java 8213120 macosx-all
java/awt/Window/MainKeyWindowTest/TestMainKeyWindow.java 8213126 macosx-all

java/awt/GraphicsDevice/DisplayModes/CycleDMImage.java 7099223 linux-all,windows-all
java/awt/Window/WindowResizing/DoubleClickTitleBarTest.java 8233557 macosx-all
Expand Down
55 changes: 34 additions & 21 deletions test/jdk/java/awt/Window/MainKeyWindowTest/TestMainKeyWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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 Down Expand Up @@ -29,6 +29,7 @@
* @bug 8194327
* @summary [macosx] AWT windows have incorrect main/key window behaviors
* @author Alan Snyder
* @library /test/lib
* @run main/othervm/native TestMainKeyWindow
* @requires (os.family == "mac")
*/
Expand All @@ -42,6 +43,8 @@
import java.util.Objects;
import javax.swing.*;

import jdk.test.lib.process.ProcessTools;

public class TestMainKeyWindow
{
static TestMainKeyWindow theTest;
Expand All @@ -65,7 +68,7 @@ public class TestMainKeyWindow
private Object actionTarget;

private int failureCount;
private boolean isApplicationOpened;
private Process process;

public TestMainKeyWindow()
{
Expand All @@ -83,7 +86,7 @@ public TestMainKeyWindow()

try {
robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoDelay(150);
} catch (AWTException ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -146,19 +149,21 @@ private void performTest(Object windowIdentification, boolean selectColorPanel)
performMenuItemTest(windowIdentification, selectColorPanel);
}

private void openOtherApplication() {
private Process execute() {
try {
String[] cmd = { "/usr/bin/open", "/Applications/System Preferences.app" };
Runtime.getRuntime().exec(cmd);
if (!isApplicationOpened) {
String[] cmd2 = { "/usr/bin/osascript", "-e",
"tell application \"System Preferences\" to set bounds of window 1 to {400, 180, 1068, 821}" };
Runtime.getRuntime().exec(cmd2);
}
isApplicationOpened = true;
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
TestMainKeyWindow.class.getSimpleName(), "mark");
return ProcessTools.startProcess("Other frame", pb);
} catch (IOException ex) {
throw new RuntimeException("Unable to deactivate test application");
throw new RuntimeException("Unable to execute command");
}
}

private void openOtherApplication() {
if (process != null) {
process.destroyForcibly();
}
process = execute();
robot.delay(1000);
}

Expand Down Expand Up @@ -341,13 +346,8 @@ void dispose()
frame2.dispose();
takedown();
Desktop.getDesktop().setDefaultMenuBar(null);
if (isApplicationOpened) {
try {
String[] cmd = { "/usr/bin/osascript", "-e", "tell application \"System Preferences\" to close window 1" };
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
} catch (IOException | InterruptedException ex) {
}
if (process != null) {
process.destroyForcibly();
}
}

Expand All @@ -374,7 +374,7 @@ public void actionPerformed(ActionEvent e)
private static native void takedown();
private static native void activateApplication();

public static void main(String[] args)
public static void main(String[] args) throws Exception
{
if (!System.getProperty("os.name").contains("OS X")) {
System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
Expand All @@ -383,6 +383,19 @@ public static void main(String[] args)

System.setProperty("apple.laf.useScreenMenuBar", "true");

if (args.length != 0) {
Frame frame = new Frame();
MenuBar mb = new MenuBar();
mb.add(new Menu("Hello"));
frame.setMenuBar(mb);
frame.setBounds(400, 180, 1068, 821);
frame.setVisible(true);
frame.toFront();
Thread.sleep(20_000);
System.exit(0);
return;
}

try {
runSwing(() -> {
theTest = new TestMainKeyWindow();
Expand Down

1 comment on commit 2e99e28

@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.