1 /* 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @key headful 27 * @bug 6917744 28 * @summary JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents 29 * @author Pavel Porvatov 30 * @run main bug6917744 31 */ 32 33 import java.awt.*; 34 import java.awt.event.KeyEvent; 35 import java.io.IOException; 36 import javax.swing.*; 37 38 public class bug6917744 { 39 private static JFrame frame; 40 41 private static JEditorPane editorPane; 42 43 private static JScrollPane scrollPane; 44 45 private static Robot robot; 46 47 public static void main(String[] args) throws Exception { 48 49 robot = new Robot(); 50 robot.setAutoDelay(100); 51 52 SwingUtilities.invokeAndWait(new Runnable() { 53 public void run() { 54 frame = new JFrame(); 55 56 editorPane = new JEditorPane(); 57 58 try { 59 editorPane.setPage(bug6917744.class.getResource("/test.html")); 60 } catch (IOException e) { 61 throw new RuntimeException("HTML resource not found", e); 62 } 63 64 scrollPane = new JScrollPane(editorPane); 65 66 frame.getContentPane().add(scrollPane); 67 frame.setSize(400, 300); 68 frame.setVisible(true); 69 } 70 }); 71 72 robot.waitForIdle(); 73 74 for (int i = 0; i < 50; i++) { 75 robot.keyPress(KeyEvent.VK_PAGE_DOWN); 76 robot.keyRelease(KeyEvent.VK_PAGE_DOWN); 77 } 78 79 robot.waitForIdle(); 80 81 // Check that we at the end of document 82 SwingUtilities.invokeAndWait(new Runnable() { 83 public void run() { 84 BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel(); 85 86 if (model.getValue() + model.getExtent() != model.getMaximum()) { 87 throw new RuntimeException("Invalid HTML position"); 88 } 89 } 90 }); 91 92 robot.waitForIdle(); 93 94 for (int i = 0; i < 50; i++) { 95 robot.keyPress(KeyEvent.VK_PAGE_UP); 96 robot.keyRelease(KeyEvent.VK_PAGE_UP); 97 } 98 99 robot.waitForIdle(); 100 101 // Check that we at the begin of document 102 SwingUtilities.invokeAndWait(new Runnable() { 103 public void run() { 104 BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel(); 105 106 if (model.getValue() != model.getMinimum()) { 107 throw new RuntimeException("Invalid HTML position"); 108 } 109 110 frame.dispose(); 111 } 112 }); 113 } 114 }