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