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

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

Issue 375543002: [fsp] Add support for deleting entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + cleaned up. 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
« no previous file with comments | « chrome/test/data/extensions/api_test/file_system_provider/delete_entry/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/delete_entry/test.js b/chrome/test/data/extensions/api_test/file_system_provider/delete_entry/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..214b3a7613745ac8e363f2642e8e36ccf0a08b26
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system_provider/delete_entry/test.js
@@ -0,0 +1,153 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+/**
+ * @type {Object}
+ * @const
+ */
+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)
+});
+
+/**
+ * Deletes an entry.
+ *
+ * @param {DeleteEntryRequestedOptions} options Options.
+ * @param {function(Object)} onSuccess Success callback
+ * @param {function(string)} onError Error callback with an error code.
+ */
+function onDeleteEntryRequested(options, onSuccess, onError) {
+ if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
+ onError('SECURITY'); // enum ProviderError.
+ return;
+ }
+
+ if (options.entryPath == '/') {
+ onError('INVALID_OPERATION');
+ return;
+ }
+
+ if (options.entryPath == '/' + TESTING_A_DIRECTORY.name) {
+ if (options.recursive)
+ onSuccess();
+ else
+ onError('INVALID_OPERATION');
+ return;
+ }
+
+ if (options.entryPath == '/' + TESTING_C_FILE.name ||
+ options.entryPath == '/' + TESTING_A_DIRECTORY.name + '/' +
+ TESTING_B_DIRECTORY.name) {
+ onSuccess();
+ return;
+ }
+
+ onError('NOT_FOUND'); // enum ProviderError.
+}
+
+/**
+ * Sets up the tests. Called once per all test cases. In case of a failure,
+ * the callback is not called.
+ *
+ * @param {function()} callback Success callback.
+ */
+function setUp(callback) {
+ chrome.fileSystemProvider.onGetMetadataRequested.addListener(
+ test_util.onGetMetadataRequestedDefault);
+
+ test_util.defaultMetadata['/' + TESTING_A_DIRECTORY.name] =
+ TESTING_A_DIRECTORY;
+ test_util.defaultMetadata['/' + TESTING_A_DIRECTORY.name + '/' +
+ TESTING_B_DIRECTORY.name] = TESTING_B_DIRECTORY;
+ test_util.defaultMetadata['/' + TESTING_C_FILE.name] =
+ TESTING_C_FILE;
+
+ chrome.fileSystemProvider.onDeleteEntryRequested.addListener(
+ onDeleteEntryRequested);
+
+ test_util.mountFileSystem(callback);
+}
+
+/**
+ * Runs all of the test cases, one by one.
+ */
+function runTests() {
+ chrome.test.runTests([
+ // Delete a file. Should succeed.
+ function deleteDirectorySuccessSimple() {
+ var onSuccess = chrome.test.callbackPass();
+ test_util.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();
+ test_util.fileSystem.root.getDirectory(
+ TESTING_A_DIRECTORY.name, {create: false},
+ function(entry) {
+ chrome.test.assertEq(TESTING_A_DIRECTORY.name, entry.name);
+ chrome.test.assertTrue(entry.isDirectory);
+ entry.remove(function() {
+ chrome.test.fail('Unexpectedly succeded to remove a directory.');
+ }, onSuccess);
+ }, function(error) {
+ chrome.test.fail(error.name);
+ });
+ },
+ // Delete a directory which has contents, recursively. Should succeed.
+ function deleteDirectoryRecursively() {
+ var onSuccess = chrome.test.callbackPass();
+ test_util.fileSystem.root.getDirectory(
+ TESTING_A_DIRECTORY.name, {create: false},
+ function(entry) {
+ 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.fail(error.name);
+ });
+ }
+ ]);
+}
+
+// Setup and run all of the test cases.
+setUp(runTests);
« no previous file with comments | « chrome/test/data/extensions/api_test/file_system_provider/delete_entry/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698