Path: blob/master/test/jdk/java/awt/FileDialog/MoveToTrashTest.java
41149 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@key headful26@bug 8190515 819346827@summary java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac.28@run main MoveToTrashTest29*/3031import java.io.File;32import java.awt.Desktop;33import java.awt.Robot;34import java.io.IOException;35import java.awt.AWTException;3637public class MoveToTrashTest {38private static File file = null;39private static boolean fileStatus = false;4041public static void main(String[] args) {42if (!Desktop.getDesktop().isSupported(Desktop.Action.MOVE_TO_TRASH)) {43System.out.println("Move to trash action is not supported on the"+44" platform under test. Marking the test passed");45} else {46try {47file = File.createTempFile("TestFile","txt");48} catch (IOException ex) {49throw new RuntimeException("Test failed. Exception thrown: ", ex);50}5152// In case any UI that may pop up while deleting the file would53// block this thread until the user actions them. Hence do file54// check in a different thread and we assume it takes about sometime55// till it deletes the file(or popup) on the main thread.56new Thread(null, MoveToTrashTest::checkFileExistence, "FileCheck", 0, false).start();57fileStatus = Desktop.getDesktop().moveToTrash(file);58}59}6061private static void checkFileExistence() {62Robot robot = null;63try {64robot = new Robot();65} catch (AWTException ex) {66throw new RuntimeException("Test failed. Exception thrown: ", ex);67}6869robot.delay(1500);7071if (!fileStatus) {72throw new RuntimeException("Test failed due to error while deleting the file");73} else {74if (file.exists()) {75throw new RuntimeException("Test failed");76} else {77System.out.println("Test passed");78}79}80}81}82838485