Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/List/FirstItemRemoveTest/FirstItemRemoveTest.java
41153 views
1
/*
2
* Copyright (c) 2013, 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 6299858
28
@summary PIT. Focused border not shown on List if selected item is removed, XToolkit
29
@library /test/lib
30
@build jdk.test.lib.Platform
31
@run main FirstItemRemoveTest
32
*/
33
34
import jdk.test.lib.Platform;
35
36
import java.awt.*;
37
import java.awt.event.*;
38
39
public class FirstItemRemoveTest extends Frame
40
{
41
List list = new List(4, false);
42
Panel panel = new Panel();
43
44
public static void main(final String[] args) {
45
FirstItemRemoveTest app = new FirstItemRemoveTest();
46
app.init();
47
app.start();
48
}
49
50
public void init()
51
{
52
list.add("000");
53
list.add("111");
54
list.add("222");
55
list.add("333");
56
list.add("444");
57
list.add("555");
58
59
panel.setLayout(new FlowLayout ());
60
panel.add(list);
61
62
this.add(panel);
63
this.setLayout (new FlowLayout ());
64
}//End init()
65
66
public void start ()
67
{
68
setSize (200,200);
69
setUndecorated(true);
70
setLocationRelativeTo(null);
71
setVisible(true);
72
validate();
73
74
test();
75
}// start()
76
77
private void test(){
78
79
if (Platform.isOSX()) {
80
System.err.println("Skipped. This test is not for OS X.");
81
return;
82
}
83
84
Robot r;
85
try {
86
r = new Robot();
87
} catch(AWTException e) {
88
throw new RuntimeException(e.getMessage());
89
}
90
91
// Removing first item in order to reproduce incorrect behaviour
92
r.delay(1000);
93
list.remove(0);
94
r.delay(1000);
95
96
// Request focus to list
97
Point loc = this.getLocationOnScreen();
98
r.delay(1000);
99
100
r.mouseMove(loc.x+10, loc.y+10);
101
r.delay(10);
102
r.mousePress(InputEvent.BUTTON1_MASK);
103
r.delay(10);
104
r.mouseRelease(InputEvent.BUTTON1_MASK);
105
r.delay(1000);
106
107
list.requestFocusInWindow();
108
r.delay(1000);
109
r.waitForIdle();
110
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list){
111
throw new RuntimeException("Test failed - list isn't focus owner.");
112
}
113
114
// The focus index should be set to first item after removing
115
// So if we press VK_SPACE then the selected item will be equals 0.
116
r.delay(100);
117
r.keyPress(KeyEvent.VK_SPACE);
118
r.delay(10);
119
r.keyRelease(KeyEvent.VK_SPACE);
120
r.delay(1000);
121
r.waitForIdle();
122
123
int selectedIndex = list.getSelectedIndex();
124
if (selectedIndex != 0){
125
throw new RuntimeException("Test failed. list.getSelectedIndex() = "+selectedIndex);
126
}
127
128
}
129
130
}// class AutomaticAppletTest
131
132