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.
8 * Extension ID of gallery app.
12 var GALLERY_APP_ID = 'nlkncpkkdoccmpiclbokaimcnedabhhm';
14 var gallery = new RemoteCallGallery(GALLERY_APP_ID);
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
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
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]);
40 return entriesPromise.then(function(result) {
42 return gallery.callRemoteTestUtil('openGallery', null, [urls]);
43 }).then(function(windowId) {
44 chrome.test.assertTrue(!!windowId);
46 return gallery.waitForElement(appId, 'div.gallery');
47 }).then(function(args) {
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.');
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.
79 chrome.test.fail(error.stack || error);
84 * Namespace for test cases.
88 // Ensure the test cases are loaded.
89 window.addEventListener('load', function() {
91 // Check for the guest mode.
93 chrome.test.sendMessage(
94 JSON.stringify({name: 'isInGuestMode'}), steps.shift());
96 // Obtain the test case name.
98 if (JSON.parse(result) != chrome.extension.inIncognitoContext)
100 chrome.test.sendMessage(
101 JSON.stringify({name: 'getRootPaths'}), steps.shift());
103 // Obtain the root entry paths.
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];
115 chrome.test.fail(testCaseName + ' is not found.');
118 // Specify the name of test to the test system.
119 targetTest.generatedName = testCaseName;
120 chrome.test.runTests([function() {
121 return testPromise(targetTest());