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

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

Issue 389893002: [fsp] Add support for creating files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. 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/create_file/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/create_file/test.js
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/create_file/test.js b/chrome/test/data/extensions/api_test/file_system_provider/create_file/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..1473608a3dcb09392ed4d8a63b51dcd716d71127
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system_provider/create_file/test.js
@@ -0,0 +1,121 @@
+// 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_FILE = Object.freeze({
+ isDirectory: false,
+ name: 'kitty',
+ size: 0,
+ modificationTime: new Date(2014, 4, 28, 10, 39, 15)
+});
+
+/**
+ * @type {Object}
+ * @const
+ */
+var TESTING_NEW_FILE = Object.freeze({
+ isDirectory: false,
+ name: 'puppy',
+ size: 0,
+ modificationTime: new Date(2014, 4, 28, 10, 39, 15)
+});
+
+/**
+ * Creates a file.
+ *
+ * @param {CreateFileRequestedOptions} options Options.
+ * @param {function(Object)} onSuccess Success callback
+ * @param {function(string)} onError Error callback with an error code.
+ */
+function onCreateFileRequested(options, onSuccess, onError) {
+ if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
+ onError('SECURITY'); // enum ProviderError.
+ return;
+ }
+
+ if (options.filePath == '/') {
+ onError('INVALID_OPERATION');
+ return;
+ }
+
+ if (options.filePath in test_util.defaultMetadata) {
+ onError('EXISTS');
+ return;
+ }
+
+ test_util.defaultMetadata[options.filePath] = TESTING_FILE;
+ onSuccess(); // 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_FILE.name] = TESTING_FILE;
+
+ chrome.fileSystemProvider.onCreateFileRequested.addListener(
+ onCreateFileRequested);
+
+ test_util.mountFileSystem(callback);
+}
+
+/**
+ * Runs all of the test cases, one by one.
+ */
+function runTests() {
+ chrome.test.runTests([
+ // Create a file which doesn't exist. Should succeed.
+ function createFileSuccessSimple() {
+ var onSuccess = chrome.test.callbackPass();
+ test_util.fileSystem.root.getFile(
+ TESTING_NEW_FILE.name, {create: true},
+ function(entry) {
+ chrome.test.assertEq(TESTING_NEW_FILE.name, entry.name);
+ chrome.test.assertFalse(entry.isDirectory);
+ onSuccess();
+ }, function(error) {
+ chrome.test.fail(error.name);
+ });
+ },
+ // Create a file which exists, non-exclusively. Should succeed.
+ function createFileOrOpenSuccess() {
+ var onSuccess = chrome.test.callbackPass();
+ test_util.fileSystem.root.getFile(
+ TESTING_FILE.name, {create: true, exclusive: false},
+ function(entry) {
+ chrome.test.assertEq(TESTING_FILE.name, entry.name);
+ chrome.test.assertFalse(entry.isDirectory);
+ onSuccess();
+ }, function(error) {
+ chrome.test.fail(error.name);
+ });
+ },
+ // Create a file which exists, exclusively. Should fail.
+ function createFileExistsError() {
+ var onSuccess = chrome.test.callbackPass();
+ test_util.fileSystem.root.getFile(
+ TESTING_FILE.name, {create: true, exclusive: true},
+ function(entry) {
+ chrome.test.fail('Created a file, but should fail.');
+ }, function(error) {
+ chrome.test.assertEq('InvalidModificationError', error.name);
+ onSuccess();
+ });
+ },
+ ]);
+}
+
+// Setup and run all of the test cases.
+setUp(runTests);
« no previous file with comments | « chrome/test/data/extensions/api_test/file_system_provider/create_file/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698