jdk/test/java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
parent 31660 1a4e2e5c15e1
child 39056 d99e63b6d962
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
  @bug 6359129
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary REGRESSION: Popup menus dont respond to selections when extend outside Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @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
    29
  @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
    30
           java.desktop/sun.awt
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 31660
diff changeset
    31
  @library /java/awt/patchlib  ../../regtesthelpers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 31660
diff changeset
    32
  @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
    33
  @build Util UtilInternal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  @run main EmbeddedFrameTest1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * EmbeddedFrameTest1.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * summary: REGRESSION: Popup menus dont respond to selections when extend outside Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Robot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.TextArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
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
    50
import java.awt.AWTException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.swing.JButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.JPopupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
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
    59
import test.java.awt.regtesthelpers.UtilInternal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class EmbeddedFrameTest1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
{
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    63
    public static void main( String args[] ) throws AWTException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            final Frame frame = new Frame("AWT Frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            frame.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            frame.setSize(200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    70
            final Frame embedded_frame = UtilInternal.createEmbeddedFrame(frame);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            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
    72
            System.out.println("embedded_frame = " + embedded_frame);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            final JPopupMenu menu = new JPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            JButton item = new JButton("A button in popup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            item.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                        System.out.println("Button pressed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            menu.add(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            final JButton btn = new JButton("Press me to see popup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            btn.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        menu.show(btn, 0, btn.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            final Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            p.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            embedded_frame.add(p,BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            embedded_frame.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            p.add(btn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            p.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            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
    98
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            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
   100
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            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
   103
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (item.getMousePosition() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                throw new RuntimeException("Popup was not closed (mouse above it)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            embedded_frame.remove(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            embedded_frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } catch (Throwable thr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            thr.printStackTrace();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   112
            throw new RuntimeException("TEST FAILED: " + thr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}