6997102: Test case has hard code, so that applet thread threw exception
authorrupashka
Fri, 18 Feb 2011 20:09:35 +0300
changeset 8381 13cb9caa1601
parent 8380 9b9f901a909d
child 8382 0d231bdb78cf
child 8519 ce545cf57630
6997102: Test case has hard code, so that applet thread threw exception Reviewed-by: alexp
jdk/test/javax/swing/JFileChooser/6798062/bug6798062.html
jdk/test/javax/swing/JFileChooser/6798062/bug6798062.java
--- a/jdk/test/javax/swing/JFileChooser/6798062/bug6798062.html	Fri Feb 18 19:21:57 2011 +0300
+++ b/jdk/test/javax/swing/JFileChooser/6798062/bug6798062.html	Fri Feb 18 20:09:35 2011 +0300
@@ -1,6 +1,8 @@
 <html>
 <body>
 <applet  code="bug6798062.class" width=400 height=300></applet>
+The test is suitable only for Windows
+
 1. Create a link
 2. Copy path to the link into TextField
 3. Run the Windows Task Manager. Select the Processes tab and find the java process
--- a/jdk/test/javax/swing/JFileChooser/6798062/bug6798062.java	Fri Feb 18 19:21:57 2011 +0300
+++ b/jdk/test/javax/swing/JFileChooser/6798062/bug6798062.java	Fri Feb 18 20:09:35 2011 +0300
@@ -28,6 +28,7 @@
    @run applet/manual=done bug6798062.html
 */
 
+import sun.awt.OSInfo;
 import sun.awt.shell.ShellFolder;
 
 import javax.swing.*;
@@ -68,13 +69,23 @@
         add(initialize());
     }
 
-    private JPanel initialize() {
-        File file = new File("c:/");
+    private JComponent initialize() {
+        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
+            return new JLabel("The test is suitable only for Windows");
+        }
+
+        String tempDir = System.getProperty("java.io.tmpdir");
+
+        if (tempDir.length() == 0) { // 'java.io.tmpdir' isn't guaranteed to be defined
+            tempDir = System.getProperty("user.home");
+        }
+
+        System.out.println("Temp directory: " + tempDir);
 
         try {
-            folder = ShellFolder.getShellFolder(file);
+            folder = ShellFolder.getShellFolder(new File(tempDir));
         } catch (FileNotFoundException e) {
-            fail("Directory " + file.getPath() + " not found");
+            fail("Directory " + tempDir + " not found");
         }
 
         slider.setMajorTickSpacing(10);