jdk/test/java/awt/Window/FindOwner/FindOwnerTest.java
author ihse
Tue, 09 May 2017 12:57:30 +0200
changeset 45028 b0ea3c0bfb81
parent 36896 d854fedad94e
permissions -rw-r--r--
8179889: Fix typographic errors in copyright headers Reviewed-by: erikj, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36883
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     1
/*
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 36896
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
36883
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     4
 *
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     8
 *
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    13
 * accompanied this code).
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    14
 *
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    18
 *
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    21
 * questions.
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    22
 */
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    23
36896
d854fedad94e 8152201: [TEST_BUG] test/java/awt/Window/FindOwner/FindOwnerTest.java has @test tag
ssadetsky
parents: 36883
diff changeset
    24
/* @bug 8139227
36883
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    25
   @summary Text fields in JPopupMenu structure do not receive focus in hosted
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    26
            Applets
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    27
   @author Semyon Sadetsky
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    28
*/
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    29
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    30
import java.applet.Applet;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    31
import java.awt.*;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    32
import java.awt.event.*;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    33
import javax.swing.*;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    34
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    35
public class FindOwnerTest extends Applet
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    36
{
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    37
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    38
    private boolean gained;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    39
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    40
    public void init() {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    41
        super.init();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    42
    }
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    43
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    44
    @Override
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    45
    public void start() {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    46
        Window owner = SwingUtilities.windowForComponent(this);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    47
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    48
        Window window1 = new Window(owner);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    49
        window1.setVisible(true);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    50
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    51
        Window window2 = new Window(window1);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    52
        window2.setFocusable(true);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    53
        JTextField field = new JTextField("JTextField");
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    54
        field.addFocusListener(new FocusListener() {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    55
            @Override
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    56
            public void focusGained(FocusEvent e) {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    57
                gained = true;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    58
            }
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    59
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    60
            @Override
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    61
            public void focusLost(FocusEvent e) {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    62
            }
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    63
        });
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    64
        window2.setBounds(100, 100, 200, 200);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    65
        window2.add(field);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    66
        window2.setVisible(true);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    67
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    68
        try {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    69
            gained = false;
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    70
            Robot robot = new Robot();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    71
            robot.setAutoDelay(50);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    72
            robot.waitForIdle();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    73
            robot.delay(200);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    74
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    75
            Point p = field.getLocationOnScreen();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    76
            System.out.println(p);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    77
            robot.mouseMove(p.x + 1, p.y + 1);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    78
            robot.mousePress(InputEvent.BUTTON1_MASK);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    79
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    80
            robot.waitForIdle();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    81
            robot.delay(200);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    82
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    83
            if (!gained) {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    84
                throw new Exception("Focus is not gained upon mouse click");
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    85
            }
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    86
            System.out.println("ok");
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    87
        } catch (SecurityException e) {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    88
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    89
            JOptionPane optionPane = new JOptionPane(
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    90
                    "You are in the browser so test is manual. Try to " +
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    91
                    "click \"JTextField\" in the opened window then press OK " +
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    92
                    "below",
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    93
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    94
            JDialog dialog =
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    95
                    optionPane.createDialog(null,"FindOwnerTest instruction");
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    96
            dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    97
            dialog.setVisible(true);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    98
            if (!gained) {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
    99
                throw new RuntimeException(
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   100
                        "Focus is not gained upon mouse click");
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   101
            }
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   102
            System.out.println("ok");
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   103
        } catch (Exception e) {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   104
            throw new RuntimeException(e);
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   105
        } finally {
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   106
            window1.dispose();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   107
            stop();
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   108
        }
0256b6d86efb 8139227: Text fields in JPopupMenu structure do not receive focus in hosted Applets
ssadetsky
parents:
diff changeset
   109
    }
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 36896
diff changeset
   110
}