Path: blob/master/test/jdk/java/awt/Choice/ChoiceLocationTest/ChoiceLocationTest.java
41152 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*/2223/*24* @test25* @key headful26* @bug 715956627* @summary The choice positioned in the top of applet when clicking the choice.28* @author Petr Pchelko29* @library ../../regtesthelpers30* @build Util31* @run main ChoiceLocationTest32*/3334import java.awt.*;35import javax.swing.*;36import java.awt.event.InputEvent;37import java.util.stream.Stream;3839import test.java.awt.regtesthelpers.Util;4041public class ChoiceLocationTest {4243private static final int FRAME_LOCATION = 100;44private static final int FRAME_SIZE = 400;45private static final int CLICK_STEP = 5;4647private static String[] choiceItems = new String[] {48"test item 1",49"test item 2",50"test item 3"51};5253private static volatile Frame frame;54private static volatile Choice choice;5556public static void main(String[] args) throws Exception {57try {58SwingUtilities.invokeAndWait(ChoiceLocationTest::initAndShowUI);59Robot r = new Robot();60r.waitForIdle();61r.delay(100);6263Util.clickOnComp(choice, r);6465choice.addItemListener(event -> {throw new RuntimeException("Failed: the choice popup is in the wrong place");});6667// Test: click in several places on the top of the frame an ensure there' no choice there68Point locOnScreen = frame.getLocationOnScreen();69int x = locOnScreen.x + FRAME_SIZE / 2;70for (int y = locOnScreen.y + frame.getInsets().top + 10; y < locOnScreen.y + FRAME_SIZE / 3 ; y += CLICK_STEP) {71r.mouseMove(x, y);72r.waitForIdle();73r.mousePress(InputEvent.BUTTON1_MASK);74r.mouseRelease(InputEvent.BUTTON1_MASK);75r.waitForIdle();76r.delay(100);77}78} finally {79if (frame != null) {80frame.dispose();81}82}8384}8586private static void initAndShowUI() {87frame = new Frame("Test frame");88choice = new Choice();89Stream.of(choiceItems).forEach(choice::add);90frame.add(choice);91frame.setBounds(FRAME_LOCATION, FRAME_LOCATION, FRAME_SIZE, FRAME_SIZE);92frame.setVisible(true);93}949596}979899