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

Unified Diff: chrome/test/data/extensions/api_test/file_system_provider/test_util/test_util.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/test_util/test_util.js
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/test_util/test_util.js b/chrome/test/data/extensions/api_test/file_system_provider/test_util/test_util.js
new file mode 100644
index 0000000000000000000000000000000000000000..ed572ed787ecd307eff42b6c0e86b7e1fb38fdc0
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system_provider/test_util/test_util.js
@@ -0,0 +1,77 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+// Namespace for testing utilities.
+var test_util = {};
+
+/**
+ * @type {string}
+ * @const
+ */
+test_util.FILE_SYSTEM_ID = 'vanilla.txt';
+
+/**
+ * @type {string}
+ * @const
+ */
+test_util.FILE_SYSTEM_NAME = 'Vanilla';
+
+/**
+ * @type {FileSystem}
+ */
+test_util.fileSystem = null;
+
+/**
+ * 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.
+ */
+test_util.getVolumeInfo = function(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);
+ });
+};
+
+/**
+ * Mounts a testing file system and calls the callback in case of a success.
+ * On failure, the current test case is failed on an assertion.
+ *
+ * @param {function()} callback Success callback.
+ */
+test_util.mountFileSystem = function(callback) {
+ chrome.fileSystemProvider.mount(
+ {
+ fileSystemId: test_util.FILE_SYSTEM_ID,
+ displayName: test_util.FILE_SYSTEM_NAME
+ },
+ function() {
+ var volumeId =
+ 'provided:' + chrome.runtime.id + '-' + test_util.FILE_SYSTEM_ID +
+ '-user';
+
+ test_util.getVolumeInfo(test_util.FILE_SYSTEM_ID, function(volumeInfo) {
+ chrome.test.assertTrue(!!volumeInfo);
+ chrome.fileBrowserPrivate.requestFileSystem(
+ volumeInfo.volumeId,
+ function(inFileSystem) {
+ chrome.test.assertTrue(!!inFileSystem);
+ test_util.fileSystem = inFileSystem;
+ callback();
+ });
+ });
+ }, function() {
+ chrome.test.fail();
+ });
+};

Powered by Google App Engine
This is Rietveld 408576698