Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EmbeddedFrame/EmbeddedFrameGrabTest/EmbeddedFrameGrabTest.java
38821 views
/*1* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 634500226@summary grab problems with EmbeddedFrame27@requires (os.family == "windows")28@author [email protected] area=EmbeddedFrame29@run main EmbeddedFrameGrabTest30*/31/**32* EmbeddedFrameGrabTest.java33*34* summary: grab problems with EmbeddedFrame35*/36import java.awt.Frame;37import java.awt.peer.FramePeer;38import javax.swing.JComboBox;39import java.awt.Panel;40import java.awt.BorderLayout;41import java.awt.Robot;42import java.awt.event.InputEvent;43import java.awt.Rectangle;44import java.awt.TextArea;45import java.awt.Dialog;4647import java.lang.reflect.Constructor;48import java.lang.reflect.Field;4950import sun.awt.AWTAccessor;5152public class EmbeddedFrameGrabTest {5354/**55* Test fails if it throws any exception.56*57* @throws Exception58*/59private void init() throws Exception {6061if (!System.getProperty("os.name").startsWith("Windows")) {62System.out.println("This is Windows only test.");63return;64}6566final Frame frame = new Frame("AWT Frame");67frame.pack();68frame.setSize(200, 200);69FramePeer frame_peer = (FramePeer) AWTAccessor.getComponentAccessor()70.getPeer(frame);71Class comp_peer_class72= Class.forName("sun.awt.windows.WComponentPeer");73Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");74hwnd_field.setAccessible(true);75long hwnd = hwnd_field.getLong(frame_peer);7677Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");78Constructor constructor79= clazz.getConstructor(new Class[]{long.class});80final Frame embedded_frame81= (Frame) constructor.newInstance(new Object[]{82new Long(hwnd)});;83final JComboBox<String> combo = new JComboBox<>(new String[]{84"Item 1", "Item 2"85});86combo.setSelectedIndex(1);87final Panel p = new Panel();88p.setLayout(new BorderLayout());89embedded_frame.add(p, BorderLayout.CENTER);90embedded_frame.validate();91p.add(combo);92p.validate();93frame.setVisible(true);94Robot robot = new Robot();95robot.delay(2000);96Rectangle clos = new Rectangle(97combo.getLocationOnScreen(), combo.getSize());98robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);99robot.mousePress(InputEvent.BUTTON1_MASK);100robot.mouseRelease(InputEvent.BUTTON1_MASK);101robot.delay(1000);102if (!combo.isPopupVisible()) {103throw new RuntimeException("Combobox popup is not visible!");104}105robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);106robot.mousePress(InputEvent.BUTTON1_MASK);107robot.mouseRelease(InputEvent.BUTTON1_MASK);108robot.delay(1000);109if (combo.getSelectedIndex() != 0) {110throw new RuntimeException("Combobox selection has not changed!");111}112embedded_frame.remove(p);113embedded_frame.dispose();114frame.dispose();115116}117118public static void main(String args[]) throws Exception {119new EmbeddedFrameGrabTest().init();120}121122}123124125