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

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

Issue 374543002: [fsp] Simplify browser tests by extracting the common code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. 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
Index: chrome/test/data/extensions/api_test/file_system_provider/evil/test.js
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/evil/test.js b/chrome/test/data/extensions/api_test/file_system_provider/evil/test.js
index 129334661a866471772fa09901eb0b8e494e6b87..a42ada8759b245a4be46f528f9e828c638d46867 100644
--- a/chrome/test/data/extensions/api_test/file_system_provider/evil/test.js
+++ b/chrome/test/data/extensions/api_test/file_system_provider/evil/test.js
@@ -17,12 +17,6 @@ var fileSystem = null;
var openedFiles = {};
/**
- * @type {string}
- * @const
- */
-var FILE_SYSTEM_ID = 'chocolate-id';
-
-/**
* @type {Object}
* @const
*/
@@ -82,26 +76,6 @@ var TESTING_RELATIVE_NAME_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
@@ -113,7 +87,7 @@ function getVolumeInfo(fileSystemId, callback) {
* @param {function(string)} onError Error callback with an error code.
*/
function onGetMetadataRequested(options, onSuccess, onError) {
- if (options.fileSystemId != FILE_SYSTEM_ID) {
+ if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
onError('INVALID_OPERATION'); // enum ProviderError.
return;
}
@@ -155,7 +129,7 @@ function onGetMetadataRequested(options, onSuccess, onError) {
* @param {function(string)} onError Error callback.
*/
function onOpenFileRequested(options, onSuccess, onError) {
- if (options.fileSystemId != FILE_SYSTEM_ID) {
+ if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
onError('INVALID_OPERATION'); // enum ProviderError.
return;
}
@@ -185,7 +159,7 @@ function onOpenFileRequested(options, onSuccess, onError) {
* @param {function(string)} onError Error callback.
*/
function onCloseFileRequested(options, onSuccess, onError) {
- if (options.fileSystemId != FILE_SYSTEM_ID ||
+ if (options.fileSystemId != test_util.FILE_SYSTEM_ID ||
!openedFiles[options.openRequestId]) {
onError('INVALID_OPERATION'); // enum ProviderError.
return;
@@ -206,7 +180,7 @@ function onCloseFileRequested(options, onSuccess, onError) {
*/
function onReadFileRequested(options, onSuccess, onError) {
var filePath = openedFiles[options.openRequestId];
- if (options.fileSystemId != FILE_SYSTEM_ID || !filePath) {
+ if (options.fileSystemId != test_util.FILE_SYSTEM_ID || !filePath) {
onError('INVALID_OPERATION'); // enum ProviderError.
return;
}
@@ -256,32 +230,15 @@ function onReadFileRequested(options, onSuccess, onError) {
* @param {function()} callback Success callback.
*/
function setUp(callback) {
- chrome.fileSystemProvider.mount(
- {fileSystemId: FILE_SYSTEM_ID, displayName: 'chocolate.zip'},
- function() {
- chrome.fileSystemProvider.onGetMetadataRequested.addListener(
- onGetMetadataRequested);
- chrome.fileSystemProvider.onOpenFileRequested.addListener(
- onOpenFileRequested);
- chrome.fileSystemProvider.onReadFileRequested.addListener(
- onReadFileRequested);
- var volumeId =
- 'provided:' + chrome.runtime.id + '-' + FILE_SYSTEM_ID + '-user';
-
- getVolumeInfo(FILE_SYSTEM_ID, function(volumeInfo) {
- chrome.test.assertTrue(!!volumeInfo);
- chrome.fileBrowserPrivate.requestFileSystem(
- volumeInfo.volumeId,
- function(inFileSystem) {
- chrome.test.assertTrue(!!inFileSystem);
-
- fileSystem = inFileSystem;
- callback();
- });
- });
- }, function() {
- chrome.test.fail();
- });
+ chrome.fileSystemProvider.onGetMetadataRequested.addListener(
+ onGetMetadataRequested);
+ chrome.fileSystemProvider.onOpenFileRequested.addListener(
+ onOpenFileRequested);
+ chrome.fileSystemProvider.onReadFileRequested.addListener(
+ onReadFileRequested);
+ chrome.fileSystemProvider.onCloseFileRequested.addListener(
+ onCloseFileRequested);
+ test_util.mountFileSystem(callback);
}
/**
@@ -293,7 +250,7 @@ function runTests() {
// and also much more than requested 1 KB of data).
function returnTooLargeChunk() {
var onTestSuccess = chrome.test.callbackPass();
- fileSystem.root.getFile(
+ test_util.fileSystem.root.getFile(
TESTING_TOO_LARGE_CHUNK_FILE.name,
{create: false},
function(fileEntry) {
@@ -322,7 +279,7 @@ function runTests() {
// doesn't cause any harm.
function invalidCallback() {
var onTestSuccess = chrome.test.callbackPass();
- fileSystem.root.getFile(
+ test_util.fileSystem.root.getFile(
TESTING_INVALID_CALLBACK_FILE.name,
{create: false},
function(fileEntry) {
@@ -350,7 +307,7 @@ function runTests() {
// Test that reading from files with negative size is not allowed.
function negativeSize() {
var onTestSuccess = chrome.test.callbackPass();
- fileSystem.root.getFile(
+ test_util.fileSystem.root.getFile(
TESTING_NEGATIVE_SIZE_FILE.name,
{create: false},
function(fileEntry) {
@@ -381,7 +338,7 @@ function runTests() {
// escaped.
function relativeName() {
var onTestSuccess = chrome.test.callbackPass();
- fileSystem.root.getFile(
+ test_util.fileSystem.root.getFile(
TESTING_RELATIVE_NAME_FILE.name,
{create: false},
function(fileEntry) {

Powered by Google App Engine
This is Rietveld 408576698