Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8253682: The AppletInitialFocusTest1.java is unstable
Reviewed-by: jdv
  • Loading branch information
mrserb committed Oct 1, 2020
1 parent 5dd9353 commit 1d88172
Showing 1 changed file with 31 additions and 45 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, 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,65 +21,51 @@
* questions.
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

/*
@test
@key headful
@bug 4411534 4517274
@summary ensures that user's requestFocus() during applet initialization
is not ignored
@library ../../regtesthelpers
@build Util
@run main AppletInitialFocusTest1
/**
* @test
* @key headful
* @bug 4411534 4517274
* @summary ensures that user's requestFocus() during applet initialization
* is not ignored
*/
public class AppletInitialFocusTest1 extends Frame implements FocusListener {

Button button1 = new Button("Button1");
Button button2 = new Button("Button2");

Object lock = new Object();
private static volatile Object focused;

public static void main(final String[] args) throws Exception {
AppletInitialFocusTest1 app = new AppletInitialFocusTest1();
app.init();
Thread.sleep(10000);
}

public void init() {
setSize(200, 200);
setLocationRelativeTo(null);
setLayout(new FlowLayout());
try {
app.setSize(200, 200);
app.setLocationRelativeTo(null);
app.setLayout(new FlowLayout());

Component parent = this;
while (parent != null && !(parent instanceof Window)) {
parent = parent.getParent();
}
/*
* This applet is designed to be run only with appletviewer,
* so there always should be a toplevel frame.
*/
if (parent == null) {
synchronized (lock) {
System.err.println("appletviewer not running");
System.exit(3);
app.button1.addFocusListener(app);
app.button2.addFocusListener(app);
app.add(app.button1);
app.add(app.button2);
app.setVisible(true);
app.button2.requestFocus();
// wait for the very very last focus event
Thread.sleep(10000);
if (app.button2 != focused) {
throw new RuntimeException("Wrong focus owner: " + focused);
}
} finally {
app.dispose();
}
button1.addFocusListener(this);
button2.addFocusListener(this);
add(button1);
add(button2);
setVisible(true);
button2.requestFocus();
}

public void focusGained(FocusEvent e) {
if (e.getSource() == button1) {
synchronized (lock) {
throw new RuntimeException("failed: focus on the wrong button");
}
}
focused = e.getSource();
System.out.println("focused = " + focused);
}

public void focusLost(FocusEvent e) {
Expand Down

3 comments on commit 1d88172

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 1d88172 Oct 1, 2020

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 1d88172 Sep 17, 2021

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 1d88172 Sep 17, 2021

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-1d88172c in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-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 1d88172c from the openjdk/jdk repository.

The commit being backported was authored by Sergey Bylokhov on 1 Oct 2020 and was reviewed by Jayathirth D V.

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/jdk11u-dev:

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

Please sign in to comment.