Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/FileDialog/MoveToTrashTest.java
41149 views
1
/*
2
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
@test
26
@key headful
27
@bug 8190515 8193468
28
@summary java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac.
29
@run main MoveToTrashTest
30
*/
31
32
import java.io.File;
33
import java.awt.Desktop;
34
import java.awt.Robot;
35
import java.io.IOException;
36
import java.awt.AWTException;
37
38
public class MoveToTrashTest {
39
private static File file = null;
40
private static boolean fileStatus = false;
41
42
public static void main(String[] args) {
43
if (!Desktop.getDesktop().isSupported(Desktop.Action.MOVE_TO_TRASH)) {
44
System.out.println("Move to trash action is not supported on the"+
45
" platform under test. Marking the test passed");
46
} else {
47
try {
48
file = File.createTempFile("TestFile","txt");
49
} catch (IOException ex) {
50
throw new RuntimeException("Test failed. Exception thrown: ", ex);
51
}
52
53
// In case any UI that may pop up while deleting the file would
54
// block this thread until the user actions them. Hence do file
55
// check in a different thread and we assume it takes about sometime
56
// till it deletes the file(or popup) on the main thread.
57
new Thread(null, MoveToTrashTest::checkFileExistence, "FileCheck", 0, false).start();
58
fileStatus = Desktop.getDesktop().moveToTrash(file);
59
}
60
}
61
62
private static void checkFileExistence() {
63
Robot robot = null;
64
try {
65
robot = new Robot();
66
} catch (AWTException ex) {
67
throw new RuntimeException("Test failed. Exception thrown: ", ex);
68
}
69
70
robot.delay(1500);
71
72
if (!fileStatus) {
73
throw new RuntimeException("Test failed due to error while deleting the file");
74
} else {
75
if (file.exists()) {
76
throw new RuntimeException("Test failed");
77
} else {
78
System.out.println("Test passed");
79
}
80
}
81
}
82
}
83
84
85