8258645: Bring Jemmy 1.3.11 to JDK test base

Reviewed-by: serb
This commit is contained in:
Alexandre Iline 2020-12-18 21:16:35 +00:00
parent 7f92d187b1
commit 6a78b2a2b2
9 changed files with 114 additions and 54 deletions

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
@ -30,6 +29,10 @@ import java.util.function.Predicate;
import javax.swing.UIManager;
import static org.testng.AssertJUnit.*;
import org.netbeans.jemmy.drivers.DriverManager;
import org.netbeans.jemmy.drivers.scrolling.KeyboardJSliderScrollDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.ComponentChooser;
@ -68,6 +71,11 @@ public class SliderDemoTest {
private static final int VERTICAL_MINOR_TICKS_SLIDER_MINIMUM = 0;
private static final int VERTICAL_MINOR_TICKS_SLIDER_MAXIMUM = 100;
@BeforeClass
public void useKeyboardSliderDriver() {
DriverManager.setScrollDriver(new KeyboardJSliderScrollDriver());
}
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
public void test(String lookAndFeel) throws Exception {
UIManager.setLookAndFeel(lookAndFeel);
@ -139,70 +147,81 @@ public class SliderDemoTest {
private void checkMaximum(JSliderOperator jso, int maxValue) {
jso.scrollToMaximum();
waitSliderValue(jso, jSlider -> jSlider.getValue() == maxValue);
waitSliderValue(jso, jSlider -> jSlider.getValue() == maxValue,
"value == " + maxValue);
}
private void checkMinimum(JSliderOperator jso, int minValue) {
jso.scrollToMinimum();
waitSliderValue(jso, jSlider -> jSlider.getValue() == minValue);
waitSliderValue(jso, jSlider -> jSlider.getValue() == minValue,
"value == " + minValue);
}
private void checkKeyboard(JSliderOperator jso) {
boolean isMotif = LookAndFeel.isMotif();
checkKeyPress(jso, KeyEvent.VK_HOME,
jSlider -> jSlider.getValue() == jso.getMinimum());
jSlider -> jSlider.getValue() == jso.getMinimum(),
"value == " + jso.getMinimum());
{
int expectedValue = jso.getValue() + 1;
checkKeyPress(jso, KeyEvent.VK_UP,
jSlider -> jSlider.getValue() >= expectedValue);
jSlider -> jSlider.getValue() >= expectedValue,
"value >= " + expectedValue);
}
{
int expectedValue = jso.getValue() + 1;
checkKeyPress(jso, KeyEvent.VK_RIGHT,
jSlider -> jSlider.getValue() >= expectedValue);
jSlider -> jSlider.getValue() >= expectedValue,
"value >= " + expectedValue);
}
if (!isMotif) {
int expectedValue = jso.getValue() + 11;
checkKeyPress(jso, KeyEvent.VK_PAGE_UP,
jSlider -> jSlider.getValue() >= expectedValue);
jSlider -> jSlider.getValue() >= expectedValue,
"value >= " + expectedValue);
}
checkKeyPress(jso, KeyEvent.VK_END,
jSlider -> jSlider.getValue() == jso.getMaximum());
jSlider -> jSlider.getValue() == jso.getMaximum(),
"value == " + jso.getMaximum());
{
int expectedValue = jso.getValue() - 1;
checkKeyPress(jso, KeyEvent.VK_DOWN,
jSlider -> jSlider.getValue() <= expectedValue);
jSlider -> jSlider.getValue() <= expectedValue,
"value <= " + expectedValue);
}
{
int expectedValue = jso.getValue() - 1;
checkKeyPress(jso, KeyEvent.VK_LEFT,
jSlider -> jSlider.getValue() <= expectedValue);
jSlider -> jSlider.getValue() <= expectedValue,
"value <= " + expectedValue);
}
if (!isMotif) {
int expectedValue = jso.getValue() - 11;
checkKeyPress(jso, KeyEvent.VK_PAGE_DOWN,
jSlider -> jSlider.getValue() <= expectedValue);
jSlider -> jSlider.getValue() <= expectedValue,
"value <= " + expectedValue);
}
}
private void checkKeyPress(JSliderOperator jso, int keyCode,
Predicate<JSliderOperator> predicate) {
Predicate<JSliderOperator> predicate,
String description) {
jso.pushKey(keyCode);
waitSliderValue(jso, predicate);
waitSliderValue(jso, predicate, description);
}
private void waitSliderValue(JSliderOperator jso,
Predicate<JSliderOperator> predicate) {
Predicate<JSliderOperator> predicate, String description) {
jso.waitState(new ComponentChooser() {
public boolean checkComponent(Component comp) {
return predicate.test(jso);
}
public String getDescription() {
return "Wait till Slider attains the specified state.";
return description;
}
});
}
@ -211,14 +230,16 @@ public class SliderDemoTest {
jso.setValue(jso.getMinimum());
int finalValue = jso.getValue() + value;
jso.scrollToValue(finalValue);
waitSliderValue(jso, jSlider -> jSlider.getValue() == finalValue);
waitSliderValue(jso, jSlider -> jSlider.getValue() == finalValue,
"value == " + finalValue);
}
private void checkSnapToTick(JSliderOperator jso, int expectedLower,
int expectedHigher) {
jso.pressMouse(jso.getCenterXForClick(), jso.getCenterYForClick());
waitSliderValue(jso, jSlider -> jSlider.getValue() == expectedLower
|| jSlider.getValue() == expectedHigher);
|| jSlider.getValue() == expectedHigher,
"value is either" + expectedLower + " or " + expectedHigher);
jso.releaseMouse();
}
@ -230,13 +251,15 @@ public class SliderDemoTest {
jso.setValue((jso.getMaximum() + jso.getMinimum()) / 2);
jso.pressMouse(jso.getCenterXForClick(), jso.getCenterYForClick());
jso.dragMouse(jso.getWidth() + 10, jso.getHeight());
waitSliderValue(jso, jSlider -> jSlider.getValue() == jSlider.getMaximum());
waitSliderValue(jso, jSlider -> jSlider.getValue() == jSlider.getMaximum(),
"value == " + jso.getMaximum());
jso.releaseMouse();
// Check mouse click by clicking on the center of the track 2 times
// and waiting till the slider value has changed from its previous
// value as a result of the clicks.
jso.clickMouse(jso.getCenterXForClick(), jso.getCenterYForClick(), 2);
waitSliderValue(jso, jSlider -> jSlider.getValue() != jSlider.getMaximum());
waitSliderValue(jso, jSlider -> jSlider.getValue() != jSlider.getMaximum(),
"value != " + jso.getMaximum());
}
}

View File

@ -24,8 +24,6 @@
*/
package org.netbeans.jemmy.drivers;
import javax.swing.UIManager;
import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.JemmyException;
import org.netbeans.jemmy.JemmyProperties;
@ -41,7 +39,7 @@ import org.netbeans.jemmy.drivers.lists.ListKeyboardDriver;
import org.netbeans.jemmy.drivers.menus.DefaultJMenuDriver;
import org.netbeans.jemmy.drivers.menus.QueueJMenuDriver;
import org.netbeans.jemmy.drivers.scrolling.JScrollBarDriver;
import org.netbeans.jemmy.drivers.scrolling.KeyboardJSliderScrollDriver;
import org.netbeans.jemmy.drivers.scrolling.JSliderDriver;
import org.netbeans.jemmy.drivers.scrolling.JSplitPaneDriver;
import org.netbeans.jemmy.drivers.scrolling.ScrollPaneDriver;
import org.netbeans.jemmy.drivers.scrolling.ScrollbarDriver;
@ -110,7 +108,7 @@ public class DefaultDriverInstaller extends ArrayDriverInstaller {
new ScrollPaneDriver(),
new JScrollBarDriver(),
new JSplitPaneDriver(),
new KeyboardJSliderScrollDriver(),
new JSliderDriver(),
createSpinnerDriver(),
new ButtonMouseDriver(),
new JTabMouseDriver(),

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -78,6 +78,8 @@ import org.netbeans.jemmy.drivers.FocusDriver;
import org.netbeans.jemmy.drivers.KeyDriver;
import org.netbeans.jemmy.drivers.MouseDriver;
import javax.accessibility.AccessibleContext;
/**
* Root class for all component operators.
*
@ -122,6 +124,20 @@ public class ComponentOperator extends Operator
*/
public static final String NAME_DPROP = "Name:";
/**
* Identifier for a name property.
*
* @see #getDump
*/
public static final String ACCESSIBLE_NAME_DPROP = "Accessible name:";
/**
* Identifier for a name property.
*
* @see #getDump
*/
public static final String ACCESSIBLE_DESCRIPTION_DPROP = "Accessible description:";
/**
* Identifier for a visible property.
*
@ -1222,7 +1238,7 @@ public class ComponentOperator extends Operator
/**
* Wait till the component reaches exact location on screen.
*
* @param exactLocation exact expected screen location.
* @param exactlocation exact expected screen location.
*/
public void waitComponentLocationOnScreen(Point exactlocation) {
waitComponentLocationOnScreen(exactlocation, exactlocation);
@ -1270,6 +1286,15 @@ public class ComponentOperator extends Operator
if (getSource().getName() != null) {
result.put(NAME_DPROP, getSource().getName());
}
AccessibleContext context = source.getAccessibleContext();
if(context != null) {
if(context.getAccessibleName() != null) {
result.put(ACCESSIBLE_NAME_DPROP, context.getAccessibleName());
}
if(context.getAccessibleDescription() != null) {
result.put(ACCESSIBLE_DESCRIPTION_DPROP, context.getAccessibleDescription());
}
}
result.put(IS_VISIBLE_DPROP, getSource().isVisible() ? "true" : "false");
result.put(IS_SHOWING_DPROP, getSource().isShowing() ? "true" : "false");
result.put(X_DPROP, Integer.toString(getSource().getX()));

View File

@ -43,6 +43,7 @@ import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
@ -341,18 +342,18 @@ public class JFileChooserOperator extends JComponentOperator
* @return a component being used to display directory content.
*/
public Component getFileList() {
int index = 0;
// In GTK and Motif L&F, there are two JLists, one is to list folders
// and second one one is to list files
final String fileListName;
if (LookAndFeel.isMotif() || LookAndFeel.isGTK()) {
index =1;
fileListName = UIManager.getString("FileChooser.filesLabelText", getLocale());
} else {
fileListName = UIManager.getString("FileChooser.filesListAccessibleName", getLocale());
}
return innerSearcher.
findComponent(new ComponentChooser() {
@Override
public boolean checkComponent(Component comp) {
return (comp != null
&& (comp instanceof JList || comp instanceof JTable));
return ((comp instanceof JList && fileListName.equals(comp.getAccessibleContext().getAccessibleName()))
|| comp instanceof JTable);
}
@Override
@ -364,7 +365,7 @@ public class JFileChooserOperator extends JComponentOperator
public String toString() {
return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
}
}, index);
});
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -828,10 +828,8 @@ public class JTextComponentOperator extends JComponentOperator
public Hashtable<String, Object> getDump() {
Hashtable<String, Object> result = super.getDump();
result.put(TEXT_DPROP, ((JTextComponent) getSource()).getText());
if (((JTextComponent) getSource()).getSelectedText() != null
&& !((JTextComponent) getSource()).getSelectedText().equals("")) {
result.put(SELECTED_TEXT_DPROP, ((JTextComponent) getSource()).getSelectedText());
}
String selected = ((JTextComponent) getSource()).getSelectedText();
result.put(SELECTED_TEXT_DPROP, (selected != null) ? selected : "");
result.put(IS_EDITABLE_DPROP, ((JTextComponent) getSource()).isEditable() ? "true" : "false");
return result;
}

View File

@ -320,9 +320,8 @@ public class JToolTipOperator extends JComponentOperator {
try {
return stateWaiter.waitAction(null);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw (new JemmyException("Waiting of " + waitable.getDescription()
+ " state has been interrupted!"));
throw new JemmyException("Waiting of " + waitable.getDescription()
+ " state has been interrupted!");
}
}

View File

@ -720,10 +720,9 @@ public abstract class Operator
try {
return stateWaiter.waitAction(null);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw (new JemmyException(
throw new JemmyException(
"Waiting of \"" + waitable.getDescription()
+ "\" state has been interrupted!"));
+ "\" state has been interrupted!");
}
}
@ -735,14 +734,22 @@ public abstract class Operator
* defined by {@code "ComponentOperator.WaitStateTimeout"}
*/
public void waitStateOnQueue(final ComponentChooser state) {
waitState((comp) -> {
return (boolean) (queueTool.invokeSmoothly(
new QueueTool.QueueAction<Object>("checkComponent") {
@Override
public final Object launch() throws Exception {
return state.checkComponent(comp);
}
}));
waitState(new ComponentChooser() {
@Override
public boolean checkComponent(Component comp) {
return (boolean) (queueTool.invokeSmoothly(
new QueueTool.QueueAction<Object>("checkComponent") {
@Override
public final Object launch() throws Exception {
return state.checkComponent(comp);
}
}));
}
@Override
public String getDescription() {
return state.getDescription();
}
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -58,6 +58,13 @@ public class TextComponentOperator extends ComponentOperator
*/
public static final String TEXT_DPROP = "Text";
/**
* Identifier for a "selected text" property.
*
* @see #getDump
*/
public static final String SELECTED_TEXT_DPROP = "Selected text";
private final static long PUSH_KEY_TIMEOUT = 0;
private final static long BETWEEN_KEYS_TIMEOUT = 0;
private final static long CHANGE_CARET_POSITION_TIMEOUT = 60000;
@ -505,6 +512,8 @@ public class TextComponentOperator extends ComponentOperator
public Hashtable<String, Object> getDump() {
Hashtable<String, Object> result = super.getDump();
result.put(TEXT_DPROP, ((TextComponent) getSource()).getText());
String selected = ((TextComponent) getSource()).getSelectedText();
result.put(SELECTED_TEXT_DPROP, (selected != null) ? selected : "");
return result;
}

View File

@ -1,6 +1,6 @@
Manifest-version: 1.0
Main-Class: org.netbeans.jemmy.JemmyProperties
Jemmy-MajorVersion: 3.0
Jemmy-MinorVersion: 8.0
Jemmy-MinorVersion: 11.0
Jemmy-Build: @BUILD_NUMBER@