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 b9d7b0846a3f040030f247c015e21752daa74bf6..6cff9d2be9bf8e01534d3c4de77dd54166946864 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 |
@@ -5,12 +5,7 @@ |
'use strict'; |
/** |
- * @type {number} |
- */ |
-var fileSystemId = 0; |
- |
-/** |
- * @type {?DOMFileSystem} |
+ * @type {DOMFileSystem} |
*/ |
var fileSystem = null; |
@@ -22,6 +17,12 @@ var fileSystem = null; |
var openedFiles = {}; |
/** |
+ * @type {string} |
+ * @const |
+ */ |
+var FILE_SYSTEM_ID = 'chocolate-id'; |
+ |
+/** |
* @type {Object} |
* @const |
*/ |
@@ -64,20 +65,39 @@ var TESTING_BROKEN_TIRAMISU_FILE = Object.freeze({ |
}); |
/** |
+ * Gets volume information for the provided file system. |
+ * |
+ * @param {string} fileSystemId Id of the provided file system. |
+ * @param {function(Object)} callback Callback to be called on result, with the |
+ * volume information object in case of success, or null if not found. |
+ */ |
+function getVolumeInfo(fileSystemId, callback) { |
+ chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) { |
+ for (var i = 0; i < volumeList.length; i++) { |
+ if (volumeList[i].extensionId == chrome.runtime.id && |
+ volumeList[i].fileSystemId == fileSystemId) { |
+ callback(volumeList[i]); |
+ return; |
+ } |
+ } |
+ callback(null); |
+ }); |
+} |
+ |
+/** |
* Returns metadata for the requested entry. |
* |
* To successfully acquire a DirectoryEntry, or even a DOMFileSystem, this event |
* must be implemented and return correct values. |
* |
- * @param {number} inFileSystemId ID of the file system. |
+ * @param {string} inFileSystemId ID of the file system. |
* @param {string} entryPath Path of the requested entry. |
* @param {function(Object)} onSuccess Success callback with metadata passed |
* an argument. |
* @param {function(string)} onError Error callback with an error code. |
*/ |
-function onGetMetadataRequested( |
- inFileSystemId, entryPath, onSuccess, onError) { |
- if (inFileSystemId != fileSystemId) { |
+function onGetMetadataRequested(inFileSystemId, entryPath, onSuccess, onError) { |
+ if (inFileSystemId != FILE_SYSTEM_ID) { |
onError('SECURITY_ERROR'); // enum ProviderError. |
return; |
} |
@@ -104,7 +124,7 @@ function onGetMetadataRequested( |
* Requests opening a file at <code>filePath</code>. Further file operations |
* will be associated with the <code>requestId</code> |
* |
- * @param {number} inFileSystemId ID of the file system. |
+ * @param {string} inFileSystemId ID of the file system. |
* @param {number} requestId ID of the opening request. Used later for reading. |
* @param {string} filePath Path of the file to be opened. |
* @param {string} mode Mode, either reading or writing. |
@@ -114,7 +134,7 @@ function onGetMetadataRequested( |
*/ |
function onOpenFileRequested( |
inFileSystemId, requestId, filePath, mode, create, onSuccess, onError) { |
- if (inFileSystemId != fileSystemId || mode != 'READ' || create) { |
+ if (inFileSystemId != FILE_SYSTEM_ID || mode != 'READ' || create) { |
onError('SECURITY_ERROR'); // enum ProviderError. |
return; |
} |
@@ -131,14 +151,14 @@ function onOpenFileRequested( |
/** |
* Requests closing a file previously opened with <code>openRequestId</code>. |
* |
- * @param {number} inFileSystemId ID of the file system. |
+ * @param {string} inFileSystemId ID of the file system. |
* @param {number} openRequestId ID of the request used to open the file. |
* @param {function()} onSuccess Success callback. |
* @param {function(string)} onError Error callback. |
*/ |
function onCloseFileRequested( |
inFileSystemId, openRequestId, onSuccess, onError) { |
- if (inFileSystemId != fileSystemId || !openedFiles[openRequestId]) { |
+ if (inFileSystemId != FILE_SYSTEM_ID || !openedFiles[openRequestId]) { |
onError('SECURITY_ERROR'); // enum ProviderError. |
return; |
} |
@@ -151,7 +171,7 @@ function onCloseFileRequested( |
* Requests reading contents of a file, previously opened with <code> |
* openRequestId</code>. |
* |
- * @param {number} inFileSystemId ID of the file system. |
+ * @param {string} inFileSystemId ID of the file system. |
* @param {number} openRequestId ID of the request used to open the file. |
* @param {number} offset Offset of the file. |
* @param {number} length Number of bytes to read. |
@@ -162,7 +182,7 @@ function onCloseFileRequested( |
function onReadFileRequested( |
inFileSystemId, openRequestId, offset, length, onSuccess, onError) { |
var filePath = openedFiles[openRequestId]; |
- if (inFileSystemId != fileSystemId || !filePath) { |
+ if (inFileSystemId != FILE_SYSTEM_ID || !filePath) { |
onError('SECURITY_ERROR'); // enum ProviderError. |
return; |
} |
@@ -201,8 +221,7 @@ function onReadFileRequested( |
* @param {function()} callback Success callback. |
*/ |
function setUp(callback) { |
- chrome.fileSystemProvider.mount('chocolate.zip', function(id) { |
- fileSystemId = id; |
+ chrome.fileSystemProvider.mount(FILE_SYSTEM_ID, 'chocolate.zip', function() { |
chrome.fileSystemProvider.onGetMetadataRequested.addListener( |
onGetMetadataRequested); |
chrome.fileSystemProvider.onOpenFileRequested.addListener( |
@@ -210,16 +229,19 @@ function setUp(callback) { |
chrome.fileSystemProvider.onReadFileRequested.addListener( |
onReadFileRequested); |
var volumeId = |
- 'provided:' + chrome.runtime.id + '-' + fileSystemId + '-user'; |
+ 'provided:' + chrome.runtime.id + '-' + FILE_SYSTEM_ID + '-user'; |
- chrome.fileBrowserPrivate.requestFileSystem( |
- volumeId, |
- function(inFileSystem) { |
- chrome.test.assertTrue(!!inFileSystem); |
+ getVolumeInfo(FILE_SYSTEM_ID, function(volumeInfo) { |
+ chrome.test.assertTrue(!!volumeInfo); |
+ chrome.fileBrowserPrivate.requestFileSystem( |
+ volumeInfo.volumeId, |
+ function(inFileSystem) { |
+ chrome.test.assertTrue(!!inFileSystem); |
- fileSystem = inFileSystem; |
- callback(); |
- }); |
+ fileSystem = inFileSystem; |
+ callback(); |
+ }); |
+ }); |
}, function() { |
chrome.test.fail(); |
}); |