test/jdk/java/awt/TrayIcon/ActionEventMask/ActionEventMask.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 if ActionEvent triggered when a TrayIcon is double
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    32
 *          (single, on Mac) clicked is visible by an AWTEventListener
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    33
 *          added to the Toolkit. It also checks if all listeners are
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    34
 *          triggered when multiple AWTEventListeners and ActionListeners
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    35
 *          are added.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    36
 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    37
 * @modules java.desktop/java.awt:open
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
    38
 * @library /java/awt/patchlib
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    39
 * @library ../../../../lib/testlibrary ../
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34788
diff changeset
    40
 * @build java.desktop/java.awt.Helper
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    41
 * @build ExtendedRobot SystemTrayIconHelper
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    42
 * @run main ActionEventMask
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    43
 */
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    44
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    45
public class ActionEventMask {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    46
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    47
    private Image image;
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
    TrayIcon icon;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    50
    ExtendedRobot robot;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    51
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    52
    boolean actionPerformed = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    53
    boolean listenersInvoked = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    54
    Object actionLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    55
    Object listenersLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    56
    static boolean isMacOS = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    57
    static final int clickDelay = 50;
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
    ActionListener[] listeners;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    60
    boolean[] listenerStatus;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    61
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    62
    Object lLock = new Object();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    63
    boolean doTest, listenerAdded;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    64
    Button b1;
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
    public static void main(String[] args) throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    67
        if (! SystemTray.isSupported()) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    68
            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
    69
                               "Marking the test passed");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    70
        } else {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    71
            if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    72
                isMacOS = true;
34788
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    73
            } else if (SystemTrayIconHelper.isOel7()) {
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    74
                System.out.println("OEL 7 doesn't support double click in " +
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    75
                        "systray. Skipped");
176e7a6529d4 8081457: TrayIcon tests fail in OEL 7 only
ssadetsky
parents: 25137
diff changeset
    76
                return;
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    77
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    78
            new ActionEventMask().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
    public ActionEventMask() throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    83
        EventQueue.invokeAndWait(this::initializeGUI);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    84
    }
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
    void initializeGUI() {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    87
        SystemTray tray = SystemTray.getSystemTray();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    88
        icon = new TrayIcon(new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "Sample Icon");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    89
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    90
        Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    91
            if (doTest) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    92
                System.out.println("ActionListener AWTEventListener");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    93
                if (! icon.equals(event.getSource())) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    94
                    throw new RuntimeException("FAIL: ActionEvent not triggered for icon");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    95
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    96
                actionPerformed = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    97
                synchronized (actionLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    98
                    try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    99
                        actionLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   100
                    } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   101
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   102
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   103
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   104
        }, AWTEvent.ACTION_EVENT_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   105
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
            tray.add(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   108
        } catch (AWTException e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   109
            throw new RuntimeException(e);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   110
        }
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
        listeners = new ActionListener[3];
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   113
        listenerStatus = new boolean[3];
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   114
        for (int i = 0; i < listeners.length; i++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   115
            final int index = i;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   116
            listeners[i] = event -> {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   117
                listenerStatus[index] = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   118
                System.out.println("ActionListener listeners[" + index + "]");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   119
                for (int j = 0; j < listenerStatus.length; j++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   120
                    if (! listenerStatus[j]) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   121
                        break;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   122
                    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   123
                    listenersInvoked = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   124
                    synchronized (listenersLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   125
                        try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   126
                            listenersLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   127
                        } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   128
                        }
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
            };
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   132
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   133
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   134
        Frame frame = new Frame("Test frame");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   135
        b1 = new Button("Add ActionListener");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   136
        b1.addActionListener(event -> {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   137
            for (int i = 0; i < listeners.length; i++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   138
                icon.addActionListener(listeners[i]);
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
            listenerAdded = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   141
            synchronized (lLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   142
                try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   143
                    lLock.notifyAll();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   144
                } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   145
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   146
            }
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
        frame.setLayout(new FlowLayout());
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   149
        frame.add(b1);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   150
        frame.setSize(200, 200);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   151
        frame.addWindowListener(new WindowAdapter() {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   152
            public void windowClosing(WindowEvent event) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   153
                System.err.println("User closed the window");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   154
                System.exit(1);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   155
            }
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
        frame.setVisible(true);
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
    private void doTest() throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   161
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   162
        robot = new ExtendedRobot();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   163
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   164
        Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   165
        if (iconPosition == null)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   166
            throw new RuntimeException("Unable to find the icon location!");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   167
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   168
        robot.mouseMove(iconPosition.x, iconPosition.y);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   169
        robot.waitForIdle();
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
        actionPerformed = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   172
        doTest = true;
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
        if(isMacOS) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   175
            robot.click(InputEvent.BUTTON3_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   176
        }else{
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   177
            robot.mousePress(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   178
            robot.delay(clickDelay);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   179
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   180
            robot.delay(clickDelay);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   181
            robot.mousePress(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   182
            robot.delay(clickDelay);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   183
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   184
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   185
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   186
        if (! actionPerformed) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   187
            synchronized (actionLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   188
                try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   189
                    actionLock.wait(3000);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   190
                } catch (Exception e) {
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
        if (! actionPerformed)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   195
            throw new RuntimeException("FAIL: AWTEventListener not notified when TrayIcon " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   196
                               "is "+(isMacOS ? "" :"double ")+ "clicked");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   197
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   198
        doTest = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   199
        listenerAdded = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   200
        robot.mouseMove(b1.getLocationOnScreen().x + b1.getSize().width / 2,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   201
                        b1.getLocationOnScreen().y + b1.getSize().height / 2);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   202
        robot.waitForIdle();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   203
        robot.click();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   204
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   205
        if (! listenerAdded) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   206
            synchronized (lLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   207
                try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   208
                    lLock.wait(3000);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   209
                } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   210
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   211
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   212
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   213
        if (! listenerAdded)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   214
            throw new RuntimeException("FAIL: ActionListener could not be added at runtime. " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   215
                               "b1 did not trigger ActionEvent");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   216
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   217
        doTest = true;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   218
        actionPerformed = false;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   219
        robot.mouseMove(iconPosition.x, iconPosition.y);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   220
        robot.waitForIdle();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   221
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   222
        if(isMacOS) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   223
            robot.click(InputEvent.BUTTON3_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   224
        }else{
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   225
            robot.mousePress(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   226
            robot.delay(clickDelay);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   227
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   228
            robot.delay(clickDelay);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   229
            robot.mousePress(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   230
            robot.delay(clickDelay);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   231
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   232
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   233
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   234
        if (! listenersInvoked) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   235
            synchronized (listenersLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   236
                try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   237
                    listenersLock.wait(3000);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   238
                } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   239
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   240
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   241
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   242
        if (! listenersInvoked) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   243
            System.err.println("FAIL: All the listeners not invoked!");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   244
            for (int i = 0; i < listenerStatus.length; i++)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   245
                throw new RuntimeException("Listener[" + i + "] invoked: " + listenerStatus[i]);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   246
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   247
        if (! actionPerformed) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   248
            synchronized (actionLock) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   249
                try {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   250
                    actionLock.wait(3000);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   251
                } catch (Exception e) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   252
                }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   253
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   254
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   255
        if (! actionPerformed)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   256
            throw new RuntimeException("FAIL: AWTEventListener not notified when TrayIcon " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
   257
                    "is "+(isMacOS? "" : "double ")+ "clicked. A set of listeners were added after it");
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
}