jdk/test/java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 36511 9d0388c6b336
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 36511
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 36511
diff changeset
    26
  @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @bug 6359129
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @summary REGRESSION: Popup menus dont respond to selections when extend outside Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @author oleg.sukhodolsky area=awt.grab
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents: 28087
diff changeset
    30
  @modules java.desktop/java.awt.peer
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents: 28087
diff changeset
    31
           java.desktop/sun.awt
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 31660
diff changeset
    32
  @library /java/awt/patchlib  ../../regtesthelpers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 31660
diff changeset
    33
  @build java.desktop/java.awt.Helper
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    34
  @build Util UtilInternal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  @run main EmbeddedFrameTest1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * EmbeddedFrameTest1.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * summary: REGRESSION: Popup menus dont respond to selections when extend outside Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.Robot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.TextArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.Toolkit;
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    51
import java.awt.AWTException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.JButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.swing.JPopupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import test.java.awt.regtesthelpers.Util;
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    60
import test.java.awt.regtesthelpers.UtilInternal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class EmbeddedFrameTest1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
{
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    64
    public static void main( String args[] ) throws AWTException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            final Frame frame = new Frame("AWT Frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            frame.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            frame.setSize(200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    71
            final Frame embedded_frame = UtilInternal.createEmbeddedFrame(frame);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            embedded_frame.setSize(200, 200);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    73
            System.out.println("embedded_frame = " + embedded_frame);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            final JPopupMenu menu = new JPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            JButton item = new JButton("A button in popup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            item.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                        System.out.println("Button pressed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            menu.add(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            final JButton btn = new JButton("Press me to see popup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            btn.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        menu.show(btn, 0, btn.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            final Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            p.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            embedded_frame.add(p,BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            embedded_frame.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            p.add(btn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            p.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            Robot robot = new Robot();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    99
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            Util.clickOnComp(btn, robot);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   101
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            Util.clickOnComp(item, robot);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   104
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (item.getMousePosition() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                throw new RuntimeException("Popup was not closed (mouse above it)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            embedded_frame.remove(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            embedded_frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        } catch (Throwable thr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            thr.printStackTrace();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   113
            throw new RuntimeException("TEST FAILED: " + thr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}