X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Ftest%2Fdata%2Fextensions%2Fapi_test%2Ffile_system_provider%2Fread_file%2Ftest.js;h=e392c7ede42708f7d41e29af65d931bdf49abf91;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=4164b7b76d6451f7af2320f80f5558ea5f1e7571;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js b/src/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js index 4164b7b..e392c7e 100644 --- a/src/chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js +++ b/src/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 * openRequestId. * @@ -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) {