jdk/test/java/awt/WMSpecificTests/Mutter/MutterMaximizeTest.java
author amurillo
Wed, 15 Aug 2012 16:49:38 -0700
changeset 13465 d3fc5d192448
parent 12829 506020af237a
child 32286 5ffa8d8b4a2d
permissions -rw-r--r--
7191765: make jdk8 the default jprt release for hs24 Reviewed-by: jcoomes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     1
/*
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     2
 * Copyright 2012 Red Hat, Inc.  All Rights Reserved.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     3
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     5
 *
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     8
 * published by the Free Software Foundation.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
     9
 *
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    14
 * accompanied this code).
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    15
 *
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    19
 *
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    22
 * questions.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    23
 */
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    24
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    25
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    26
/*
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    27
  @test
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    28
  @bug      7043963
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    29
  @summary  Tests  that the screen location of windows is
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    30
            updated properly after a maximize.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    31
  @author   Denis Lila
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    32
  @library  ../../regtesthelpers
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    33
  @build    Util
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    34
  @run      main MutterMaximizeTest
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    35
*/
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    36
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    37
import java.awt.AWTException;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    38
import java.awt.Dimension;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    39
import java.awt.Frame;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    40
import java.awt.Point;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    41
import java.awt.Robot;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    42
import java.awt.Window;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    43
import java.awt.event.InputEvent;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    44
import java.awt.event.WindowAdapter;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    45
import java.awt.event.WindowEvent;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    46
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    47
import test.java.awt.regtesthelpers.Util;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    48
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    49
@SuppressWarnings("serial")
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    50
public class MutterMaximizeTest extends Frame {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    51
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    52
    public static void main(String[] args) throws InterruptedException {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    53
        if (Util.getWMID() != Util.MUTTER_WM) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    54
            System.out.println("This test is only useful on Mutter");
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    55
            return;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    56
        }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    57
        MutterMaximizeTest frame = new MutterMaximizeTest();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    58
        frame.addWindowListener(Util.getClosingWindowAdapter());
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    59
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    60
        //Display the window.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    61
        frame.setSize(500, 500);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    62
        Util.showWindowWait(frame);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    63
        runRobotTest(frame);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    64
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    65
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    66
    private static void runRobotTest(Frame frame) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    67
        try {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    68
            Thread robotThread = startRegTest(frame);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    69
            robotThread.start();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    70
            waitForThread(robotThread);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    71
        } finally {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    72
            frame.dispose();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    73
        }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    74
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    75
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    76
    private static void waitForThread(Thread t) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    77
        while (t.isAlive()) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    78
            try {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    79
                t.join();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    80
            } catch (InterruptedException e) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    81
            }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    82
        }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    83
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    84
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    85
    private static void sleepFor(long millis) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    86
        long dT = 0;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    87
        long start = System.nanoTime();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    88
        while (dT < millis) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    89
            try {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    90
                long toSleep = millis - dT/1000000;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    91
                if (toSleep > 0) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    92
                    Thread.sleep(toSleep);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    93
                }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    94
                // if this ends without an interrupted exception,
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    95
                // that's good enough.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    96
                break;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    97
            } catch (InterruptedException e) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    98
                long now = System.nanoTime();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
    99
                dT = now - start;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   100
            }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   101
        }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   102
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   103
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   104
    private static void rmove(Robot robot, Point p) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   105
        robot.mouseMove(p.x, p.y);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   106
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   107
    private static void rdown(Robot robot) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   108
        robot.mousePress(InputEvent.BUTTON1_MASK);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   109
        robot.delay(50);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   110
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   111
    private static void rup(Robot robot) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   112
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   113
        robot.delay(50);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   114
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   115
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   116
    public static void click(Robot robot) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   117
        rdown(robot);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   118
        rup(robot);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   119
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   120
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   121
    public static void doubleClick(Robot robot) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   122
        click(robot);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   123
        click(robot);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   124
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   125
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   126
    private static void dragWindow(Window w, int dx, int dy, Robot robot) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   127
        Point p = Util.getTitlePoint(w);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   128
        rmove(robot, p);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   129
        rdown(robot);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   130
        p.translate(dx, dy);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   131
        rmove(robot, p);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   132
        rup(robot);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   133
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   134
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   135
    // f must be visible
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   136
    private static Thread startRegTest(final Frame f) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   137
        Thread robot = new Thread(new Runnable() {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   138
            public void run() {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   139
                Robot r = Util.createRobot();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   140
                dragWindow(f, 100, 100, r);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   141
                // wait for the location to be set.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   142
                sleepFor(2000);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   143
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   144
                final Point l2 = f.getLocationOnScreen();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   145
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   146
                // double click should maximize the frame
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   147
                doubleClick(r);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   148
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   149
                // wait for location again.
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   150
                sleepFor(2000);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   151
                final Point l3 = f.getLocationOnScreen();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   152
                if (l3.equals(l2)) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   153
                    throw new RuntimeException("Bad location after maximize. Window location has not moved");
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   154
                }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   155
            }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   156
        });
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   157
        return robot;
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   158
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   159
}
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents:
diff changeset
   160