Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/SplashScreen/FullscreenAfterSplash/FullScreenAfterSplash.java
38828 views
/*1* Copyright (c) 2013, 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*/2223import sun.awt.OSInfo;2425import java.awt.*;26import java.awt.Robot;27import java.awt.event.InputEvent;28import java.lang.InterruptedException;29import java.lang.System;30import java.lang.Thread;31import java.lang.reflect.Method;32import java.lang.reflect.Proxy;33import javax.swing.*;3435/*36* @test37* @bug 802418538* @summary Native Mac OS X full screen does not work after showing the splash39* @requires (os.family == "mac")40* @library ../41* @build GenerateTestImage42* @run main GenerateTestImage43* @author Petr Pchelko area=awt.event44* @run main/othervm -splash:test.png FullScreenAfterSplash45*/46public class FullScreenAfterSplash {4748private static JFrame frame;4950private static volatile boolean windowEnteringFullScreen = false;51private static volatile boolean windowEnteredFullScreen = false;5253public static void main(String[] args) throws Exception {5455if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {56System.out.println("The test is applicable only to Mac OS X. Passed");57return;58}59try {60//Move the mouse out, because it could interfere with the test.61Robot r = new Robot();62r.mouseMove(0, 0);63sleep();6465SwingUtilities.invokeAndWait(FullScreenAfterSplash::createAndShowGUI);66sleep();6768Point fullScreenButtonPos = frame.getLocation();69fullScreenButtonPos.translate(frame.getWidth() - 10, 10);70r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);7172//Cant use waitForIdle for full screen transition.73int waitCount = 0;74while (!windowEnteringFullScreen) {75r.mousePress(InputEvent.BUTTON1_MASK);76r.mouseRelease(InputEvent.BUTTON1_MASK);77Thread.sleep(100);78if (waitCount++ > 10) {79System.err.println("Can't enter full screen mode. Failed.");80System.exit(1);81}82}8384waitCount = 0;85while (!windowEnteredFullScreen) {86Thread.sleep(100);87if (waitCount++ > 10) {88System.err.println("Can't enter full screen mode. Failed.");89System.exit(1);90}91}92} finally {93if (frame != null) {94frame.dispose();95}96}97}9899private static void createAndShowGUI() {100frame = new JFrame(" Fullscreen OSX Bug ");101frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);102enableFullScreen(frame);103frame.setBounds(100, 100, 100, 100);104frame.pack();105frame.setVisible(true);106}107108/*109* Use reflection to make a test compilable on not Mac OS X110*/111private static void enableFullScreen(Window window) {112try {113Class<?> fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities");114Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", Window.class, boolean.class);115setWindowCanFullScreen.invoke(fullScreenUtilities, window, true);116Class fullScreenListener = Class.forName("com.apple.eawt.FullScreenListener");117Object listenerObject = Proxy.newProxyInstance(fullScreenListener.getClassLoader(), new Class[]{fullScreenListener}, (proxy, method, args) -> {118switch (method.getName()) {119case "windowEnteringFullScreen":120windowEnteringFullScreen = true;121break;122case "windowEnteredFullScreen":123windowEnteredFullScreen = true;124break;125}126return null;127});128Method addFullScreenListener = fullScreenUtilities.getMethod("addFullScreenListenerTo", Window.class, fullScreenListener);129addFullScreenListener.invoke(fullScreenUtilities, window, listenerObject);130} catch (Exception e) {131throw new RuntimeException("FullScreen utilities not available", e);132}133}134135private static void sleep() {136try {137Thread.sleep(500);138} catch (InterruptedException ignored) { }139}140}141142143