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