6988188: The test failed due to Applet thread threw exception
authorrupashka
Tue, 30 Nov 2010 10:35:55 +0300
changeset 7265 1a663d3536b6
parent 7264 57b1b85c8cb9
child 7266 4aa488565add
child 7500 dec4b445efc6
6988188: The test failed due to Applet thread threw exception Reviewed-by: alexp
jdk/test/javax/swing/JFileChooser/4150029/bug4150029.html
jdk/test/javax/swing/JFileChooser/4150029/bug4150029.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFileChooser/4150029/bug4150029.html	Tue Nov 30 10:35:55 2010 +0300
@@ -0,0 +1,9 @@
+<html>
+<body>
+<applet  code="bug4150029.class" width=200 height=200></applet>
+1.Go into 'subDir' folder.
+2.Press BACKSPACE key.
+3.Push OPEN button.
+4.Push DONE button.
+</body>
+</html> 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFileChooser/4150029/bug4150029.java	Tue Nov 30 10:35:55 2010 +0300
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+   @bug 4150029
+   @summary BackSpace keyboard button does not lead to parent directory
+   @author Oleg Mokhovikov
+   @run applet/manual=done bug4150029.html
+*/
+
+import javax.swing.*;
+import java.io.File;
+import java.io.IOException;
+
+public class bug4150029 extends JApplet {
+    private boolean res;
+
+    public void init() {
+        String tmpDir = System.getProperty("java.io.tmpdir");
+
+        if (tmpDir.length() == 0) {//'java.io.tmpdir' isn't guaranteed to be defined
+            tmpDir = System.getProperty("user.home");
+        }
+
+        System.out.println("Temp directory: " + tmpDir);
+
+        File testDir = new File(tmpDir, "testDir");
+
+        testDir.mkdir();
+
+        File subDir = new File(testDir, "subDir");
+
+        subDir.mkdir();
+
+        System.out.println("Created directory: " + testDir);
+        System.out.println("Created sub-directory: " + subDir);
+
+        JFileChooser fileChooser = new JFileChooser(testDir);
+
+        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+
+        try {
+            res = fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION ||
+                    testDir.getCanonicalPath().equals(fileChooser.getSelectedFile().getCanonicalPath());
+        } catch (IOException e) {
+            res = false;
+
+            e.printStackTrace();
+        }
+
+        try {
+            subDir.delete();
+            testDir.delete();
+        } catch (SecurityException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void destroy() {
+        if (!res) {
+            throw new RuntimeException("BackSpace keyboard button does not lead to parent directory");
+        }
+    }
+}