Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Choice/ChoiceLocationTest/ChoiceLocationTest.java
47490 views
/*1* Copyright (c) 2014, 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 715956626@summary The choice positioned in the top of applet when clicking the choice.27@author Petr Pchelko28@library ../../regtesthelpers29@build Util30@run main ChoiceLocationTest31*/3233import java.awt.*;34import javax.swing.*;35import java.awt.event.InputEvent;36import java.util.stream.Stream;3738import test.java.awt.regtesthelpers.Util;3940public class ChoiceLocationTest {4142private static final int FRAME_LOCATION = 100;43private static final int FRAME_SIZE = 400;44private static final int CLICK_STEP = 5;4546private static String[] choiceItems = new String[] {47"test item 1",48"test item 2",49"test item 3"50};5152private static volatile Frame frame;53private static volatile Choice choice;5455public static void main(String[] args) throws Exception {56try {57SwingUtilities.invokeAndWait(ChoiceLocationTest::initAndShowUI);58Robot r = new Robot();59r.waitForIdle();60r.delay(100);6162Util.clickOnComp(choice, r);6364choice.addItemListener(event -> {throw new RuntimeException("Failed: the choice popup is in the wrong place");});6566// Test: click in several places on the top of the frame an ensure there' no choice there67Point locOnScreen = frame.getLocationOnScreen();68int x = locOnScreen.x + FRAME_SIZE / 2;69for (int y = locOnScreen.y + frame.getInsets().top + 10; y < locOnScreen.y + FRAME_SIZE / 3 ; y += CLICK_STEP) {70r.mouseMove(x, y);71r.waitForIdle();72r.mousePress(InputEvent.BUTTON1_MASK);73r.mouseRelease(InputEvent.BUTTON1_MASK);74r.waitForIdle();75r.delay(100);76}77} finally {78if (frame != null) {79frame.dispose();80}81}8283}8485private static void initAndShowUI() {86frame = new Frame("Test frame");87choice = new Choice();88Stream.of(choiceItems).forEach(choice::add);89frame.add(choice);90frame.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);91frame.setVisible(true);92}939495}969798