1 /* 2 * Copyright (c) 2018, 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 /* @test 25 * @bug 8130655 26 * @summary Tests that window owned by EmbeddedFrame can receive keyboard input 27 * @requires (os.family == "mac") 28 * @modules java.desktop/sun.awt 29 * @library ../../regtesthelpers 30 * @build Util 31 * @run main WindowOwnedByEmbeddedFrameTest 32 */ 33 34 import sun.awt.EmbeddedFrame; 35 36 import java.awt.Robot; 37 import java.awt.TextField; 38 import java.awt.Window; 39 import java.awt.event.KeyEvent; 40 41 import test.java.awt.regtesthelpers.Util; 42 43 public class WindowOwnedByEmbeddedFrameTest { 44 private static TextField textField; 45 private static EmbeddedFrame embeddedFrame; 46 private static Window window; 47 48 public static void main(String[] args) { 49 try { 50 Robot robot = Util.createRobot(); 51 robot.setAutoDelay(50); 52 53 embeddedFrame = createEmbeddedFrame(); 54 55 textField = new TextField(""); 56 57 window = new Window(embeddedFrame); 58 window.setSize(200, 200); 59 window.setLocationRelativeTo(null); 60 window.add(textField); 61 window.setVisible(true); 62 63 Util.waitForIdle(robot); 64 65 Util.clickOnComp(textField, robot); 66 Util.waitForIdle(robot); 67 68 robot.keyPress(KeyEvent.VK_T); 69 robot.keyRelease(KeyEvent.VK_T); 70 Util.waitForIdle(robot); 71 72 robot.keyPress(KeyEvent.VK_E); 73 robot.keyRelease(KeyEvent.VK_E); 74 Util.waitForIdle(robot); 75 76 robot.keyPress(KeyEvent.VK_S); 77 robot.keyRelease(KeyEvent.VK_S); 78 Util.waitForIdle(robot); 79 80 robot.keyPress(KeyEvent.VK_T); 81 robot.keyRelease(KeyEvent.VK_T); 82 Util.waitForIdle(robot); 83 84 if ("".equals(textField.getText())) { 85 throw new RuntimeException("Keyboard input in text field isn't possible"); 86 } 87 } finally { 88 if (embeddedFrame != null) { 89 embeddedFrame.dispose(); 90 } 91 if (window != null) { 92 window.dispose(); 93 } 94 } 95 } 96 97 private static EmbeddedFrame createEmbeddedFrame() { 98 try { 99 return (EmbeddedFrame) Class.forName("sun.lwawt.macosx.CEmbeddedFrame").newInstance(); 100 } catch (Exception e) { 101 throw new RuntimeException("Cannot create EmbeddedFrame", e); 102 } 103 } 104 } 105