author | juh |
Tue, 25 Jun 2013 14:41:46 -0700 | |
changeset 18552 | 005e115dc6ee |
parent 5958 | b0e23a175789 |
child 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
5958
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
1 |
/* |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
4 |
* |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
8 |
* |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
14 |
* |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
18 |
* |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
21 |
* questions. |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
22 |
*/ |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
23 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
24 |
/* |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
25 |
* @test |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
26 |
* @bug 6495920 |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
27 |
* @summary Tests that if the JPopupMenu.setVisible method throws an exception, |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
28 |
interaction with GNOME is not crippled |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
29 |
* @author Sergey Malenkov |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
30 |
* @library ../.. |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
31 |
*/ |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
32 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
33 |
import sun.awt.AppContext; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
34 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
35 |
import java.awt.Point; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
36 |
import java.awt.Robot; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
37 |
import java.awt.event.InputEvent; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
38 |
import java.lang.reflect.Field; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
39 |
import javax.swing.JFrame; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
40 |
import javax.swing.JMenuItem; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
41 |
import javax.swing.JPanel; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
42 |
import javax.swing.JPopupMenu; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
43 |
import javax.swing.SwingUtilities; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
44 |
import javax.swing.plaf.basic.BasicPopupMenuUI; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
45 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
46 |
public class bug6495920 implements Thread.UncaughtExceptionHandler { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
47 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
48 |
public static void main(String[] args) throws Throwable { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
49 |
SwingTest.start(bug6495920.class); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
50 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
51 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
52 |
private static Robot robot; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
53 |
private final JPanel panel; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
54 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
55 |
public bug6495920(JFrame frame) { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
56 |
JPopupMenu menu = new JPopupMenu() { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
57 |
public void setVisible(boolean visible) { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
58 |
super.setVisible(visible); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
59 |
throw new AssertionError(visible ? "show popup" : "hide popup"); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
60 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
61 |
}; |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
62 |
for (int i = 0; i < 10; i++) { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
63 |
menu.add(new JMenuItem(String.valueOf(i))); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
64 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
65 |
this.panel = new JPanel(); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
66 |
this.panel.setComponentPopupMenu(menu); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
67 |
frame.add(this.panel); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
68 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
69 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
70 |
public void firstShowPopup() throws Exception { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
71 |
Point point = this.panel.getLocation(); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
72 |
SwingUtilities.convertPointToScreen(point, this.panel); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
73 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
74 |
robot = new Robot(); // initialize shared static field first time |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
75 |
robot.mouseMove(point.x + 1, point.y + 1); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
76 |
robot.mousePress(InputEvent.BUTTON3_MASK); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
77 |
Thread.currentThread().setUncaughtExceptionHandler(this); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
78 |
robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
79 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
80 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
81 |
public void secondHidePopup() { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
82 |
Point point = this.panel.getLocation(); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
83 |
SwingUtilities.convertPointToScreen(point, this.panel); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
84 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
85 |
robot.mouseMove(point.x - 1, point.y - 1); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
86 |
Thread.currentThread().setUncaughtExceptionHandler(this); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
87 |
robot.mousePress(InputEvent.BUTTON1_MASK); // causes second AssertionError on EDT |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
88 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
89 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
90 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
91 |
public void thirdValidate() throws Exception { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
92 |
Field key = BasicPopupMenuUI.class.getDeclaredField("MOUSE_GRABBER_KEY"); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
93 |
key.setAccessible(true); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
94 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
95 |
Object grabber = AppContext.getAppContext().get(key.get(null)); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
96 |
if (grabber == null) { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
97 |
throw new Exception("cannot find a mouse grabber in app's context"); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
98 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
99 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
100 |
Field field = grabber.getClass().getDeclaredField("grabbedWindow"); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
101 |
field.setAccessible(true); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
102 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
103 |
Object window = field.get(grabber); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
104 |
if (window != null) { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
105 |
throw new Exception("interaction with GNOME is crippled"); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
106 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
107 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
108 |
|
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
109 |
public void uncaughtException(Thread thread, Throwable throwable) { |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
110 |
System.out.println(throwable); |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
111 |
} |
b0e23a175789
6894597: test/closed/javax/swing/JPopupMenu/6495920/bug6495920.java fails
malenkov
parents:
diff
changeset
|
112 |
} |