Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / video_player / 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 video player with the given 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  * @return {Promise} Promise to be fulfilled with the video player element.
18  */
19 function launch(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   var appWindow = null;
28   return entriesPromise.then(function(entries) {
29     return open(entries.map(function(entry) {
30       return {entry: entry, title: entry.name, url: entry.toURL()};
31     })).then(function() {
32       appWindow = appWindowsForTest[entries[0].name];
33     });
34   }).then(function() {
35     return waitForElement(appWindow, 'body').then(function() {
36       var script = document.createElement('script');
37       script.src =
38           'chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/' +
39           'video_player/test_helper_on_ui_page.js';
40       appWindow.contentWindow.document.body.appendChild(script);
41     });
42   }).then(function() {
43     return Promise.all([
44       waitForElement(appWindow, '#video-player[first-video][last-video]'),
45       waitForElement(appWindow, '.play.media-button[state="playing"]'),
46     ]).then(function(args) {
47       return [appWindow, args[0]];
48     });
49   });
50 }
51
52 /**
53  * Loads the mock cast extension to the content page.
54  * @param {AppWindow} appWindow The target video player window.
55  */
56 function loadMockCastExtesntion(appWindow) {
57   var script = document.createElement('script');
58   script.src =
59       'chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/' +
60       'cast_extension_mock/load.js';
61   appWindow.contentWindow.document.body.appendChild(script);
62 }