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