jdk/test/java/awt/Frame/FrameLocation/FrameLocation.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 6822 0a6eba317c96
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6822
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 6822
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
6822
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     4
 *
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     8
 *
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    13
 * accompanied this code).
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    14
 *
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    18
 *
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    21
 * questions.
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    22
 */
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    23
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    24
/*
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 6822
diff changeset
    26
  @key headful
6822
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    27
  @bug 6895647
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    28
  @summary X11 Frame locations should be what we set them to
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    29
  @author anthony.petrov@oracle.com: area=awt.toplevel
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    30
  @run main FrameLocation
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    31
 */
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    32
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    33
import java.awt.*;
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    34
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    35
public class FrameLocation {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    36
    private static final int X = 250;
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    37
    private static final int Y = 250;
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    38
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    39
    public static void main(String[] args) {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    40
        Frame f = new Frame("test");
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    41
        f.setBounds(X, Y, 250, 250); // the size doesn't matter
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    42
        f.setVisible(true);
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    43
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    44
        for (int i = 0; i < 10; i++) {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    45
            // 2 seconds must be enough for the WM to show the window
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    46
            try {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    47
                Thread.sleep(2000);
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    48
            } catch (InterruptedException ex) {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    49
            }
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    50
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    51
            // Check the location
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    52
            int x = f.getX();
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    53
            int y = f.getY();
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    54
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    55
            if (x != X || y != Y) {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    56
                throw new RuntimeException("The frame location is wrong! Current: " + x + ", " + y + ";  expected: " + X + ", " + Y);
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    57
            }
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    58
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    59
            // Emulate what happens when setGraphicsConfiguration() is called
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    60
            synchronized (f.getTreeLock()) {
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    61
                f.removeNotify();
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    62
                f.addNotify();
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    63
            }
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    64
        }
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    65
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    66
        f.dispose();
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    67
    }
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    68
}
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents:
diff changeset
    69