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_FILE = Object.freeze({
15 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
22 var TESTING_ANOTHER_FILE = Object.freeze({
26 modificationTime: new Date(2014, 4, 28, 9, 38, 14)
33 var TESTING_NEW_FILE_NAME = 'puppy.txt';
36 * Moves an entry within the same file system.
38 * @param {MoveEntryRequestedOptions} options Options.
39 * @param {function(Object)} onSuccess Success callback
40 * @param {function(string)} onError Error callback with an error code.
42 function onMoveEntryRequested(options, onSuccess, onError) {
43 if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
44 onError('SECURITY'); // enum ProviderError.
48 if (options.sourcePath == '/') {
49 onError('INVALID_OPERATION');
53 if (!(options.sourcePath in test_util.defaultMetadata)) {
58 if (options.targetPath in test_util.defaultMetadata) {
63 // Move the metadata with changing the 'name' field.
65 JSON.parse(JSON.stringify(test_util.defaultMetadata[options.sourcePath]));
66 newMetadata.name = options.targetPath.split('/').pop();
67 test_util.defaultMetadata[options.targetPath] = newMetadata;
69 // Remove the source file.
70 delete test_util.defaultMetadata[options.sourcePath];
72 onSuccess(); // enum ProviderError.
76 * Sets up the tests. Called once per all test cases. In case of a failure,
77 * the callback is not called.
79 * @param {function()} callback Success callback.
81 function setUp(callback) {
82 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
83 test_util.onGetMetadataRequestedDefault);
85 test_util.defaultMetadata['/' + TESTING_FILE.name] = TESTING_FILE;
86 test_util.defaultMetadata['/' + TESTING_ANOTHER_FILE.name] =
89 chrome.fileSystemProvider.onMoveEntryRequested.addListener(
90 onMoveEntryRequested);
92 test_util.mountFileSystem(callback);
96 * Runs all of the test cases, one by one.
99 chrome.test.runTests([
100 // Move an existing file to a non-existing destination. Should succeed.
101 function moveEntrySuccess() {
102 var onSuccess = chrome.test.callbackPass();
103 test_util.fileSystem.root.getFile(
104 TESTING_FILE.name, {create: false},
105 function(sourceEntry) {
106 chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
107 chrome.test.assertFalse(sourceEntry.isDirectory);
109 test_util.fileSystem.root,
110 TESTING_NEW_FILE_NAME,
111 function(targetEntry) {
112 chrome.test.assertEq(TESTING_NEW_FILE_NAME, targetEntry.name);
113 chrome.test.assertFalse(targetEntry.isDirectory);
114 // The source file should be deleted.
115 test_util.fileSystem.root.getFile(
116 TESTING_FILE.name, {create: false},
117 function(newSourceEntry) {
118 chrome.test.fail('Source file not deleted.');
121 chrome.test.assertEq('NotFoundError', error.name);
125 chrome.test.fail(error.name);
128 chrome.test.fail(error.name);
132 // Move an existing file to a location which already holds a file.
134 function moveEntryExistsError() {
135 var onSuccess = chrome.test.callbackPass();
136 test_util.fileSystem.root.getFile(
137 TESTING_ANOTHER_FILE.name, {create: false},
138 function(sourceEntry) {
139 chrome.test.assertEq(TESTING_ANOTHER_FILE.name, sourceEntry.name);
140 chrome.test.assertFalse(sourceEntry.isDirectory);
142 test_util.fileSystem.root,
143 TESTING_NEW_FILE_NAME,
144 function(targetEntry) {
145 chrome.test.fail('Succeeded, but should fail.');
147 chrome.test.assertEq('InvalidModificationError', error.name);
151 chrome.test.fail(error.name);
157 // Setup and run all of the test cases.