DecoratedFrameInsetsTest.java revision 15803:549ce3ab727d
1/*
2 * Copyright (c) 2016, 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
24/*
25 * @test
26 * @bug 8165619
27 * @summary Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
28 * @run main DecoratedFrameInsetsTest
29 */
30
31import java.awt.*;
32
33public class DecoratedFrameInsetsTest {
34    static Robot robot;
35    private static Insets expectedInsets;
36
37    public static void main(String[] args) throws Exception {
38        robot = new Robot();
39        expectedInsets = getExpectedInsets();
40        System.out.println("Normal state insets: " + expectedInsets);
41        testState(Frame.MAXIMIZED_BOTH);
42        testState(Frame.ICONIFIED);
43        testState(Frame.MAXIMIZED_HORIZ);
44        testState(Frame.MAXIMIZED_VERT);
45    }
46
47    private static Insets getExpectedInsets() {
48        Frame frame = new Frame();
49        frame.setVisible(true);
50        robot.waitForIdle();
51        robot.delay(200);
52        Insets expectedInsets = frame.getInsets();
53        frame.dispose();
54        return expectedInsets;
55    }
56
57    static void testState(int state) {
58        Frame frame = new Frame();
59        if( Toolkit.getDefaultToolkit().isFrameStateSupported(state)) {
60            frame.setBounds(150, 150, 200, 200);
61            frame.setExtendedState(state);
62            frame.setVisible(true);
63            robot.waitForIdle();
64            robot.delay(200);
65            System.out.println("State " + state +
66                                               " insets: " + frame.getInsets());
67
68            frame.setExtendedState(Frame.NORMAL);
69            frame.toFront();
70            robot.waitForIdle();
71            robot.delay(200);
72            Insets insets = frame.getInsets();
73            frame.dispose();
74            System.out.println("State " + state +
75                                           " back to normal insets: " + insets);
76            if(!expectedInsets.equals(insets)) {
77                throw new RuntimeException("Insets are wrong " + insets);
78            }
79        }
80    }
81}
82