jdk/test/java/awt/Modal/LWModalTest/LWModalTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 32286 5ffa8d8b4a2d
child 42338 a60f280f803c
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:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 32286
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 32286
diff changeset
    26
  @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @bug 6178755
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @summary The test checks that Container's method startLWModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
and stopLWModal work correctly. The test scenario is very close
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
to JOptionPane.showInternal*Dialog methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @author artem.ananiev@...: area=awt.modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  @run main LWModalTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class LWModalTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static JFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static volatile JInternalFrame internalFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static volatile boolean passed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static void init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        frame = new JFrame("JFrame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        frame.setBounds(100, 100, 320, 240);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        Util.waitForIdle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        new Thread(new Runnable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            public void run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                JOptionPane p = new JOptionPane("Message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                internalFrame = p.createInternalFrame(frame.getContentPane(), "Title");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                internalFrame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                    Method m = Container.class.getDeclaredMethod("startLWModal", (Class[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    m.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    m.invoke(internalFrame, (Object[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                catch (Exception z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    z.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                    LWModalTest.fail(z.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                passed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            Thread.sleep(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            Util.waitForIdle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            internalFrame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            Method m = Container.class.getDeclaredMethod("stopLWModal", (Class[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            m.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            m.invoke(internalFrame, (Object[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            Thread.sleep(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            Util.waitForIdle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        catch (Exception z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            z.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            LWModalTest.fail(z.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (passed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            LWModalTest.pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            LWModalTest.fail("showInternalMessageDialog() has not returned");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static boolean theTestPassed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static boolean testGeneratedInterrupt = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static String failureMessage = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static Thread mainThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static int sleepTime = 60000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static void main(String args[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        mainThread = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        catch (TestPassedException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            Thread.sleep( sleepTime );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new RuntimeException("Timed out after " + sleepTime/1000 + " seconds");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        catch (InterruptedException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if(!testGeneratedInterrupt) throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            testGeneratedInterrupt = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if (theTestPassed == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                throw new RuntimeException(failureMessage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static synchronized void setTimeoutTo(int seconds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        sleepTime = seconds * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static synchronized void pass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (mainThread == Thread.currentThread())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            theTestPassed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new TestPassedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        theTestPassed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        testGeneratedInterrupt = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        mainThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public static synchronized void fail()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        fail("it just plain failed! :-)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static synchronized void fail(String whyFailed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (mainThread == Thread.currentThread())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new RuntimeException(whyFailed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        theTestPassed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        testGeneratedInterrupt = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        failureMessage = whyFailed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        mainThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
class TestPassedException extends RuntimeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}