jdk/test/javax/swing/text/StyledEditorKit/4506788/bug4506788.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 28071 3acb75b8df45
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:
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
     2
 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     4
 *
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     8
 *
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    13
 * accompanied this code).
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    14
 *
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    18
 *
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    21
 * questions.
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    22
 */
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    23
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    24
/*
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    25
 * @test
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    26
 * @key headful
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    27
 * @bug 4506788 7147408
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    28
 * @summary  Tests if cursor gets stuck after insertion a character
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    29
 * @author Denis Sharypov
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    30
 * @run applet bug4506788.html
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    31
 */
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 28071
diff changeset
    32
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    33
import java.awt.*;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    34
import java.awt.event.*;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    35
import java.lang.reflect.InvocationTargetException;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    36
import javax.swing.*;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    37
import javax.swing.event.*;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    38
import javax.swing.text.*;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    39
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    40
public class bug4506788 extends JApplet {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    41
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    42
    private volatile boolean passed = false;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    43
    private JEditorPane jep;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    44
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    45
    @Override
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    46
    public void init() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    47
        try {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    48
            SwingUtilities.invokeAndWait(new Runnable() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    49
                @Override
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    50
                public void run() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    51
                    createAndShowGUI();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    52
                }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    53
            });
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    54
        } catch (InterruptedException | InvocationTargetException ex) {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    55
            ex.printStackTrace();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    56
            throw new RuntimeException("FAILED: SwingUtilities.invokeAndWait method failed then creating and showing GUI");
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    57
        }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    58
    }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    59
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    60
    @Override
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    61
    public void start() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    62
        Robot robot;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    63
        try {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    64
            robot = new Robot();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    65
        } catch (AWTException e) {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    66
            throw new RuntimeException("Robot could not be created");
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    67
        }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    68
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 14497
diff changeset
    69
        robot.waitForIdle();
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    70
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    71
        Point p;
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    72
        try {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    73
            p = getJEPLocOnScreen();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    74
        } catch (Exception e) {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    75
            throw new RuntimeException("Could not get JEditorPane location on screen");
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    76
        }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    77
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    78
        robot.setAutoDelay(50);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    79
        robot.mouseMove(p.x, p.y);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    80
        robot.mousePress(InputEvent.BUTTON1_MASK);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    81
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 14497
diff changeset
    82
        robot.keyPress(KeyEvent.VK_HOME);
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 14497
diff changeset
    83
        robot.keyRelease(KeyEvent.VK_HOME);
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    84
        robot.keyPress(KeyEvent.VK_RIGHT);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    85
        robot.keyRelease(KeyEvent.VK_RIGHT);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    86
        robot.keyPress(KeyEvent.VK_X);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    87
        robot.keyRelease(KeyEvent.VK_X);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    88
        robot.keyPress(KeyEvent.VK_RIGHT);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    89
        robot.keyRelease(KeyEvent.VK_RIGHT);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    90
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 14497
diff changeset
    91
        robot.waitForIdle();
14497
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    92
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    93
        if (!passed) {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    94
            throw new RuntimeException("Test failed.");
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    95
        }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    96
    }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    97
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    98
    private Point getJEPLocOnScreen() throws Exception {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
    99
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   100
        final Point[] result = new Point[1];
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   101
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   102
        SwingUtilities.invokeAndWait(new Runnable() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   103
            @Override
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   104
            public void run() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   105
                result[0] = jep.getLocationOnScreen();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   106
            }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   107
        });
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   108
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   109
        return result[0];
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   110
    }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   111
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   112
    private void createAndShowGUI() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   113
        jep = new JEditorPane();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   114
        String text = "abc";
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   115
        JFrame f = new JFrame();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   116
        jep.setEditorKit(new StyledEditorKit());
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   117
        jep.setText(text);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   118
        jep.addCaretListener(new CaretListener() {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   119
            @Override
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   120
            public void caretUpdate(CaretEvent e) {
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   121
                passed = (e.getDot() == 3);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   122
            }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   123
        });
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   124
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   125
        DefaultStyledDocument doc = (DefaultStyledDocument) jep.getDocument();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   126
        MutableAttributeSet atr = new SimpleAttributeSet();
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   127
        StyleConstants.setBold(atr, true);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   128
        doc.setCharacterAttributes(1, 1, atr, false);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   129
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   130
        f.getContentPane().add(jep);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   131
        f.setSize(100, 100);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   132
        f.setVisible(true);
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   133
    }
e2413038bfbc 7147408: [macosx] Add autodelay to fix a regression test
kshefov
parents:
diff changeset
   134
}