Move action_runner.py out of actions folder prior to moving actions to internal.
[chromium-blink-merge.git] / ui / file_manager / integration_tests / gallery / background.js
blobb7cfb94bd1d0f592b24085b265f416a18d7290e9
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.
5 'use strict';
7 /**
8 * Extension ID of gallery app.
9 * @type {string}
10 * @const
12 var GALLERY_APP_ID = 'nlkncpkkdoccmpiclbokaimcnedabhhm';
14 var gallery = new RemoteCallGallery(GALLERY_APP_ID);
16 /**
17 * Launches the gallery with the given entries.
19 * @param {string} testVolumeName Test volume name passed to the addEntries
20 * function. Either 'drive' or 'local'.
21 * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
22 * @param {Array.<TestEntryInfo>} entries Entries to be parepared and passed to
23 * the application.
24 * @param {Array.<TestEntryInfo>=} opt_selected Entries to be selected. Should
25 * be a sub-set of the entries argument.
26 * @return {Promise} Promise to be fulfilled with the data of the main element
27 * in the allery.
29 function launch(testVolumeName, volumeType, entries, opt_selected) {
30 var entriesPromise = addEntries([testVolumeName], entries).then(function() {
31 var selectedEntries = opt_selected || entries;
32 var selectedEntryNames =
33 selectedEntries.map(function(entry) { return entry.nameText; });
34 return gallery.callRemoteTestUtil(
35 'getFilesUnderVolume', null, [volumeType, selectedEntryNames]);
36 });
38 var appId = null;
39 var urls = [];
40 return entriesPromise.then(function(result) {
41 urls = result;
42 return gallery.callRemoteTestUtil('openGallery', null, [urls]);
43 }).then(function(windowId) {
44 chrome.test.assertTrue(!!windowId);
45 appId = windowId;
46 return gallery.waitForElement(appId, 'div.gallery');
47 }).then(function(args) {
48 return {
49 appId: appId,
50 mailElement: args[0],
51 urls: urls,
53 });
56 /**
57 * Verifies if there are no Javascript errors in any of the app windows.
58 * @param {function()} Completion callback.
60 function checkIfNoErrorsOccured(callback) {
61 var countPromise = gallery.callRemoteTestUtil('getErrorCount', null, []);
62 countPromise.then(function(count) {
63 chrome.test.assertEq(0, count, 'The error count is not 0.');
64 callback();
65 });
68 /**
69 * Adds check of chrome.test to the end of the given promise.
70 * @param {Promise} promise Promise.
72 function testPromise(promise) {
73 promise.then(function() {
74 return new Promise(checkIfNoErrorsOccured);
75 }).then(chrome.test.callbackPass(function() {
76 // The callbacPass is necessary to avoid prematurely finishing tests.
77 // Don't put chrome.test.succeed() here to avoid doubled success log.
78 }), function(error) {
79 chrome.test.fail(error.stack || error);
80 });
83 /**
84 * Namespace for test cases.
86 var testcase = {};
88 // Ensure the test cases are loaded.
89 window.addEventListener('load', function() {
90 var steps = [
91 // Check for the guest mode.
92 function() {
93 chrome.test.sendMessage(
94 JSON.stringify({name: 'isInGuestMode'}), steps.shift());
96 // Obtain the test case name.
97 function(result) {
98 if (JSON.parse(result) != chrome.extension.inIncognitoContext)
99 return;
100 chrome.test.sendMessage(
101 JSON.stringify({name: 'getRootPaths'}), steps.shift());
103 // Obtain the root entry paths.
104 function(result) {
105 var roots = JSON.parse(result);
106 RootPath.DOWNLOADS = roots.downloads;
107 RootPath.DRIVE = roots.drive;
108 chrome.test.sendMessage(
109 JSON.stringify({name: 'getTestName'}), steps.shift());
111 // Run the test case.
112 function(testCaseName) {
113 var targetTest = testcase[testCaseName];
114 if (!targetTest) {
115 chrome.test.fail(testCaseName + ' is not found.');
116 return;
118 // Specify the name of test to the test system.
119 targetTest.generatedName = testCaseName;
120 chrome.test.runTests([function() {
121 return testPromise(targetTest());
122 }]);
125 steps.shift()();