8213168: Enable different look and feel tests in SwingSet3 demo test FileChooserDemoTest
authorakolarkunnu
Mon, 05 Nov 2018 18:53:51 -0800
changeset 52753 b5c564a1367c
parent 52752 5e7dba63836d
child 52754 fe70e9638c42
8213168: Enable different look and feel tests in SwingSet3 demo test FileChooserDemoTest Reviewed-by: serb Contributed-by: abdul.kolarkunnu@oracle.com
test/jdk/sanity/client/SwingSet/src/FileChooserDemoTest.java
test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JFileChooserOperator.java
test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/version_info
--- a/test/jdk/sanity/client/SwingSet/src/FileChooserDemoTest.java	Tue Nov 20 16:40:40 2018 +0530
+++ b/test/jdk/sanity/client/SwingSet/src/FileChooserDemoTest.java	Mon Nov 05 18:53:51 2018 -0800
@@ -40,19 +40,26 @@
 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.getRotateRightCount;
+
 import java.awt.Container;
+import java.awt.event.KeyEvent;
 import java.io.File;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import org.testng.annotations.Test;
+import javax.swing.UIManager;
+
 import org.netbeans.jemmy.ClassReference;
 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.JComboBoxOperator;
 import org.netbeans.jemmy.operators.JToggleButtonOperator;
 import org.netbeans.jemmy.operators.JFileChooserOperator;
 import org.netbeans.jemmy.operators.JDialogOperator;
+import org.netbeans.jemmy.operators.JComponentOperator.JComponentByTipFinder;
 import org.netbeans.jemmy.util.Platform;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Listeners;
@@ -72,7 +79,7 @@
  *          java.logging
  * @build org.jemmy2ext.JemmyExt
  * @build com.sun.swingset3.demos.filechooser.FileChooserDemo
- * @run testng FileChooserDemoTest
+ * @run testng/timeout=600 FileChooserDemoTest
  */
 @Listeners(GuiTestListener.class)
 public class FileChooserDemoTest {
@@ -83,8 +90,8 @@
     public static final String IMAGE = "duke.jpg";
     private static final String YES = "Yes";
     private static final String NO = "No";
-    private static final String SCRATCH = "scratch";
     private static final String OPEN = "Open";
+    private static final String OK = "OK";
     private static final String CANCEL = "Cancel";
     private static final String USER_HOME = "user.home";
     private static final String DESKTOP = "Desktop";
@@ -116,8 +123,9 @@
         Files.copy(IMAGE_DIR.resolve(IMAGE), TEST_WORK_DIR.resolve(IMAGE));
     }
 
-    @Test
-    public void test() throws Exception {
+    @Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
+    public void test(String lookAndFeel) throws Exception {
+        UIManager.setLookAndFeel(lookAndFeel);
         new ClassReference(FileChooserDemo.class.getCanonicalName()).startApplication();
         frame = new JFrameOperator(DEMO_TITLE);
         initializeSelectImageButtons();
@@ -131,13 +139,15 @@
     private void checkSelectImage() throws Exception {
         selectImageButton.push();
         fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource()));
-        // In Mac, JFileChooser does not have "Go Home","Up One Level","Get Details","Get List" buttons.
-        if (!Platform.isOSX()) {
-            initializeFileChooserButtons();
+        // In Aqua, GTK and Motif L&Fs, JFileChooser does not have
+        // "Go Home", "Up One Level", "Get Details", "Get List" buttons.
+        if (!UIManager.getLookAndFeel().getID().equals("Aqua")
+                && !UIManager.getLookAndFeel().getID().equals("Motif")
+                && !UIManager.getLookAndFeel().getID().equals("GTK")) {
             File previousDirectory = fileChooser.getCurrentDirectory();
             fileChooser.goHome();
             // 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()) {
                 waitCurrentPath(Paths.get(System.getProperty(USER_HOME)));
             } else {
@@ -145,15 +155,32 @@
             }
             fileChooser.setCurrentDirectory(previousDirectory);
             fileChooser.rescanCurrentDirectory();
-            upLevelButton.push();
-            waitCurrentPath(previousDirectory.getParentFile().toPath());
-            fileChooser.enterSubDir(SCRATCH);
-            getListToggleButton.push();
-            getListToggleButton.waitSelected(true);
-            getDetailsToggleButton.push();
-            getDetailsToggleButton.waitSelected(true);
-            getListToggleButton.push();
-            fileChooser.rescanCurrentDirectory();
+            // In Windows and Windows Classic L&F, List and Details views are
+            // implemented as a popup menu item
+            if(UIManager.getLookAndFeel().getID().equals("Windows")) {
+                JButtonOperator popupButton = new JButtonOperator(fileChooser, new JComponentByTipFinder(
+                        UIManager.getString("FileChooser.viewMenuButtonToolTipText", fileChooser.getLocale())));
+                popupButton.push();
+                JPopupMenuOperator popup = new JPopupMenuOperator();
+                popup.pushKey(KeyEvent.VK_ENTER);
+                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
             fileChooser.waitFileCount(1);
             fileChooser.selectFile(IMAGE);
@@ -245,7 +272,13 @@
     private void initializeSelectWithPreviewDialog() {
         fileChooser = new JFileChooserOperator();
         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);
     }
 
@@ -281,9 +314,9 @@
     }
 
     private void waitCurrentPath(Path expectedPath) {
-        Path currentPath = fileChooser.getCurrentDirectory().toPath();
         //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));
     }
 
 }
+
--- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JFileChooserOperator.java	Tue Nov 20 16:40:40 2018 +0530
+++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/operators/JFileChooserOperator.java	Mon Nov 05 18:53:51 2018 -0800
@@ -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;
@@ -340,6 +341,13 @@
      * @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
+        if (UIManager.getLookAndFeel().getID().equals("Motif")
+                || UIManager.getLookAndFeel().getID().equals("GTK")) {
+            index =1;
+        }
         return innerSearcher.
                 findComponent(new ComponentChooser() {
                     @Override
@@ -357,7 +365,7 @@
                     public String toString() {
                         return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
                     }
-                });
+                }, index);
     }
 
     /**
@@ -433,7 +441,15 @@
         getQueueTool().waitEmpty();
         output.printTrace("Go home in JFileChooser\n    : "
                 + 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.setOutput(output.createErrorOutput());
         homeOper.push();
--- a/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/version_info	Tue Nov 20 16:40:40 2018 +0530
+++ b/test/jdk/sanity/client/lib/jemmy/src/org/netbeans/jemmy/version_info	Mon Nov 05 18:53:51 2018 -0800
@@ -1,6 +1,6 @@
 Manifest-version: 1.0
 Main-Class: org.netbeans.jemmy.JemmyProperties
 Jemmy-MajorVersion: 3.0
-Jemmy-MinorVersion: 5.0
+Jemmy-MinorVersion: 6.0
 Jemmy-Build: @BUILD_NUMBER@