1 // Copyright (c) 2013 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.
6 * Extension ID of Files.app.
10 var FILE_MANAGER_EXTENSIONS_ID = 'hhaomjibdihmijegdhdafkllkbggdgoj';
13 * Calls a remote test util in Files.app's extension. See: test_util.js.
15 * @param {string} func Function name.
16 * @param {?string} appId Target window's App ID or null for functions
17 * not requiring a window.
18 * @param {Array.<*>} args Array of arguments.
19 * @param {function(*)} callback Callback handling the function's result.
21 function callRemoteTestUtil(func, appId, args, callback) {
22 chrome.runtime.sendMessage(
23 FILE_MANAGER_EXTENSIONS_ID, {
32 * Executes a sequence of test steps.
35 function StepsRunner() {
38 * @type {Array.<function>}
45 * Creates a StepsRunner instance and runs the passed steps.
47 StepsRunner.run = function(steps) {
48 var stepsRunner = new StepsRunner();
49 stepsRunner.run_(steps);
52 StepsRunner.prototype = {
54 * @return {function} The next closure.
57 return this.steps_[0];
62 * Runs a sequence of the added test steps.
63 * @type {Array.<function>} List of the sequential steps.
65 StepsRunner.prototype.run_ = function(steps) {
66 this.steps_ = steps.slice(0);
68 // An extra step which acts as an empty callback for optional asynchronous
69 // calls in the last provided step.
70 this.steps_.push(function() {});
72 this.steps_ = this.steps_.map(function(f) {
73 return chrome.test.callbackPass(function() {
75 f.apply(this, arguments);
83 * Adds the givin entries to the target volume(s).
84 * @param {Array.<string>} volumeNames Names of target volumes.
85 * @param {Array.<TestEntryInfo>} entries List of entries to be added.
86 * @param {function(boolean)} callback Callback function to be passed the result
87 * of function. The argument is true on success.
89 function addEntries(volumeNames, entries, callback) {
90 if (volumeNames.length == 0) {
94 chrome.test.sendMessage(JSON.stringify({
96 volume: volumeNames.shift(),
98 }), chrome.test.callbackPass(function(result) {
99 if (result == "onEntryAdded")
100 addEntries(volumeNames, entries, callback);
107 // Check for the guest mode.
109 chrome.test.sendMessage(
110 JSON.stringify({name: 'isInGuestMode'}), steps.shift());
112 // Obtain the test case name.
114 if (JSON.parse(result) != chrome.extension.inIncognitoContext)
116 chrome.test.sendMessage(
117 JSON.stringify({name: 'getTestName'}), steps.shift());
119 // Run the test case.
120 function(testCaseName) {
121 if (!testcase[testCaseName])
123 chrome.test.runTests([testcase[testCaseName]]);