| Index: chrome/test/data/extensions/api_test/file_system_provider/delete_entry/test.js
|
| diff --git a/chrome/test/data/extensions/api_test/file_system_provider/create_directory/test.js b/chrome/test/data/extensions/api_test/file_system_provider/delete_entry/test.js
|
| similarity index 56%
|
| copy from chrome/test/data/extensions/api_test/file_system_provider/create_directory/test.js
|
| copy to chrome/test/data/extensions/api_test/file_system_provider/delete_entry/test.js
|
| index f82117e69fa0a4a988fa7d19dec12b2587c04b7a..687e8453f0193b13e27a006f3105a09de28f294b 100644
|
| --- a/chrome/test/data/extensions/api_test/file_system_provider/create_directory/test.js
|
| +++ b/chrome/test/data/extensions/api_test/file_system_provider/delete_entry/test.js
|
| @@ -10,11 +10,6 @@
|
| var fileSystem = null;
|
|
|
| /**
|
| - * @type {Array.<string>}
|
| - */
|
| -var createdDirectories = [];
|
| -
|
| -/**
|
| * @type {string}
|
| * @const
|
| */
|
| @@ -35,13 +30,34 @@ var TESTING_ROOT = Object.freeze({
|
| * @type {Object}
|
| * @const
|
| */
|
| -var TESTING_DIRECTORY = Object.freeze({
|
| - isDirectory: false,
|
| - name: 'kitty',
|
| +var TESTING_A_DIRECTORY = Object.freeze({
|
| + isDirectory: true,
|
| + name: 'a',
|
| size: 0,
|
| modificationTime: new Date(2014, 4, 28, 10, 39, 15)
|
| });
|
|
|
| +/**
|
| + * @type {Object}
|
| + * @const
|
| + */
|
| +var TESTING_B_DIRECTORY = Object.freeze({
|
| + isDirectory: true,
|
| + name: 'b',
|
| + size: 0,
|
| + modificationTime: new Date(2014, 4, 28, 10, 39, 15)
|
| +});
|
| +
|
| +/**
|
| + * @type {Object}
|
| + * @const
|
| + */
|
| +var TESTING_C_FILE = Object.freeze({
|
| + isDirectory: false,
|
| + name: 'c',
|
| + size: 0,
|
| + modificationTime: new Date(2014, 4, 28, 10, 39, 15)
|
| +});
|
|
|
| /**
|
| * Gets volume information for the provided file system.
|
| @@ -82,9 +98,18 @@ function onGetMetadataRequested(options, onSuccess, onError) {
|
| return;
|
| }
|
|
|
| - // For every created directory, return the same metadata (for simplicity).
|
| - if (options.entryPath in createdDirectories) {
|
| - onSuccess(TESTING_DIRECTORY);
|
| + if (options.entryPath == '/' + TESTING_A_DIRECTORY.name) {
|
| + onSuccess(TESTING_A_DIRECTORY);
|
| + return;
|
| + }
|
| +
|
| + if (options.entryPath == '/' + TESTING_A_DIRECTORY.name +
|
| + '/' + TESTING_B_DIRECTORY.name) {
|
| + onSuccess(TESTING_B_DIRECTORY);
|
| + return;
|
| + }
|
| + if (options.entryPath == '/' + TESTING_C_FILE.name) {
|
| + onSuccess(TESTING_C_FILE);
|
| return;
|
| }
|
|
|
| @@ -92,31 +117,39 @@ function onGetMetadataRequested(options, onSuccess, onError) {
|
| }
|
|
|
| /**
|
| - * Creates a directory.
|
| + * Deletes an entry.
|
| *
|
| - * @param {CreateDirectoryRequestedOptions} options Options.
|
| + * @param {DeleteEntryRequestedOptions} options Options.
|
| * @param {function(Object)} onSuccess Success callback
|
| * @param {function(string)} onError Error callback with an error code.
|
| */
|
| -function onCreateDirectoryRequested(options, onSuccess, onError) {
|
| +function onDeleteEntryRequested(options, onSuccess, onError) {
|
| if (options.fileSystemId != FILE_SYSTEM_ID) {
|
| onError('SECURITY'); // enum ProviderError.
|
| return;
|
| }
|
|
|
| - if (options.directoryPath == '/' || options.recursive) {
|
| + if (options.entryPath == '/') {
|
| onError('INVALID_OPERATION');
|
| return;
|
| }
|
|
|
| - if (options.exclusive && (createdDirectories.indexOf(
|
| - options.directoryPath) != -1)) {
|
| - onError('EXISTS');
|
| + if (options.entryPath == '/' + TESTING_A_DIRECTORY.name) {
|
| + if (options.recursive)
|
| + onSuccess();
|
| + else
|
| + onError('INVALID_OPERATION');
|
| return;
|
| }
|
|
|
| - createdDirectories.push(options.directoryPath);
|
| - onSuccess(); // enum ProviderError.
|
| + if (options.entryPath == '/' + TESTING_C_FILE.name ||
|
| + options.entryPath == '/' + TESTING_A_DIRECTORY.name + '/' +
|
| + TESTING_B_DIRECTORY.name) {
|
| + onSuccess();
|
| + return;
|
| + }
|
| +
|
| + onError('NOT_FOUND'); // enum ProviderError.
|
| }
|
|
|
| /**
|
| @@ -131,8 +164,8 @@ function setUp(callback) {
|
| function() {
|
| chrome.fileSystemProvider.onGetMetadataRequested.addListener(
|
| onGetMetadataRequested);
|
| - chrome.fileSystemProvider.onCreateDirectoryRequested.addListener(
|
| - onCreateDirectoryRequested);
|
| + chrome.fileSystemProvider.onDeleteEntryRequested.addListener(
|
| + onDeleteEntryRequested);
|
|
|
| getVolumeInfo(FILE_SYSTEM_ID, function(volumeInfo) {
|
| chrome.test.assertTrue(!!volumeInfo);
|
| @@ -147,7 +180,7 @@ function setUp(callback) {
|
| });
|
| },
|
| function() {
|
| - chrome.test.fail('Failed to mount a file system.');
|
| + chrome.test.fail();
|
| });
|
| }
|
|
|
| @@ -156,32 +189,51 @@ function setUp(callback) {
|
| */
|
| function runTests() {
|
| chrome.test.runTests([
|
| - // Create a directory (not exclusive). Should succeed.
|
| - function createDirectorySuccessSimple() {
|
| + // Delete a file. Should succeed.
|
| + function deleteDirectorySuccessSimple() {
|
| + var onSuccess = chrome.test.callbackPass();
|
| + fileSystem.root.getFile(
|
| + TESTING_C_FILE.name, {create: false},
|
| + function(entry) {
|
| + chrome.test.assertEq(TESTING_C_FILE.name, entry.name);
|
| + chrome.test.assertFalse(entry.isDirectory);
|
| + entry.remove(onSuccess, function(error) {
|
| + chrome.test.fail(error.name);
|
| + });
|
| + }, function(error) {
|
| + chrome.test.fail(error.name);
|
| + });
|
| + },
|
| + // Delete a directory which has contents, non-recursively. Should fail.
|
| + function deleteDirectoryErrorNotEmpty() {
|
| var onSuccess = chrome.test.callbackPass();
|
| fileSystem.root.getDirectory(
|
| - TESTING_DIRECTORY.name, {create: true, exclusive: false},
|
| + TESTING_A_DIRECTORY.name, {create: false},
|
| function(entry) {
|
| - chrome.test.assertEq(TESTING_DIRECTORY.name, entry.name);
|
| + chrome.test.assertEq(TESTING_A_DIRECTORY.name, entry.name);
|
| chrome.test.assertTrue(entry.isDirectory);
|
| - onSuccess();
|
| + entry.remove(function() {
|
| + chrome.test.fail('Unexpectedly succeded to remove a directory.');
|
| + }, onSuccess);
|
| }, function(error) {
|
| chrome.test.fail(error.name);
|
| });
|
| },
|
| - // Create a directory (exclusive). Should fail, since the directory already
|
| - // exists.
|
| - function createDirectoryErrorExists() {
|
| + // Delete a directory which has contents, recursively. Should succeed.
|
| + function deleteDirectoryRecursively() {
|
| var onSuccess = chrome.test.callbackPass();
|
| fileSystem.root.getDirectory(
|
| - TESTING_DIRECTORY.name, {create: true, exclusive: true},
|
| + TESTING_A_DIRECTORY.name, {create: false},
|
| function(entry) {
|
| - chrome.test.fail('Created a directory, but should fail.');
|
| + chrome.test.assertEq(TESTING_A_DIRECTORY.name, entry.name);
|
| + chrome.test.assertTrue(entry.isDirectory);
|
| + entry.removeRecursively(onSuccess, function(error) {
|
| + chrome.test.fail(error);
|
| + });
|
| }, function(error) {
|
| - chrome.test.assertEq('InvalidModificationError', error.name);
|
| - onSuccess();
|
| + chrome.test.fail(error.name);
|
| });
|
| - },
|
| + }
|
| ]);
|
| }
|
|
|
|
|