test/jdk/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java
author serb
Wed, 27 Feb 2019 18:46:55 -0800
changeset 54231 e4813eded7cb
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213110: Remove the use of applets in automatic tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     1
/*
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     4
 *
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     8
 *
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    13
 * accompanied this code).
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    14
 *
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    18
 *
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    21
 * questions.
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    22
 */
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    23
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    24
/*
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    25
  @test
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    26
  @key headful
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    27
  @bug 6387275
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    28
  @summary List: the focus is at the top of the first item, XAWT
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    29
  @requires (os.family == "linux" | os.family == "solaris")
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    30
  @modules java.desktop/sun.awt
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    31
           java.desktop/java.awt.peer
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    32
           java.desktop/sun.awt.X11:open
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    33
  @run main FocusEmptyListTest
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    34
*/
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    35
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    36
import java.awt.*;
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    37
import java.lang.reflect.*;
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    38
import java.awt.peer.ListPeer;
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    39
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    40
import sun.awt.AWTAccessor;
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    41
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    42
public class FocusEmptyListTest extends Frame {
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    43
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    44
    public static void main(final String[] args) {
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    45
        FocusEmptyListTest app = new FocusEmptyListTest();
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    46
        app.start();
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    47
    }
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    48
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    49
    public void start() {
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    50
        boolean isXToolkit = Toolkit.getDefaultToolkit()
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    51
            .getClass().getName().equals("sun.awt.X11.XToolkit");
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    52
        if (!isXToolkit) {
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    53
            System.out.println("The test is XAWT-only.");
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    54
            return;
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    55
        }
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    56
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    57
        List list = new List();
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    58
        Object isIndexDisplayed = null;
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    59
        setLayout(new FlowLayout());
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    60
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    61
        getToolkit().addAWTEventListener(System.out::println,
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    62
            AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    63
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    64
        add(list);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    65
        list.add("item1");
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    66
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    67
        setSize(200, 200);
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    68
        setUndecorated(true);
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 47216
diff changeset
    69
        setLocationRelativeTo(null);
33505
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    70
        setVisible(true);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    71
        validate();
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    72
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    73
        list.removeAll();
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    74
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    75
        try {
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    76
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    77
            // peer = List.getPeer()
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    78
            ListPeer peer = AWTAccessor.getComponentAccessor().getPeer(list);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    79
            System.out.println("peer = " + peer);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    80
            Class peerClass = peer.getClass();
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    81
            System.out.println("peer's class = " + peerClass);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    82
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    83
            // isIndexDisplayed = peer.isIndexDisplayed(-1)
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    84
            Method isIndexDisplayedM
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    85
                = peerClass.getDeclaredMethod("isIndexDisplayed", Integer.TYPE);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    86
            System.out.println("method = " + isIndexDisplayedM);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    87
            isIndexDisplayedM.setAccessible(true);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    88
            isIndexDisplayed = isIndexDisplayedM.invoke(peer, -1);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    89
            System.out.println("isIndexDisplayed=" + isIndexDisplayed);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    90
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    91
        } catch (Throwable thr) {
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    92
            throw new RuntimeException("TEST FAILED: " + thr);
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    93
        }
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    94
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    95
        if ((Boolean) isIndexDisplayed) {
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    96
            throw new RuntimeException("TEST FAILED: -1 should be"
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    97
                + " invisible index");
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    98
        }
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
    99
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
   100
    }// start()
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
   101
5929d216087d 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw
yan
parents:
diff changeset
   102
}// class AutomaticAppletTest