1/*
2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24import java.awt.Dimension;
25import java.awt.Point;
26import java.awt.Robot;
27import java.awt.event.ActionEvent;
28import java.awt.event.ActionListener;
29import javax.swing.BoxLayout;
30import javax.swing.JComboBox;
31import javax.swing.JFrame;
32import javax.swing.SwingUtilities;
33import test.java.awt.regtesthelpers.Util;
34
35
36/**
37 * AWT/Swing overlapping test for {@link javax.swing.JCombobox } component.
38 * <p>This test creates combobox and test if heavyweight component is drawn correctly then dropdown is shown.
39 * <p>See base class for details.
40 */
41/*
42 * @test
43 * @key headful
44 * @summary Overlapping test for javax.swing.JScrollPane
45 * @author sergey.grinev@oracle.com: area=awt.mixing
46 * @library /java/awt/patchlib  ../../regtesthelpers
47 * @modules java.desktop/sun.awt
48 *          java.desktop/java.awt.peer
49 * @build java.desktop/java.awt.Helper
50 * @build Util
51 * @run main JComboBoxOverlapping
52 */
53public class JComboBoxOverlapping extends OverlappingTestBase {
54
55    private boolean lwClicked = false;
56    private Point loc;
57    private Point loc2;
58    private JComboBox cb;
59    private JFrame frame;
60
61    {testEmbeddedFrame = true;}
62
63    protected void prepareControls() {
64        frame = new JFrame("Mixing : Dropdown Overlapping test");
65        frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
66        frame.setSize(200, 200);
67        frame.setVisible(true);
68
69        cb = new JComboBox(petStrings);
70        cb.setPreferredSize(new Dimension(frame.getContentPane().getWidth(), 20));
71        cb.addActionListener(new ActionListener() {
72
73            public void actionPerformed(ActionEvent e) {
74                if (e.getSource() == cb) {
75                    lwClicked = true;
76                }
77            }
78        });
79
80        frame.add(cb);
81        propagateAWTControls(frame);
82        frame.setVisible(true);
83    }
84
85    @Override
86    protected boolean performTest() {
87        // run robot
88        Robot robot = Util.createRobot();
89        robot.setAutoDelay(ROBOT_DELAY);
90        robot.waitForIdle();
91        robot.delay(200);
92        try {
93            SwingUtilities.invokeAndWait(() -> {
94                loc = cb.getLocationOnScreen();
95                loc2 = frame.getContentPane().getLocationOnScreen();
96            });
97        } catch (Exception e) {
98            throw new RuntimeException(e);
99        }
100
101        loc2.translate(75, 75);
102        pixelPreCheck(robot, loc2, currentAwtControl);
103
104        loc.translate(3, 3);
105        clickAndBlink(robot, loc, false);
106
107        clickAndBlink(robot, loc2, false);
108
109        return lwClicked;
110    }
111
112    // this strange plumbing stuff is required due to "Standard Test Machinery" in base class
113    public static void main(String args[]) throws InterruptedException {
114        instance = new JComboBoxOverlapping();
115        OverlappingTestBase.doMain(args);
116    }
117}
118