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 /* @test
  25  * @bug 6917744
  26  * @summary JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
  27  * @author Pavel Porvatov
  28  * @run main bug6917744
  29  */
  30 
  31 import java.awt.*;
  32 import java.awt.event.KeyEvent;
  33 import java.io.IOException;
  34 import javax.swing.*;
  35 
  36 import sun.awt.SunToolkit;
  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         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  49 
  50         robot = new Robot();
  51         robot.setAutoDelay(100);
  52 
  53         SwingUtilities.invokeAndWait(new Runnable() {
  54             public void run() {
  55                 frame = new JFrame();
  56 
  57                 editorPane = new JEditorPane();
  58 
  59                 try {
  60                     editorPane.setPage(bug6917744.class.getResource("/test.html"));
  61                 } catch (IOException e) {
  62                     throw new RuntimeException("HTML resource not found", e);
  63                 }
  64 
  65                 scrollPane = new JScrollPane(editorPane);
  66 
  67                 frame.getContentPane().add(scrollPane);
  68                 frame.setSize(400, 300);
  69                 frame.setVisible(true);
  70             }
  71         });
  72 
  73         toolkit.realSync();
  74 
  75         for (int i = 0; i < 50; i++) {
  76             robot.keyPress(KeyEvent.VK_PAGE_DOWN);
  77         }
  78 
  79         toolkit.realSync();
  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         toolkit.realSync();
  93 
  94         for (int i = 0; i < 50; i++) {
  95             robot.keyPress(KeyEvent.VK_PAGE_UP);
  96         }
  97 
  98         toolkit.realSync();
  99 
 100         // Check that we at the begin of document
 101         SwingUtilities.invokeAndWait(new Runnable() {
 102             public void run() {
 103                 BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
 104 
 105                 if (model.getValue() != model.getMinimum()) {
 106                     throw new RuntimeException("Invalid HTML position");
 107                 }
 108 
 109                 frame.dispose();
 110             }
 111         });
 112     }
 113 }