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 var onSuccess = chrome.test.callbackPass();
87 test_util.fileSystem.root.getFile(
88 TESTING_FILE.name, {create: false},
89 function(sourceEntry) {
90 chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
91 chrome.test.assertFalse(sourceEntry.isDirectory);
93 test_util.fileSystem.root,
94 TESTING_NEW_FILE_NAME,
95 function(targetEntry) {
96 chrome.test.assertEq(TESTING_NEW_FILE_NAME, targetEntry.name);
97 chrome.test.assertFalse(targetEntry.isDirectory);
100 chrome.test.fail(error.name);
103 chrome.test.fail(error.name);
107 // Copy an existing file to a location which already holds a file.
109 function copyEntryExistsError() {
110 var onSuccess = chrome.test.callbackPass();
111 test_util.fileSystem.root.getFile(
112 TESTING_FILE.name, {create: false},
113 function(sourceEntry) {
114 chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
115 chrome.test.assertFalse(sourceEntry.isDirectory);
117 test_util.fileSystem.root,
118 TESTING_NEW_FILE_NAME,
119 function(targetEntry) {
120 chrome.test.fail('Succeeded, but should fail.');
122 chrome.test.assertEq('InvalidModificationError', error.name);
126 chrome.test.fail(error.name);
132 // Setup and run all of the test cases.