8213168: Enable different look and feel tests in SwingSet3 demo test FileChooserDemoTest
Reviewed-by: serb
This commit is contained in:
parent
ee1a5e3c1e
commit
9380cf342b
@ -40,19 +40,26 @@ import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getFlipVertica
|
|||||||
import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getLastAppliedFilterId;
|
import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getLastAppliedFilterId;
|
||||||
import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateLeftCount;
|
import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateLeftCount;
|
||||||
import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateRightCount;
|
import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateRightCount;
|
||||||
|
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import org.netbeans.jemmy.ClassReference;
|
import org.netbeans.jemmy.ClassReference;
|
||||||
import org.netbeans.jemmy.operators.JFrameOperator;
|
import org.netbeans.jemmy.operators.JFrameOperator;
|
||||||
|
import org.netbeans.jemmy.operators.JPopupMenuOperator;
|
||||||
|
import org.netbeans.jemmy.operators.JRadioButtonMenuItemOperator;
|
||||||
import org.netbeans.jemmy.operators.JButtonOperator;
|
import org.netbeans.jemmy.operators.JButtonOperator;
|
||||||
import org.netbeans.jemmy.operators.JComboBoxOperator;
|
import org.netbeans.jemmy.operators.JComboBoxOperator;
|
||||||
import org.netbeans.jemmy.operators.JToggleButtonOperator;
|
import org.netbeans.jemmy.operators.JToggleButtonOperator;
|
||||||
import org.netbeans.jemmy.operators.JFileChooserOperator;
|
import org.netbeans.jemmy.operators.JFileChooserOperator;
|
||||||
import org.netbeans.jemmy.operators.JDialogOperator;
|
import org.netbeans.jemmy.operators.JDialogOperator;
|
||||||
|
import org.netbeans.jemmy.operators.JComponentOperator.JComponentByTipFinder;
|
||||||
import org.netbeans.jemmy.util.Platform;
|
import org.netbeans.jemmy.util.Platform;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Listeners;
|
import org.testng.annotations.Listeners;
|
||||||
@ -72,7 +79,7 @@ import org.jemmy2ext.JemmyExt.ByToolTipChooser;
|
|||||||
* java.logging
|
* java.logging
|
||||||
* @build org.jemmy2ext.JemmyExt
|
* @build org.jemmy2ext.JemmyExt
|
||||||
* @build com.sun.swingset3.demos.filechooser.FileChooserDemo
|
* @build com.sun.swingset3.demos.filechooser.FileChooserDemo
|
||||||
* @run testng FileChooserDemoTest
|
* @run testng/timeout=600 FileChooserDemoTest
|
||||||
*/
|
*/
|
||||||
@Listeners(GuiTestListener.class)
|
@Listeners(GuiTestListener.class)
|
||||||
public class FileChooserDemoTest {
|
public class FileChooserDemoTest {
|
||||||
@ -83,8 +90,8 @@ public class FileChooserDemoTest {
|
|||||||
public static final String IMAGE = "duke.jpg";
|
public static final String IMAGE = "duke.jpg";
|
||||||
private static final String YES = "Yes";
|
private static final String YES = "Yes";
|
||||||
private static final String NO = "No";
|
private static final String NO = "No";
|
||||||
private static final String SCRATCH = "scratch";
|
|
||||||
private static final String OPEN = "Open";
|
private static final String OPEN = "Open";
|
||||||
|
private static final String OK = "OK";
|
||||||
private static final String CANCEL = "Cancel";
|
private static final String CANCEL = "Cancel";
|
||||||
private static final String USER_HOME = "user.home";
|
private static final String USER_HOME = "user.home";
|
||||||
private static final String DESKTOP = "Desktop";
|
private static final String DESKTOP = "Desktop";
|
||||||
@ -116,8 +123,9 @@ public class FileChooserDemoTest {
|
|||||||
Files.copy(IMAGE_DIR.resolve(IMAGE), TEST_WORK_DIR.resolve(IMAGE));
|
Files.copy(IMAGE_DIR.resolve(IMAGE), TEST_WORK_DIR.resolve(IMAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
|
||||||
public void test() throws Exception {
|
public void test(String lookAndFeel) throws Exception {
|
||||||
|
UIManager.setLookAndFeel(lookAndFeel);
|
||||||
new ClassReference(FileChooserDemo.class.getCanonicalName()).startApplication();
|
new ClassReference(FileChooserDemo.class.getCanonicalName()).startApplication();
|
||||||
frame = new JFrameOperator(DEMO_TITLE);
|
frame = new JFrameOperator(DEMO_TITLE);
|
||||||
initializeSelectImageButtons();
|
initializeSelectImageButtons();
|
||||||
@ -131,13 +139,15 @@ public class FileChooserDemoTest {
|
|||||||
private void checkSelectImage() throws Exception {
|
private void checkSelectImage() throws Exception {
|
||||||
selectImageButton.push();
|
selectImageButton.push();
|
||||||
fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource()));
|
fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource()));
|
||||||
// In Mac, JFileChooser does not have "Go Home","Up One Level","Get Details","Get List" buttons.
|
// In Aqua, GTK and Motif L&Fs, JFileChooser does not have
|
||||||
if (!Platform.isOSX()) {
|
// "Go Home", "Up One Level", "Get Details", "Get List" buttons.
|
||||||
initializeFileChooserButtons();
|
if (!UIManager.getLookAndFeel().getID().equals("Aqua")
|
||||||
|
&& !UIManager.getLookAndFeel().getID().equals("Motif")
|
||||||
|
&& !UIManager.getLookAndFeel().getID().equals("GTK")) {
|
||||||
File previousDirectory = fileChooser.getCurrentDirectory();
|
File previousDirectory = fileChooser.getCurrentDirectory();
|
||||||
fileChooser.goHome();
|
fileChooser.goHome();
|
||||||
// In Windows, pressing goHome navigates to Desktop inside the home directory.
|
// In Windows, pressing goHome navigates to Desktop inside the home directory.
|
||||||
// This seems to be the expected behavior for windows.
|
// This is the expected behavior for windows.
|
||||||
if (!Platform.isWindows()) {
|
if (!Platform.isWindows()) {
|
||||||
waitCurrentPath(Paths.get(System.getProperty(USER_HOME)));
|
waitCurrentPath(Paths.get(System.getProperty(USER_HOME)));
|
||||||
} else {
|
} else {
|
||||||
@ -145,15 +155,32 @@ public class FileChooserDemoTest {
|
|||||||
}
|
}
|
||||||
fileChooser.setCurrentDirectory(previousDirectory);
|
fileChooser.setCurrentDirectory(previousDirectory);
|
||||||
fileChooser.rescanCurrentDirectory();
|
fileChooser.rescanCurrentDirectory();
|
||||||
upLevelButton.push();
|
// In Windows and Windows Classic L&F, List and Details views are
|
||||||
waitCurrentPath(previousDirectory.getParentFile().toPath());
|
// implemented as a popup menu item
|
||||||
fileChooser.enterSubDir(SCRATCH);
|
if(UIManager.getLookAndFeel().getID().equals("Windows")) {
|
||||||
getListToggleButton.push();
|
JButtonOperator popupButton = new JButtonOperator(fileChooser, new JComponentByTipFinder(
|
||||||
getListToggleButton.waitSelected(true);
|
UIManager.getString("FileChooser.viewMenuButtonToolTipText", fileChooser.getLocale())));
|
||||||
getDetailsToggleButton.push();
|
popupButton.push();
|
||||||
getDetailsToggleButton.waitSelected(true);
|
JPopupMenuOperator popup = new JPopupMenuOperator();
|
||||||
getListToggleButton.push();
|
popup.pushKey(KeyEvent.VK_ENTER);
|
||||||
fileChooser.rescanCurrentDirectory();
|
JRadioButtonMenuItemOperator detailsMenuItem = new JRadioButtonMenuItemOperator(popup, 1);
|
||||||
|
detailsMenuItem.push();
|
||||||
|
detailsMenuItem.waitSelected(true);
|
||||||
|
popupButton.push();
|
||||||
|
JRadioButtonMenuItemOperator listMenuItem = new JRadioButtonMenuItemOperator(popup);
|
||||||
|
listMenuItem.push();
|
||||||
|
listMenuItem.waitSelected(true);
|
||||||
|
} else {
|
||||||
|
initializeFileChooserButtons();
|
||||||
|
upLevelButton.push();
|
||||||
|
waitCurrentPath(previousDirectory.getParentFile().toPath());
|
||||||
|
fileChooser.setCurrentDirectory(previousDirectory);
|
||||||
|
fileChooser.rescanCurrentDirectory();
|
||||||
|
getDetailsToggleButton.push();
|
||||||
|
getDetailsToggleButton.waitSelected(true);
|
||||||
|
getListToggleButton.push();
|
||||||
|
getListToggleButton.waitSelected(true);
|
||||||
|
}
|
||||||
// Wait for the count of number of files to be 1
|
// Wait for the count of number of files to be 1
|
||||||
fileChooser.waitFileCount(1);
|
fileChooser.waitFileCount(1);
|
||||||
fileChooser.selectFile(IMAGE);
|
fileChooser.selectFile(IMAGE);
|
||||||
@ -245,7 +272,13 @@ public class FileChooserDemoTest {
|
|||||||
private void initializeSelectWithPreviewDialog() {
|
private void initializeSelectWithPreviewDialog() {
|
||||||
fileChooser = new JFileChooserOperator();
|
fileChooser = new JFileChooserOperator();
|
||||||
fileChooserDialog = new JDialogOperator(OPEN);
|
fileChooserDialog = new JDialogOperator(OPEN);
|
||||||
openButton = new JButtonOperator(fileChooser, OPEN);
|
String openButtonText = OPEN;
|
||||||
|
// In GTK and Motif L&F, open button text is 'OK'
|
||||||
|
if (UIManager.getLookAndFeel().getID().equals("Motif")
|
||||||
|
|| UIManager.getLookAndFeel().getID().equals("GTK")) {
|
||||||
|
openButtonText = OK;
|
||||||
|
}
|
||||||
|
openButton = new JButtonOperator(fileChooser, openButtonText);
|
||||||
cancelButton = new JButtonOperator(fileChooser, CANCEL);
|
cancelButton = new JButtonOperator(fileChooser, CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,9 +314,9 @@ public class FileChooserDemoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void waitCurrentPath(Path expectedPath) {
|
private void waitCurrentPath(Path expectedPath) {
|
||||||
Path currentPath = fileChooser.getCurrentDirectory().toPath();
|
|
||||||
//Wait for the current path to be same as expected path
|
//Wait for the current path to be same as expected path
|
||||||
fileChooser.waitState(chooser -> currentPath.equals(expectedPath));
|
fileChooser.waitState(chooser -> fileChooser.getCurrentDirectory().toPath().equals(expectedPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ import javax.swing.JTable;
|
|||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.ListModel;
|
import javax.swing.ListModel;
|
||||||
|
import javax.swing.UIManager;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
import javax.swing.filechooser.FileSystemView;
|
import javax.swing.filechooser.FileSystemView;
|
||||||
import javax.swing.filechooser.FileView;
|
import javax.swing.filechooser.FileView;
|
||||||
@ -340,6 +341,13 @@ public class JFileChooserOperator extends JComponentOperator
|
|||||||
* @return a component being used to display directory content.
|
* @return a component being used to display directory content.
|
||||||
*/
|
*/
|
||||||
public Component getFileList() {
|
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
|
||||||
|
if (UIManager.getLookAndFeel().getID().equals("Motif")
|
||||||
|
|| UIManager.getLookAndFeel().getID().equals("GTK")) {
|
||||||
|
index =1;
|
||||||
|
}
|
||||||
return innerSearcher.
|
return innerSearcher.
|
||||||
findComponent(new ComponentChooser() {
|
findComponent(new ComponentChooser() {
|
||||||
@Override
|
@Override
|
||||||
@ -357,7 +365,7 @@ public class JFileChooserOperator extends JComponentOperator
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
|
return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
|
||||||
}
|
}
|
||||||
});
|
}, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -433,7 +441,15 @@ public class JFileChooserOperator extends JComponentOperator
|
|||||||
getQueueTool().waitEmpty();
|
getQueueTool().waitEmpty();
|
||||||
output.printTrace("Go home in JFileChooser\n : "
|
output.printTrace("Go home in JFileChooser\n : "
|
||||||
+ toStringSource());
|
+ toStringSource());
|
||||||
JButtonOperator homeOper = new JButtonOperator(getHomeButton());
|
AbstractButtonOperator homeOper;
|
||||||
|
// In Windows and Windows Classic L&F, there is no 'Go Home' button,
|
||||||
|
// but there is a toggle button to go desktop. In Windows platform
|
||||||
|
// 'Go Home' button usually navigates to Desktop only.
|
||||||
|
if(UIManager.getLookAndFeel().getID().equals("Windows")) {
|
||||||
|
homeOper =new JToggleButtonOperator(this, 1);
|
||||||
|
} else {
|
||||||
|
homeOper = new JButtonOperator(getHomeButton());
|
||||||
|
}
|
||||||
homeOper.copyEnvironment(this);
|
homeOper.copyEnvironment(this);
|
||||||
homeOper.setOutput(output.createErrorOutput());
|
homeOper.setOutput(output.createErrorOutput());
|
||||||
homeOper.push();
|
homeOper.push();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Manifest-version: 1.0
|
Manifest-version: 1.0
|
||||||
Main-Class: org.netbeans.jemmy.JemmyProperties
|
Main-Class: org.netbeans.jemmy.JemmyProperties
|
||||||
Jemmy-MajorVersion: 3.0
|
Jemmy-MajorVersion: 3.0
|
||||||
Jemmy-MinorVersion: 5.0
|
Jemmy-MinorVersion: 6.0
|
||||||
Jemmy-Build: @BUILD_NUMBER@
|
Jemmy-Build: @BUILD_NUMBER@
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user