test/jdk/java/awt/TrayIcon/SecurityCheck/FunctionalityCheck/FunctionalityCheck.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
child 52739 7199c4da1a6f
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
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
/*
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
     2
 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     4
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     8
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    13
 * accompanied this code).
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    14
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    21
 * questions.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    22
 */
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    23
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    24
import java.awt.*;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    25
import java.awt.event.*;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    26
import java.awt.image.BufferedImage;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    27
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
 * @test
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    30
 * @key headful
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    31
 * @summary Check for MouseEvents with all mouse buttons
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    32
 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    33
 * @modules java.desktop/java.awt:open
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
    34
 * @library /java/awt/patchlib
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    35
 * @library ../../../../../lib/testlibrary ../../
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
    36
 * @build java.desktop/java.awt.Helper
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    37
 * @build ExtendedRobot SystemTrayIconHelper
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    38
 * @run main/othervm/policy=tray.policy -Djava.security.manager FunctionalityCheck
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    39
 */
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
public class FunctionalityCheck {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    42
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    43
    TrayIcon icon;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    44
    ExtendedRobot robot;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    45
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    46
    boolean actionPerformed = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    47
    Object actionLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    48
    Object pressLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    49
    Object releaseLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    50
    Object clickLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    51
    Object moveLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    52
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    53
    String caption = "Sample Icon";
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    54
    boolean mousePressed = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    55
    boolean mouseReleased = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    56
    boolean mouseClicked = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    57
    boolean mouseMoved = false;
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    58
    static boolean isOEL7;
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    59
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    60
    static final int[] buttonTypes = {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    61
        InputEvent.BUTTON1_MASK,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    62
        InputEvent.BUTTON2_MASK,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    63
        InputEvent.BUTTON3_MASK
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    64
    };
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
    static final String[] buttonNames = {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    67
        "BUTTON1",
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    68
        "BUTTON2",
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    69
        "BUTTON3"
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    70
    };
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    71
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    72
    public static void main(String[] args) throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    73
        if (! SystemTray.isSupported()) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    74
            System.out.println("SystemTray not supported on the platform under test. " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    75
                               "Marking the test passed");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    76
        } else {
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    77
            isOEL7 = SystemTrayIconHelper.isOel7();
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    78
            new FunctionalityCheck().doTest();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    79
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    80
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    81
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    82
    FunctionalityCheck() throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    83
        robot = new ExtendedRobot();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    84
        EventQueue.invokeAndWait(this::initializeGUI);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    85
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    86
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    87
    void initializeGUI() {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    88
        SystemTray tray = SystemTray.getSystemTray();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    89
        icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), caption);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    90
        icon.addActionListener(event -> {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    91
            actionPerformed = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    92
            synchronized (actionLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    93
                try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    94
                    actionLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    95
                } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    96
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    97
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    98
        });
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    99
        icon.addMouseListener(new MouseAdapter() {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   100
            public void mousePressed(MouseEvent event) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   101
                mousePressed = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   102
                Point p = event.getPoint();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   103
                if (p.x != event.getX() || p.y != event.getY())
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   104
                    throw new RuntimeException("FAIL: MouseEvent.getPoint() did " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   105
                            "not return the same value as getX/getY " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   106
                            "for mousePressed");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   107
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   108
                if (! icon.equals(event.getSource()))
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   109
                    throw new RuntimeException("FAIL: mousePressed: MouseEvent.getSource " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   110
                            "did not return TrayIcon object");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   111
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   112
                synchronized (pressLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   113
                    try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   114
                        pressLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   115
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   116
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   117
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   118
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   119
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   120
            public void mouseReleased(MouseEvent event) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   121
                mouseReleased = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   122
                Point p = event.getPoint();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   123
                if (p.x != event.getX() || p.y != event.getY())
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   124
                    throw new RuntimeException("FAIL: MouseEvent.getPoint() did " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   125
                            "not return the same value as getX/getY " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   126
                            "for mouseReleased");
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
                if (! icon.equals(event.getSource()))
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   129
                    throw new RuntimeException("FAIL: mouseReleased: MouseEvent.getSource " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   130
                            "did not return TrayIcon object");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   131
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   132
                synchronized (releaseLock) {
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
                        releaseLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   135
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   136
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   137
                }
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
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   140
            public void mouseClicked(MouseEvent event) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   141
                mouseClicked = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   142
                Point p = event.getPoint();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   143
                if (p.x != event.getX() || p.y != event.getY())
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   144
                    throw new RuntimeException("FAIL: MouseEvent.getPoint() did " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   145
                            "not return the same value as getX/getY " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   146
                            "for mouseClicked");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   147
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   148
                if (! icon.equals(event.getSource()))
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   149
                    throw new RuntimeException("FAIL: mouseClicked: MouseEvent.getSource " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   150
                            "did not return TrayIcon object");
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
                synchronized (clickLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   153
                    try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   154
                        clickLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   155
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   156
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   157
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   158
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   159
        });
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   160
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   161
        icon.addMouseMotionListener(new MouseMotionAdapter() {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   162
            public void mouseMoved(MouseEvent event) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   163
                mouseMoved = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   164
                Point p = event.getPoint();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   165
                if (p.x != event.getX() || p.y != event.getY())
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   166
                    throw new RuntimeException("FAIL: MouseEvent.getPoint() did " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   167
                            "not return the same value as getX/getY " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   168
                            "for mouseMoved");
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
                if (! icon.equals(event.getSource()))
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   171
                    throw new RuntimeException("FAIL: mouseMoved: MouseEvent.getSource " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   172
                            "did not return TrayIcon object");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   173
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   174
                synchronized (moveLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   175
                    try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   176
                        moveLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   177
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   178
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   179
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   180
            }
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
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   183
        try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   184
            tray.add(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   185
        } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   186
            throw new RuntimeException(e);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   187
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   188
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   189
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   190
    private void doTest() throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   191
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   192
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   193
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   194
        Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   195
        if (iconPosition == null)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   196
            throw new RuntimeException("Unable to find the icon location!");
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   197
        if (isOEL7) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   198
            // close tray
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   199
            robot.mouseMove(100,100);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   200
            robot.click(InputEvent.BUTTON1_MASK);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   201
            robot.waitForIdle(2000);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   202
        }
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   203
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   204
        robot.mouseMove(iconPosition.x, iconPosition.y);
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   205
        robot.waitForIdle();
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   206
        if(!isOEL7) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   207
            SystemTrayIconHelper.doubleClick(robot);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   208
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   209
            if (!actionPerformed) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   210
                synchronized (actionLock) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   211
                    try {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   212
                        actionLock.wait(3000);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   213
                    } catch (Exception e) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   214
                    }
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   215
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   216
            }
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   217
            if (!actionPerformed)
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   218
                throw new RuntimeException("FAIL: ActionEvent not triggered when TrayIcon is double clicked");
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   219
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   220
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   221
        for (int i = 0; i < buttonTypes.length; i++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   222
            mousePressed = false;
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   223
            if(isOEL7) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   224
                SystemTrayIconHelper.openTrayIfNeeded(robot);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   225
                robot.mouseMove(iconPosition.x, iconPosition.y);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   226
                robot.click(buttonTypes[i]);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   227
            } else {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   228
                robot.mousePress(buttonTypes[i]);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   229
            }
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   230
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   231
            if (! mousePressed) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   232
                synchronized (pressLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   233
                    try {
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   234
                        pressLock.wait(6000);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   235
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   236
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   237
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   238
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   239
            if (! mousePressed)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   240
                if (! SystemTrayIconHelper.skip(buttonTypes[i]) )
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   241
                    throw new RuntimeException("FAIL: mousePressed not triggered when " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   242
                            buttonNames[i] + " pressed");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   243
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   244
            mouseReleased = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   245
            mouseClicked = false;
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   246
            if(isOEL7) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   247
                SystemTrayIconHelper.openTrayIfNeeded(robot);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   248
                robot.mouseMove(iconPosition.x, iconPosition.y);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   249
                robot.click(buttonTypes[i]);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   250
            } else {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   251
                robot.mouseRelease(buttonTypes[i]);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   252
            }
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   253
            if (! mouseReleased) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   254
                synchronized (releaseLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   255
                    try {
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   256
                        releaseLock.wait(6000);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   257
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   258
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   259
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   260
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   261
            if (! mouseReleased)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   262
                if (! SystemTrayIconHelper.skip(buttonTypes[i]) )
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   263
                    throw new RuntimeException("FAIL: mouseReleased not triggered when " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   264
                            buttonNames[i] + " released");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   265
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   266
            if (! mouseClicked) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   267
                synchronized (clickLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   268
                    try {
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   269
                        clickLock.wait(6000);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   270
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   271
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   272
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   273
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   274
            if (! mouseClicked)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   275
                throw new RuntimeException("FAIL: mouseClicked not triggered when " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   276
                        buttonNames[i] + " pressed & released");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   277
        }
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   278
        if(!isOEL7) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   279
            mouseMoved = false;
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   280
            robot.mouseMove(iconPosition.x + 100, iconPosition.y);
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   281
            robot.glide(iconPosition.x, iconPosition.y);
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   282
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   283
            if (!mouseMoved)
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   284
                if (!SystemTrayIconHelper.skip(0))
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   285
                    throw new RuntimeException("FAIL: mouseMoved not triggered even when mouse moved over the icon");
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
   286
        }
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   287
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   288
}