Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / gallery / test_util.js
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 /**
8  * Launches the Gallery app with the test entries.
9  *
10  * @param {string} testVolumeName Test volume name passed to the addEntries
11  *     function. Either 'drive' or 'local'.
12  * @param {VolumeManagerCommon.VolumeType} volumeType Volume type.
13  * @param {Array.<TestEntryInfo>} entries Entries to be parepared and passed to
14  *     the application.
15  * @param {Array.<TestEntryInfo>=} opt_selected Entries to be selected. Should
16  *     be a sub-set of the entries argument.
17  */
18 function launchWithTestEntries(
19     testVolumeName, volumeType, entries, opt_selected) {
20   var entriesPromise = addEntries([testVolumeName], entries).then(function() {
21     var selectedEntries = opt_selected || entries;
22     return getFilesUnderVolume(
23         volumeType,
24         selectedEntries.map(function(entry) { return entry.nameText; }));
25   });
26
27   return launch(entriesPromise).then(function() {
28     var launchedPromise = Promise.all([appWindowPromise, entriesPromise]);
29     return launchedPromise.then(function(results) {
30       return {appWindow: results[0], entries: results[1]};
31     });
32   });
33 }
34
35 /**
36  * Waits until the expected image is shown.
37  *
38  * @param {document} document Document.
39  * @param {number} width Expected width of the image.
40  * @param {number} height Expected height of the image.
41  * @param {string} name Expected name of the image.
42  * @return {Promise} Promsie to be fulfilled when the check is passed.
43  */
44 function waitForSlideImage(document, width, height, name) {
45   var expected = {width: width, height: height, name: name};
46   return repeatUntil(function() {
47     var fullResCanvas = document.querySelector(
48         '.gallery[mode="slide"] .content canvas.fullres');
49     var nameBox = document.querySelector('.namebox');
50     var actual = {
51       width: fullResCanvas && fullResCanvas.width,
52       height: fullResCanvas && fullResCanvas.height,
53       name: nameBox && nameBox.value
54     };
55     if (!chrome.test.checkDeepEq(expected, actual)) {
56       return pending('Slide mode state, expected is %j, actual is %j.',
57                      expected, actual);
58     }
59     return actual;
60   });
61 }