Path: blob/master/test/jdk/javax/swing/JEditorPane/6917744/bug6917744.java
58462 views
/*1* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 6917744 819476727* @summary JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents28* @author Pavel Porvatov29* @run main bug691774430*/3132import java.awt.*;33import java.awt.event.InputEvent;34import java.awt.event.KeyEvent;35import java.io.IOException;36import javax.swing.*;3738public class bug6917744 {39private static JFrame frame;4041private static JEditorPane editorPane;4243private static JScrollPane scrollPane;4445private static Robot robot;4647private static Point p = null;4849static void blockTillDisplayed(JComponent comp) throws Exception {50while (p == null) {51try {52SwingUtilities.invokeAndWait(() -> {53p = comp.getLocationOnScreen();54});55} catch (IllegalStateException e) {56try {57Thread.sleep(1000);58} catch (InterruptedException ie) {59}60}61}62}6364public static void main(String[] args) throws Exception {6566robot = new Robot();67robot.setAutoDelay(100);6869SwingUtilities.invokeAndWait(new Runnable() {70public void run() {71frame = new JFrame();7273editorPane = new JEditorPane();7475try {76editorPane.setPage(bug6917744.class.getResource("/test.html"));77} catch (IOException e) {78frame.dispose();79throw new RuntimeException("HTML resource not found", e);80}8182scrollPane = new JScrollPane(editorPane);8384frame.getContentPane().add(scrollPane);85frame.setSize(400, 300);86frame.setVisible(true);87}88});8990blockTillDisplayed(editorPane);91robot.mouseMove(p.x+50, p.y+50);92robot.waitForIdle();93robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);94robot.waitForIdle();95robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);96robot.waitForIdle();9798for (int i = 0; i < 50; i++) {99robot.keyPress(KeyEvent.VK_PAGE_DOWN);100robot.keyRelease(KeyEvent.VK_PAGE_DOWN);101}102103robot.waitForIdle();104105// Check that we at the end of document106SwingUtilities.invokeAndWait(new Runnable() {107public void run() {108BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();109110if (model.getValue() + model.getExtent() != model.getMaximum()) {111frame.dispose();112throw new RuntimeException("Invalid HTML position");113}114}115});116117robot.waitForIdle();118119for (int i = 0; i < 50; i++) {120robot.keyPress(KeyEvent.VK_PAGE_UP);121robot.keyRelease(KeyEvent.VK_PAGE_UP);122}123124robot.waitForIdle();125126// Check that we at the begin of document127SwingUtilities.invokeAndWait(new Runnable() {128public void run() {129BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();130131if (model.getValue() != model.getMinimum()) {132frame.dispose();133throw new RuntimeException("Invalid HTML position");134}135136frame.dispose();137}138});139}140}141142143