Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/6691503/bug6691503.java
41155 views
1
/*
2
* Copyright (c) 2008, 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 6691503
28
* @summary Checks that there is no opportunity for a malicious applet
29
* to show a popup menu which has whole screen size.
30
* a heaviweight popup menu is shown from an applet.
31
* @author Mikhail Lapshin
32
* @run main/othervm -Djava.security.manager=allow bug6691503
33
*/
34
35
import javax.swing.*;
36
import java.awt.*;
37
38
public class bug6691503 {
39
private JPopupMenu popupMenu;
40
private JFrame frame;
41
private boolean isAlwaysOnTop1 = false;
42
private boolean isAlwaysOnTop2 = true;
43
44
public static void main(String[] args) {
45
bug6691503 test = new bug6691503();
46
test.setupUI();
47
test.testApplication();
48
test.testApplet();
49
test.checkResult();
50
test.stopEDT();
51
}
52
53
private void setupUI() {
54
SwingUtilities.invokeLater(new Runnable() {
55
public void run() {
56
frame = new JFrame();
57
frame.setVisible(true);
58
popupMenu = new JPopupMenu();
59
JMenuItem click = new JMenuItem("Click");
60
popupMenu.add(click);
61
}
62
});
63
}
64
65
private void testApplication() {
66
SwingUtilities.invokeLater(new Runnable() {
67
public void run() {
68
popupMenu.show(frame, 0, 0);
69
Window popupWindow = (Window)
70
(popupMenu.getParent().getParent().getParent().getParent());
71
isAlwaysOnTop1 = popupWindow.isAlwaysOnTop();
72
System.out.println(
73
"Application: popupWindow.isAlwaysOnTop() = " + isAlwaysOnTop1);
74
popupMenu.setVisible(false);
75
}
76
});
77
}
78
79
private void testApplet() {
80
SwingUtilities.invokeLater(new Runnable() {
81
public void run() {
82
System.setSecurityManager(new SecurityManager());
83
popupMenu.show(frame, 0, 0);
84
Window popupWindow = (Window)
85
(popupMenu.getParent().getParent().getParent().getParent());
86
isAlwaysOnTop2 = popupWindow.isAlwaysOnTop();
87
System.out.println(
88
"Applet: popupWindow.isAlwaysOnTop() = " + isAlwaysOnTop2);
89
popupMenu.setVisible(false);
90
}
91
});
92
}
93
94
private void checkResult() {
95
try {
96
Robot robot = new Robot();
97
robot.waitForIdle();
98
}catch(Exception ex) {
99
ex.printStackTrace();
100
throw new RuntimeException("Unexpected failure");
101
}
102
if (!isAlwaysOnTop1 || isAlwaysOnTop2) {
103
throw new RuntimeException("Malicious applet can show always-on-top " +
104
"popup menu which has whole screen size");
105
}
106
System.out.println("Test passed");
107
}
108
109
private void stopEDT() {
110
SwingUtilities.invokeLater(new Runnable() {
111
public void run() {
112
frame.dispose();
113
}
114
});
115
}
116
}
117
118