jdk/test/java/awt/TrayIcon/SystemTrayIconHelper.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 36511 9d0388c6b336
child 44752 97a2817b5a9b
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     1
import java.awt.*;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     2
import java.awt.event.*;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     3
import java.awt.geom.Point2D;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     4
import java.awt.image.BufferedImage;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     5
import java.lang.reflect.Field;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     6
import java.lang.reflect.Method;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     7
import java.security.AccessController;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     8
import java.security.PrivilegedActionException;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     9
import java.security.PrivilegedExceptionAction;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    10
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    11
/*
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    12
 * @summary This is a helper class to find the location of a system tray icon,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    13
 *          and skip some OS specific cases in tests.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    14
 * @library ../../../../../lib/testlibrary
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    15
 * @build ExtendedRobot SystemTrayIconHelper
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    16
 */
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    17
public class SystemTrayIconHelper {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    18
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    19
    static Frame frame;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    20
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    21
    /**
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    22
     * Call this method if the tray icon need to be followed in an automated manner
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    23
     * This method will be called by automated testcases
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    24
     */
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    25
    static Point getTrayIconLocation(TrayIcon icon) throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    26
        if (icon == null) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    27
            return null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    28
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    29
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    30
        //This is added just in case the tray's native menu is visible.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    31
        //It has to be hidden if visible. For that, we are showing a Frame
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    32
        //and clicking on it - the assumption is, the menu will
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    33
        //be closed if another window is clicked
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    34
        ExtendedRobot robot = new ExtendedRobot();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    35
        try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    36
           EventQueue.invokeAndWait(() -> {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    37
               frame = new Frame();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    38
               frame.setSize(100, 100);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    39
               frame.setVisible(true);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    40
           });
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    41
            robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth() / 2,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    42
                    frame.getLocationOnScreen().y + frame.getHeight() / 2);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    43
            robot.waitForIdle();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    44
            robot.click();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    45
            EventQueue.invokeAndWait(frame::dispose);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    46
        } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    47
            return null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    48
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    49
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    50
        if (System.getProperty("os.name").startsWith("Win")) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    51
            try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    52
                // sun.awt.windows.WTrayIconPeer
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    53
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    54
                Dimension iconSize = icon.getSize();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    55
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    56
                int width = (int) iconSize.getWidth();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    57
                int height = (int) iconSize.getHeight();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    58
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    59
                // Some previously created icons may not be removed
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    60
                // from tray until mouse move on it. So we glide
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    61
                // through the whole tray bar.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    62
                robot.glide((int) screenSize.getWidth(), (int) (screenSize.getHeight()-15), 0, (int) (screenSize.getHeight() - 15), 1, 2);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    63
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    64
                BufferedImage screen = robot.createScreenCapture(new Rectangle(screenSize));
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    65
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    66
                for (int x = (int) (screenSize.getWidth()-width); x > 0; x--) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    67
                    for (int y = (int) (screenSize.getHeight()-height); y > (screenSize.getHeight()-50); y--) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    68
                        if (imagesEquals(((BufferedImage)icon.getImage()).getSubimage(0, 0, width, height), screen.getSubimage(x, y, width, height))) {
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    69
                            Point point = new Point(x + 5, y + 5);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    70
                            System.out.println("Icon location " + point);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    71
                            return point;
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    72
                        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    73
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    74
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    75
            } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    76
                e.printStackTrace();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    77
                return null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    78
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    79
        } else if (System.getProperty("os.name").startsWith("Mac")) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    80
            Point2D point2d;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    81
            try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    82
                // sun.lwawt.macosx.CTrayIcon
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    83
                Field f_peer = getField( java.awt.TrayIcon.class, "peer");
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 36511
diff changeset
    84
                Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
    85
                m_addExports.invoke(null, "sun.lwawt.macosx", robot.getClass().getModule());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
    86
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    87
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    88
                Object peer = f_peer.get(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    89
                Method m_getModel = peer.getClass().getDeclaredMethod(
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    90
                        "getModel");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    91
                m_getModel.setAccessible(true);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    92
                long model = (Long) (m_getModel.invoke(peer, new Object[]{}));
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    93
                Method m_getLocation = peer.getClass().getDeclaredMethod(
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    94
                        "nativeGetIconLocation", new Class[]{Long.TYPE});
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    95
                m_getLocation.setAccessible(true);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    96
                point2d = (Point2D)m_getLocation.invoke(peer, new Object[]{model});
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    97
                Point po = new Point((int)(point2d.getX()), (int)(point2d.getY()));
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    98
                po.translate(10, -5);
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    99
                System.out.println("Icon location " + po);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   100
                return po;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   101
            }catch(Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   102
                e.printStackTrace();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   103
                return null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   104
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   105
        } else {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   106
            try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   107
                // sun.awt.X11.XTrayIconPeer
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 36511
diff changeset
   108
                Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
   109
                m_addExports.invoke(null, "sun.awt.X11", robot.getClass().getModule());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
   110
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   111
                Field f_peer = getField(java.awt.TrayIcon.class, "peer");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   112
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   113
                SystemTrayIconHelper.openTrayIfNeeded(robot);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   114
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   115
                Object peer = f_peer.get(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   116
                Method m_getLOS = peer.getClass().getDeclaredMethod(
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   117
                        "getLocationOnScreen", new Class[]{});
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   118
                m_getLOS.setAccessible(true);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   119
                Point point = (Point)m_getLOS.invoke(peer, new Object[]{});
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   120
                point.translate(5, 5);
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   121
                System.out.println("Icon location " + point);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   122
                return point;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   123
            } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   124
                e.printStackTrace();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   125
                return null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   126
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   127
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   128
        return null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   129
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   130
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   131
    static Field getField(final Class clz, final String fieldName) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   132
        Field res = null;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   133
        try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   134
            res = (Field)AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   135
                Field f = clz.getDeclaredField(fieldName);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   136
                f.setAccessible(true);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   137
                return f;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   138
            });
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   139
        } catch (PrivilegedActionException ex) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   140
            ex.printStackTrace();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   141
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   142
        return res;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   143
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   144
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   145
    static boolean imagesEquals(BufferedImage img1, BufferedImage img2) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   146
        for (int x = 0; x < img1.getWidth(); x++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   147
            for (int y = 0; y < img1.getHeight(); y++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   148
                if (img1.getRGB(x, y) != img2.getRGB(x, y))
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   149
                    return false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   150
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   151
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   152
        return true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   153
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   154
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   155
    static void doubleClick(Robot robot) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   156
        if (System.getProperty("os.name").startsWith("Mac")) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   157
            robot.mousePress(InputEvent.BUTTON3_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   158
            robot.delay(50);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   159
            robot.mouseRelease(InputEvent.BUTTON3_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   160
        } else {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   161
            robot.mousePress(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   162
            robot.delay(50);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   163
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   164
            robot.delay(50);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   165
            robot.mousePress(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   166
            robot.delay(50);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   167
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   168
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   169
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   170
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   171
    // Method for skipping some OS specific cases
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   172
    static boolean skip(int button) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   173
        if (System.getProperty("os.name").toLowerCase().startsWith("win")){
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   174
            if (button == InputEvent.BUTTON1_MASK){
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   175
                // See JDK-6827035
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   176
                return true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   177
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   178
        } else if (System.getProperty("os.name").toLowerCase().contains("os x")){
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   179
            // See JDK-7153700
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   180
            return true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   181
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   182
        return false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   183
    }
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   184
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   185
    public static boolean openTrayIfNeeded(Robot robot) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   186
        String sysv = System.getProperty("os.version");
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   187
        System.out.println("System version is " + sysv);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   188
        //Additional step to raise the system try in Gnome 3 in OEL 7
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   189
        if(isOel7()) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   190
            System.out.println("OEL 7 detected");
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   191
            GraphicsConfiguration gc = GraphicsEnvironment.
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   192
                    getLocalGraphicsEnvironment().getDefaultScreenDevice().
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   193
                    getDefaultConfiguration();
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   194
            Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   195
            if(insets.bottom > 0) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   196
                Dimension screenSize = Toolkit.getDefaultToolkit()
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   197
                        .getScreenSize();
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   198
                robot.mouseMove(screenSize.width - insets.bottom / 2,
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   199
                        screenSize.height - insets.bottom / 2);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   200
                robot.delay(50);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   201
                robot.mousePress(InputEvent.BUTTON1_MASK);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   202
                robot.delay(50);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   203
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   204
                robot.waitForIdle();
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   205
                robot.delay(1000);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   206
                System.out.println("Tray is opened");
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   207
                return true;
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   208
            }
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   209
        }
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   210
        return false;
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   211
    }
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   212
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   213
    public static boolean isOel7() {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   214
        return System.getProperty("os.name").toLowerCase()
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   215
                .contains("linux") && System.getProperty("os.version")
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   216
                .toLowerCase().contains("el7");
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   217
    }
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   218
}