Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5773)

Unified Diff: chrome/test/data/extensions/api_test/file_system_provider/move_entry/test.js

Issue 389973002: [fsp] Add support for moving files within a provided file system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/file_system_provider/move_entry/test.js
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/copy_entry/test.js b/chrome/test/data/extensions/api_test/file_system_provider/move_entry/test.js
similarity index 67%
copy from chrome/test/data/extensions/api_test/file_system_provider/copy_entry/test.js
copy to chrome/test/data/extensions/api_test/file_system_provider/move_entry/test.js
index 6ff163696858e75335abaf6e7bd9716040497316..99a27b13256e05341d38aa83b93ba8840e86d433 100644
--- a/chrome/test/data/extensions/api_test/file_system_provider/copy_entry/test.js
+++ b/chrome/test/data/extensions/api_test/file_system_provider/move_entry/test.js
@@ -16,19 +16,30 @@ var TESTING_FILE = Object.freeze({
});
/**
+ * @type {Object}
+ * @const
+ */
+var TESTING_ANOTHER_FILE = Object.freeze({
+ isDirectory: false,
+ name: 'bunny',
+ size: 2048,
+ modificationTime: new Date(2014, 4, 28, 9, 38, 14)
+});
+
+/**
* @type {string}
* @const
*/
var TESTING_NEW_FILE_NAME = 'puppy.txt';
/**
- * Copies an entry within the same file system.
+ * Moves an entry within the same file system.
*
- * @param {CopyEntryRequestedOptions} options Options.
+ * @param {MoveEntryRequestedOptions} options Options.
* @param {function(Object)} onSuccess Success callback
* @param {function(string)} onError Error callback with an error code.
*/
-function onCopyEntryRequested(options, onSuccess, onError) {
+function onMoveEntryRequested(options, onSuccess, onError) {
if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
onError('SECURITY'); // enum ProviderError.
return;
@@ -49,12 +60,15 @@ function onCopyEntryRequested(options, onSuccess, onError) {
return;
}
- // Copy the metadata, but change the 'name' field.
+ // Move the metadata with changing the 'name' field.
var newMetadata =
JSON.parse(JSON.stringify(test_util.defaultMetadata[options.sourcePath]));
newMetadata.name = options.targetPath.split('/').pop();
test_util.defaultMetadata[options.targetPath] = newMetadata;
+ // Remove the source file.
+ delete test_util.defaultMetadata[options.sourcePath];
+
onSuccess(); // enum ProviderError.
}
@@ -69,9 +83,11 @@ function setUp(callback) {
test_util.onGetMetadataRequestedDefault);
test_util.defaultMetadata['/' + TESTING_FILE.name] = TESTING_FILE;
+ test_util.defaultMetadata['/' + TESTING_ANOTHER_FILE.name] =
+ TESTING_ANOTHER_FILE;
- chrome.fileSystemProvider.onCopyEntryRequested.addListener(
- onCopyEntryRequested);
+ chrome.fileSystemProvider.onMoveEntryRequested.addListener(
+ onMoveEntryRequested);
test_util.mountFileSystem(callback);
}
@@ -81,21 +97,30 @@ function setUp(callback) {
*/
function runTests() {
chrome.test.runTests([
- // Copy an existing file to a non-existing destination. Should succeed.
- function copyEntrySuccess() {
+ // Move an existing file to a non-existing destination. Should succeed.
+ function moveEntrySuccess() {
var onSuccess = chrome.test.callbackPass();
test_util.fileSystem.root.getFile(
TESTING_FILE.name, {create: false},
function(sourceEntry) {
chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
chrome.test.assertFalse(sourceEntry.isDirectory);
- sourceEntry.copyTo(
+ sourceEntry.moveTo(
test_util.fileSystem.root,
TESTING_NEW_FILE_NAME,
function(targetEntry) {
chrome.test.assertEq(TESTING_NEW_FILE_NAME, targetEntry.name);
chrome.test.assertFalse(targetEntry.isDirectory);
- onSuccess();
+ // The source file should be deleted.
+ test_util.fileSystem.root.getFile(
+ TESTING_FILE.name, {create: false},
+ function(newSourceEntry) {
+ chrome.test.fail('Source file not deleted.');
+ },
+ function(error) {
+ chrome.test.assertEq('NotFoundError', error.name);
+ onSuccess();
+ });
}, function(error) {
chrome.test.fail(error.name);
});
@@ -103,16 +128,17 @@ function runTests() {
chrome.test.fail(error.name);
});
},
- // Copy an existing file to a location which already holds a file.
+
+ // Move an existing file to a location which already holds a file.
// Should fail.
- function copyEntryExistsError() {
+ function moveEntryExistsError() {
var onSuccess = chrome.test.callbackPass();
test_util.fileSystem.root.getFile(
- TESTING_FILE.name, {create: false},
+ TESTING_ANOTHER_FILE.name, {create: false},
function(sourceEntry) {
- chrome.test.assertEq(TESTING_FILE.name, sourceEntry.name);
+ chrome.test.assertEq(TESTING_ANOTHER_FILE.name, sourceEntry.name);
chrome.test.assertFalse(sourceEntry.isDirectory);
- sourceEntry.copyTo(
+ sourceEntry.moveTo(
test_util.fileSystem.root,
TESTING_NEW_FILE_NAME,
function(targetEntry) {

Powered by Google App Engine
This is Rietveld 408576698