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_NEW_FILE_NAME = 'puppy.txt';
25 * Copies an entry within the same file system.
27 * @param {CopyEntryRequestedOptions} options Options.
28 * @param {function(Object)} onSuccess Success callback
29 * @param {function(string)} onError Error callback with an error code.
31 function onCopyEntryRequested(options, onSuccess, onError) {
32 if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
33 onError('SECURITY'); // enum ProviderError.
37 if (options.sourcePath == '/') {
38 onError('INVALID_OPERATION');
42 if (!(options.sourcePath in test_util.defaultMetadata)) {
47 if (options.targetPath in test_util.defaultMetadata) {
52 // Copy the metadata, but change the 'name' field.
54 JSON.parse(JSON.stringify(test_util.defaultMetadata[options.sourcePath]));
55 newMetadata.name = options.targetPath.split('/').pop();
56 test_util.defaultMetadata[options.targetPath] = newMetadata;
58 onSuccess(); // enum ProviderError.
62 * Sets up the tests. Called once per all test cases. In case of a failure,
63 * the callback is not called.
65 * @param {function()} callback Success callback.
67 function setUp(callback) {
68 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
69 test_util.onGetMetadataRequestedDefault);
71 test_util.defaultMetadata['/' + TESTING_FILE.name] = TESTING_FILE;
73 chrome.fileSystemProvider.onCopyEntryRequested.addListener(
74 onCopyEntryRequested);
76 test_util.mountFileSystem(callback);
80 * Runs all of the test cases, one by one.
83 chrome.test.runTests([
84 // Copy an existing file to a non-existing destination. Should succeed.
85 function copyEntrySuccess() {
86 test_util.fileSystem.root.getFile(
87 TESTING_FILE.name, {create: false},
88 chrome.test.callbackPass(function(sourceEntry) {
89 chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
90 chrome.test.assertFalse(sourceEntry.isDirectory);
92 test_util.fileSystem.root,
93 TESTING_NEW_FILE_NAME,
94 chrome.test.callbackPass(function(targetEntry) {
95 chrome.test.assertEq(TESTING_NEW_FILE_NAME, targetEntry.name);
96 chrome.test.assertFalse(targetEntry.isDirectory);
98 chrome.test.fail(error.name);
100 }), function(error) {
101 chrome.test.fail(error.name);
105 // Copy an existing file to a location which already holds a file.
107 function copyEntryExistsError() {
108 test_util.fileSystem.root.getFile(
109 TESTING_FILE.name, {create: false},
110 chrome.test.callbackPass(function(sourceEntry) {
111 chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
112 chrome.test.assertFalse(sourceEntry.isDirectory);
114 test_util.fileSystem.root,
115 TESTING_NEW_FILE_NAME,
116 function(targetEntry) {
117 chrome.test.fail('Succeeded, but should fail.');
118 }, chrome.test.callbackPass(function(error) {
119 chrome.test.assertEq('InvalidModificationError', error.name);
121 }), function(error) {
122 chrome.test.fail(error.name);
128 // Setup and run all of the test cases.