--- /dev/null 2015-11-25 10:20:59.000000000 +0530 +++ new/test/java/awt/FileDialog/8019280/ValidateDirectorySelection.java 2015-11-25 10:20:59.000000000 +0530 @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2015, 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 8019280 + * @summary CFileDialog should show Choose for Mac OS X for Directory selection + * @requires (os.family=="mac") + * @run main/manual ValidateDirectorySelection + */ +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ValidateDirectorySelection { + + private static Frame frame; + private static FileDialog chooser; + private static TextArea textArea; + private static Button openCFileDialogButton; + private static Button passButton; + private static Button failButton; + private static boolean theTestPassed; + private static boolean testGeneratedInterrupt; + private static Thread mainThread; + private static final int sleepTime = 300000; + + public static void main(String[] args) throws Exception { + mainThread = Thread.currentThread(); + try { + createUIandManualTest(); + mainThread.sleep(sleepTime); + } catch (InterruptedException ex) { + cleanUp(); + if (!theTestPassed && testGeneratedInterrupt) { + throw new RuntimeException("Test Failed"); + } + } catch (Exception ex) { + cleanUp(); + Logger.getLogger(ValidateDirectorySelection.class.getName()) + .log(Level.SEVERE, null, ex); + return; + } + if (!testGeneratedInterrupt) { + cleanUp(); + throw new RuntimeException("Test Timed out"); + } + } + + public static synchronized void pass() { + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + public static synchronized void fail() { + theTestPassed = false; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + private static void createUIandManualTest() throws Exception { + frame = new Frame("Validate for directory selection only"); + frame.setLayout(new GridBagLayout()); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + try { + cleanUp(); + } catch (Exception ex) { + Logger.getLogger(ValidateDirectorySelection.class.getName()) + .log(Level.SEVERE, null, ex); + } + } + }); + String instructions = "\n(1) Press Directory Dialog button." + + "\n(2) Find a button labeled Choose." + + "\n(3) Make due note of the availability of the Choose button" + + "\n(4) This is expected behavior for Directory chooser in Mac" + + "\n\nIf the Choose button is validated, press Pass button." + + "\nOtherwise, press Fail button. \n"; + textArea = new TextArea(); + textArea.setText(instructions); + openCFileDialogButton = new Button(" Directory Dialog "); + openCFileDialogButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.setProperty("apple.awt.fileDialogForDirectories", + "true"); + chooser = new FileDialog(frame, "Select Target Folder"); + chooser.setVisible(true); + } + }); + passButton = new Button(" Pass "); + passButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ValidateDirectorySelection.pass(); + } + }); + failButton = new Button(" Fail "); + failButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ValidateDirectorySelection.fail(); + } + }); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 0; + frame.add(textArea, gbc); + Panel buttonPanel = new Panel(); + gbc.gridx = 0; + gbc.gridy = 0; + buttonPanel.add(openCFileDialogButton, gbc); + gbc.gridx = 1; + gbc.gridy = 0; + buttonPanel.add(passButton, gbc); + gbc.gridx = 2; + gbc.gridy = 0; + buttonPanel.add(failButton, gbc); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.gridx = 0; + gbc.gridy = 1; + frame.add(buttonPanel, gbc); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private static void cleanUp() { + if (frame != null) { + frame.dispose(); + } + } +}