Skip to content

Commit

Permalink
8299052: ViewportOverlapping test fails intermittently on Win10 & Win11
Browse files Browse the repository at this point in the history
Reviewed-by: aivanov
  • Loading branch information
Harshitha Onkar committed Jun 12, 2023
1 parent 3028295 commit 2dca5ae
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 60 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 8274106 macosx-aarch64
java/awt/Mouse/EnterExitEvents/DragWindowTest.java 8298823 macosx-all
java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java 8280392 windows-x64
java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java 8294264 windows-x64
java/awt/Mixing/AWT_Mixing/ViewportOverlapping.java 8253184,8295813 windows-x64

javax/swing/JColorChooser/Test6827032.java 8224968 windows-x64
java/awt/dnd/MissingDragExitEventTest/MissingDragExitEventTest.java 8288839 windows-x64
Expand Down
69 changes: 43 additions & 26 deletions test/jdk/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, 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,18 +21,39 @@
* questions.
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.Canvas;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.List;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Scrollbar;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.peer.ComponentPeer;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javax.swing.*;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import sun.awt.AWTAccessor;
import sun.awt.EmbeddedFrame;
import java.io.*;
import sun.awt.OSInfo;

import test.java.awt.regtesthelpers.Util;

/**
Expand Down Expand Up @@ -401,16 +422,16 @@ protected void clickAndBlink(Robot robot, Point lLoc, boolean defaultShift) {
Util.waitForIdle(robot);
try{
Thread.sleep(500);
}catch(Exception exx){
} catch (Exception exx) {
exx.printStackTrace();
}

if (defaultShift) {
loc.translate(shift.x, shift.y);
}
if (!(System.getProperty("os.name").toLowerCase().contains("os x"))) {
if (!(OSInfo.getOSType() == OSInfo.OSType.MACOSX)) {
Color c = robot.getPixelColor(loc.x, loc.y);
System.out.println("C&B. color: "+c+" compare with "+AWT_VERIFY_COLOR);
System.out.println("C&B. color: " + c + " compare with " + AWT_VERIFY_COLOR);
if (c.equals(AWT_VERIFY_COLOR)) {
fail(failMessageColorCheck);
passed = false;
Expand All @@ -422,8 +443,8 @@ protected void clickAndBlink(Robot robot, Point lLoc, boolean defaultShift) {

robot.mouseMove(loc.x, loc.y);

robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(robot);
}

Expand Down Expand Up @@ -454,36 +475,32 @@ protected void cleanup() {
*/
protected Component currentAwtControl;

private void testComponent(Component component) throws InterruptedException, InvocationTargetException {
private void testComponent(Component component) throws InterruptedException,
InvocationTargetException {
Robot robot = null;
try {
robot = new Robot();
}catch(Exception ignorex) {
} catch (Exception ignored) {
}
currentAwtControl = component;
System.out.println("Testing " + currentAwtControl.getClass().getSimpleName());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
prepareControls();
}
});

SwingUtilities.invokeAndWait(() -> prepareControls());

if (component != null) {
Util.waitTillShown(component);
}
Util.waitForIdle(robot);
try {
Thread.sleep(500); // wait for graphic effects on systems like Win7
} catch (InterruptedException ex) {
}

// wait for graphic effects on systems like Win7
robot.delay(500);

if (!instance.performTest()) {
fail(failMessage);
passed = false;
}
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
cleanup();
}
});

SwingUtilities.invokeAndWait(() -> cleanup());
}

private void testEmbeddedFrame() throws InvocationTargetException, InterruptedException {
Expand Down
85 changes: 52 additions & 33 deletions test/jdk/java/awt/Mixing/AWT_Mixing/ViewportOverlapping.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, 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 @@ -26,18 +26,22 @@
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import test.java.awt.regtesthelpers.Util;

/**
* AWT/Swing overlapping test for viewport
Expand Down Expand Up @@ -65,6 +69,7 @@ public class ViewportOverlapping extends OverlappingTestBase {
private Point vLoc;
private Point testLoc;
private Point resizeLoc;
private static Robot robot;

private JFrame f;
private JPanel p;
Expand All @@ -81,7 +86,6 @@ protected void prepareControls() {

f = new JFrame();
f.addMouseListener(new MouseAdapter() {

@Override
public void mouseClicked(MouseEvent e) {
frameClicked++;
Expand All @@ -99,60 +103,75 @@ public void mouseClicked(MouseEvent e) {
@Override
protected boolean performTest() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// prepare test data
frameClicked = 0;
SwingUtilities.invokeAndWait(() -> {
// prepare test data
frameClicked = 0;

b.requestFocus();
b.requestFocus();

scrollPane.getHorizontalScrollBar().setUnitIncrement(40);
scrollPane.getVerticalScrollBar().setUnitIncrement(40);
scrollPane.getHorizontalScrollBar().setUnitIncrement(40);
scrollPane.getVerticalScrollBar().setUnitIncrement(40);

hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();
hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);
vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();
vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);
hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();
hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);
vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();
vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);

testLoc = p.getLocationOnScreen();
testLoc.translate(-3, -3);
testLoc = p.getLocationOnScreen();
testLoc.translate(-3, -3);

resizeLoc = f.getLocationOnScreen();
resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);
}
resizeLoc = f.getLocationOnScreen();
resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Problem preparing test GUI.");
}
// run robot
Robot robot = Util.createRobot();
robot.setAutoDelay(ROBOT_DELAY);

robot.mouseMove(hLoc.x, hLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
captureScreen("Img_1");

robot.mouseMove(vLoc.x, vLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
captureScreen("Img_2");

clickAndBlink(robot, testLoc, false);
robot.mouseMove(resizeLoc.x, resizeLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();
captureScreen("Img_3");

clickAndBlink(robot, testLoc, false);
return frameClicked == 2;
captureScreen("Img_4");
return (frameClicked == 2);
}

// this strange plumbing stuff is required due to "Standard Test Machinery" in base class
public static void main(String args[]) throws InterruptedException {
public static void main(String[] args) throws Exception {
robot = new Robot();
robot.setAutoDelay(ROBOT_DELAY);

instance = new ViewportOverlapping();
OverlappingTestBase.doMain(args);
captureScreen("Img_5");
}

private static void captureScreen(String filename) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
try {
ImageIO.write(
robot.createScreenCapture(new Rectangle(0, 0, screenSize.width, screenSize.height)),
"png",
new File(filename + ".png")
);
} catch (IOException ignored) {
}
}
}

1 comment on commit 2dca5ae

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