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

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

Issue 496953003: [fsp] Make the reading operation abortable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. 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
Index: chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js b/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js
index 4164b7b76d6451f7af2320f80f5558ea5f1e7571..e392c7ede42708f7d41e29af65d931bdf49abf91 100644
--- a/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js
+++ b/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js
@@ -43,6 +43,19 @@ var TESTING_BROKEN_TIRAMISU_FILE = Object.freeze({
});
/**
+ * Metadata of a broken file used to read contents from, but it simulates
+ * a very long read, in order to verify the aborting mechanism.
+ * @type {Object}
+ * @const
+ */
+var TESTING_VANILLA_FOR_ABORT_FILE = Object.freeze({
+ isDirectory: false,
+ name: 'vanilla.txt',
+ size: TESTING_TEXT.length,
+ modificationTime: new Date(2014, 1, 25, 7, 36, 12)
+});
+
+/**
* Requests reading contents of a file, previously opened with <code>
* openRequestId</code>.
*
@@ -77,6 +90,11 @@ function onReadFileRequested(options, onSuccess, onError) {
return;
}
+ if (filePath == '/' + TESTING_VANILLA_FOR_ABORT_FILE.name) {
+ // Do nothing. This simulates a very slow read.
+ return;
+ }
+
if (filePath == '/' + TESTING_BROKEN_TIRAMISU_FILE.name) {
onError('ACCESS_DENIED'); // enum ProviderError.
return;
@@ -103,6 +121,8 @@ function setUp(callback) {
TESTING_TIRAMISU_FILE;
test_util.defaultMetadata['/' + TESTING_BROKEN_TIRAMISU_FILE.name] =
TESTING_BROKEN_TIRAMISU_FILE;
+ test_util.defaultMetadata['/' + TESTING_VANILLA_FOR_ABORT_FILE.name] =
+ TESTING_VANILLA_FOR_ABORT_FILE;
chrome.fileSystemProvider.onReadFileRequested.addListener(
onReadFileRequested);
@@ -143,7 +163,8 @@ function runTests() {
chrome.test.fail(error.name);
});
},
- // Read contents of a file file, but with an error on the way. This should
+
+ // Read contents of a file, but with an error on the way. This should
// result in an error.
function readEntriesError() {
var onTestSuccess = chrome.test.callbackPass();
@@ -163,7 +184,56 @@ function runTests() {
fileReader.readAsText(file);
},
function(error) {
- chrome.test.fail();
+ chrome.test.fail(error.name);
+ });
+ },
+ function(error) {
+ chrome.test.fail(error.name);
+ });
+ },
+
+ // Abort reading a file with a registered abort handler. Should result in a
+ // gracefully terminated reading operation.
+ function abortReadingSuccess() {
+ 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_VANILLA_FOR_ABORT_FILE.name,
+ {create: false, exclusive: false},
+ function(fileEntry) {
+ fileEntry.file(function(file) {
+ var hadAbort = false;
+ var fileReader = new FileReader();
+ fileReader.onload = function(e) {
+ if (!hadAbort) {
+ chrome.test.fail(
+ 'Unexpectedly finished writing, despite aborting.');
+ return;
+ }
+ chrome.test.fail();
+ };
+ fileReader.onerror = function(e) {
+ chrome.test.assertEq(
+ 'AbortError', fileReader.error.name);
+ };
+ fileReader.readAsText(file);
+ setTimeout(function() {
+ // Abort the operation after it's started.
+ fileReader.abort();
+ }, 0);
+ },
+ function(error) {
+ chrome.test.fail(error.name);
});
},
function(error) {

Powered by Google App Engine
This is Rietveld 408576698