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

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

Issue 440653003: [fsp] Add support for aborting running operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed DCHECKs. Created 6 years, 4 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/renderer/resources/extensions/file_system_provider_custom_bindings.js ('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/write_file/test.js
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/write_file/test.js b/chrome/test/data/extensions/api_test/file_system_provider/write_file/test.js
index b57b292fa9da3bf410c137a55b8d4afa43eaa084..07540019198747912422e64286a6dd193dbe5c82 100644
--- a/chrome/test/data/extensions/api_test/file_system_provider/write_file/test.js
+++ b/chrome/test/data/extensions/api_test/file_system_provider/write_file/test.js
@@ -15,20 +15,20 @@ var fileContents = {};
* @type {string}
* @const
*/
-var TESTING_INITIAL_TEXT = "Hello world. How are you today?";
+var TESTING_INITIAL_TEXT = 'Hello world. How are you today?';
/**
* Initial contents of testing files.
* @type {string}
- ";
+ * @const
*/
-var TESTING_TEXT_TO_WRITE = "Vanilla ice creams are the best.";
+var TESTING_TEXT_TO_WRITE = 'Vanilla ice creams are the best.';
/**
* @type {string}
* @const
*/
-var TESTING_NEW_FILE_NAME = "perfume.txt"
+var TESTING_NEW_FILE_NAME = 'perfume.txt';
/**
* @type {string}
@@ -43,6 +43,12 @@ var TESTING_TIRAMISU_FILE_NAME = 'tiramisu.txt';
var TESTING_BROKEN_TIRAMISU_FILE_NAME = 'broken-tiramisu.txt';
/**
+ * @type {string}
+ * @const
+ */
+var TESTING_CHOCOLATE_FILE_NAME = 'chocolate.txt';
+
+/**
* Requests writing contents to a file, previously opened with <code>
* openRequestId</code>.
*
@@ -69,6 +75,11 @@ function onWriteFileRequested(options, onSuccess, onError) {
return;
}
+ if (filePath == '/' + TESTING_CHOCOLATE_FILE_NAME) {
+ // Do not call any callback to simulate a very slow network connection.
+ return;
+ }
+
// Writing beyond the end of the file.
if (options.offset > metadata.size) {
onError('INVALID_OPERATION');
@@ -84,7 +95,7 @@ function onWriteFileRequested(options, onSuccess, onError) {
metadata.size = newContents.length;
fileContents[filePath] = newContents;
onSuccess();
- }
+ };
reader.readAsText(new Blob([options.data]));
}
@@ -119,8 +130,16 @@ function setUp(callback) {
modificationTime: new Date(2014, 1, 25, 7, 36, 12)
};
+ test_util.defaultMetadata['/' + TESTING_CHOCOLATE_FILE_NAME] = {
+ isDirectory: false,
+ name: TESTING_CHOCOLATE_FILE_NAME,
+ size: TESTING_INITIAL_TEXT.length,
+ modificationTime: new Date(2014, 1, 26, 8, 37, 13)
+ };
+
fileContents['/' + TESTING_TIRAMISU_FILE_NAME] = TESTING_INITIAL_TEXT;
fileContents['/' + TESTING_BROKEN_TIRAMISU_FILE_NAME] = TESTING_INITIAL_TEXT;
+ fileContents['/' + TESTING_CHOCOLATE_FILE_NAME] = TESTING_INITIAL_TEXT;
chrome.fileSystemProvider.onWriteFileRequested.addListener(
onWriteFileRequested);
@@ -294,6 +313,57 @@ function runTests() {
function(error) {
chrome.test.fail(error.name);
});
+ },
+
+ // Abort writing to a valid file with a registered abort handler. Should
+ // resurt in a gracefully terminated writing operation.
+ function abortWritingSuccess() {
+ var onTestSuccess = chrome.test.callbackPass();
+
+ var onAbortRequested = function(options, onSuccess, onError) {
+ chrome.fileSystemProvider.onAbortRequested.removeListener(
+ onAbortRequested);
+ onSuccess();
+ onTestSuccess();
+ };
+
+ chrome.fileSystemProvider.onAbortRequested.addListener(
+ onAbortRequested);
+
+ test_util.fileSystem.root.getFile(
+ TESTING_CHOCOLATE_FILE_NAME,
+ {create: false, exclusive: false},
+ function(fileEntry) {
+ var hadAbort = false;
+ fileEntry.createWriter(function(fileWriter) {
+ fileWriter.onwriteend = function(e) {
+ if (!hadAbort) {
+ chrome.test.fail(
+ 'Unexpectedly finished writing, despite aborting.');
+ return;
+ }
+ };
+ fileWriter.onerror = function(e) {
+ chrome.test.assertEq(
+ 'AbortError', fileWriter.error.name);
+ };
+ fileWriter.onabort = function(e) {
+ hadAbort = true;
+ };
+ var blob = new Blob(['A lot of cherries.'], {type: 'text/plain'});
+ fileWriter.write(blob);
+ setTimeout(function() {
+ // Abort the operation after it's started.
+ fileWriter.abort();
+ }, 0);
+ },
+ function(error) {
+ chrome.test.fail();
+ });
+ },
+ function(error) {
+ chrome.test.fail(error.name);
+ });
}
]);
}
« no previous file with comments | « chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698