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 import sun.awt.SunToolkit;
  39 
  40 public class bug6917744 {
  41     private static JFrame frame;
  42 
  43     private static JEditorPane editorPane;
  44 
  45     private static JScrollPane scrollPane;
  46 
  47     private static Robot robot;
  48 
  49     public static void main(String[] args) throws Exception {
  50         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  51 
  52         robot = new Robot();
  53         robot.setAutoDelay(100);
  54 
  55         SwingUtilities.invokeAndWait(new Runnable() {
  56             public void run() {
  57                 frame = new JFrame();
  58 
  59                 editorPane = new JEditorPane();
  60 
  61                 try {
  62                     editorPane.setPage(bug6917744.class.getResource("/test.html"));
  63                 } catch (IOException e) {
  64                     throw new RuntimeException("HTML resource not found", e);
  65                 }
  66 
  67                 scrollPane = new JScrollPane(editorPane);
  68 
  69                 frame.getContentPane().add(scrollPane);
  70                 frame.setSize(400, 300);
  71                 frame.setVisible(true);
  72             }
  73         });
  74 
  75         toolkit.realSync();
  76 
  77         for (int i = 0; i < 50; i++) {
  78             robot.keyPress(KeyEvent.VK_PAGE_DOWN);
  79         }
  80 
  81         toolkit.realSync();
  82 
  83         // Check that we at the end of document
  84         SwingUtilities.invokeAndWait(new Runnable() {
  85             public void run() {
  86                 BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
  87 
  88                 if (model.getValue() + model.getExtent() != model.getMaximum()) {
  89                     throw new RuntimeException("Invalid HTML position");
  90                 }
  91             }
  92         });
  93 
  94         toolkit.realSync();
  95 
  96         for (int i = 0; i < 50; i++) {
  97             robot.keyPress(KeyEvent.VK_PAGE_UP);
  98         }
  99 
 100         toolkit.realSync();
 101 
 102         // Check that we at the begin of document
 103         SwingUtilities.invokeAndWait(new Runnable() {
 104             public void run() {
 105                 BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
 106 
 107                 if (model.getValue() != model.getMinimum()) {
 108                     throw new RuntimeException("Invalid HTML position");
 109                 }
 110 
 111                 frame.dispose();
 112             }
 113         });
 114     }
 115 }