Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/CycleThroughFrameTest/CycleThroughFrameTest.java
38828 views
/*1* Copyright (c) 2018, 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 820639226@requires (os.family == "mac")27@summary Cycle through frames using keyboard shortcut doesn't work on Mac28@compile CycleThroughFrameTest.java29@run main/manual CycleThroughFrameTest30*/3132import java.awt.Frame;33import java.awt.Button;34import java.awt.TextArea;35import java.awt.FlowLayout;36import javax.swing.JFrame;37import javax.swing.SwingUtilities;3839public class CycleThroughFrameTest {4041public static final int maxFrames = 5;42private static JFrame[] frame;43private static Frame instructionFrame;44private static volatile boolean testContinueFlag = true;4546private static final String TEST_INSTRUCTIONS =47" This is a manual test\n\n" +48" 1) Configure Keyboard shortcut if not done in your system:\n" +49" 2) Open System Preferences, go to -> Keyboard -> Shortcuts -> Keyboard\n" +50" 3) Enable 'Move focus to next window' if disabled\n" +51" 4) Enable 'Move focus to next window drawer' if disabled\n" +52" 5) Close System Preferences\n" +53" 5) Press COMMAND + ` keys to cycle through frames in forward order\n" +54" 6) Press FAIL if focus doesn't move to next frame\n" +55" 7) Press COMMAND + SHIFT + ` to cycle through frames in reverse order\n" +56" 8) Press FAIL if focus doesn't move to next frame in reverse order\n" +57" 9) Press PASS otherwise";5859private static final String FAIL_MESSAGE = "Focus doesn't move to next frame";6061public void showJFrame(int frameNumber) {6263String title = "Frame " + frameNumber;64frame[frameNumber] = new JFrame(title);65frame[frameNumber].setSize(300, 200);66frame[frameNumber].setLocation(50+(frameNumber*20), 50+(frameNumber*20));67frame[frameNumber].setVisible(true);68}6970private void createAndShowFrame() throws Exception {71SwingUtilities.invokeAndWait(new Runnable() {72public void run() {73frame = new JFrame[maxFrames];74for (int i = 0; i < maxFrames; i++) {75showJFrame(i);76}77}78});79}8081public void createAndShowInstructionFrame() {82Button passButton = new Button("Pass");83passButton.setEnabled(true);8485Button failButton = new Button("Fail");86failButton.setEnabled(true);8788TextArea instructions = new TextArea(12, 70);89instructions.setText(TEST_INSTRUCTIONS);9091instructionFrame = new Frame("Test Instructions");92instructionFrame.add(passButton);93instructionFrame.add(failButton);94instructionFrame.add(instructions);95instructionFrame.setSize(200,200);96instructionFrame.setLayout(new FlowLayout());97instructionFrame.pack();98instructionFrame.setVisible(true);99100passButton.addActionListener(ae -> {101dispose();102testContinueFlag = false;103});104105failButton.addActionListener(ae -> {106dispose();107testContinueFlag = false;108throw new RuntimeException(FAIL_MESSAGE);109});110}111112private static void dispose() {113for (int i = 0; i < maxFrames; i++) {114frame[i].dispose();115}116instructionFrame.dispose();117}118119public static void main(String[] args) throws Exception {120121CycleThroughFrameTest testObj = new CycleThroughFrameTest();122testObj.createAndShowFrame();123testObj.createAndShowInstructionFrame();124125final int sleepTime = 300000;126final int sleepLoopTime = 1000;127int remainingSleepTime = sleepTime;128while(remainingSleepTime > 0 && testContinueFlag) {129Thread.sleep(sleepLoopTime);130remainingSleepTime -= sleepLoopTime;131}132133if (testContinueFlag) {134dispose();135throw new RuntimeException("Timed out after " +136(sleepTime - remainingSleepTime) / 1000 + " seconds");137}138}139}140141142143