1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 var TESTING_A_DIRECTORY = Object.freeze({
15 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
22 var TESTING_B_DIRECTORY = Object.freeze({
26 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
33 var TESTING_C_FILE = Object.freeze({
37 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
43 * @param {DeleteEntryRequestedOptions} options Options.
44 * @param {function(Object)} onSuccess Success callback
45 * @param {function(string)} onError Error callback with an error code.
47 function onDeleteEntryRequested(options, onSuccess, onError) {
48 if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
49 onError('SECURITY'); // enum ProviderError.
53 if (options.entryPath == '/') {
54 onError('INVALID_OPERATION');
58 if (options.entryPath == '/' + TESTING_A_DIRECTORY.name) {
59 if (options.recursive)
62 onError('INVALID_OPERATION');
66 if (options.entryPath == '/' + TESTING_C_FILE.name ||
67 options.entryPath == '/' + TESTING_A_DIRECTORY.name + '/' +
68 TESTING_B_DIRECTORY.name) {
73 onError('NOT_FOUND'); // enum ProviderError.
77 * Sets up the tests. Called once per all test cases. In case of a failure,
78 * the callback is not called.
80 * @param {function()} callback Success callback.
82 function setUp(callback) {
83 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
84 test_util.onGetMetadataRequestedDefault);
86 test_util.defaultMetadata['/' + TESTING_A_DIRECTORY.name] =
88 test_util.defaultMetadata['/' + TESTING_A_DIRECTORY.name + '/' +
89 TESTING_B_DIRECTORY.name] = TESTING_B_DIRECTORY;
90 test_util.defaultMetadata['/' + TESTING_C_FILE.name] =
93 chrome.fileSystemProvider.onDeleteEntryRequested.addListener(
94 onDeleteEntryRequested);
96 test_util.mountFileSystem(callback);
100 * Runs all of the test cases, one by one.
102 function runTests() {
103 chrome.test.runTests([
104 // Delete a file. Should succeed.
105 function deleteDirectorySuccessSimple() {
106 test_util.fileSystem.root.getFile(
107 TESTING_C_FILE.name, {create: false},
108 chrome.test.callbackPass(function(entry) {
109 chrome.test.assertEq(TESTING_C_FILE.name, entry.name);
110 chrome.test.assertFalse(entry.isDirectory);
111 entry.remove(chrome.test.callbackPass(), function(error) {
112 chrome.test.fail(error.name);
114 }), function(error) {
115 chrome.test.fail(error.name);
118 // Delete a directory which has contents, non-recursively. Should fail.
119 function deleteDirectoryErrorNotEmpty() {
120 test_util.fileSystem.root.getDirectory(
121 TESTING_A_DIRECTORY.name, {create: false},
122 chrome.test.callbackPass(function(entry) {
123 chrome.test.assertEq(TESTING_A_DIRECTORY.name, entry.name);
124 chrome.test.assertTrue(entry.isDirectory);
125 entry.remove(function() {
126 chrome.test.fail('Unexpectedly succeded to remove a directory.');
127 }, chrome.test.callbackPass);
128 }), function(error) {
129 chrome.test.fail(error.name);
132 // Delete a directory which has contents, recursively. Should succeed.
133 function deleteDirectoryRecursively() {
134 test_util.fileSystem.root.getDirectory(
135 TESTING_A_DIRECTORY.name, {create: false},
136 chrome.test.callbackPass(function(entry) {
137 chrome.test.assertEq(TESTING_A_DIRECTORY.name, entry.name);
138 chrome.test.assertTrue(entry.isDirectory);
139 entry.removeRecursively(
140 chrome.test.callbackPass(),
142 chrome.test.fail(error);
144 }), function(error) {
145 chrome.test.fail(error.name);
151 // Setup and run all of the test cases.