Commit 6939ba35 authored by yoshiki's avatar yoshiki Committed by Commit bot

Files.app Test: check the cast icon in drive volume

This patch introduces the mock cast API which provide a dummy cast list and the cast icon is shown on the window. So we can check if the icon is shown correctly.

BUG=405415
TEST=manually tested

Review URL: https://codereview.chromium.org/505043002

Cr-Commit-Position: refs/heads/master@{#292944}
parent 92a819b0
...@@ -1436,6 +1436,12 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase { ...@@ -1436,6 +1436,12 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase {
FileManagerBrowserTestBase::SetUp(); FileManagerBrowserTestBase::SetUp();
} }
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(
chromeos::switches::kEnableVideoPlayerChromecastSupport);
FileManagerBrowserTestBase::SetUpCommandLine(command_line);
}
virtual std::string OnMessage(const std::string& name, virtual std::string OnMessage(const std::string& name,
const base::Value* value) OVERRIDE; const base::Value* value) OVERRIDE;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileOverview This file loads the MOCK cast APIs for test.
*/
chrome.cast = {};
/**
* @enum {string}
* @const
*/
chrome.cast.ReceiverAvailability = {
UNAVAILABLE: 'unavailable',
AVAILABLE: 'available',
};
Object.freeze(chrome.cast.ReceiverAvailability);
/**
* @constructor
*/
chrome.cast.SessionRequest = function() {
};
/**
* @constructor
* @param {chrome.cast.SessionRequest} sessionRequest
* @param {function(chrome.cast.Session)} onSession
* @param {function(chrome.cast.ReceiverAvailability)} onReceiver
*/
chrome.cast.ApiConfig = function(sessionRequest, onSession, onReceiver) {
this.onReceiver_ = onReceiver;
Object.seal(this);
};
/**
* @param {chrome.cast.ApiConfig} apiConfig
* @param {function()} onInitSuccess
* @param {function(chrome.cast.Error)} onError
*/
chrome.cast.initialize = function(apiConfig, onInitSuccess, onError) {
this.apiConfig_ = apiConfig;
var receiver1 = {friendlyName: 'test cast', label: 'testcast'};
var receivers = [receiver1];
setTimeout(this.apiConfig_.onReceiver_.bind(
null, chrome.cast.ReceiverAvailability.UNAVAILABLE, []));
setTimeout(this.apiConfig_.onReceiver_.bind(
null, chrome.cast.ReceiverAvailability.AVAILABLE, receivers), 1000);
onInitSuccess();
};
/**
* Initialized apiConfig value.
* @type {chrome.cast.ApiConfig}
* @private
*/
chrome.cast.apiConfig_ = null;
/**
* @const
*/
chrome.cast.isAvailable = true;
Object.seal(chrome.cast);
// Invokes the handler.
if (window['__onGCastApiAvailable'])
window['__onGCastApiAvailable'](true, null);
...@@ -13,12 +13,13 @@ ...@@ -13,12 +13,13 @@
*/ */
function openSingleVideo(volumeName, volumeType) { function openSingleVideo(volumeName, volumeType) {
var entries = [ENTRIES.world]; var entries = [ENTRIES.world];
return launch(volumeName, volumeType, entries).then(function(videoPlayer) { return launch(volumeName, volumeType, entries).then(function(args) {
var videoPlayer = args[1];
chrome.test.assertTrue(videoPlayer.hasAttribute('first-video')); chrome.test.assertTrue(videoPlayer.hasAttribute('first-video'));
chrome.test.assertTrue(videoPlayer.hasAttribute('last-video')); chrome.test.assertTrue(videoPlayer.hasAttribute('last-video'));
chrome.test.assertFalse(videoPlayer.hasAttribute('multiple')); chrome.test.assertFalse(videoPlayer.hasAttribute('multiple'));
chrome.test.assertFalse(videoPlayer.hasAttribute('disabled')); chrome.test.assertFalse(videoPlayer.hasAttribute('disabled'));
return videoPlayer; return args;
}); });
} }
...@@ -28,7 +29,8 @@ function openSingleVideo(volumeName, volumeType) { ...@@ -28,7 +29,8 @@ function openSingleVideo(volumeName, volumeType) {
*/ */
function openSingleVideoOnDownloads() { function openSingleVideoOnDownloads() {
var test = openSingleVideo('local', VolumeManagerCommon.VolumeType.DOWNLOADS); var test = openSingleVideo('local', VolumeManagerCommon.VolumeType.DOWNLOADS);
return test.then(function(videoPlayer) { return test.then(function(args) {
var videoPlayer = args[1];
chrome.test.assertFalse(videoPlayer.hasAttribute('cast-available')); chrome.test.assertFalse(videoPlayer.hasAttribute('cast-available'));
}); });
} }
...@@ -39,8 +41,13 @@ function openSingleVideoOnDownloads() { ...@@ -39,8 +41,13 @@ function openSingleVideoOnDownloads() {
*/ */
function openSingleVideoOnDrive() { function openSingleVideoOnDrive() {
var test = openSingleVideo('drive', VolumeManagerCommon.VolumeType.DRIVE); var test = openSingleVideo('drive', VolumeManagerCommon.VolumeType.DRIVE);
return test.then(function(videoPlayer) { return test.then(function(args) {
// TODO(yoshiki): flip this after launching the feature. var appWindow = args[0];
var videoPlayer = args[1];
chrome.test.assertFalse(videoPlayer.hasAttribute('cast-available')); chrome.test.assertFalse(videoPlayer.hasAttribute('cast-available'));
// Loads cast extension and wait for available cast.
loadMockCastExtesntion(appWindow);
return waitForElement(appWindow, '#video-player[cast-available]');
}); });
} }
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* Overrides fileBrowserPrivate.getDownloadUrl
* @param {string} url
* @param {function(string)} callback
*/
chrome.fileBrowserPrivate.getDownloadUrl = function(url, callback) {
var dummyUrl = 'http://example.com/test.mp4?access_token=ACCESSTOKEN;
setTimeout(callback.bind(null, dummyUrl));
};
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
* @return {Promise} Promise to be fulfilled with the video player element. * @return {Promise} Promise to be fulfilled with the video player element.
*/ */
function launch(testVolumeName, volumeType, entries, opt_selected) { function launch(testVolumeName, volumeType, entries, opt_selected) {
var entriesPromise = addEntries([testVolumeName], entries).then(function() { var entriesPromise = addEntries([testVolumeName], entries).then(function() {
var selectedEntries = opt_selected || entries; var selectedEntries = opt_selected || entries;
return getFilesUnderVolume( return getFilesUnderVolume(
...@@ -32,12 +31,32 @@ function launch(testVolumeName, volumeType, entries, opt_selected) { ...@@ -32,12 +31,32 @@ function launch(testVolumeName, volumeType, entries, opt_selected) {
})).then(function() { })).then(function() {
appWindow = appWindowsForTest[entries[0].name]; appWindow = appWindowsForTest[entries[0].name];
}); });
}).then(function() {
return waitForElement(appWindow, 'body').then(function() {
var script = document.createElement('script');
script.src =
'chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/' +
'video_player/test_helper_on_ui_page.js';
appWindow.contentWindow.document.body.appendChild(script);
});
}).then(function() { }).then(function() {
return Promise.all([ return Promise.all([
waitForElement(appWindow, '#video-player[first-video][last-video]'), waitForElement(appWindow, '#video-player[first-video][last-video]'),
waitForElement(appWindow, '.play.media-button[state="playing"]'), waitForElement(appWindow, '.play.media-button[state="playing"]'),
]).then(function(args) { ]).then(function(args) {
return args[0]; return [appWindow, args[0]];
}); });
}); });
} }
/**
* Loads the mock cast extension to the content page.
* @param {AppWindow} appWindow The target video player window.
*/
function loadMockCastExtesntion(appWindow) {
var script = document.createElement('script');
script.src =
'chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/' +
'cast_extension_mock/load.js';
appWindow.contentWindow.document.body.appendChild(script);
}
...@@ -84,9 +84,13 @@ function open(videos) { ...@@ -84,9 +84,13 @@ function open(videos) {
// Stores the window for test purpose. // Stores the window for test purpose.
appWindowsForTest[videos[0].entry.name] = createdWindow; appWindowsForTest[videos[0].entry.name] = createdWindow;
createdWindow.setIcon('images/icon/video-player-64.png');
createdWindow.contentWindow.videos = videos; createdWindow.contentWindow.videos = videos;
chrome.runtime.sendMessage({ready: true}, function() {}); createdWindow.setIcon('images/icon/video-player-64.png');
if (chrome.test)
createdWindow.contentWindow.loadMockCastExtensionForTest = true;
chrome.runtime.sendMessage({ready: true});
}).catch(function(error) { }).catch(function(error) {
console.error('Launch failed', error.stack || error); console.error('Launch failed', error.stack || error);
return Promise.reject(error); return Promise.reject(error);
......
...@@ -22,6 +22,13 @@ util.addPageLoadHandler(function() { ...@@ -22,6 +22,13 @@ util.addPageLoadHandler(function() {
* Starts initialization of cast-related feature. * Starts initialization of cast-related feature.
*/ */
function initialize() { function initialize() {
if (window.loadMockCastExtensionForTest) {
// If the test flag is set, the mock extension for test will be laoded by
// the test script. Sets the handler to wait for loading.
onLoadCastExtension(initializeApi);
return;
}
CastExtensionDiscoverer.findInstalledExtension(function(foundId) { CastExtensionDiscoverer.findInstalledExtension(function(foundId) {
if (foundId) if (foundId)
loadCastAPI(initializeApi); loadCastAPI(initializeApi);
...@@ -31,7 +38,10 @@ function initialize() { ...@@ -31,7 +38,10 @@ function initialize() {
} }
/** /**
* Executes the given callback after the cast extension is initialized. * Loads the cast API extention. If not install, the extension is installed
* in background before load. The cast API will load the cast SDK automatically.
* The given callback is executes after the cast SDK extension is initialized.
*
* @param {function} callback Callback (executed asynchronously). * @param {function} callback Callback (executed asynchronously).
* @param {boolean=} opt_secondTry Spericy try if it's second call after * @param {boolean=} opt_secondTry Spericy try if it's second call after
* installation of Cast API extension. * installation of Cast API extension.
...@@ -66,32 +76,37 @@ function loadCastAPI(callback, opt_secondTry) { ...@@ -66,32 +76,37 @@ function loadCastAPI(callback, opt_secondTry) {
}.wrap()); }.wrap());
}.wrap(); }.wrap();
var onLoad = function() { // Trys to load the cast API extention which is defined in manifest.json.
if(!chrome.cast || !chrome.cast.isAvailable) {
var checkTimer = setTimeout(function() {
console.error('Either "Google Cast API" or "Google Cast" extension ' +
'seems not to be installed?');
}.wrap(), 5000);
window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
clearTimeout(checkTimer);
if (loaded)
callback();
else
console.error('Google Cast extension load failed.', errorInfo);
}.wrap();
} else {
setTimeout(callback); // Runs asynchronously.
}
}.wrap();
script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js'; script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js';
script.addEventListener('error', onError); script.addEventListener('error', onError);
script.addEventListener('load', onLoad); script.addEventListener('load', onLoadCastExtension.bind(null, callback));
document.body.appendChild(script); document.body.appendChild(script);
} }
/**
* Loads the cast sdk extension.
* @param {function()} callback Callback (executed asynchronously).
*/
function onLoadCastExtension(callback) {
if(!chrome.cast || !chrome.cast.isAvailable) {
var checkTimer = setTimeout(function() {
console.error('Either "Google Cast API" or "Google Cast" extension ' +
'seems not to be installed?');
}.wrap(), 5000);
window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
clearTimeout(checkTimer);
if (loaded)
callback();
else
console.error('Google Cast extension load failed.', errorInfo);
}.wrap();
} else {
setTimeout(callback); // Runs asynchronously.
}
};
/** /**
* Initialize Cast API. * Initialize Cast API.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment