Skip to content

Commit

Permalink
Files.app Test: check the cast icon in drive volume
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
yoshikig authored and Commit bot committed Sep 2, 2014
1 parent 92a819b commit 6939ba3
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,12 @@ class VideoPlayerBrowserTestBase : public FileManagerBrowserTestBase {
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,
const base::Value* value) OVERRIDE;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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);
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*/
function openSingleVideo(volumeName, volumeType) {
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('last-video'));
chrome.test.assertFalse(videoPlayer.hasAttribute('multiple'));
chrome.test.assertFalse(videoPlayer.hasAttribute('disabled'));
return videoPlayer;
return args;
});
}

Expand All @@ -28,7 +29,8 @@ function openSingleVideo(volumeName, volumeType) {
*/
function openSingleVideoOnDownloads() {
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'));
});
}
Expand All @@ -39,8 +41,13 @@ function openSingleVideoOnDownloads() {
*/
function openSingleVideoOnDrive() {
var test = openSingleVideo('drive', VolumeManagerCommon.VolumeType.DRIVE);
return test.then(function(videoPlayer) {
// TODO(yoshiki): flip this after launching the feature.
return test.then(function(args) {
var appWindow = args[0];
var videoPlayer = args[1];
chrome.test.assertFalse(videoPlayer.hasAttribute('cast-available'));

// Loads cast extension and wait for available cast.
loadMockCastExtesntion(appWindow);
return waitForElement(appWindow, '#video-player[cast-available]');
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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));
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* @return {Promise} Promise to be fulfilled with the video player element.
*/
function launch(testVolumeName, volumeType, entries, opt_selected) {

var entriesPromise = addEntries([testVolumeName], entries).then(function() {
var selectedEntries = opt_selected || entries;
return getFilesUnderVolume(
Expand All @@ -32,12 +31,32 @@ function launch(testVolumeName, volumeType, entries, opt_selected) {
})).then(function() {
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() {
return Promise.all([
waitForElement(appWindow, '#video-player[first-video][last-video]'),
waitForElement(appWindow, '.play.media-button[state="playing"]'),
]).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);
}
8 changes: 6 additions & 2 deletions ui/file_manager/video_player/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ function open(videos) {
// Stores the window for test purpose.
appWindowsForTest[videos[0].entry.name] = createdWindow;

createdWindow.setIcon('images/icon/video-player-64.png');
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) {
console.error('Launch failed', error.stack || error);
return Promise.reject(error);
Expand Down
59 changes: 37 additions & 22 deletions ui/file_manager/video_player/js/cast/caster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ util.addPageLoadHandler(function() {
* Starts initialization of cast-related feature.
*/
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) {
if (foundId)
loadCastAPI(initializeApi);
Expand All @@ -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 {boolean=} opt_secondTry Spericy try if it's second call after
* installation of Cast API extension.
Expand Down Expand Up @@ -66,32 +76,37 @@ function loadCastAPI(callback, opt_secondTry) {
}.wrap());
}.wrap();

var onLoad = function() {
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();

// Trys to load the cast API extention which is defined in manifest.json.
script.src = '_modules/mafeflapfdfljijmlienjedomfjfmhpd/cast_sender.js';
script.addEventListener('error', onError);
script.addEventListener('load', onLoad);
script.addEventListener('load', onLoadCastExtension.bind(null, callback));
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.
*/
Expand Down

0 comments on commit 6939ba3

Please sign in to comment.