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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 // Namespace for testing utilities.
8 var test_util = {};
9
10 /**
11 * @type {string}
12 * @const
13 */
14 test_util.FILE_SYSTEM_ID = 'vanilla.txt';
15
16 /**
17 * @type {string}
18 * @const
19 */
20 test_util.FILE_SYSTEM_NAME = 'Vanilla';
21
22 /**
23 * @type {FileSystem}
24 */
25 test_util.fileSystem = null;
26
27 /**
28 * Gets volume information for the provided file system.
29 *
30 * @param {string} fileSystemId Id of the provided file system.
31 * @param {function(Object)} callback Callback to be called on result, with the
32 * volume information object in case of success, or null if not found.
33 */
34 test_util.getVolumeInfo = function(fileSystemId, callback) {
35 chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
36 for (var i = 0; i < volumeList.length; i++) {
37 if (volumeList[i].extensionId == chrome.runtime.id &&
38 volumeList[i].fileSystemId == fileSystemId) {
39 callback(volumeList[i]);
40 return;
41 }
42 }
43 callback(null);
44 });
45 };
46
47 /**
48 * Mounts a testing file system and calls the callback in case of a success.
49 * On failure, the current test case is failed on an assertion.
50 *
51 * @param {function()} callback Success callback.
52 */
53 test_util.mountFileSystem = function(callback) {
54 chrome.fileSystemProvider.mount(
55 {
56 fileSystemId: test_util.FILE_SYSTEM_ID,
57 displayName: test_util.FILE_SYSTEM_NAME
58 },
59 function() {
60 var volumeId =
61 'provided:' + chrome.runtime.id + '-' + test_util.FILE_SYSTEM_ID +
62 '-user';
63
64 test_util.getVolumeInfo(test_util.FILE_SYSTEM_ID, function(volumeInfo) {
65 chrome.test.assertTrue(!!volumeInfo);
66 chrome.fileBrowserPrivate.requestFileSystem(
67 volumeInfo.volumeId,
68 function(inFileSystem) {
69 chrome.test.assertTrue(!!inFileSystem);
70 test_util.fileSystem = inFileSystem;
71 callback();
72 });
73 });
74 }, function() {
75 chrome.test.fail();
76 });
77 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698