Skip to content

Commit

Permalink
8285867: Convert applet manual tests SelectionVisible.java to Frame a…
Browse files Browse the repository at this point in the history
…nd automate

Reviewed-by: prr
  • Loading branch information
lawrence-andrew authored and prrace committed May 11, 2022
1 parent ccbe8fa commit 44a60ce
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 141 deletions.
42 changes: 0 additions & 42 deletions test/jdk/java/awt/TextArea/SelectionVisible/SelectionVisible.html

This file was deleted.

76 changes: 48 additions & 28 deletions test/jdk/java/awt/TextArea/SelectionVisible/SelectionVisible.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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,42 +21,62 @@
* questions.
*/


import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.Frame;
import java.awt.TextArea;
import java.lang.reflect.InvocationTargetException;

import static java.awt.EventQueue.invokeAndWait;

/*
@test
@key headful
@bug 4082144 7150100
@summary Ensures that TextArea.select() works when called
before setVisible()
@run main SelectionVisible
*/

public final class SelectionVisible extends Applet {
public class SelectionVisible {

private TextArea ta;
private static TextArea ta;
private static Frame frame;

@Override
public void init() {
public static void createTestUI() {
frame = new Frame("Test 4082144 7150100");
ta = new TextArea(4, 20);
ta.setText("01234\n56789");
ta.select(3, 9);

final TextArea instruction = new TextArea("INSTRUCTIONS:\n"
+ "The text 34567 should be selected in the TextArea.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
instruction.setEditable(false);
instruction.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(ta);
setLayout(new BorderLayout());
add(instruction, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
}
frame.add(ta);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);

@Override
public void start() {
setVisible(true);
ta.requestFocus();
}

public static void test() throws InterruptedException,
InvocationTargetException {
String selectedText = ta.getSelectedText();
System.out.println("selectedText : " + selectedText);
invokeAndWait(SelectionVisible::disposeFrame);
if (!selectedText.equals("34\n567")) {
throw new RuntimeException("Expected '34\n567' to be " +
"selected text, but got " + selectedText);
}
System.out.println("Test passed");
}

public static void disposeFrame() {
if (frame != null) {
frame.dispose();
}
}

public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
invokeAndWait(SelectionVisible::createTestUI);
test();
}

}
42 changes: 0 additions & 42 deletions test/jdk/java/awt/TextField/SelectionVisible/SelectionVisible.html

This file was deleted.

72 changes: 43 additions & 29 deletions test/jdk/java/awt/TextField/SelectionVisible/SelectionVisible.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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,43 +21,57 @@
* questions.
*/


import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.Frame;
import java.awt.TextField;
import java.lang.reflect.InvocationTargetException;

import static java.awt.EventQueue.invokeAndWait;
/*
@test
@key headful
@bug 4082144 7150100
@summary Ensures that TextField.select() works when called
before setVisible()
@run main SelectionVisible
*/

public final class SelectionVisible extends Applet {
public class SelectionVisible {

TextField tf;
private static Frame frame;
private static TextField tf;

@Override
public void init() {
public static void createTestUI() {
frame = new Frame("Test TextField.select()");
tf = new TextField(20);
tf.setText("0123456789");
tf.select(0, 6);
frame.add(tf);
frame.setSize(200,200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

private static void test() throws InterruptedException,
InvocationTargetException {
String selectedText = tf.getSelectedText();
System.out.println("Selected Text : " + selectedText);
invokeAndWait(SelectionVisible::disposeFrame);
if (!selectedText.equals("012345")) {
throw new RuntimeException("Expected 012345 to be selected but " +
"got " + selectedText);
}
System.out.println("Test passed");
}

final TextArea ta = new TextArea("INSTRUCTIONS:\n"
+ "The text 012345 should be selected in the TextField.\n"
+ "If this is what you observe, then the test passes.\n"
+ "Otherwise, the test fails.", 40, 5,
TextArea.SCROLLBARS_NONE);
ta.setEditable(false);
ta.setPreferredSize(new Dimension(300, 70));
final Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(tf);
setLayout(new BorderLayout());
add(ta, BorderLayout.CENTER);
add(panel, BorderLayout.PAGE_END);
private static void disposeFrame() {
if (frame != null) {
frame.dispose();
}
}

@Override
public void start() {
setVisible(true);
tf.requestFocus();
public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
invokeAndWait(SelectionVisible::createTestUI);
test();
}
}

3 comments on commit 44a60ce

@openjdk-notifier
Copy link

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 44a60ce Sep 22, 2023

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 44a60ce Sep 22, 2023

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

The commit being backported was authored by lawrence.andrews on 11 May 2022 and was reviewed by Phil Race.

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

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

Please sign in to comment.