Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/awt/Choice/ChoiceMouseWheelTest/ChoiceMouseWheelTest.java
48795 views
/*1* Copyright (c) 2011, 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@bug 705093526@summary closed/java/awt/Choice/WheelEventsConsumed/WheelEventsConsumed.html fails on win3227@library ../../regtesthelpers28@author Oleg Pekhovskiy: area=awt-choice29@build Util30@run main ChoiceMouseWheelTest31*/3233import test.java.awt.regtesthelpers.Util;3435import java.awt.*;36import java.awt.event.*;3738public class ChoiceMouseWheelTest extends Frame {3940private volatile boolean itemChanged = false;41private volatile boolean wheelMoved = false;42private volatile boolean frameExited = false;4344public static void main(String[] args) {45new ChoiceMouseWheelTest();46}4748ChoiceMouseWheelTest() {49super("ChoiceMouseWheelTest");50setLayout(new FlowLayout());5152Choice choice = new Choice();5354addWindowListener(new WindowAdapter() {55@Override56public void windowClosing(WindowEvent e) {57System.exit(0);58}59});6061for(Integer i = 0; i < 50; i++) {62choice.add(i.toString());63}6465choice.addItemListener(new ItemListener() {66public void itemStateChanged(ItemEvent e) {67itemChanged = true;68}69});70choice.addMouseWheelListener(new MouseWheelListener() {71public void mouseWheelMoved(MouseWheelEvent e) {72wheelMoved = true;73}74});7576addMouseListener(new MouseAdapter() {77@Override78public void mouseExited(MouseEvent e) {79frameExited = true;80}81});8283add(choice);84setSize(200, 300);85setVisible(true);86toFront();8788try {89Robot robot = new Robot();90robot.setAutoDelay(20);91Util.waitForIdle(robot);9293Point pt = choice.getLocationOnScreen();94Dimension size = choice.getSize();95int x = pt.x + size.width / 3;96robot.mouseMove(x, pt.y + size.height / 2);9798// Test mouse wheel over the choice99String name = Toolkit.getDefaultToolkit().getClass().getName();100101// mouse wheel doesn't work for the choice on X11 and Mac, so skip it102if(!name.equals("sun.awt.X11.XToolkit")103&& !name.equals("sun.lwawt.macosx.LWCToolkit")) {104robot.mouseWheel(1);105Util.waitForIdle(robot);106107if(!wheelMoved || !itemChanged) {108throw new RuntimeException("Mouse Wheel over the choice failed!");109}110}111112// Test mouse wheel over the drop-down list113robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);114Util.waitForIdle(robot);115robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);116Util.waitForIdle(robot);117118int y = getLocationOnScreen().y + getSize().height;119while(!frameExited && y >= 0) { // move to the bottom of drop-down list120robot.mouseMove(x, --y);121Util.waitForIdle(robot);122}123124if(x < 0) {125throw new RuntimeException("Could not enter drop-down list!");126}127128y -= choice.getHeight() / 2;129robot.mouseMove(x, y); // move to the last visible item in the drop-down list130Util.waitForIdle(robot);131132robot.mouseWheel(choice.getItemCount()); // wheel to the last item133Util.waitForIdle(robot);134135// click the last item136itemChanged = false;137robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);138Util.waitForIdle(robot);139robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);140Util.waitForIdle(robot);141142if(!itemChanged || choice.getSelectedIndex() != choice.getItemCount() - 1) {143throw new RuntimeException("Mouse Wheel scroll position error!");144}145146dispose();147} catch (AWTException e) {148throw new RuntimeException("AWTException occurred - problem creating robot!");149}150}151}152153154155