Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Unified Diff: ui/file_manager/video_player/js/cast/caster.js

Issue 505043002: Files.app Test: check the cast icon in drive volume (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a test Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/file_manager/video_player/js/background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/video_player/js/cast/caster.js
diff --git a/ui/file_manager/video_player/js/cast/caster.js b/ui/file_manager/video_player/js/cast/caster.js
index e349f03bf7965db772d6d9868fcf140490d917d0..a626a69cedcaaa17f441ad0a9e13fecae958afbf 100644
--- a/ui/file_manager/video_player/js/cast/caster.js
+++ b/ui/file_manager/video_player/js/cast/caster.js
@@ -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);
@@ -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.
@@ -66,33 +76,38 @@ 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.
*/
function initializeApi() {
« no previous file with comments | « ui/file_manager/video_player/js/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698