changeset 17:d68de8bda9d8

7902202: [macosx]Jemmy JInternalFrameOperator: APIs maximize(), demaximize() and iconify() are failing with NullPointerException in Mac OSx Summary: Implemented a new deriver InternalFrameAPIDriver which do all actions based on APIs Reviewed-by: shurailine Contributed-by: abdul.kolarkunnu@oracle.com
author akolarkunnu
date Thu, 09 Aug 2018 08:18:24 -0700
parents 919c96a548b7
children ca5106c73209
files src/org/netbeans/jemmy/drivers/APIDriverInstaller.java src/org/netbeans/jemmy/drivers/windows/InternalFrameAPIDriver.java src/org/netbeans/jemmy/operators/JInternalFrameOperator.java src/org/netbeans/jemmy/util/Platform.java src/org/netbeans/jemmy/version_info test/org/netbeans/jemmy/operators/JInternalFrameOperatorTest.java
diffstat 6 files changed, 272 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/netbeans/jemmy/drivers/APIDriverInstaller.java	Tue May 08 13:50:15 2018 -0700
+++ b/src/org/netbeans/jemmy/drivers/APIDriverInstaller.java	Thu Aug 09 08:18:24 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -49,8 +49,8 @@
 import org.netbeans.jemmy.drivers.text.SwingTextKeyboardDriver;
 import org.netbeans.jemmy.drivers.trees.JTreeAPIDriver;
 import org.netbeans.jemmy.drivers.windows.DefaultFrameDriver;
-import org.netbeans.jemmy.drivers.windows.DefaultInternalFrameDriver;
 import org.netbeans.jemmy.drivers.windows.DefaultWindowDriver;
+import org.netbeans.jemmy.drivers.windows.InternalFrameAPIDriver;
 
 /**
  * Installs all necessary drivers for Jemmy operators except low-level drivers
@@ -121,9 +121,9 @@
                     new ChoiceDriver(),
                     new DefaultFrameDriver(),
                     new DefaultWindowDriver(),
-                    new DefaultInternalFrameDriver(),
-                    new DefaultInternalFrameDriver(),
-                    new DefaultInternalFrameDriver(),
+                    new InternalFrameAPIDriver(),
+                    new InternalFrameAPIDriver(),
+                    new InternalFrameAPIDriver(),
                     new APIFocusDriver(),
                     new MouseFocusDriver(),
                     (shortcutEvents ? new QueueJMenuDriver() : new DefaultJMenuDriver()),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/netbeans/jemmy/drivers/windows/InternalFrameAPIDriver.java	Thu Aug 09 08:18:24 2018 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.netbeans.jemmy.drivers.windows;
+
+import java.awt.Component;
+
+import org.netbeans.jemmy.drivers.FrameDriver;
+import org.netbeans.jemmy.drivers.InternalFrameDriver;
+import org.netbeans.jemmy.drivers.LightSupportiveDriver;
+import org.netbeans.jemmy.drivers.WindowDriver;
+import org.netbeans.jemmy.operators.ComponentOperator;
+import org.netbeans.jemmy.operators.JInternalFrameOperator;
+
+/**
+ * InternalFrameDriver to do all actions using internal frame APIs.
+ *
+ * Note: There is no API to get title component, so this driver throws
+ *       UnsupportedOperationException for all title component related APIs.
+ */
+public class InternalFrameAPIDriver extends LightSupportiveDriver
+        implements WindowDriver, FrameDriver, InternalFrameDriver {
+
+    public InternalFrameAPIDriver() {
+        super(new String[]{"org.netbeans.jemmy.operators.JInternalFrameOperator"});
+    }
+
+    @Override
+    public void activate(ComponentOperator oper) {
+        checkSupported(oper);
+        ((JInternalFrameOperator) oper).moveToFront();
+        ((JInternalFrameOperator) oper).setSelected(true);
+    }
+
+    @Override
+    public void maximize(ComponentOperator oper) {
+        checkSupported(oper);
+        if (!((JInternalFrameOperator) oper).isSelected()) {
+            activate(oper);
+        }
+        ((JInternalFrameOperator) oper).setMaximum(true);
+    }
+
+    @Override
+    public void demaximize(ComponentOperator oper) {
+        checkSupported(oper);
+        if (!((JInternalFrameOperator) oper).isSelected()) {
+            activate(oper);
+        }
+        ((JInternalFrameOperator) oper).setMaximum(false);
+    }
+
+    @Override
+    public void iconify(ComponentOperator oper) {
+        checkSupported(oper);
+        ((JInternalFrameOperator) oper).setIcon(true);
+    }
+
+    @Override
+    public void deiconify(ComponentOperator oper) {
+        checkSupported(oper);
+        ((JInternalFrameOperator) oper).setIcon(false);
+    }
+
+    @Override
+    public void requestClose(ComponentOperator oper) {
+        checkSupported(oper);
+        ((JInternalFrameOperator) oper).setClosed(true);
+    }
+
+    @Override
+    public void move(ComponentOperator oper, int x, int y) {
+        checkSupported(oper);
+        oper.setLocation(x, y);
+    }
+
+    @Override
+    public void resize(ComponentOperator oper, int width, int height) {
+        checkSupported(oper);
+        oper.setSize(width, height);
+    }
+
+    @Override
+    public Component getTitlePane(ComponentOperator oper) {
+        throw new UnsupportedOperationException(
+                "There is no way to get title pane of an internal frame.");
+    }
+
+    @Override
+    public void requestCloseAndThenHide(ComponentOperator oper) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    @Deprecated
+    public void close(ComponentOperator oper) {
+        requestClose(oper);
+    }
+}
--- a/src/org/netbeans/jemmy/operators/JInternalFrameOperator.java	Tue May 08 13:50:15 2018 -0700
+++ b/src/org/netbeans/jemmy/operators/JInternalFrameOperator.java	Thu Aug 09 08:18:24 2018 -0700
@@ -57,6 +57,7 @@
 import org.netbeans.jemmy.drivers.InternalFrameDriver;
 import org.netbeans.jemmy.drivers.WindowDriver;
 import org.netbeans.jemmy.util.EmptyVisualizer;
+import org.netbeans.jemmy.util.Platform;
 
 /**
  * Class provides necessary functionality to operate with
@@ -682,7 +683,11 @@
      * @return an icon operator.
      */
     public JDesktopIconOperator getIconOperator() {
-        initOperators();
+        if(Platform.isOSX()) {
+            initIconOperator();
+        } else {
+            initOperators();
+        }
         return iconOperator;
     }
 
@@ -1371,20 +1376,32 @@
     }
 
     /**
+     * Initialize icon operator
+     */
+    protected void initIconOperator() {
+        iconOperator = new JDesktopIconOperator(((JInternalFrame) getSource()).getDesktopIcon());
+        iconOperator.copyEnvironment(this);
+    }
+
+    /**
      * Initiaites suboperators.
      */
     protected void initOperators() {
-        iconOperator = new JDesktopIconOperator(((JInternalFrame) getSource()).getDesktopIcon());
-        iconOperator.copyEnvironment(this);
-        Container titlePane = findTitlePane();
-        if (!isIcon() && titlePane != null) {
-            if (titleOperator == null) {
-                titleOperator = new ContainerOperator<>(titlePane);
-                if (getContainer(new ComponentChooser() {
-                    @Override
-                    public boolean checkComponent(Component comp) {
-                        return comp instanceof JDesktopPane;
-                    }
+        initIconOperator();
+        if(Platform.isOSX()) {
+            throw new UnsupportedOperationException(
+                    "Jemmy doesn't support getting or intializing title"
+                    + " related operators on Mac OSx");
+        } else {
+            Container titlePane = findTitlePane();
+            if (!isIcon() && titlePane != null) {
+                if (titleOperator == null) {
+                    titleOperator = new ContainerOperator<>(titlePane);
+                    if (getContainer(new ComponentChooser() {
+                        @Override
+                        public boolean checkComponent(Component comp) {
+                            return comp instanceof JDesktopPane;
+                        }
 
                     @Override
                     public String getDescription() {
@@ -1420,6 +1437,7 @@
             minOper = null;
             maxOper = null;
             closeOper = null;
+            }
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/netbeans/jemmy/util/Platform.java	Thu Aug 09 08:18:24 2018 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.netbeans.jemmy.util;
+
+/**
+ * Class to provide platform related utility APIs
+ */
+public class Platform {
+
+    private static final String osName = System.getProperty("os.name");
+
+    /**
+     * Checking whether the platform is linux
+     * @return
+     */
+    public static boolean isLinux() {
+        return isOs("linux");
+    }
+
+    /**
+     * Checking whether the platform is OSX
+     * @return
+     */
+    public static boolean isOSX() {
+        return isOs("mac");
+    }
+
+    /**
+     * Checking whether the platform is Solaris
+     * @return
+     */
+    public static boolean isSolaris() {
+        return isOs("sunos");
+    }
+
+    /**
+     * Checking whether the platform is Windows
+     * @return
+     */
+    public static boolean isWindows() {
+        return isOs("win");
+    }
+
+    private static boolean isOs(String osname) {
+        return osName.toLowerCase().startsWith(osname.toLowerCase());
+    }
+}
--- a/src/org/netbeans/jemmy/version_info	Tue May 08 13:50:15 2018 -0700
+++ b/src/org/netbeans/jemmy/version_info	Thu Aug 09 08:18:24 2018 -0700
@@ -1,6 +1,6 @@
 Manifest-version: 1.0
 Main-Class: org.netbeans.jemmy.JemmyProperties
 Jemmy-MajorVersion: 3.0
-Jemmy-MinorVersion: 1.0
+Jemmy-MinorVersion: 2.0
 Jemmy-Build: @BUILD_NUMBER@
 
--- a/test/org/netbeans/jemmy/operators/JInternalFrameOperatorTest.java	Tue May 08 13:50:15 2018 -0700
+++ b/test/org/netbeans/jemmy/operators/JInternalFrameOperatorTest.java	Thu Aug 09 08:18:24 2018 -0700
@@ -29,6 +29,7 @@
 import static org.netbeans.jemmy.operators.JInternalFrameOperator.MAXIMIZE_BUTTON_TOOLTIP;
 import static org.netbeans.jemmy.operators.JInternalFrameOperator.MINIMIZE_BUTTON_TOOLTIP;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
 
 import java.awt.Dimension;
 import java.awt.Point;
@@ -37,6 +38,7 @@
 import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 
+import org.netbeans.jemmy.util.Platform;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -49,6 +51,9 @@
 
     private JDesktopPane desktop;
 
+    private final static String OSX_EXCEPT_MESSAGE = "Jemmy doesn't support"
+            + " getting or intializing title related operators on Mac OSx";
+
     @BeforeClass
     protected void setUp() throws Exception {
         JFrame frame = new JFrame();
@@ -107,20 +112,47 @@
 
     @Test
     public void testTitleButtons() {
-        // Close, Maximize, and Minimize buttons are adding along with the
-        // construction of internal frame itself
-        JInternalFrame interanlFrame1 = new JInternalFrame(
-                "JInternalFrameButtonTest1", true, true, true, true);
-        verifyTitleButtons(interanlFrame1);
+        if(!Platform.isOSX()) {
+            // Close, Maximize, and Minimize buttons are adding along with the
+            // construction of internal frame itself
+            JInternalFrame interanlFrame1 = new JInternalFrame(
+                    "JInternalFrameButtonTest1", true, true, true, true);
+            verifyTitleButtons(interanlFrame1);
 
-        // Close, Maximize, and Minimize buttons are adding after the
-        // construction of internal frame by using APIs
-        JInternalFrame interanlFrame2 = new JInternalFrame(
-                "JInternalFrameButtonTest2", false, false, false, false);
-        interanlFrame2.setClosable(true);
-        interanlFrame2.setMaximizable(true);
-        interanlFrame2.setIconifiable(true);
-        verifyTitleButtons(interanlFrame2);
+            // Close, Maximize, and Minimize buttons are adding after the
+            // construction of internal frame by using APIs
+            JInternalFrame interanlFrame2 = new JInternalFrame(
+                    "JInternalFrameButtonTest2", false, false, false, false);
+            interanlFrame2.setClosable(true);
+            interanlFrame2.setMaximizable(true);
+            interanlFrame2.setIconifiable(true);
+            verifyTitleButtons(interanlFrame2);
+        } else {
+            JInternalFrame interanlFrame = new JInternalFrame(
+                    "JInternalFrameButtonTest3", true, true, true, true);
+            interanlFrame.setSize(200, 200);
+            interanlFrame.setVisible(true);
+            desktop.add(interanlFrame);
+            JInternalFrameOperator interanlFrameOper = new JInternalFrameOperator(interanlFrame);
+            try {
+                interanlFrameOper.getMaximizeButton();
+                fail();
+            } catch (UnsupportedOperationException e) {
+                assertEquals(e.getMessage(), OSX_EXCEPT_MESSAGE);
+            }
+            try {
+                interanlFrameOper.getMinimizeButton();
+                fail();
+            } catch (UnsupportedOperationException e) {
+                assertEquals(e.getMessage(), OSX_EXCEPT_MESSAGE);
+            }
+            try {
+                interanlFrameOper.getCloseButton();
+                fail();
+            } catch (UnsupportedOperationException e) {
+                assertEquals(e.getMessage(), OSX_EXCEPT_MESSAGE);
+            }
+        }
     }
 
     private void verifyTitleButtons(JInternalFrame interanlFrame) {