Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8258645: Bring Jemmy 1.3.11 to JDK test base #1831

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions test/jdk/sanity/client/SwingSet/src/SliderDemoTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,6 +29,10 @@
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -139,70 +147,81 @@ private void disabled(JFrameOperator jfo, String accessibleName)

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;
}
});
}
Expand All @@ -211,14 +230,16 @@ private void checkMoveForward(JSliderOperator jso, int value) {
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();
}

Expand All @@ -230,13 +251,15 @@ private void checkMouse(JSliderOperator jso) {
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +39,7 @@
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;
Expand Down Expand Up @@ -110,7 +108,7 @@ public DefaultDriverInstaller(boolean shortcutEvents) {
new ScrollPaneDriver(),
new JScrollBarDriver(),
new JSplitPaneDriver(),
new KeyboardJSliderScrollDriver(),
new JSliderDriver(),
createSpinnerDriver(),
new ButtonMouseDriver(),
new JTabMouseDriver(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -78,6 +78,8 @@
import org.netbeans.jemmy.drivers.KeyDriver;
import org.netbeans.jemmy.drivers.MouseDriver;

import javax.accessibility.AccessibleContext;

/**
* Root class for all component operators.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -1222,7 +1238,7 @@ public String toString() {
/**
* 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);
Expand Down Expand Up @@ -1270,6 +1286,15 @@ public Hashtable<String, Object> getDump() {
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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;
Expand Down Expand Up @@ -341,18 +342,18 @@ public String toString() {
* @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
Expand All @@ -364,7 +365,7 @@ public String getDescription() {
public String toString() {
return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
}
}, index);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -828,10 +828,8 @@ public String toString() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ public String toString() {
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!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,9 @@ public <R> R waitState(Waitable<R, Void> waitable) {
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!");
}
}

Expand All @@ -735,14 +734,22 @@ public <R> R waitState(Waitable<R, Void> waitable) {
* 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();
}
});
}

Expand Down
Loading