Path: blob/master/test/jdk/java/awt/Frame/CycleThroughFrameTest/CycleThroughFrameTest.java
41154 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@key headful26@bug 820639227@requires (os.family == "mac")28@summary Cycle through frames using keyboard shortcut doesn't work on Mac29@compile CycleThroughFrameTest.java30@run main/manual CycleThroughFrameTest31*/3233import java.awt.Frame;34import java.awt.Button;35import java.awt.TextArea;36import java.awt.FlowLayout;37import javax.swing.JFrame;38import javax.swing.SwingUtilities;3940public class CycleThroughFrameTest {4142public static final int maxFrames = 5;43private static JFrame[] frame;44private static Frame instructionFrame;45private static volatile boolean testContinueFlag = true;4647private static final String TEST_INSTRUCTIONS =48" This is a manual test\n\n" +49" 1) Configure Keyboard shortcut if not done in your system:\n" +50" 2) Open System Preferences, go to -> Keyboard -> Shortcuts -> Keyboard\n" +51" 3) Enable 'Move focus to next window' if disabled\n" +52" 4) Enable 'Move focus to next window drawer' if disabled\n" +53" 5) Close System Preferences\n" +54" 5) Press COMMAND + ` keys to cycle through frames in forward order\n" +55" 6) Press FAIL if focus doesn't move to next frame\n" +56" 7) Press COMMAND + SHIFT + ` to cycle through frames in reverse order\n" +57" 8) Press FAIL if focus doesn't move to next frame in reverse order\n" +58" 9) Press PASS otherwise";5960private static final String FAIL_MESSAGE = "Focus doesn't move to next frame";6162public void showJFrame(int frameNumber) {6364String title = "Frame " + frameNumber;65frame[frameNumber] = new JFrame(title);66frame[frameNumber].setSize(300, 200);67frame[frameNumber].setLocation(50+(frameNumber*20), 50+(frameNumber*20));68frame[frameNumber].setVisible(true);69}7071private void createAndShowFrame() throws Exception {72SwingUtilities.invokeAndWait(new Runnable() {73public void run() {74frame = new JFrame[maxFrames];75for (int i = 0; i < maxFrames; i++) {76showJFrame(i);77}78}79});80}8182public void createAndShowInstructionFrame() {83Button passButton = new Button("Pass");84passButton.setEnabled(true);8586Button failButton = new Button("Fail");87failButton.setEnabled(true);8889TextArea instructions = new TextArea(12, 70);90instructions.setText(TEST_INSTRUCTIONS);9192instructionFrame = new Frame("Test Instructions");93instructionFrame.add(passButton);94instructionFrame.add(failButton);95instructionFrame.add(instructions);96instructionFrame.setSize(200,200);97instructionFrame.setLayout(new FlowLayout());98instructionFrame.pack();99instructionFrame.setVisible(true);100101passButton.addActionListener(ae -> {102dispose();103testContinueFlag = false;104});105106failButton.addActionListener(ae -> {107dispose();108testContinueFlag = false;109throw new RuntimeException(FAIL_MESSAGE);110});111}112113private static void dispose() {114for (int i = 0; i < maxFrames; i++) {115frame[i].dispose();116}117instructionFrame.dispose();118}119120public static void main(String[] args) throws Exception {121122CycleThroughFrameTest testObj = new CycleThroughFrameTest();123testObj.createAndShowFrame();124testObj.createAndShowInstructionFrame();125126final int sleepTime = 300000;127final int sleepLoopTime = 1000;128int remainingSleepTime = sleepTime;129while(remainingSleepTime > 0 && testContinueFlag) {130Thread.sleep(sleepLoopTime);131remainingSleepTime -= sleepLoopTime;132}133134if (testContinueFlag) {135dispose();136throw new RuntimeException("Timed out after " +137(sleepTime - remainingSleepTime) / 1000 + " seconds");138}139}140}141142143144