Skip to content

Commit 49681f2

Browse files
committed
8239827: The test OpenByUNCPathNameTest.java should be changed to be manual
Backport-of: 7cc3ba5
1 parent 611d729 commit 49681f2

File tree

2 files changed

+131
-52
lines changed

2 files changed

+131
-52
lines changed

test/jdk/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114

115115
# jdk_awt
116116

117-
java/awt/Desktop/OpenByUNCPathNameTest/OpenByUNCPathNameTest.java 8239827 windows-all
118117
java/awt/event/MouseEvent/MouseClickTest/MouseClickTest.java 8168389 windows-all,macosx-all
119118
java/awt/event/KeyEvent/SwallowKeyEvents/SwallowKeyEvents.java 8224055 macosx-all
120119
java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowBlockingTest.java 8168408 windows-all,macosx-all
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,78 +27,158 @@
2727
@requires (os.family == "windows")
2828
@summary java.awt.Desktop cannot open file with Windows UNC filename
2929
@author Anton Litvinov
30+
@run main/manual OpenByUNCPathNameTest
3031
*/
3132

32-
import java.awt.*;
33-
import java.awt.event.*;
34-
import java.io.*;
33+
import javax.swing.JButton;
34+
import javax.swing.JFrame;
35+
import javax.swing.JPanel;
36+
import javax.swing.JTextArea;
37+
import javax.swing.SwingUtilities;
38+
import javax.swing.WindowConstants;
39+
import java.awt.BorderLayout;
40+
import java.awt.Desktop;
41+
import java.awt.FlowLayout;
42+
import java.io.IOException;
43+
import java.io.File;
44+
import java.util.concurrent.CountDownLatch;
45+
import java.util.concurrent.TimeUnit;
3546

3647
public class OpenByUNCPathNameTest {
48+
private static volatile CountDownLatch countDownLatch;
49+
private static JFrame instructionFrame;
50+
private static JFrame testFrame;
51+
private static volatile boolean testPassed = false;
52+
private static File file;
53+
3754
private static boolean validatePlatform() {
3855
String osName = System.getProperty("os.name");
3956
if (osName == null) {
40-
throw new RuntimeException("Name of the current OS could not be retrieved.");
57+
throw new RuntimeException("Name of the current OS could not be" +
58+
" retrieved.");
4159
}
4260
return osName.startsWith("Windows");
4361
}
4462

63+
private static void createInstructionUI() {
64+
SwingUtilities.invokeLater(() -> {
65+
String instructions =
66+
"1. Make sure that disk C is shared \n"
67+
+ "2. Click on openFileByLocalPath Button to test Test"
68+
+ " opening of the file with Windows local file path\n"
69+
+ "3. Check that the file is opened successfully\n"
70+
+ "4. Close the file\n"
71+
+ "5. Click on openFileByUNCPath Button to test Test"
72+
+ " opening of the file with Windows UNC pathname\n"
73+
+ "6. Check that the file is opened successfully\n"
74+
+ "7. Close the file\n"
75+
+ "8. If all the conditions are met then press PASS else "
76+
+ "press FAIL";
77+
instructionFrame = new JFrame("InstructionFrame");
78+
JTextArea textArea = new JTextArea(instructions);
79+
textArea.setEditable(false);
80+
final JButton passButton = new JButton("PASS");
81+
passButton.addActionListener((e) -> {
82+
testPassed = true;
83+
instructionFrame.dispose();
84+
testFrame.dispose();
85+
file.delete();
86+
countDownLatch.countDown();
87+
});
88+
final JButton failButton = new JButton("FAIL");
89+
failButton.addActionListener((e) -> {
90+
instructionFrame.dispose();
91+
testFrame.dispose();
92+
file.delete();
93+
countDownLatch.countDown();
94+
});
95+
96+
97+
JPanel mainPanel = new JPanel(new BorderLayout());
98+
mainPanel.add(textArea, BorderLayout.CENTER);
99+
100+
JPanel buttonPanel = new JPanel(new FlowLayout());
101+
buttonPanel.add(passButton);
102+
buttonPanel.add(failButton);
103+
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
104+
instructionFrame.setDefaultCloseOperation(
105+
WindowConstants.DISPOSE_ON_CLOSE);
106+
instructionFrame.setBounds(0,0,500,500);
107+
instructionFrame.add(mainPanel);
108+
instructionFrame.pack();
109+
instructionFrame.setVisible(true);
110+
});
111+
}
112+
45113
private static void openFile() throws IOException {
46114
if (!Desktop.isDesktopSupported()) {
47-
System.out.println("java.awt.Desktop is not supported on this platform.");
48-
} else {
49-
Desktop desktop = Desktop.getDesktop();
50-
if (!desktop.isSupported(Desktop.Action.OPEN)) {
51-
System.out.println("Action.OPEN is not supported on this platform.");
52-
return;
53-
}
54-
File file = File.createTempFile("Read Me File", ".txt");
115+
System.out.println("java.awt.Desktop is not supported on this"+
116+
" platform.");
117+
return;
118+
}
119+
120+
Desktop desktop = Desktop.getDesktop();
121+
if (!desktop.isSupported(Desktop.Action.OPEN)) {
122+
System.out.println("Action.OPEN is not supported on this" +
123+
" platform.");
124+
return;
125+
}
126+
file = File.createTempFile("Read Me File", ".txt");
127+
testFrame = new JFrame("Test Frame");
128+
JPanel testButtonPanel = new JPanel(new FlowLayout());
129+
final JButton openFileByLocalPathButton = new
130+
JButton("OpenFileByLocalPath");
131+
final JButton openFileByUNCPathButton = new
132+
JButton("OpenFileByUNCPath");
133+
openFileByLocalPathButton.addActionListener((e) -> {
55134
try {
56-
// Test opening of the file with Windows local file path.
57135
desktop.open(file);
58-
Robot robot = null;
59-
try {
60-
Thread.sleep(5000);
61-
robot = new Robot();
62-
} catch (Exception e) {
63-
e.printStackTrace();
64-
}
65-
pressAltF4Keys(robot);
66-
67-
// Test opening of the file with Windows UNC pathname.
68-
String uncFilePath = "\\\\127.0.0.1\\" + file.getAbsolutePath().replace(':', '$');
69-
File uncFile = new File(uncFilePath);
70-
if (!uncFile.exists()) {
71-
throw new RuntimeException(String.format(
72-
"File with UNC pathname '%s' does not exist.", uncFilePath));
73-
}
74-
desktop.open(uncFile);
75-
try {
76-
Thread.sleep(5000);
77-
} catch (InterruptedException ie) {
78-
ie.printStackTrace();
79-
}
80-
pressAltF4Keys(robot);
81-
} finally {
82-
file.delete();
136+
} catch (IOException ioException) {
83137
}
84-
}
85-
}
138+
});
139+
140+
SwingUtilities.invokeLater(()->{
141+
testButtonPanel.add(openFileByLocalPathButton);
142+
testButtonPanel.add(openFileByUNCPathButton);
143+
testFrame.setDefaultCloseOperation(
144+
WindowConstants.DISPOSE_ON_CLOSE);
145+
testFrame.setBounds(600,0,1000,200);
146+
testFrame.add(testButtonPanel);
147+
testFrame.pack();
148+
testFrame.setVisible(true);
149+
});
86150

87-
private static void pressAltF4Keys(Robot robot) {
88-
if (robot != null) {
89-
robot.keyPress(KeyEvent.VK_ALT);
90-
robot.keyPress(KeyEvent.VK_F4);
91-
robot.delay(50);
92-
robot.keyRelease(KeyEvent.VK_F4);
93-
robot.keyRelease(KeyEvent.VK_ALT);
151+
// Test opening of the file with Windows UNC pathname.
152+
String uncFilePath = "\\\\127.0.0.1\\" +
153+
file.getAbsolutePath().replace(':', '$');
154+
File uncFile = new File(uncFilePath);
155+
if (!uncFile.exists()) {
156+
throw new RuntimeException(String.format("File "+
157+
"with UNC pathname '%s' does not exist.", uncFilePath));
94158
}
159+
openFileByUNCPathButton.addActionListener((e) -> {
160+
try {
161+
desktop.open(uncFile);
162+
} catch (IOException ioException) {
163+
}
164+
});
95165
}
96166

97-
public static void main(String[] args) throws IOException {
167+
public static void main(String[] args) throws Exception {
98168
if (!validatePlatform()) {
99169
System.out.println("This test is only for MS Windows OS.");
100-
} else {
101-
openFile();
170+
return;
171+
}
172+
countDownLatch = new CountDownLatch(1);
173+
OpenByUNCPathNameTest openByUNCPathNameTest =
174+
new OpenByUNCPathNameTest();
175+
176+
openByUNCPathNameTest.createInstructionUI();
177+
openByUNCPathNameTest.openFile();
178+
countDownLatch.await(15, TimeUnit.MINUTES);
179+
180+
if(!testPassed) {
181+
throw new RuntimeException("Test failed!");
102182
}
103183
}
104184
}

0 commit comments

Comments
 (0)