test/jdk/java/awt/FileDialog/MoveToTrashTest.java
author sveerabhadra
Wed, 03 Jan 2018 15:37:35 +0530
changeset 48426 c08f1067ef57
parent 48287 e53948132278
child 49090 82c1fe23c469
permissions -rw-r--r--
8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux Reviewed-by: aghaisas, serb
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
48426
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    26
  @bug 8190515 8193468
48287
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    27
  @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
    28
  @run main MoveToTrashTest
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    29
*/
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
import java.io.File;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    32
import java.awt.Desktop;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    33
import java.awt.Robot;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    34
import java.io.IOException;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    35
import java.awt.AWTException;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    36
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    37
public class MoveToTrashTest {
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    38
    private static File file = null;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    39
    private static boolean fileStatus = false;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    40
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    41
    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
    42
        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
    43
            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
    44
               " 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
    45
        } else {
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    46
            try {
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    47
                file = File.createTempFile("TestFile","txt");
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    48
            } catch (IOException ex) {
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    49
                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
    50
            }
48287
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    51
48426
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    52
            // 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
    53
            // 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
    54
            // 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
    55
            // 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
    56
            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
    57
            fileStatus = Desktop.getDesktop().moveToTrash(file);
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    58
        }
48287
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    59
    }
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
    private static void checkFileExistence() {
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    62
        Robot robot = null;
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    63
        try {
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    64
            robot = new Robot();
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    65
        } catch (AWTException ex) {
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    66
            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
    67
        }
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
        robot.delay(1500);
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    70
48426
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    71
        if (!fileStatus) {
48287
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    72
            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
    73
        } else {
48426
c08f1067ef57 8193468: [PIT][TEST BUG]: java/awt/FileDialog/MoveToTrashTest.java fails on Linux
sveerabhadra
parents: 48287
diff changeset
    74
            if (file.exists()) {
48287
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    75
                throw new RuntimeException("Test failed");
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    76
            } else {
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    77
                System.out.println("Test passed");
e53948132278 8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
diff changeset
    78
            }
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