Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / ui / file_manager / integration_tests / audio_player / background.js
blob2638afc2930a7530d24eea049705a82fb52e2bd8
1 // Copyright 2015 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 audio player.
9 * @type {string}
10 * @const
12 var AUDIO_PLAYER_APP_ID = 'cjbfomnbifhcdnihkgipgfcihmgjfhbf';
14 var remoteCallAudioPlayer = new RemoteCall(AUDIO_PLAYER_APP_ID);
16 /**
17 * Launches the audio player 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 audio player element.
28 function launch(testVolumeName, volumeType, entries, opt_selected) {
29 var entriesPromise = addEntries([testVolumeName], entries).then(function() {
30 var selectedEntries = opt_selected || entries;
31 var selectedEntryNames =
32 selectedEntries.map(function(entry) { return entry.nameText; });
33 return remoteCallAudioPlayer.getFilesUnderVolume(
34 volumeType, selectedEntryNames);
35 });
37 var appWindow = null;
38 return entriesPromise.then(function(urls) {
39 return remoteCallAudioPlayer.callRemoteTestUtil(
40 'openAudioPlayer', null, [urls]);
41 }).then(function(windowId) {
42 appWindow = windowId;
43 return remoteCallAudioPlayer.waitForElement(appWindow, 'body');
44 }).then(function() {
45 return Promise.all([
46 remoteCallAudioPlayer.waitForElement(
47 appWindow, 'audio-player[playing]'),
48 ]);
49 }).then(function(args) {
50 return [appWindow, args[0]];
51 });
54 /**
55 * Namespace for test cases.
57 var testcase = {};
59 // Ensure the test cases are loaded.
60 window.addEventListener('load', function() {
61 var steps = [
62 // Check for the guest mode.
63 function() {
64 chrome.test.sendMessage(
65 JSON.stringify({name: 'isInGuestMode'}), steps.shift());
67 // Obtain the test case name.
68 function(result) {
69 if (JSON.parse(result) != chrome.extension.inIncognitoContext)
70 return;
71 chrome.test.sendMessage(
72 JSON.stringify({name: 'getRootPaths'}), steps.shift());
74 // Obtain the root entry paths.
75 function(result) {
76 var roots = JSON.parse(result);
77 RootPath.DOWNLOADS = roots.downloads;
78 RootPath.DRIVE = roots.drive;
79 chrome.test.sendMessage(
80 JSON.stringify({name: 'getTestName'}), steps.shift());
82 // Run the test case.
83 function(testCaseName) {
84 var targetTest = testcase[testCaseName];
85 if (!targetTest) {
86 chrome.test.fail(testCaseName + ' is not found.');
87 return;
89 // Specify the name of test to the test system.
90 targetTest.generatedName = testCaseName;
91 chrome.test.runTests([function() {
92 return testPromiseAndApps(targetTest(), [remoteCallAudioPlayer]);
93 }]);
96 steps.shift()();
97 });