Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/swing/JEditorPane/6917744/bug6917744.java
58462 views
1
/*
2
* Copyright (c) 2010, 2018, 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 8194767
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.InputEvent;
35
import java.awt.event.KeyEvent;
36
import java.io.IOException;
37
import javax.swing.*;
38
39
public class bug6917744 {
40
private static JFrame frame;
41
42
private static JEditorPane editorPane;
43
44
private static JScrollPane scrollPane;
45
46
private static Robot robot;
47
48
private static Point p = null;
49
50
static void blockTillDisplayed(JComponent comp) throws Exception {
51
while (p == null) {
52
try {
53
SwingUtilities.invokeAndWait(() -> {
54
p = comp.getLocationOnScreen();
55
});
56
} catch (IllegalStateException e) {
57
try {
58
Thread.sleep(1000);
59
} catch (InterruptedException ie) {
60
}
61
}
62
}
63
}
64
65
public static void main(String[] args) throws Exception {
66
67
robot = new Robot();
68
robot.setAutoDelay(100);
69
70
SwingUtilities.invokeAndWait(new Runnable() {
71
public void run() {
72
frame = new JFrame();
73
74
editorPane = new JEditorPane();
75
76
try {
77
editorPane.setPage(bug6917744.class.getResource("/test.html"));
78
} catch (IOException e) {
79
frame.dispose();
80
throw new RuntimeException("HTML resource not found", e);
81
}
82
83
scrollPane = new JScrollPane(editorPane);
84
85
frame.getContentPane().add(scrollPane);
86
frame.setSize(400, 300);
87
frame.setVisible(true);
88
}
89
});
90
91
blockTillDisplayed(editorPane);
92
robot.mouseMove(p.x+50, p.y+50);
93
robot.waitForIdle();
94
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
95
robot.waitForIdle();
96
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
97
robot.waitForIdle();
98
99
for (int i = 0; i < 50; i++) {
100
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
101
robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
102
}
103
104
robot.waitForIdle();
105
106
// Check that we at the end of document
107
SwingUtilities.invokeAndWait(new Runnable() {
108
public void run() {
109
BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
110
111
if (model.getValue() + model.getExtent() != model.getMaximum()) {
112
frame.dispose();
113
throw new RuntimeException("Invalid HTML position");
114
}
115
}
116
});
117
118
robot.waitForIdle();
119
120
for (int i = 0; i < 50; i++) {
121
robot.keyPress(KeyEvent.VK_PAGE_UP);
122
robot.keyRelease(KeyEvent.VK_PAGE_UP);
123
}
124
125
robot.waitForIdle();
126
127
// Check that we at the begin of document
128
SwingUtilities.invokeAndWait(new Runnable() {
129
public void run() {
130
BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
131
132
if (model.getValue() != model.getMinimum()) {
133
frame.dispose();
134
throw new RuntimeException("Invalid HTML position");
135
}
136
137
frame.dispose();
138
}
139
});
140
}
141
}
142
143