From 47daf49f310022450f5516a5ffb2bbf413fca652 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Wed, 8 May 2019 09:43:59 -0700 Subject: [PATCH] Use arrow functions for callbacks. This is an automated change to convert use of "function" functions to arrow functions. This doesn't change all uses of bind() that could be converted. This also doesn't remove all "function" functions. Change-Id: I40ac7d086bcef947a1be083359c8fd1d4499a9c3 --- .eslintrc.js | 1 + demo/cast_receiver/receiver_app.js | 4 +- demo/main.js | 2 +- demo/service_worker.js | 4 +- lib/cast/cast_proxy.js | 40 +- lib/cast/cast_receiver.js | 54 +-- lib/cast/cast_sender.js | 8 +- lib/cast/cast_utils.js | 4 +- lib/dash/content_protection.js | 6 +- lib/dash/dash_parser.js | 42 +- lib/dash/mpd_utils.js | 10 +- lib/dash/segment_base.js | 2 +- lib/dash/segment_list.js | 6 +- lib/dash/segment_template.js | 2 +- lib/hls/hls_classes.js | 2 +- lib/hls/hls_parser.js | 30 +- lib/hls/hls_utils.js | 4 +- lib/media/drm_engine.js | 42 +- lib/media/media_source_engine.js | 18 +- lib/media/mp4_segment_index_parser.js | 4 +- lib/media/presentation_timeline.js | 2 +- lib/media/segment_index.js | 2 +- lib/media/streaming_engine.js | 68 ++-- lib/net/http_fetch_plugin.js | 2 +- lib/net/http_xhr_plugin.js | 4 +- lib/offline/storage.js | 6 +- lib/player.js | 18 +- lib/polyfill/mediasource.js | 2 +- lib/polyfill/video_play_promise.js | 2 +- lib/text/mp4_ttml_parser.js | 6 +- lib/text/mp4_vtt_parser.js | 20 +- lib/text/simple_text_displayer.js | 6 +- lib/text/text_engine.js | 12 +- lib/text/ttml_text_parser.js | 2 +- lib/text/vtt_text_parser.js | 2 +- lib/util/array_utils.js | 2 +- lib/util/functional.js | 4 +- lib/util/manifest_parser_utils.js | 8 +- lib/util/public_promise.js | 4 +- lib/util/stream_utils.js | 14 +- lib/util/xml_utils.js | 4 +- test/abr/simple_abr_manager_unit.js | 38 +- test/assumptions/uint8_array_unit.js | 4 +- test/cast/cast_proxy_unit.js | 150 ++++---- test/cast/cast_receiver_integration.js | 36 +- test/cast/cast_receiver_unit.js | 112 +++--- test/cast/cast_sender_unit.js | 204 +++++----- test/cast/cast_utils_unit.js | 42 +- .../dash_parser_content_protection_unit.js | 30 +- test/dash/dash_parser_live_unit.js | 142 +++---- test/dash/dash_parser_manifest_unit.js | 26 +- test/dash/dash_parser_segment_base_unit.js | 6 +- test/dash/dash_parser_segment_list_unit.js | 10 +- .../dash/dash_parser_segment_template_unit.js | 20 +- test/dash/mpd_utils_unit.js | 62 +-- test/deprecate/version_unit.js | 22 +- test/hls/hls_live_unit.js | 86 ++--- test/hls/hls_parser_unit.js | 52 +-- test/hls/manifest_text_parser_unit.js | 48 +-- test/media/adaptation_set_criteria_unit.js | 26 +- test/media/adaptation_set_unit.js | 14 +- test/media/drm_engine_integration.js | 38 +- test/media/drm_engine_unit.js | 164 ++++---- test/media/media_source_engine_integration.js | 10 +- test/media/media_source_engine_unit.js | 104 ++--- test/media/mp4_segment_index_parser_unit.js | 8 +- test/media/playhead_unit.js | 80 ++-- test/media/presentation_timeline_unit.js | 52 +-- test/media/segment_index_unit.js | 70 ++-- test/media/segment_reference_unit.js | 12 +- test/media/streaming_engine_integration.js | 10 +- test/media/streaming_engine_unit.js | 362 +++++++++--------- test/media/time_ranges_utils_unit.js | 30 +- test/media/transmuxer_integration.js | 24 +- test/media/webm_segment_index_parser_unit.js | 10 +- test/net/data_uri_plugin_unit.js | 28 +- test/net/http_plugin_unit.js | 46 +-- test/net/networking_engine_unit.js | 276 ++++++------- test/offline/indexeddb_storage_unit.js | 14 +- test/offline/manifest_convert_unit.js | 26 +- test/offline/offline_integration.js | 14 +- test/offline/offline_manifest_parser_unit.js | 18 +- test/offline/offline_scheme_unit.js | 14 +- test/offline/offline_uri_unit.js | 12 +- test/offline/storage_unit.js | 102 ++--- test/offline/v1_indexeddb_storage_unit.js | 20 +- test/player_integration.js | 38 +- test/player_unit.js | 208 +++++----- test/test/boot.js | 2 +- test/test/util/dash_parser_util.js | 6 +- test/test/util/jasmine_fetch.js | 16 +- test/test/util/manifest_generator.js | 2 +- test/test/util/offline_utils.js | 2 +- test/test/util/simple_fakes.js | 38 +- test/test/util/stream_generator.js | 8 +- test/test/util/streaming_engine_util.js | 16 +- test/test/util/test_scheme.js | 8 +- test/test/util/util.js | 26 +- test/text/cue_integration.js | 6 +- test/text/mp4_ttml_parser_unit.js | 16 +- test/text/mp4_vtt_parser_unit.js | 18 +- test/text/simple_text_displayer_unit.js | 26 +- test/text/text_engine_unit.js | 122 +++--- test/text/text_track_integration.js | 30 +- test/text/ttml_text_parser_unit.js | 60 +-- test/text/vtt_text_parser_unit.js | 70 ++-- test/ui/localization_unit.js | 48 +-- test/ui/ui_integration.js | 2 +- test/ui/ui_unit.js | 84 ++-- test/util/abortable_operation_unit.js | 66 ++-- test/util/array_utils_unit.js | 4 +- test/util/data_view_reader_unit.js | 62 +-- test/util/ebml_parser_unit.js | 38 +- test/util/event_manager_unit.js | 22 +- test/util/fake_event_target_unit.js | 36 +- test/util/iterables_unit.js | 26 +- test/util/language_utils_unit.js | 80 ++-- test/util/manifest_parser_utils_unit.js | 12 +- test/util/mp4_parser_unit.js | 48 +-- test/util/object_utils_unit.js | 14 +- test/util/pssh_unit.js | 18 +- test/util/stream_utils_unit.js | 38 +- test/util/string_utils_unit.js | 34 +- test/util/text_parser_unit.js | 60 +-- test/util/xml_utils_unit.js | 42 +- ui/controls.js | 2 +- ui/language_utils.js | 2 +- ui/resolution_selection.js | 6 +- ui/ui.js | 2 +- 129 files changed, 2307 insertions(+), 2306 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c3a09e166..d9a1a5ac1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -142,6 +142,7 @@ module.exports = { }], "no-useless-constructor": "error", "operator-assignment": "error", + "prefer-arrow-callback": "error", // }}} }, "overrides": [ diff --git a/demo/cast_receiver/receiver_app.js b/demo/cast_receiver/receiver_app.js index 5216eaab6..aa0b0e444 100644 --- a/demo/cast_receiver/receiver_app.js +++ b/demo/cast_receiver/receiver_app.js @@ -178,9 +178,9 @@ ShakaReceiver.prototype.onPlayStateChange_ = function() { } else { // Show controls for 3 seconds. this.controlsElement_.style.opacity = 1; - this.controlsTimerId_ = window.setTimeout(function() { + this.controlsTimerId_ = window.setTimeout(() => { this.controlsElement_.style.opacity = 0; - }.bind(this), 3000); + }, 3000); } }; diff --git a/demo/main.js b/demo/main.js index b6aeaea68..07b5f5ac2 100644 --- a/demo/main.js +++ b/demo/main.js @@ -655,7 +655,7 @@ class ShakaDemoMain { elem.removeAttribute('disabled'); elem.addEventListener('click', () => { const rawParams = location.hash.substr(1).split(';'); - const newParams = rawParams.filter(function(param) { + const newParams = rawParams.filter((param) => { // Remove current build type param(s). return param != 'compiled' && param.split('=')[0] != 'build'; }); diff --git a/demo/service_worker.js b/demo/service_worker.js index d9c05bdea..0d2d77f61 100644 --- a/demo/service_worker.js +++ b/demo/service_worker.js @@ -300,9 +300,9 @@ async function fetchAndCache(cache, request) { function timeout(seconds, asyncProcess) { return Promise.race([ asyncProcess, - new Promise(function(_, reject) { + new Promise(((_, reject) => { setTimeout(reject, seconds * 1000); - }), + })), ]); } diff --git a/lib/cast/cast_proxy.js b/lib/cast/cast_proxy.js index 2b51a867d..3ed24688a 100644 --- a/lib/cast/cast_proxy.js +++ b/lib/cast/cast_proxy.js @@ -196,7 +196,7 @@ shaka.cast.CastProxy.prototype.cast = function() { // TODO: transfer manually-selected tracks? // TODO: transfer side-loaded text tracks? - return this.sender_.cast(initState).then(function() { + return this.sender_.cast(initState).then(() => { if (!this.localPlayer_) { // We've already been destroyed. return; @@ -204,7 +204,7 @@ shaka.cast.CastProxy.prototype.cast = function() { // Unload the local manifest when casting succeeds. return this.localPlayer_.unload(); - }.bind(this)); + }); }; @@ -246,15 +246,15 @@ shaka.cast.CastProxy.prototype.init_ = function() { this.eventManager_ = new shaka.util.EventManager(); - shaka.cast.CastUtils.VideoEvents.forEach(function(name) { + shaka.cast.CastUtils.VideoEvents.forEach((name) => { this.eventManager_.listen(this.localVideo_, name, this.videoProxyLocalEvent_.bind(this)); - }.bind(this)); + }); - shaka.cast.CastUtils.PlayerEvents.forEach(function(name) { + shaka.cast.CastUtils.PlayerEvents.forEach((name) => { this.eventManager_.listen(this.localPlayer_, name, this.playerProxyLocalEvent_.bind(this)); - }.bind(this)); + }); // We would like to use Proxy here, but it is not supported on IE11 or Safari. this.videoProxy_ = {}; @@ -303,9 +303,9 @@ shaka.cast.CastProxy.prototype.getInitState_ = function() { // Pause local playback before capturing state. this.localVideo_.pause(); - shaka.cast.CastUtils.VideoInitStateAttributes.forEach(function(name) { + shaka.cast.CastUtils.VideoInitStateAttributes.forEach((name) => { initState['video'][name] = this.localVideo_[name]; - }.bind(this)); + }); // If the video is still playing, set the startTime. // Has no effect if nothing is loaded. @@ -313,21 +313,21 @@ shaka.cast.CastProxy.prototype.getInitState_ = function() { initState['startTime'] = this.localVideo_.currentTime; } - shaka.cast.CastUtils.PlayerInitState.forEach(function(pair) { + shaka.cast.CastUtils.PlayerInitState.forEach((pair) => { const getter = pair[0]; const setter = pair[1]; const value = /** @type {Object} */(this.localPlayer_)[getter](); initState['player'][setter] = value; - }.bind(this)); + }); - shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach(function(pair) { + shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach((pair) => { const getter = pair[0]; const setter = pair[1]; const value = /** @type {Object} */(this.localPlayer_)[getter](); initState['playerAfterLoad'][setter] = value; - }.bind(this)); + }); return initState; }; @@ -361,12 +361,12 @@ shaka.cast.CastProxy.prototype.onFirstCastStateUpdate_ = function() { */ shaka.cast.CastProxy.prototype.onResumeLocal_ = function() { // Transfer back the player state. - shaka.cast.CastUtils.PlayerInitState.forEach(function(pair) { + shaka.cast.CastUtils.PlayerInitState.forEach((pair) => { const getter = pair[0]; const setter = pair[1]; const value = this.sender_.get('player', getter)(); /** @type {Object} */(this.localPlayer_)[setter](value); - }.bind(this)); + }); // Get the most recent manifest URI and ended state. const assetUri = this.sender_.get('player', 'getAssetUri')(); @@ -392,9 +392,9 @@ shaka.cast.CastProxy.prototype.onResumeLocal_ = function() { // Get the video state into a temp variable since we will apply it async. const videoState = {}; - shaka.cast.CastUtils.VideoInitStateAttributes.forEach(function(name) { + shaka.cast.CastUtils.VideoInitStateAttributes.forEach((name) => { videoState[name] = this.sender_.get('video', name); - }.bind(this)); + }); // Finally, take on video state and player's "after load" state. manifestReady.then(() => { @@ -403,16 +403,16 @@ shaka.cast.CastProxy.prototype.onResumeLocal_ = function() { return; } - shaka.cast.CastUtils.VideoInitStateAttributes.forEach(function(name) { + shaka.cast.CastUtils.VideoInitStateAttributes.forEach((name) => { this.localVideo_[name] = videoState[name]; - }.bind(this)); + }); - shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach(function(pair) { + shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach((pair) => { const getter = pair[0]; const setter = pair[1]; const value = this.sender_.get('player', getter)(); /** @type {Object} */(this.localPlayer_)[setter](value); - }.bind(this)); + }); // Restore the original autoplay setting. this.localVideo_.autoplay = autoplay; diff --git a/lib/cast/cast_receiver.js b/lib/cast/cast_receiver.js index c7bb586ae..6eb9f2b53 100644 --- a/lib/cast/cast_receiver.js +++ b/lib/cast/cast_receiver.js @@ -190,15 +190,15 @@ shaka.cast.CastReceiver.prototype.init_ = function() { manager.start(); } - shaka.cast.CastUtils.VideoEvents.forEach(function(name) { + shaka.cast.CastUtils.VideoEvents.forEach((name) => { this.eventManager_.listen( this.video_, name, this.proxyEvent_.bind(this, 'video')); - }.bind(this)); + }); - shaka.cast.CastUtils.PlayerEvents.forEach(function(name) { + shaka.cast.CastUtils.PlayerEvents.forEach((name) => { this.eventManager_.listen( this.player_, name, this.proxyEvent_.bind(this, 'player')); - }.bind(this)); + }); // In our tests, the original Chromecast seems to have trouble decoding above // 1080p. It would be a waste to select a higher res anyway, given that the @@ -216,32 +216,32 @@ shaka.cast.CastReceiver.prototype.init_ = function() { // Do not start excluding values from update messages until the video is // fully loaded. - this.eventManager_.listen(this.video_, 'loadeddata', function() { + this.eventManager_.listen(this.video_, 'loadeddata', () => { this.startUpdatingUpdateNumber_ = true; - }.bind(this)); + }); // Maintain idle state. - this.eventManager_.listen(this.player_, 'loading', function() { + this.eventManager_.listen(this.player_, 'loading', () => { // No longer idle once loading. This allows us to show the spinner during // the initial buffering phase. this.isIdle_ = false; this.onCastStatusChanged_(); - }.bind(this)); - this.eventManager_.listen(this.video_, 'playing', function() { + }); + this.eventManager_.listen(this.video_, 'playing', () => { // No longer idle once playing. This allows us to replay a video without // reloading. this.isIdle_ = false; this.onCastStatusChanged_(); - }.bind(this)); - this.eventManager_.listen(this.video_, 'pause', function() { + }); + this.eventManager_.listen(this.video_, 'pause', () => { this.onCastStatusChanged_(); - }.bind(this)); - this.eventManager_.listen(this.player_, 'unloading', function() { + }); + this.eventManager_.listen(this.player_, 'unloading', () => { // Go idle when unloading content. this.isIdle_ = true; this.onCastStatusChanged_(); - }.bind(this)); - this.eventManager_.listen(this.video_, 'ended', function() { + }); + this.eventManager_.listen(this.video_, 'ended', () => { // Go idle 5 seconds after 'ended', assuming we haven't started again or // been destroyed. const timer = new shaka.util.Timer(() => { @@ -252,7 +252,7 @@ shaka.cast.CastReceiver.prototype.init_ = function() { }); timer.tickAfter(/* seconds= */ 5); - }.bind(this)); + }); // Do not start polling until after the sender's 'init' message is handled. }; @@ -281,7 +281,7 @@ shaka.cast.CastReceiver.prototype.onCastStatusChanged_ = function() { // Do this asynchronously so that synchronous changes to idle state (such as // Player calling unload() as part of load()) are coalesced before the event // goes out. - Promise.resolve().then(function() { + Promise.resolve().then(() => { if (!this.player_) { // We've already been destroyed. return; @@ -293,7 +293,7 @@ shaka.cast.CastReceiver.prototype.onCastStatusChanged_ = function() { if (!this.maybeSendMediaInfoMessage_()) { this.sendMediaStatus_(0); } - }.bind(this)); + }); }; @@ -397,9 +397,9 @@ shaka.cast.CastReceiver.prototype.pollAttributes_ = function() { 'player': {}, }; - shaka.cast.CastUtils.VideoAttributes.forEach(function(name) { + shaka.cast.CastUtils.VideoAttributes.forEach((name) => { update['video'][name] = this.video_[name]; - }.bind(this)); + }); // TODO: Instead of this variable frequency update system, instead cache the // previous player state and only send over changed values, with complete @@ -589,9 +589,9 @@ shaka.cast.CastReceiver.prototype.onShakaMessage_ = function(event) { if (targetName == 'player' && methodName == 'load') { // Wait until the manifest has actually loaded to send another media // info message, so on a new load it doesn't send the old info over. - p = p.then(function() { + p = p.then(() => { this.initialStatusUpdatePending_ = true; - }.bind(this)); + }); } // Replies must go back to the specific sender who initiated, so that we // don't have to deal with conflicting IDs between senders. @@ -639,14 +639,14 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) { break; } case 'STOP': - this.player_.unload().then(function() { + this.player_.unload().then(() => { if (!this.player_) { // We've already been destroyed. return; } this.sendMediaStatus_(0); - }.bind(this)); + }); break; case 'GET_STATUS': // TODO(ismena): According to the SDK this is supposed to be a @@ -689,7 +689,7 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) { if (autoplay) { this.video_.autoplay = true; } - this.player_.load(assetUri, currentTime).then(function() { + this.player_.load(assetUri, currentTime).then(() => { if (!this.player_) { // We've already been destroyed. return; @@ -697,7 +697,7 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) { // Notify generic controllers that the media has changed. this.sendMediaInfoMessage_(); - }.bind(this)).catch(function(error) { + }).catch((error) => { // Load failed. Dispatch the error message to the sender. let type = 'LOAD_FAILED'; if (error.category == shaka.util.Error.Category.PLAYER && @@ -709,7 +709,7 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) { 'requestId': Number(message['requestId']), 'type': type, }, this.genericBus_); - }.bind(this)); + }); break; } default: diff --git a/lib/cast/cast_sender.js b/lib/cast/cast_sender.js index d77d1d4d1..d94e4059f 100644 --- a/lib/cast/cast_sender.js +++ b/lib/cast/cast_sender.js @@ -206,8 +206,8 @@ shaka.cast.CastSender.prototype.init = function() { // TODO: Have never seen this fail. When would it and how should we react? chrome.cast.initialize(apiConfig, - function() { shaka.log.debug('CastSender: init'); }, - function(error) { shaka.log.error('CastSender: init error', error); }); + () => { shaka.log.debug('CastSender: init'); }, + (error) => { shaka.log.error('CastSender: init error', error); }); if (shaka.cast.CastSender.hasReceivers_) { // Fire a fake cast status change, to simulate the update that // would be fired normally. @@ -307,7 +307,7 @@ shaka.cast.CastSender.prototype.forceDisconnect = function() { this.rejectAllPromises_(); if (shaka.cast.CastSender.session_) { this.removeListeners_(); - shaka.cast.CastSender.session_.stop(function() {}, function() {}); + shaka.cast.CastSender.session_.stop(() => {}, () => {}); shaka.cast.CastSender.session_ = null; } }; @@ -657,6 +657,6 @@ shaka.cast.CastSender.prototype.sendMessage_ = function(message) { const session = shaka.cast.CastSender.session_; session.sendMessage(shaka.cast.CastUtils.SHAKA_MESSAGE_NAMESPACE, serialized, - function() {}, // success callback + () => {}, // success callback shaka.log.error); // error callback }; diff --git a/lib/cast/cast_utils.js b/lib/cast/cast_utils.js index 5f01036ae..5d8b1fb7e 100644 --- a/lib/cast/cast_utils.js +++ b/lib/cast/cast_utils.js @@ -255,7 +255,7 @@ shaka.cast.CastUtils.GENERIC_MESSAGE_NAMESPACE = * @return {string} */ shaka.cast.CastUtils.serialize = function(thing) { - return JSON.stringify(thing, function(key, value) { + return JSON.stringify(thing, (key, value) => { if (typeof value == 'function') { // Functions can't be (safely) serialized. return undefined; @@ -317,7 +317,7 @@ shaka.cast.CastUtils.serialize = function(thing) { * @return {?} */ shaka.cast.CastUtils.deserialize = function(str) { - return JSON.parse(str, function(key, value) { + return JSON.parse(str, (key, value) => { if (value == 'NaN') { return NaN; } else if (value == '-Infinity') { diff --git a/lib/dash/content_protection.js b/lib/dash/content_protection.js index 22741f24b..4d345d374 100644 --- a/lib/dash/content_protection.js +++ b/lib/dash/content_protection.js @@ -151,7 +151,7 @@ shaka.dash.ContentProtection.parseFromAdaptationSet = function( if (!ignoreDrmInfo) { // Find the default key ID and init data. Create a new array of all the // non-CENC elements. - parsedNonCenc = parsed.filter(function(elem) { + parsedNonCenc = parsed.filter((elem) => { if (elem.schemeUri == ContentProtection.MP4Protection_) { goog.asserts.assert(!elem.init || elem.init.length, 'Init data must be null or non-empty.'); @@ -244,8 +244,8 @@ shaka.dash.ContentProtection.parseFromRepresentation = function( } else if (repContext.drmInfos.length > 0) { // If this is not the first Representation, then we need to remove entries // from the context that do not appear in this Representation. - context.drmInfos = context.drmInfos.filter(function(asInfo) { - return repContext.drmInfos.some(function(repInfo) { + context.drmInfos = context.drmInfos.filter((asInfo) => { + return repContext.drmInfos.some((repInfo) => { return repInfo.keySystem == asInfo.keySystem; }); }); diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index 977260e17..028a8d7cd 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -379,11 +379,11 @@ shaka.dash.DashParser.prototype.stop = function() { * @exportInterface */ shaka.dash.DashParser.prototype.update = function() { - this.requestManifest_().catch(function(error) { + this.requestManifest_().catch((error) => { if (!this.playerInterface_ || !error) return; goog.asserts.assert(error instanceof shaka.util.Error, 'Bad error type'); this.playerInterface_.onError(error); - }.bind(this)); + }); }; @@ -813,20 +813,20 @@ shaka.dash.DashParser.prototype.parsePeriod_ = function( } const normalAdaptationSets = adaptationSets - .filter(function(as) { return !as.trickModeFor; }); + .filter((as) => { return !as.trickModeFor; }); const trickModeAdaptationSets = adaptationSets - .filter(function(as) { return as.trickModeFor; }); + .filter((as) => { return as.trickModeFor; }); // Attach trick mode tracks to normal tracks. - trickModeAdaptationSets.forEach(function(trickModeSet) { + trickModeAdaptationSets.forEach((trickModeSet) => { // There may be multiple trick mode streams, but we do not currently // support that. Just choose one. const trickModeVideo = trickModeSet.streams[0]; const targetId = trickModeSet.trickModeFor; - normalAdaptationSets.forEach(function(normalSet) { + normalAdaptationSets.forEach((normalSet) => { if (normalSet.id == targetId) { - normalSet.streams.forEach(function(stream) { + normalSet.streams.forEach((stream) => { stream.trickModeVideo = trickModeVideo; }); } @@ -886,7 +886,7 @@ shaka.dash.DashParser.prototype.parsePeriod_ = function( */ shaka.dash.DashParser.prototype.getSetsOfType_ = function( adaptationSets, type) { - return adaptationSets.filter(function(as) { + return adaptationSets.filter((as) => { return as.contentType == type; }); }; @@ -991,7 +991,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { let main = false; const roleElements = XmlUtils.findChildren(elem, 'Role'); - const roleValues = roleElements.map(function(role) { + const roleValues = roleElements.map((role) => { return role.getAttribute('value'); }).filter(Functional.isNotNull); @@ -1026,7 +1026,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { // ID of real AdaptationSet if this is a trick mode set: let trickModeFor = null; let unrecognizedEssentialProperty = false; - essentialProperties.forEach(function(prop) { + essentialProperties.forEach((prop) => { const schemeId = prop.getAttribute('schemeIdUri'); if (schemeId == 'http://dashif.org/guidelines/trickmode') { trickModeFor = prop.getAttribute('value'); @@ -1107,7 +1107,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { const streams = representations .map(this.parseRepresentation_.bind(this, context, contentProtection, kind, language, label, main, roleValues, closedCaptions)) - .filter(function(s) { return !!s; }); + .filter((s) => { return !!s; }); if (streams.length == 0) { // Ignore empty AdaptationSets if they are for text content. @@ -1132,16 +1132,16 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { context.adaptationSet.contentType = shaka.dash.DashParser.guessContentType_(mimeType, codecs); - streams.forEach(function(stream) { + streams.forEach((stream) => { stream.type = context.adaptationSet.contentType; }); } - streams.forEach(function(stream) { + streams.forEach((stream) => { // Some DRM license providers require that we have a default // key ID from the manifest in the wrapped license request. // Thus, it should be put in drmInfo to be accessible to request filters. - contentProtection.drmInfos.forEach(function(drmInfo) { + contentProtection.drmInfos.forEach((drmInfo) => { if (stream.keyId) { drmInfo.keyIds.push(stream.keyId); } @@ -1149,7 +1149,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { }); const repIds = representations - .map(function(node) { return node.getAttribute('id'); }) + .map((node) => { return node.getAttribute('id'); }) .filter(shaka.util.Functional.isNotNull); return { @@ -1244,7 +1244,7 @@ shaka.dash.DashParser.prototype.parseRepresentation_ = function( } return new shaka.media.SegmentReference( - 1, 0, duration, function() { return baseUris; }, 0, null); + 1, 0, duration, (() => { return baseUris; }), 0, null); }, initSegmentReference: null, scaledPresentationTimeOffset: 0, @@ -1621,7 +1621,7 @@ shaka.dash.DashParser.prototype.requestForTiming_ = * @private */ shaka.dash.DashParser.prototype.parseUtcTiming_ = function(baseUris, elems) { - const schemesAndValues = elems.map(function(elem) { + const schemesAndValues = elems.map((elem) => { return { scheme: elem.getAttribute('schemeIdUri'), value: elem.getAttribute('value'), @@ -1639,7 +1639,7 @@ shaka.dash.DashParser.prototype.parseUtcTiming_ = function(baseUris, elems) { } const Functional = shaka.util.Functional; - return Functional.createFallbackPromiseChain(schemesAndValues, function(sv) { + return Functional.createFallbackPromiseChain(schemesAndValues, (sv) => { const scheme = sv.scheme; const value = sv.value; switch (scheme) { @@ -1670,7 +1670,7 @@ shaka.dash.DashParser.prototype.parseUtcTiming_ = function(baseUris, elems) { 'Unrecognized scheme in UTCTiming element', scheme); return Promise.reject(); } - }.bind(this)).catch(function() { + }).catch(() => { shaka.log.alwaysWarn( 'A UTCTiming element should always be given in live manifests! ' + 'This content may not play on clients with bad clocks!'); @@ -1696,7 +1696,7 @@ shaka.dash.DashParser.prototype.parseEventStream_ = function( const value = elem.getAttribute('value') || ''; const timescale = XmlUtils.parseAttr(elem, 'timescale', parseNumber) || 1; - XmlUtils.findChildren(elem, 'Event').forEach(function(eventNode) { + XmlUtils.findChildren(elem, 'Event').forEach((eventNode) => { const presentationTime = XmlUtils.parseAttr(eventNode, 'presentationTime', parseNumber) || 0; const duration = @@ -1722,7 +1722,7 @@ shaka.dash.DashParser.prototype.parseEventStream_ = function( }; this.playerInterface_.onTimelineRegionAdded(region); - }.bind(this)); + }); }; diff --git a/lib/dash/mpd_utils.js b/lib/dash/mpd_utils.js index 716f7165b..6624c1168 100644 --- a/lib/dash/mpd_utils.js +++ b/lib/dash/mpd_utils.js @@ -113,7 +113,7 @@ shaka.dash.MpdUtils.fillUriTemplate = function( const re = /\$(RepresentationID|Number|Bandwidth|Time)?(?:%0([0-9]+)([diouxX]))?\$/g; - const uri = uriTemplate.replace(re, function(match, name, widthStr, format) { + const uri = uriTemplate.replace(re, (match, name, widthStr, format) => { if (match == '$$') { return '$'; } @@ -399,8 +399,8 @@ shaka.dash.MpdUtils.inheritAttribute = function(context, callback, attribute) { ].filter(Functional.isNotNull); return nodes - .map(function(s) { return s.getAttribute(attribute); }) - .reduce(function(all, part) { return all || part; }); + .map((s) => { return s.getAttribute(attribute); }) + .reduce((all, part) => { return all || part; }); }; @@ -428,8 +428,8 @@ shaka.dash.MpdUtils.inheritChild = function(context, callback, child) { const XmlUtils = shaka.util.XmlUtils; return nodes - .map(function(s) { return XmlUtils.findChild(s, child); }) - .reduce(function(all, part) { return all || part; }); + .map((s) => { return XmlUtils.findChild(s, child); }) + .reduce((all, part) => { return all || part; }); }; diff --git a/lib/dash/segment_base.js b/lib/dash/segment_base.js index d191f7b22..64dbbfbbb 100644 --- a/lib/dash/segment_base.js +++ b/lib/dash/segment_base.js @@ -152,7 +152,7 @@ shaka.dash.SegmentBase.createSegmentIndexFromUris = function( ]; localRequest = null; - return Promise.all(async).then(function(results) { + return Promise.all(async).then((results) => { const indexData = results[0]; const initData = results[1] || null; let references = null; diff --git a/lib/dash/segment_list.js b/lib/dash/segment_list.js index 31b418928..db93d7ca8 100644 --- a/lib/dash/segment_list.js +++ b/lib/dash/segment_list.js @@ -320,9 +320,9 @@ shaka.dash.SegmentList.parseMediaSegments_ = function(context) { // Search each SegmentList for one with at least one SegmentURL element, // select the first one, and convert each SegmentURL element to a tuple. return segmentLists - .map(function(node) { return XmlUtils.findChildren(node, 'SegmentURL'); }) - .reduce(function(all, part) { return all.length > 0 ? all : part; }) - .map(function(urlNode) { + .map((node) => { return XmlUtils.findChildren(node, 'SegmentURL'); }) + .reduce((all, part) => { return all.length > 0 ? all : part; }) + .map((urlNode) => { if (urlNode.getAttribute('indexRange') && !context.indexRangeWarningGiven) { context.indexRangeWarningGiven = true; diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index 6420fa8f2..65d9f072c 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -410,7 +410,7 @@ shaka.dash.SegmentTemplate.createFromTimeline_ = function(context, info) { const mediaUri = MpdUtils.fillUriTemplate( template, repId, segmentId, bandwidth, time); return ManifestParserUtils.resolveUris(baseUris, [mediaUri]) - .map(function(g) { return g.toString(); }); + .map((g) => { return g.toString(); }); }.bind(null, info.mediaTemplate, context.representation.id, context.bandwidth || null, context.representation.baseUris, segmentReplacement, timeReplacement)); diff --git a/lib/hls/hls_classes.js b/lib/hls/hls_classes.js index bcad30da0..407571ddf 100644 --- a/lib/hls/hls_classes.js +++ b/lib/hls/hls_classes.js @@ -170,7 +170,7 @@ shaka.hls.Tag.prototype.addAttribute = function(attribute) { * @return {?shaka.hls.Attribute} attribute */ shaka.hls.Tag.prototype.getAttribute = function(name) { - const attributes = this.attributes.filter(function(attr) { + const attributes = this.attributes.filter((attr) => { return attr.name == name; }); diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 9814ba394..9f6765141 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -534,14 +534,14 @@ shaka.hls.HlsParser.prototype.createPeriod_ = async function(playlist) { const tags = playlist.tags; const mediaTags = Utils.filterTagsByName(playlist.tags, 'EXT-X-MEDIA'); - const textStreamTags = mediaTags.filter(function(tag) { + const textStreamTags = mediaTags.filter((tag) => { const type = shaka.hls.HlsParser.getRequiredAttributeValue_(tag, 'TYPE'); return type == 'SUBTITLES'; - }.bind(this)); + }); - const textStreamPromises = textStreamTags.map(function(tag) { + const textStreamPromises = textStreamTags.map((tag) => { return this.createTextStream_(tag, playlist); - }.bind(this)); + }); const closedCaptionsTags = mediaTags.filter((tag) => { const type = shaka.hls.HlsParser.getRequiredAttributeValue_(tag, 'TYPE'); @@ -555,9 +555,9 @@ shaka.hls.HlsParser.prototype.createPeriod_ = async function(playlist) { // streams have been created, so that we can push text codecs found on the // variant tag back into the created text streams. const variantTags = Utils.filterTagsByName(tags, 'EXT-X-STREAM-INF'); - const variantsPromises = variantTags.map(function(tag) { + const variantsPromises = variantTags.map((tag) => { return this.createVariantsForTag_(tag, playlist); - }.bind(this)); + }); const allVariants = await Promise.all(variantsPromises); let variants = allVariants.reduce(Functional.collapseArrays, []); @@ -668,9 +668,9 @@ shaka.hls.HlsParser.prototype.createVariantsForTag_ = shaka.util.ArrayUtils.remove(codecs, textCodecs); } - const promises = mediaTags.map(function(tag) { + const promises = mediaTags.map((tag) => { return this.createStreamInfoFromMediaTag_(tag, codecs); - }.bind(this)); + }); let audioStreamInfos = []; let videoStreamInfos = []; @@ -787,9 +787,9 @@ shaka.hls.HlsParser.prototype.createVariantsForTag_ = * @private */ shaka.hls.HlsParser.prototype.filterLegacyCodecs_ = function(streamInfos) { - streamInfos.forEach(function(streamInfo) { + streamInfos.forEach((streamInfo) => { let codecs = streamInfo.stream.codecs.split(','); - codecs = codecs.filter(function(codec) { + codecs = codecs.filter((codec) => { // mp4a.40.34 is a nonstandard codec string that is sometimes used in HLS // for legacy reasons. It is not recognized by non-Apple MSE. // See https://bugs.chromium.org/p/chromium/issues/detail?id=489520 @@ -815,9 +815,9 @@ shaka.hls.HlsParser.prototype.createVariants_ = function(audioInfos, videoInfos, bandwidth, width, height, frameRate) { const DrmEngine = shaka.media.DrmEngine; - videoInfos.forEach(function(info) { + videoInfos.forEach((info) => { this.addVideoAttributes_(info.stream, width, height, frameRate); - }.bind(this)); + }); // In case of audio-only or video-only content, we create an array of // one item containing a null. This way, the double-loop works for all @@ -1139,7 +1139,7 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ = async function( /** @type {!Array.} */ const drmTags = []; - playlist.segments.forEach(function(segment) { + playlist.segments.forEach((segment) => { const segmentKeyTags = Utils.filterTagsByName(segment.tags, 'EXT-X-KEY'); drmTags.push.apply(drmTags, segmentKeyTags); @@ -1706,7 +1706,7 @@ shaka.hls.HlsParser.prototype.getStartTimeFromMp4Segment_ = .box('moov', Mp4Parser.children) .box('trak', Mp4Parser.children) .box('mdia', Mp4Parser.children) - .fullBox('mdhd', function(box) { + .fullBox('mdhd', (box) => { goog.asserts.assert( box.version == 0 || box.version == 1, 'MDHD version can only be 0 or 1'); @@ -1733,7 +1733,7 @@ shaka.hls.HlsParser.prototype.getStartTimeFromMp4Segment_ = new Mp4Parser() .box('moof', Mp4Parser.children) .box('traf', Mp4Parser.children) - .fullBox('tfdt', function(box) { + .fullBox('tfdt', (box) => { goog.asserts.assert( box.version == 0 || box.version == 1, 'TFDT version can only be 0 or 1'); diff --git a/lib/hls/hls_utils.js b/lib/hls/hls_utils.js index 6cd28b73b..dc1393b80 100644 --- a/lib/hls/hls_utils.js +++ b/lib/hls/hls_utils.js @@ -27,7 +27,7 @@ goog.require('shaka.util.ManifestParserUtils'); * @return {!Array.} */ shaka.hls.Utils.filterTagsByName = function(tags, name) { - return tags.filter(function(tag) { + return tags.filter((tag) => { return tag.name == name; }); }; @@ -55,7 +55,7 @@ shaka.hls.Utils.getFirstTagWithName = function(tags, name) { * and group id. */ shaka.hls.Utils.findMediaTags = function(tags, type, groupId) { - return tags.filter(function(tag) { + return tags.filter((tag) => { const typeAttr = tag.getAttribute('TYPE'); const groupIdAttr = tag.getAttribute('GROUP-ID'); return typeAttr.value == type && groupIdAttr.value == groupId; diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index bfce4820f..4defd2738 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -480,7 +480,7 @@ shaka.media.DrmEngine.prototype.attach = function(video) { this.eventManager_.listenOnce(this.video_, 'play', () => this.onPlay_()); let setMediaKeys = this.video_.setMediaKeys(this.mediaKeys_); - setMediaKeys = setMediaKeys.catch(function(exception) { + setMediaKeys = setMediaKeys.catch((exception) => { return Promise.reject(new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.DRM, @@ -865,19 +865,19 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { // that we can differentiate between "none of these key systems are available" // and "some are available, but you did not configure them properly." The // former takes precedence. - [true, false].forEach(function(shouldHaveLicenseServer) { + [true, false].forEach((shouldHaveLicenseServer) => { configsByKeySystem.forEach((config, keySystem) => { - const hasLicenseServer = config.drmInfos.some(function(info) { + const hasLicenseServer = config.drmInfos.some((info) => { return !!info.licenseServerUri; }); if (hasLicenseServer != shouldHaveLicenseServer) return; - p = p.catch(function() { + p = p.catch(() => { if (this.isDestroying_) { return; } return navigator.requestMediaKeySystemAccess(keySystem, [config]); - }.bind(this)); + }); }); - }.bind(this)); + }); p = p.catch(() => { return Promise.reject(new shaka.util.Error( @@ -886,7 +886,7 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { shaka.util.Error.Code.REQUESTED_KEY_SYSTEM_CONFIG_UNAVAILABLE)); }); - p = p.then(function(mediaKeySystemAccess) { + p = p.then((mediaKeySystemAccess) => { if (this.isDestroying_) { return Promise.reject(); } // Get the set of supported content types from the audio and video @@ -923,14 +923,14 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { } return mediaKeySystemAccess.createMediaKeys(); - }.bind(this)).then(function(mediaKeys) { + }).then((mediaKeys) => { if (this.isDestroying_) { return Promise.reject(); } shaka.log.info('Created MediaKeys object for key system', this.currentDrmInfo_.keySystem); this.mediaKeys_ = mediaKeys; this.initialized_ = true; - }.bind(this)).catch(function(exception) { + }).catch((exception) => { if (this.isDestroying_) { return; } // Don't rewrap a shaka.util.Error from earlier in the chain: @@ -946,7 +946,7 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { shaka.util.Error.Category.DRM, shaka.util.Error.Code.FAILED_TO_CREATE_CDM, exception.message)); - }.bind(this)); + }); instigator.reject(); return p; @@ -1040,7 +1040,7 @@ shaka.media.DrmEngine.prototype.loadOfflineSession_ = function(sessionId) { }; this.activeSessions_.set(session, metadata); - return session.load(sessionId).then(function(present) { + return session.load(sessionId).then((present) => { if (this.isDestroying_) { return Promise.reject(); } shaka.log.v2('Loaded offline session', sessionId, present); @@ -1062,7 +1062,7 @@ shaka.media.DrmEngine.prototype.loadOfflineSession_ = function(sessionId) { } return session; - }.bind(this), function(error) { + }, (error) => { if (this.isDestroying_) { return; } this.activeSessions_.delete(session); @@ -1072,7 +1072,7 @@ shaka.media.DrmEngine.prototype.loadOfflineSession_ = function(sessionId) { shaka.util.Error.Category.DRM, shaka.util.Error.Code.FAILED_TO_CREATE_SESSION, error.message)); - }.bind(this)); + }); }; @@ -1197,7 +1197,7 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { } this.playerInterface_.netEngine.request(requestType, request).promise - .then(function(response) { + .then((response) => { if (this.isDestroying_) { return Promise.reject(); } if (this.currentDrmInfo_.keySystem.startsWith('com.apple.fps')) { @@ -1205,7 +1205,7 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { } // Request succeeded, now pass the response to the CDM. - return session.update(response.data).then(function() { + return session.update(response.data).then(() => { const event = new shaka.util.FakeEvent('drmsessionupdate'); this.playerInterface_.onEvent(event); @@ -1226,8 +1226,8 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { timer.tickAfter( /* seconds= */ shaka.media.DrmEngine.SESSION_LOAD_TIMEOUT_); } - }.bind(this)); - }.bind(this), function(error) { + }); + }, (error) => { // Ignore destruction errors if (this.isDestroying_) { return; } @@ -1243,7 +1243,7 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { if (metadata && metadata.updatePromise) { metadata.updatePromise.reject(shakaErr); } - }.bind(this)).catch(function(error) { + }).catch((error) => { // Ignore destruction errors if (this.isDestroying_) { return; } @@ -1257,7 +1257,7 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { if (metadata && metadata.updatePromise) { metadata.updatePromise.reject(shakaErr); } - }.bind(this)); + }); }; @@ -1401,7 +1401,7 @@ shaka.media.DrmEngine.prototype.onKeyStatusesChange_ = function(event) { const keyStatusMap = session.keyStatuses; let hasExpiredKeys = false; - keyStatusMap.forEach(function(status, keyId) { + keyStatusMap.forEach((status, keyId) => { // The spec has changed a few times on the exact order of arguments here. // As of 2016-06-30, Edge has the order reversed compared to the current // EME spec. Given the back and forth in the spec, it may not be the only @@ -1464,7 +1464,7 @@ shaka.media.DrmEngine.prototype.onKeyStatusesChange_ = function(event) { const keyIdHex = shaka.util.Uint8ArrayUtils.toHex(new Uint8Array(keyId)); this.keyStatusByKeyId_.set(keyIdHex, status); - }.bind(this)); + }); // If the session has expired, close it. // Some CDMs do not have sub-second time resolution, so the key status may diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 5d2ccb53d..178b43c33 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -515,7 +515,7 @@ shaka.media.MediaSourceEngine.prototype.appendBuffer = return this.textEngine_.appendBuffer(data, startTime, endTime); } else if (this.transmuxers_[contentType]) { return this.transmuxers_[contentType].transmux(data).then( - function(transmuxedData) { + (transmuxedData) => { // For HLS CEA-608/708 CLOSED-CAPTIONS, text data is embedded in the // video stream, so textEngine may not have been initialized. if (!this.textEngine_) { @@ -531,7 +531,7 @@ shaka.media.MediaSourceEngine.prototype.appendBuffer = } return this.enqueueOperation_(contentType, this.append_.bind(this, contentType, transmuxedData.data.buffer)); - }.bind(this)); + }); } else if (hasClosedCaptions && window.muxjs) { if (!this.textEngine_) { this.reinitText('text/vtt'); @@ -704,7 +704,7 @@ shaka.media.MediaSourceEngine.prototype.setStreamProperties = function( * @see http://w3c.github.io/media-source/#idl-def-EndOfStreamError */ shaka.media.MediaSourceEngine.prototype.endOfStream = function(reason) { - return this.enqueueBlockingOperation_(function() { + return this.enqueueBlockingOperation_(() => { // Chrome won't let us pass undefined, but it will let us omit the // argument. Firefox does not have this problem. // TODO: File a bug about this. @@ -713,7 +713,7 @@ shaka.media.MediaSourceEngine.prototype.endOfStream = function(reason) { } else { this.mediaSource_.endOfStream(); } - }.bind(this)); + }); }; @@ -732,9 +732,9 @@ shaka.media.MediaSourceEngine.prototype.setDuration = function(duration) { this.mediaSource_.duration <= duration, 'duration cannot decrease: ' + this.mediaSource_.duration + ' -> ' + duration); - return this.enqueueBlockingOperation_(function() { + return this.enqueueBlockingOperation_(() => { this.mediaSource_.duration = duration; - }.bind(this)); + }); }; @@ -988,7 +988,7 @@ shaka.media.MediaSourceEngine.prototype.enqueueBlockingOperation_ = // Return a Promise to the real operation, which waits to begin until there // are no other in-progress operations on any SourceBuffers. - return Promise.all(allWaiters).then(function() { + return Promise.all(allWaiters).then(() => { if (goog.DEBUG) { // If we did it correctly, nothing is updating. for (const contentType in this.sourceBuffers_) { @@ -1016,7 +1016,7 @@ shaka.media.MediaSourceEngine.prototype.enqueueBlockingOperation_ = } return ret; - }.bind(this), function() { + }, () => { // One of the waiters failed, which means we've been destroyed. goog.asserts.assert(this.destroyed_, 'Should be destroyed by now'); // We haven't popped from the queue. Canceled waiters have been removed by @@ -1037,7 +1037,7 @@ shaka.media.MediaSourceEngine.prototype.enqueueBlockingOperation_ = } } return Promise.reject(); - }.bind(this)); + }); }; diff --git a/lib/media/mp4_segment_index_parser.js b/lib/media/mp4_segment_index_parser.js index 68ee0b997..6b759ce9b 100644 --- a/lib/media/mp4_segment_index_parser.js +++ b/lib/media/mp4_segment_index_parser.js @@ -42,7 +42,7 @@ shaka.media.Mp4SegmentIndexParser = function( let references; const parser = new shaka.util.Mp4Parser() - .fullBox('sidx', function(box) { + .fullBox('sidx', (box) => { references = Mp4SegmentIndexParser.parseSIDX_( sidxOffset, scaledPresentationTimeOffset, @@ -152,7 +152,7 @@ shaka.media.Mp4SegmentIndexParser.parseSIDX_ = function( scaledPresentationTimeOffset, ((unscaledStartTime + subsegmentDuration) / timescale) - scaledPresentationTimeOffset, - function() { return uris; }, + (() => { return uris; }), startByte, startByte + referenceSize - 1)); diff --git a/lib/media/presentation_timeline.js b/lib/media/presentation_timeline.js index 381bb4655..590f4ee5c 100644 --- a/lib/media/presentation_timeline.js +++ b/lib/media/presentation_timeline.js @@ -231,7 +231,7 @@ shaka.media.PresentationTimeline.prototype.notifySegments = function( this.notifyMinSegmentStartTime(firstReferenceStartTime); this.maxSegmentDuration_ = references.reduce( - function(max, r) { return Math.max(max, r.endTime - r.startTime); }, + (max, r) => { return Math.max(max, r.endTime - r.startTime); }, this.maxSegmentDuration_); this.maxSegmentEndTime_ = diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index 17abcc782..f6fff1ed1 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -301,7 +301,7 @@ if (goog.DEBUG) { * @private */ shaka.media.SegmentIndex.assertCorrectReferences_ = function(references) { - goog.asserts.assert(references.every(function(r2, i) { + goog.asserts.assert(references.every((r2, i) => { if (i == 0) return true; const r1 = references[i - 1]; if (r2.position != r1.position + 1) return false; diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index ebdbe3eac..4d2a96b11 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -1081,15 +1081,15 @@ shaka.media.StreamingEngine.prototype.setupPeriod_ = function(periodIndex) { } // Serialize Period set up. - this.setupPeriodPromise_ = this.setupPeriodPromise_.then(function() { + this.setupPeriodPromise_ = this.setupPeriodPromise_.then(() => { if (this.destroyed_) return; return this.setupStreams_(streams); - }.bind(this)).then(function() { + }).then(() => { if (this.destroyed_) return; this.canSwitchPeriod_[periodIndex].promise.resolve(); this.canSwitchPeriod_[periodIndex].resolved = true; shaka.log.v1('(all) setup Period ' + periodIndex); - }.bind(this)).catch(function(error) { + }).catch((error) => { if (this.destroyed_) return; this.canSwitchPeriod_[periodIndex].promise.catch(() => {}); this.canSwitchPeriod_[periodIndex].promise.reject(); @@ -1098,7 +1098,7 @@ shaka.media.StreamingEngine.prototype.setupPeriod_ = function(periodIndex) { goog.asserts.assert(error instanceof shaka.util.Error, 'Bad error type'); this.playerInterface_.onError(error); // Don't stop other Periods from being set up. - }.bind(this)); + }); return canSwitchRecord.promise; }; @@ -1233,9 +1233,9 @@ shaka.media.StreamingEngine.prototype.onUpdate_ = function(mediaState) { // to be the only state and buffer to the end. So we need to wait until we // have completed startup to determine if we have reached the end. if (this.startupComplete_ && - mediaStates.every(function(ms) { return ms.endOfStream; })) { + mediaStates.every((ms) => { return ms.endOfStream; })) { shaka.log.v1(logPrefix, 'calling endOfStream()...'); - this.playerInterface_.mediaSourceEngine.endOfStream().then(function() { + this.playerInterface_.mediaSourceEngine.endOfStream().then(() => { if (this.destroyed_) { return; } @@ -1249,7 +1249,7 @@ shaka.media.StreamingEngine.prototype.onUpdate_ = function(mediaState) { if (duration < this.manifest_.presentationTimeline.getDuration()) { this.manifest_.presentationTimeline.setDuration(duration); } - }.bind(this)); + }); } }; @@ -1643,7 +1643,7 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( const fetchSegment = this.fetch_(mediaState, reference); - Promise.all([initSourceBuffer, fetchSegment]).then(function(results) { + Promise.all([initSourceBuffer, fetchSegment]).then((results) => { if (this.destroyed_ || this.fatalError_) return; return this.append_(mediaState, presentationTime, @@ -1651,7 +1651,7 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( stream, reference, results[1]); - }.bind(this)).then(function() { + }).then(() => { if (this.destroyed_ || this.fatalError_) return; mediaState.performingUpdate = false; @@ -1670,7 +1670,7 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( this.handleStartup_(mediaState, stream); shaka.log.v1(logPrefix, 'finished fetch and append'); - }.bind(this)).catch(function(error) { + }).catch((error) => { if (this.destroyed_ || this.fatalError_) return; goog.asserts.assert(error instanceof shaka.util.Error, 'Should only receive a Shaka error'); @@ -1702,7 +1702,7 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( error.severity = shaka.util.Error.Severity.CRITICAL; this.handleStreamingError_(error); } - }.bind(this)); + }); }; @@ -1760,7 +1760,7 @@ shaka.media.StreamingEngine.prototype.handleQuotaExceeded_ = function( // we don't reduce the buffering goals too quickly. const mediaStates = Array.from(this.mediaStates_.values()); - const waitingForAnotherStreamToRecover = mediaStates.some(function(ms) { + const waitingForAnotherStreamToRecover = mediaStates.some((ms) => { return ms != mediaState && ms.recovering; }); @@ -1847,7 +1847,7 @@ shaka.media.StreamingEngine.prototype.initSourceBuffer_ = function( const fetchInit = this.fetch_(mediaState, mediaState.stream.initSegmentReference); - const appendInit = fetchInit.then(function(initSegment) { + const appendInit = fetchInit.then((initSegment) => { if (this.destroyed_) return; shaka.log.v1(logPrefix, 'appending init segment'); const hasClosedCaptions = mediaState.stream.closedCaptions && @@ -1855,7 +1855,7 @@ shaka.media.StreamingEngine.prototype.initSourceBuffer_ = function( return this.playerInterface_.mediaSourceEngine.appendBuffer( mediaState.type, initSegment, null /* startTime */, null /* endTime */, hasClosedCaptions); - }.bind(this)).catch(function(error) { + }).catch((error) => { mediaState.needInitSegment = true; return Promise.reject(error); }); @@ -1891,7 +1891,7 @@ shaka.media.StreamingEngine.prototype.append_ = function( .parse(segment); } - return this.evict_(mediaState, presentationTime).then(function() { + return this.evict_(mediaState, presentationTime).then(() => { if (this.destroyed_) return; shaka.log.v1(logPrefix, 'appending media segment'); @@ -1902,7 +1902,7 @@ shaka.media.StreamingEngine.prototype.append_ = function( return this.playerInterface_.mediaSourceEngine.appendBuffer( mediaState.type, segment, startTime, endTime, hasClosedCaptions); - }.bind(this)).then(function() { + }).then(() => { if (this.destroyed_) return; shaka.log.v2(logPrefix, 'appended media segment'); @@ -1911,7 +1911,7 @@ shaka.media.StreamingEngine.prototype.append_ = function( mediaState.lastSegmentReference = reference; return Promise.resolve(); - }.bind(this)); + }); }; @@ -2019,10 +2019,10 @@ shaka.media.StreamingEngine.prototype.evict_ = function( 'overflow=' + overflow); return this.playerInterface_.mediaSourceEngine.remove( - mediaState.type, startTime, startTime + overflow).then(function() { + mediaState.type, startTime, startTime + overflow).then(() => { if (this.destroyed_) return; shaka.log.v1(logPrefix, 'evicted ' + overflow + ' seconds'); - }.bind(this)); + }); }; @@ -2049,7 +2049,7 @@ shaka.media.StreamingEngine.prototype.handleStartup_ = function( // See #1696. const mediaStates = Array.from(this.mediaStates_.values()); if (mediaStates.length != 1 || mediaStates[0].type != ContentType.TEXT) { - this.startupComplete_ = mediaStates.every(function(ms) { + this.startupComplete_ = mediaStates.every((ms) => { // Startup completes once we have buffered at least one segment from each // MediaState, not counting text. if (ms.type == ContentType.TEXT) return true; @@ -2069,7 +2069,7 @@ shaka.media.StreamingEngine.prototype.handleStartup_ = function( const currentPeriodIndex = this.findPeriodContainingStream_(stream); goog.asserts.assert( - mediaStates.every(function(ms) { + mediaStates.every((ms) => { // It is possible for one stream (usually text) to buffer the whole // Period and need the next one. return ms.needPeriodIndex == currentPeriodIndex || @@ -2080,14 +2080,14 @@ shaka.media.StreamingEngine.prototype.handleStartup_ = function( // Setup the current Period if necessary, which is likely since the current // Period is probably the initial one. if (!this.canSwitchPeriod_[currentPeriodIndex]) { - this.setupPeriod_(currentPeriodIndex).then(function() { + this.setupPeriod_(currentPeriodIndex).then(() => { if (this.destroyed_) { return; } shaka.log.v1(logPrefix, 'calling onCanSwitch()...'); this.playerInterface_.onCanSwitch(); - }.bind(this)).catch(Functional.noop); + }).catch(Functional.noop); } // Now setup all known Periods. @@ -2131,14 +2131,14 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // will handle it. This only works when all streams either need the same // Period or are still performing updates. goog.asserts.assert( - mediaStates.every(function(ms) { + mediaStates.every((ms) => { return ms.needPeriodIndex == needPeriodIndex || ms.hasError || !shaka.media.StreamingEngine.isIdle_(ms); }), 'All MediaStates should need the same Period or be performing updates.'); // Only call onChooseStreams() when all MediaStates need the same Period. - const needSamePeriod = mediaStates.every(function(ms) { + const needSamePeriod = mediaStates.every((ms) => { return ms.needPeriodIndex == needPeriodIndex; }); if (!needSamePeriod) { @@ -2161,7 +2161,7 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // Ensure the Period which we need to buffer is set up and then call // onChooseStreams(). - this.setupPeriod_(needPeriodIndex).then(function() { + this.setupPeriod_(needPeriodIndex).then(() => { if (this.destroyed_) return; // If we seek during a Period transition, we can start another transition. @@ -2170,12 +2170,12 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // 2. All streams are still idle. // 3. The current stream is not in the needed Period (another transition // handled it). - const allReady = mediaStates.every(function(ms) { + const allReady = mediaStates.every((ms) => { const isIdle = shaka.media.StreamingEngine.isIdle_(ms); const currentPeriodIndex = this.findPeriodContainingStream_(ms.stream); return isIdle && ms.needPeriodIndex == needPeriodIndex && currentPeriodIndex != needPeriodIndex; - }.bind(this)); + }); if (!allReady) { // TODO: Write unit tests for this case. shaka.log.debug(logPrefix, 'ignoring transition to Period', @@ -2254,7 +2254,7 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // We've already set up the Period so call onCanSwitch() right now. shaka.log.v1(logPrefix, 'calling onCanSwitch()...'); this.playerInterface_.onCanSwitch(); - }.bind(this)).catch(Functional.noop); + }).catch(Functional.noop); }; @@ -2365,7 +2365,7 @@ shaka.media.StreamingEngine.prototype.fetch_ = function(mediaState, reference) { const op = this.playerInterface_.netEngine.request(requestType, request); mediaState.operation = op; - return op.promise.then(function(response) { + return op.promise.then((response) => { mediaState.operation = null; return response.data; }); @@ -2406,12 +2406,12 @@ shaka.media.StreamingEngine.prototype.clearBuffer_ = mediaState.type, presentationTime + safeMargin, duration); } else { p = this.playerInterface_.mediaSourceEngine.clear(mediaState.type).then( - function() { + () => { if (!this.destroyed_ && flush) { return this.playerInterface_.mediaSourceEngine.flush( mediaState.type); } - }.bind(this)); + }); } await p; @@ -2473,7 +2473,7 @@ shaka.media.StreamingEngine.prototype.handleStreamingError_ = function(error) { // If we invoke the callback right away, the application could trigger a // rapid retry cycle that could be very unkind to the server. Instead, // use the backoff system to delay and backoff the error handling. - this.failureCallbackBackoff_.attempt().then(function() { + this.failureCallbackBackoff_.attempt().then(() => { if (this.destroyed_) { return; } @@ -2486,7 +2486,7 @@ shaka.media.StreamingEngine.prototype.handleStreamingError_ = function(error) { if (!error.handled) { this.config_.failureCallback(error); } - }.bind(this)); + }); }; diff --git a/lib/net/http_fetch_plugin.js b/lib/net/http_fetch_plugin.js index 5b701fdfd..9e5133f0b 100644 --- a/lib/net/http_fetch_plugin.js +++ b/lib/net/http_fetch_plugin.js @@ -198,7 +198,7 @@ shaka.net.HttpFetchPlugin.request_ = async function( const headers = {}; /** @type {Headers} */ const responseHeaders = response.headers; - responseHeaders.forEach(function(value, key) { + responseHeaders.forEach((value, key) => { // Since IE/Edge incorrectly return the header with a leading new line // character ('\n'), we trim the header here. headers[key.trim()] = value; diff --git a/lib/net/http_xhr_plugin.js b/lib/net/http_xhr_plugin.js index 541e067dc..6c6b668da 100644 --- a/lib/net/http_xhr_plugin.js +++ b/lib/net/http_xhr_plugin.js @@ -43,7 +43,7 @@ shaka.net.HttpXHRPlugin = function(uri, request, requestType, progressUpdated) { // Last number of bytes loaded, from progress event. let lastLoaded = 0; - const promise = new Promise(function(resolve, reject) { + const promise = new Promise(((resolve, reject) => { xhr.open(request.method, uri, true); xhr.responseType = 'arraybuffer'; xhr.timeout = request.retryParameters.timeout; @@ -115,7 +115,7 @@ shaka.net.HttpXHRPlugin = function(uri, request, requestType, progressUpdated) { xhr.setRequestHeader(lowercasedKey, request.headers[key]); } xhr.send(request.body); - }); + })); return new shaka.util.AbortableOperation( promise, diff --git a/lib/offline/storage.js b/lib/offline/storage.js index 082b92095..aa1db4c25 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -1152,13 +1152,13 @@ shaka.offline.Storage.getAllSegmentIds_ = function(manifest) { const ids = []; // Get every segment for every stream in the manifest. - manifest.periods.forEach(function(period) { - period.streams.forEach(function(stream) { + manifest.periods.forEach((period) => { + period.streams.forEach((stream) => { if (stream.initSegmentKey != null) { ids.push(stream.initSegmentKey); } - stream.segments.forEach(function(segment) { + stream.segments.forEach((segment) => { ids.push(segment.dataKey); }); }); diff --git a/lib/player.js b/lib/player.js index 6956c572e..6984ce518 100644 --- a/lib/player.js +++ b/lib/player.js @@ -736,7 +736,7 @@ shaka.Player.isBrowserSupported = function() { shaka.Player.probeSupport = function() { goog.asserts.assert(shaka.Player.isBrowserSupported(), 'Must have basic support'); - return shaka.media.DrmEngine.probeSupport().then(function(drm) { + return shaka.media.DrmEngine.probeSupport().then((drm) => { const manifest = shaka.media.ManifestParser.probeSupport(); const media = shaka.media.MediaSourceEngine.probeSupport(); const ret = { @@ -2039,7 +2039,7 @@ shaka.Player.prototype.chooseCodecsAndFilterManifest_ = function() { variantsByCodecs.forEach((codecs, variants) => { let sum = 0; let num = 0; - variants.forEach(function(variant) { + variants.forEach((variant) => { sum += variant.bandwidth || 0; ++num; }); @@ -2057,8 +2057,8 @@ shaka.Player.prototype.chooseCodecsAndFilterManifest_ = function() { // Filter out any variants that don't match, forcing AbrManager to choose from // the most efficient variants possible. - this.manifest_.periods.forEach(function(period) { - period.variants = period.variants.filter(function(variant) { + this.manifest_.periods.forEach((period) => { + period.variants = period.variants.filter((variant) => { const codecs = variantCodecs(variant); if (codecs == bestCodecs) return true; @@ -3702,7 +3702,7 @@ shaka.Player.prototype.filterAllPeriods_ = function(periods) { null, this.drmEngine_, activeAudio, activeVideo); periods.forEach(filterPeriod); - const validPeriodsCount = ArrayUtils.count(periods, function(period) { + const validPeriodsCount = ArrayUtils.count(periods, (period) => { return period.variants.some(StreamUtils.isPlayable); }); @@ -3722,7 +3722,7 @@ shaka.Player.prototype.filterAllPeriods_ = function(periods) { shaka.util.Error.Code.UNPLAYABLE_PERIOD); } - periods.forEach(function(period) { + periods.forEach((period) => { const tracksChanged = shaka.util.StreamUtils.applyRestrictions( period.variants, this.config_.restrictions, this.maxHwRes_); if (tracksChanged && this.streamingEngine_ && @@ -3731,7 +3731,7 @@ shaka.Player.prototype.filterAllPeriods_ = function(periods) { } this.checkRestrictedVariants_(period.variants); - }.bind(this)); + }); }; @@ -4564,10 +4564,10 @@ shaka.Player.prototype.onKeyStatus_ = function(keyStatusMap) { // Only filter tracks for keys if we have some key statuses to look at. if (keyIds.length) { - period.variants.forEach(function(variant) { + period.variants.forEach((variant) => { const streams = shaka.util.StreamUtils.getVariantStreams(variant); - streams.forEach(function(stream) { + streams.forEach((stream) => { const originalAllowed = variant.allowedByKeySystem; // Only update if we have a key ID for the stream. diff --git a/lib/polyfill/mediasource.js b/lib/polyfill/mediasource.js index 62eb1a0dc..7911c4ff9 100644 --- a/lib/polyfill/mediasource.js +++ b/lib/polyfill/mediasource.js @@ -339,7 +339,7 @@ shaka.polyfill.MediaSource.patchCastIsTypeSupported_ = function() { let isHDR = false; let isDolbyVision = false; - const codecList = codecs.split(',').filter(function(codec) { + const codecList = codecs.split(',').filter((codec) => { if (dolbyVisionRegex.test(codec)) { isDolbyVision = true; } diff --git a/lib/polyfill/video_play_promise.js b/lib/polyfill/video_play_promise.js index ab0258b5d..7424c07eb 100644 --- a/lib/polyfill/video_play_promise.js +++ b/lib/polyfill/video_play_promise.js @@ -49,7 +49,7 @@ shaka.polyfill.VideoPlayPromise.install = function() { // catch handler on the Promise. This does not prevent the app from // also catching failures and handling them. It only prevents the // console message. - p.catch(function() {}); + p.catch(() => {}); } return p; }; diff --git a/lib/text/mp4_ttml_parser.js b/lib/text/mp4_ttml_parser.js index a333e6bf3..af824b7e6 100644 --- a/lib/text/mp4_ttml_parser.js +++ b/lib/text/mp4_ttml_parser.js @@ -50,7 +50,7 @@ shaka.text.Mp4TtmlParser.prototype.parseInit = function(data) { .box('minf', Mp4Parser.children) .box('stbl', Mp4Parser.children) .fullBox('stsd', Mp4Parser.sampleDescription) - .box('stpp', function(box) { + .box('stpp', (box) => { sawSTPP = true; box.parser.stop(); }).parse(data); @@ -72,12 +72,12 @@ shaka.text.Mp4TtmlParser.prototype.parseMedia = function(data, time) { let payload = []; new Mp4Parser() - .box('mdat', Mp4Parser.allData(function(data) { + .box('mdat', Mp4Parser.allData((data) => { sawMDAT = true; // Join this to any previous payload, in case the mp4 has multiple // mdats. payload = payload.concat(this.parser_.parseMedia(data, time)); - }.bind(this))).parse(data); + })).parse(data); if (!sawMDAT) { throw new shaka.util.Error( diff --git a/lib/text/mp4_vtt_parser.js b/lib/text/mp4_vtt_parser.js index b9621fe5a..d50e8d58b 100644 --- a/lib/text/mp4_vtt_parser.js +++ b/lib/text/mp4_vtt_parser.js @@ -56,7 +56,7 @@ shaka.text.Mp4VttParser.prototype.parseInit = function(data) { .box('moov', Mp4Parser.children) .box('trak', Mp4Parser.children) .box('mdia', Mp4Parser.children) - .fullBox('mdhd', function(box) { + .fullBox('mdhd', (box) => { goog.asserts.assert( box.version == 0 || box.version == 1, 'MDHD version can only be 0 or 1'); @@ -72,11 +72,11 @@ shaka.text.Mp4VttParser.prototype.parseInit = function(data) { box.reader.skip(8); // Skip "duration". } box.reader.skip(4); // Skip "pad", "language", and "pre-defined". - }.bind(this)) + }) .box('minf', Mp4Parser.children) .box('stbl', Mp4Parser.children) .fullBox('stsd', Mp4Parser.sampleDescription) - .box('wvtt', function(box) { + .box('wvtt', (box) => { // A valid vtt init segment, though we have no actual subtitles yet. sawWVTT = true; }).parse(data); @@ -130,7 +130,7 @@ shaka.text.Mp4VttParser.prototype.parseMedia = function(data, time) { new Mp4Parser() .box('moof', Mp4Parser.children) .box('traf', Mp4Parser.children) - .fullBox('tfdt', function(box) { + .fullBox('tfdt', (box) => { sawTFDT = true; goog.asserts.assert( box.version == 0 || box.version == 1, @@ -139,14 +139,14 @@ shaka.text.Mp4VttParser.prototype.parseMedia = function(data, time) { box.reader.readUint32() : box.reader.readUint64(); }) - .fullBox('tfhd', function(box) { + .fullBox('tfhd', (box) => { goog.asserts.assert( box.flags != null, 'A TFHD box should have a valid flags value'); defaultDuration = Mp4VttParser.parseTFHD_( box.flags, box.reader); }) - .fullBox('trun', function(box) { + .fullBox('trun', (box) => { sawTRUN = true; goog.asserts.assert( box.version != null, @@ -157,7 +157,7 @@ shaka.text.Mp4VttParser.prototype.parseMedia = function(data, time) { presentations = Mp4VttParser.parseTRUN_( box.version, box.flags, box.reader); }) - .box('mdat', Mp4Parser.allData(function(data) { + .box('mdat', Mp4Parser.allData((data) => { goog.asserts.assert(!sawMDAT, 'VTT cues in mp4 with multiple MDAT are not currently supported!'); sawMDAT = true; @@ -357,13 +357,13 @@ shaka.text.Mp4VttParser.parseVTTC_ = function(data, startTime, endTime) { let settings; new shaka.util.Mp4Parser() - .box('payl', shaka.util.Mp4Parser.allData(function(data) { + .box('payl', shaka.util.Mp4Parser.allData((data) => { payload = shaka.util.StringUtils.fromUTF8(data); })) - .box('iden', shaka.util.Mp4Parser.allData(function(data) { + .box('iden', shaka.util.Mp4Parser.allData((data) => { id = shaka.util.StringUtils.fromUTF8(data); })) - .box('sttg', shaka.util.Mp4Parser.allData(function(data) { + .box('sttg', shaka.util.Mp4Parser.allData((data) => { settings = shaka.util.StringUtils.fromUTF8(data); })) .parse(data); diff --git a/lib/text/simple_text_displayer.js b/lib/text/simple_text_displayer.js index fd190a649..4a609e03d 100644 --- a/lib/text/simple_text_displayer.js +++ b/lib/text/simple_text_displayer.js @@ -107,7 +107,7 @@ shaka.text.SimpleTextDisplayer.prototype.append = function(cues) { // Sort the cues based on start/end times. Make a copy of the array so // we can get the index in the original ordering. Out of order cues are // rejected by IE/Edge. See https://bit.ly/2K9VX3s - const sortedCues = textTrackCues.slice().sort(function(a, b) { + const sortedCues = textTrackCues.slice().sort((a, b) => { if (a.startTime != b.startTime) { return a.startTime - b.startTime; } else if (a.endTime != b.endTime) { @@ -121,9 +121,9 @@ shaka.text.SimpleTextDisplayer.prototype.append = function(cues) { } }); - sortedCues.forEach(function(cue) { + sortedCues.forEach((cue) => { this.textTrack_.addCue(cue); - }.bind(this)); + }); }; diff --git a/lib/text/text_engine.js b/lib/text/text_engine.js index 9bc3c4eb4..eccf085da 100644 --- a/lib/text/text_engine.js +++ b/lib/text/text_engine.js @@ -187,7 +187,7 @@ shaka.text.TextEngine.prototype.appendBuffer = goog.asserts.assert(this.parser_, 'The parser should already be initialized'); // Start the operation asynchronously to avoid blocking the caller. - return Promise.resolve().then(function() { + return Promise.resolve().then(() => { // Check that TextEngine hasn't been destroyed. if (!this.parser_ || !this.displayer_) return; @@ -205,10 +205,10 @@ shaka.text.TextEngine.prototype.appendBuffer = // Parse the buffer and add the new cues. const allCues = this.parser_.parseMedia(new Uint8Array(buffer), time); - const cuesToAppend = allCues.filter(function(cue) { + const cuesToAppend = allCues.filter((cue) => { return cue.startTime >= this.appendWindowStart_ && cue.startTime < this.appendWindowEnd_; - }.bind(this)); + }); this.displayer_.append(cuesToAppend); @@ -227,7 +227,7 @@ shaka.text.TextEngine.prototype.appendBuffer = 'There should not be a gap in text references >1s'); } this.bufferEnd_ = Math.min(endTime, this.appendWindowEnd_); - }.bind(this)); + }); }; @@ -238,7 +238,7 @@ shaka.text.TextEngine.prototype.appendBuffer = */ shaka.text.TextEngine.prototype.remove = function(startTime, endTime) { // Start the operation asynchronously to avoid blocking the caller. - return Promise.resolve().then(function() { + return Promise.resolve().then(() => { if (this.displayer_ && this.displayer_.remove(startTime, endTime)) { if (this.bufferStart_ == null) { goog.asserts.assert(this.bufferEnd_ == null, @@ -269,7 +269,7 @@ shaka.text.TextEngine.prototype.remove = function(startTime, endTime) { } } } - }.bind(this)); + }); }; diff --git a/lib/text/ttml_text_parser.js b/lib/text/ttml_text_parser.js index afdcf26a4..db6f0e980 100644 --- a/lib/text/ttml_text_parser.js +++ b/lib/text/ttml_text_parser.js @@ -377,7 +377,7 @@ shaka.text.TtmlTextParser.parseCue_ = function( cueElement, 'region', regionElements, /* prefix= */ ''); if (regionElement && regionElement.getAttribute('xml:id')) { const regionId = regionElement.getAttribute('xml:id'); - const regionsWithId = cueRegions.filter(function(region) { + const regionsWithId = cueRegions.filter((region) => { return region.id == regionId; }); cue.region = regionsWithId[0]; diff --git a/lib/text/vtt_text_parser.js b/lib/text/vtt_text_parser.js index 96eaba48e..a1f5876c4 100644 --- a/lib/text/vtt_text_parser.js +++ b/lib/text/vtt_text_parser.js @@ -279,7 +279,7 @@ shaka.text.VttTextParser.parseCueSetting = function(cue, word, regions) { * @private */ shaka.text.VttTextParser.getRegionById_ = function(regions, id) { - const regionsWithId = regions.filter(function(region) { + const regionsWithId = regions.filter((region) => { return region.id == id; }); if (!regionsWithId.length) { diff --git a/lib/util/array_utils.js b/lib/util/array_utils.js index 3adbb1a62..646abf43e 100644 --- a/lib/util/array_utils.js +++ b/lib/util/array_utils.js @@ -65,7 +65,7 @@ shaka.util.ArrayUtils.remove = function(array, element) { shaka.util.ArrayUtils.count = function(array, check) { let count = 0; - array.forEach(function(element) { + array.forEach((element) => { count += check(element) ? 1 : 0; }); diff --git a/lib/util/functional.js b/lib/util/functional.js index 2ca412131..a7e9c9fad 100644 --- a/lib/util/functional.js +++ b/lib/util/functional.js @@ -37,9 +37,9 @@ goog.provide('shaka.util.Functional'); * @template ELEM,RESULT */ shaka.util.Functional.createFallbackPromiseChain = function(array, callback) { - return array.reduce(function(callback, promise, elem) { + return array.reduce(((callback, promise, elem) => { return promise.catch(callback.bind(null, elem)); - }.bind(null, callback), Promise.reject()); + }).bind(null, callback), Promise.reject()); }; diff --git a/lib/util/manifest_parser_utils.js b/lib/util/manifest_parser_utils.js index bc9ad3e84..d57762d1f 100644 --- a/lib/util/manifest_parser_utils.js +++ b/lib/util/manifest_parser_utils.js @@ -42,13 +42,13 @@ shaka.util.ManifestParserUtils.resolveUris = function(baseUris, relativeUris) { } const relativeAsGoog = - relativeUris.map(function(uri) { return new goog.Uri(uri); }); + relativeUris.map((uri) => { return new goog.Uri(uri); }); // Resolve each URI relative to each base URI, creating an Array of Arrays. // Then flatten the Arrays into a single Array. - return baseUris.map(function(uri) { return new goog.Uri(uri); }) - .map(function(base) { return relativeAsGoog.map(base.resolve.bind(base)); }) + return baseUris.map((uri) => { return new goog.Uri(uri); }) + .map((base) => { return relativeAsGoog.map(base.resolve.bind(base)); }) .reduce(Functional.collapseArrays, []) - .map(function(uri) { return uri.toString(); }); + .map((uri) => { return uri.toString(); }); }; diff --git a/lib/util/public_promise.js b/lib/util/public_promise.js index fb766c018..fb8b380d0 100644 --- a/lib/util/public_promise.js +++ b/lib/util/public_promise.js @@ -41,10 +41,10 @@ shaka.util.PublicPromise = function() { // compiler will be aware of the additional properties |resolve| and // |reject|. - const promise = new Promise(function(resolve, reject) { + const promise = new Promise(((resolve, reject) => { resolvePromise = resolve; rejectPromise = reject; - }); + })); // Now cast the Promise object to our subclass PublicPromise so that the // compiler will permit us to attach resolve() and reject() to it. diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 88e916f15..0fca23296 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -182,7 +182,7 @@ shaka.util.StreamUtils.filterNewPeriod = function( }); // Filter text streams. - period.textStreams = period.textStreams.filter(function(stream) { + period.textStreams = period.textStreams.filter((stream) => { const fullMimeType = shaka.util.MimeUtils.getFullType( stream.mimeType, stream.codecs); const keep = shaka.text.TextEngine.isTypeSupported(fullMimeType); @@ -474,7 +474,7 @@ shaka.util.StreamUtils.isPlayable = function(variant) { * @return {!Array.} */ shaka.util.StreamUtils.getPlayableVariants = function(variants) { - return variants.filter(function(variant) { + return variants.filter((variant) => { return shaka.util.StreamUtils.isPlayable(variant); }); }; @@ -543,7 +543,7 @@ shaka.util.StreamUtils.filterStreamsByLanguageAndRole = function( // Start with the set of primary streams. /** @type {!Array.} */ - const primary = streams.filter(function(stream) { + const primary = streams.filter((stream) => { return stream.primary; }); @@ -554,7 +554,7 @@ shaka.util.StreamUtils.filterStreamsByLanguageAndRole = function( // Now reduce the set to one language. This covers both arbitrary language // choice and the reduction of the "primary" stream set to one language. const firstLanguage = chosen.length ? chosen[0].language : ''; - chosen = chosen.filter(function(stream) { + chosen = chosen.filter((stream) => { return stream.language == firstLanguage; }); @@ -586,7 +586,7 @@ shaka.util.StreamUtils.filterStreamsByLanguageAndRole = function( } } else { // Prefer text streams with no roles, if they exist. - const noRoleMatches = chosen.filter(function(stream) { + const noRoleMatches = chosen.filter((stream) => { return stream.roles.length == 0; }); if (noRoleMatches.length) { @@ -598,7 +598,7 @@ shaka.util.StreamUtils.filterStreamsByLanguageAndRole = function( // Choose an arbitrary role, if there are any, and filter out any other roles. // This ensures we never adapt between roles. - const allRoles = chosen.map(function(stream) { + const allRoles = chosen.map((stream) => { return stream.roles; }).reduce(shaka.util.Functional.collapseArrays, []); @@ -619,7 +619,7 @@ shaka.util.StreamUtils.filterStreamsByLanguageAndRole = function( */ shaka.util.StreamUtils.filterTextStreamsByRole_ = function(textStreams, preferredRole) { - return textStreams.filter(function(stream) { + return textStreams.filter((stream) => { return stream.roles.includes(preferredRole); }); }; diff --git a/lib/util/xml_utils.js b/lib/util/xml_utils.js index 9ac86407d..c2df29a54 100644 --- a/lib/util/xml_utils.js +++ b/lib/util/xml_utils.js @@ -69,7 +69,7 @@ shaka.util.XmlUtils.findChildNS = function(elem, ns, name) { * @return {!Array.} The child XML elements. */ shaka.util.XmlUtils.findChildren = function(elem, name) { - return Array.prototype.filter.call(elem.childNodes, function(child) { + return Array.prototype.filter.call(elem.childNodes, (child) => { return child instanceof Element && child.tagName == name; }); }; @@ -83,7 +83,7 @@ shaka.util.XmlUtils.findChildren = function(elem, name) { * @return {!Array.} The child XML elements. */ shaka.util.XmlUtils.findChildrenNS = function(elem, ns, name) { - return Array.prototype.filter.call(elem.childNodes, function(child) { + return Array.prototype.filter.call(elem.childNodes, (child) => { return child instanceof Element && child.localName == name && child.namespaceURI == ns; }); diff --git a/test/abr/simple_abr_manager_unit.js b/test/abr/simple_abr_manager_unit.js index 923cc6743..5341e5f97 100644 --- a/test/abr/simple_abr_manager_unit.js +++ b/test/abr/simple_abr_manager_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('SimpleAbrManager', function() { +describe('SimpleAbrManager', () => { const sufficientBWMultiplier = 1.06; const defaultBandwidthEstimate = 500e3; // 500kbps @@ -31,14 +31,14 @@ describe('SimpleAbrManager', function() { let variants; - beforeAll(function() { + beforeAll(() => { jasmine.clock().install(); jasmine.clock().mockDate(); // This mock is required for fakeEventLoop. PromiseMock.install(); }); - beforeEach(function() { + beforeEach(() => { switchCallback = jasmine.createSpy('switchCallback'); // Keep unsorted. @@ -77,34 +77,34 @@ describe('SimpleAbrManager', function() { abrManager.setVariants(variants); }); - afterEach(function() { + afterEach(() => { abrManager.stop(); }); - afterAll(function() { + afterAll(() => { PromiseMock.uninstall(); jasmine.clock().uninstall(); }); - it('can choose audio and video Streams right away', function() { + it('can choose audio and video Streams right away', () => { const chosen = abrManager.chooseVariant(); expect(chosen).not.toBe(null); }); - it('uses custom default estimate', function() { + it('uses custom default estimate', () => { config.defaultBandwidthEstimate = 3e6; abrManager.configure(config); const chosen = abrManager.chooseVariant(); expect(chosen.id).toBe(104); }); - it('can handle empty variants', function() { + it('can handle empty variants', () => { abrManager.setVariants([]); const chosen = abrManager.chooseVariant(); expect(chosen).toEqual(null); }); - it('can choose from audio only variants', function() { + it('can choose from audio only variants', () => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0).bandwidth(4e5) @@ -120,7 +120,7 @@ describe('SimpleAbrManager', function() { expect(chosen.video).toBe(null); }); - it('can choose from video only variants', function() { + it('can choose from video only variants', () => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0).bandwidth(4e5) @@ -136,7 +136,7 @@ describe('SimpleAbrManager', function() { expect(chosen.video).not.toBe(null); }); - [5e5, 6e5].forEach(function(bandwidth) { + [5e5, 6e5].forEach((bandwidth) => { // Simulate some segments being downloaded just above the desired // bandwidth. const bytesPerSecond = @@ -146,7 +146,7 @@ describe('SimpleAbrManager', function() { const description = 'picks correct Variant at ' + bandwidthKbps + ' kbps'; - it(description, function() { + it(description, () => { abrManager.setVariants(variants); abrManager.chooseVariant(); @@ -167,7 +167,7 @@ describe('SimpleAbrManager', function() { }); }); - it('can handle 0 duration segments', function() { + it('can handle 0 duration segments', () => { // Makes sure bandwidth estimate doesn't get set to NaN // when a 0 duration segment is encountered. // https://github.com/google/shaka-player/issues/582 @@ -190,7 +190,7 @@ describe('SimpleAbrManager', function() { }); it('picks lowest variant when there is insufficient bandwidth', - function() { + () => { const bandwidth = 2e6; abrManager.setVariants(variants); @@ -216,7 +216,7 @@ describe('SimpleAbrManager', function() { expect(switchCallback).toHaveBeenCalledWith(expectedVariant); }); - it('does not call switchCallback() if not enabled', function() { + it('does not call switchCallback() if not enabled', () => { const bandwidth = 5e5; const bytesPerSecond = sufficientBWMultiplier * bandwidth / 8.0; @@ -231,7 +231,7 @@ describe('SimpleAbrManager', function() { expect(switchCallback).not.toHaveBeenCalled(); }); - it('does not call switchCallback() in switch interval', function() { + it('does not call switchCallback() in switch interval', () => { let bandwidth = 5e5; let bytesPerSecond = sufficientBWMultiplier * bandwidth / 8.0; @@ -274,7 +274,7 @@ describe('SimpleAbrManager', function() { expect(switchCallback).toHaveBeenCalled(); }); - it('does not clear the buffer on upgrade', function() { + it('does not clear the buffer on upgrade', () => { // Simulate some segments being downloaded at a high rate, to trigger an // upgrade. const bandwidth = 5e5; @@ -298,7 +298,7 @@ describe('SimpleAbrManager', function() { expect(switchCallback).toHaveBeenCalledWith(jasmine.any(Object)); }); - it('does not clear the buffer on downgrade', function() { + it('does not clear the buffer on downgrade', () => { // Simulate some segments being downloaded at a low rate, to trigger a // downgrade. const bandwidth = 5e5; @@ -326,7 +326,7 @@ describe('SimpleAbrManager', function() { expect(switchCallback).toHaveBeenCalledWith(jasmine.any(Object)); }); - it('will respect restrictions', function() { + it('will respect restrictions', () => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(10).bandwidth(1e5) diff --git a/test/assumptions/uint8_array_unit.js b/test/assumptions/uint8_array_unit.js index 8e1ba55fc..91e190b8f 100644 --- a/test/assumptions/uint8_array_unit.js +++ b/test/assumptions/uint8_array_unit.js @@ -15,8 +15,8 @@ * limitations under the License. */ -describe('Uint8Array', function() { - it('checks equality', function() { +describe('Uint8Array', () => { + it('checks equality', () => { const subject = new Uint8Array([0, 1, 2, 3]); const same = new Uint8Array([0, 1, 2, 3]); const different = new Uint8Array([4, 5, 6, 7]); diff --git a/test/cast/cast_proxy_unit.js b/test/cast/cast_proxy_unit.js index d7cba5db6..c7a90d5ef 100644 --- a/test/cast/cast_proxy_unit.js +++ b/test/cast/cast_proxy_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('CastProxy', function() { +describe('CastProxy', () => { const CastProxy = shaka.cast.CastProxy; const FakeEvent = shaka.util.FakeEvent; const Util = shaka.test.Util; @@ -33,18 +33,18 @@ describe('CastProxy', function() { /** @type {shaka.cast.CastProxy} */ let proxy; - beforeAll(function() { + beforeAll(() => { mockCastSenderConstructor = jasmine.createSpy('CastSender constructor'); mockCastSenderConstructor.and.callFake(createMockCastSender); shaka.cast.CastSender = Util.spyFunc(mockCastSenderConstructor); }); - afterAll(function() { + afterAll(() => { shaka.cast.CastSender = originalCastSender; }); - beforeEach(function() { + beforeEach(() => { mockVideo = new shaka.test.FakeVideo(); mockPlayer = createMockPlayer(); mockSender = null; @@ -52,23 +52,23 @@ describe('CastProxy', function() { proxy = new CastProxy(mockVideo, mockPlayer, fakeAppId); }); - afterEach(function(done) { + afterEach((done) => { proxy.destroy().catch(fail).then(done); }); - describe('constructor', function() { - it('creates and initializes a CastSender', function() { + describe('constructor', () => { + it('creates and initializes a CastSender', () => { expect(mockCastSenderConstructor).toHaveBeenCalled(); expect(mockSender).toBeTruthy(); expect(mockSender.init).toHaveBeenCalled(); }); - it('listens for video and player events', function() { + it('listens for video and player events', () => { expect(Object.keys(mockVideo.on).length).toBeGreaterThan(0); expect(Object.keys(mockPlayer.listeners).length).toBeGreaterThan(0); }); - it('creates proxies for video and player', function() { + it('creates proxies for video and player', () => { expect(proxy.getVideo()).toBeTruthy(); expect(proxy.getVideo()).not.toBe(mockVideo); expect(proxy.getPlayer()).toBeTruthy(); @@ -76,8 +76,8 @@ describe('CastProxy', function() { }); }); - describe('canCast', function() { - it('is true if the API is ready and we have receivers', function() { + describe('canCast', () => { + it('is true if the API is ready and we have receivers', () => { mockSender.apiReady.and.returnValue(false); mockSender.hasReceivers.and.returnValue(false); expect(proxy.canCast()).toBe(false); @@ -90,8 +90,8 @@ describe('CastProxy', function() { }); }); - describe('isCasting', function() { - it('delegates directly to the sender', function() { + describe('isCasting', () => { + it('delegates directly to the sender', () => { mockSender.isCasting.and.returnValue(false); expect(proxy.isCasting()).toBe(false); mockSender.isCasting.and.returnValue(true); @@ -99,8 +99,8 @@ describe('CastProxy', function() { }); }); - describe('receiverName', function() { - it('delegates directly to the sender', function() { + describe('receiverName', () => { + it('delegates directly to the sender', () => { mockSender.receiverName.and.returnValue('abc'); expect(proxy.receiverName()).toBe('abc'); mockSender.receiverName.and.returnValue('xyz'); @@ -108,8 +108,8 @@ describe('CastProxy', function() { }); }); - describe('setAppData', function() { - it('delegates directly to the sender', function() { + describe('setAppData', () => { + it('delegates directly to the sender', () => { const fakeAppData = {key: 'value'}; expect(mockSender.setAppData).not.toHaveBeenCalled(); proxy.setAppData(fakeAppData); @@ -117,21 +117,21 @@ describe('CastProxy', function() { }); }); - describe('disconnect', function() { - it('delegates directly to the sender', function() { + describe('disconnect', () => { + it('delegates directly to the sender', () => { expect(mockSender.showDisconnectDialog).not.toHaveBeenCalled(); proxy.suggestDisconnect(); expect(mockSender.showDisconnectDialog).toHaveBeenCalled(); }); }); - describe('cast', function() { - it('pauses the local video', function() { + describe('cast', () => { + it('pauses the local video', () => { proxy.cast(); expect(mockVideo.pause).toHaveBeenCalled(); }); - it('passes initial state to sender', function() { + it('passes initial state to sender', () => { mockVideo.loop = true; mockVideo.playbackRate = 3; mockVideo.currentTime = 12; @@ -159,7 +159,7 @@ describe('CastProxy', function() { } }); - it('does not provide a start time if the video has ended', function() { + it('does not provide a start time if the video has ended', () => { mockVideo.ended = true; mockVideo.currentTime = 12; @@ -172,27 +172,27 @@ describe('CastProxy', function() { } }); - it('unloads the local player after casting is complete', function(done) { + it('unloads the local player after casting is complete', (done) => { const p = new shaka.util.PublicPromise(); mockSender.cast.and.returnValue(p); proxy.cast(); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { // unload() has not been called yet. expect(mockPlayer.unload).not.toHaveBeenCalled(); // Resolve the cast() promise. p.resolve(); return shaka.test.Util.delay(0.1); - }).then(function() { + }).then(() => { // unload() has now been called. expect(mockPlayer.unload).toHaveBeenCalled(); }).catch(fail).then(done); }); }); - describe('video proxy', function() { - describe('get', function() { - it('returns local values when we are playing back locally', function() { + describe('video proxy', () => { + describe('get', () => { + it('returns local values when we are playing back locally', () => { mockVideo.currentTime = 12; mockVideo.paused = true; expect(proxy.getVideo().currentTime).toEqual(mockVideo.currentTime); @@ -205,7 +205,7 @@ describe('CastProxy', function() { expect(mockVideo.play.calls.mostRecent().object).toBe(mockVideo); }); - it('returns cached remote values when we are casting', function() { + it('returns cached remote values when we are casting', () => { // Local values that will be ignored: mockVideo.currentTime = 12; mockVideo.paused = true; @@ -220,7 +220,7 @@ describe('CastProxy', function() { paused: false, play: jasmine.createSpy('play'), }}; - mockSender.get.and.callFake(function(targetName, property) { + mockSender.get.and.callFake((targetName, property) => { expect(targetName).toEqual('video'); return cache.video[property]; }); @@ -238,7 +238,7 @@ describe('CastProxy', function() { expect(cache.video.play).toHaveBeenCalled(); }); - it('returns local values when we have no remote values yet', function() { + it('returns local values when we have no remote values yet', () => { mockVideo.currentTime = 12; mockVideo.paused = true; @@ -248,7 +248,7 @@ describe('CastProxy', function() { // Simulate remote method: const playSpy = jasmine.createSpy('play'); - mockSender.get.and.callFake(function(targetName, property) { + mockSender.get.and.callFake((targetName, property) => { expect(targetName).toEqual('video'); expect(property).toEqual('play'); return playSpy; @@ -267,8 +267,8 @@ describe('CastProxy', function() { }); }); - describe('set', function() { - it('writes local values when we are playing back locally', function() { + describe('set', () => { + it('writes local values when we are playing back locally', () => { mockVideo.currentTime = 12; expect(proxy.getVideo().currentTime).toEqual(12); @@ -279,7 +279,7 @@ describe('CastProxy', function() { expect(mockVideo.currentTime).toEqual(24); }); - it('writes values remotely when we are casting', function() { + it('writes values remotely when we are casting', () => { mockVideo.currentTime = 12; // Set up the sender in casting mode: @@ -296,8 +296,8 @@ describe('CastProxy', function() { }); }); - describe('local events', function() { - it('forward to the proxy when we are playing back locally', function() { + describe('local events', () => { + it('forward to the proxy when we are playing back locally', () => { const proxyListener = jasmine.createSpy('listener'); proxy.getVideo().addEventListener( 'timeupdate', Util.spyFunc(proxyListener)); @@ -311,7 +311,7 @@ describe('CastProxy', function() { })); }); - it('are ignored when we are casting', function() { + it('are ignored when we are casting', () => { const proxyListener = jasmine.createSpy('listener'); proxy.getVideo().addEventListener( 'timeupdate', Util.spyFunc(proxyListener)); @@ -327,8 +327,8 @@ describe('CastProxy', function() { }); }); - describe('remote events', function() { - it('forward to the proxy when we are casting', function() { + describe('remote events', () => { + it('forward to the proxy when we are casting', () => { const proxyListener = jasmine.createSpy('listener'); proxy.getVideo().addEventListener( 'timeupdate', Util.spyFunc(proxyListener)); @@ -348,9 +348,9 @@ describe('CastProxy', function() { }); }); - describe('player proxy', function() { - describe('get', function() { - it('returns local values when we are playing back locally', function() { + describe('player proxy', () => { + describe('get', () => { + it('returns local values when we are playing back locally', () => { const fakeConfig = {key: 'value'}; mockPlayer.getConfiguration.and.returnValue(fakeConfig); expect(proxy.getPlayer().getConfiguration()).toEqual(fakeConfig); @@ -362,7 +362,7 @@ describe('CastProxy', function() { expect(mockPlayer.trickPlay.calls.mostRecent().object).toBe(mockPlayer); }); - it('returns cached remote values when we are casting', function() { + it('returns cached remote values when we are casting', () => { // Local values that will be ignored: const fakeConfig = {key: 'value'}; mockPlayer.getConfiguration.and.returnValue(fakeConfig); @@ -379,7 +379,7 @@ describe('CastProxy', function() { isTextTrackVisible: true, trickPlay: jasmine.createSpy('trickPlay'), }}; - mockSender.get.and.callFake(function(targetName, property) { + mockSender.get.and.callFake((targetName, property) => { expect(targetName).toEqual('player'); const value = cache.player[property]; // methods: @@ -399,7 +399,7 @@ describe('CastProxy', function() { expect(cache.player.trickPlay).toHaveBeenCalledWith(5); }); - it('returns local values when we have no remote values yet', function() { + it('returns local values when we have no remote values yet', () => { const fakeConfig = {key: 'value'}; mockPlayer.getConfiguration.and.returnValue(fakeConfig); mockPlayer.isTextTrackVisible.and.returnValue(true); @@ -410,7 +410,7 @@ describe('CastProxy', function() { // Simulate remote method: const trickPlaySpy = jasmine.createSpy('trickPlay'); - mockSender.get.and.callFake(function(targetName, property) { + mockSender.get.and.callFake((targetName, property) => { expect(targetName).toEqual('player'); expect(property).toEqual('trickPlay'); return trickPlaySpy; @@ -428,7 +428,7 @@ describe('CastProxy', function() { expect(trickPlaySpy).toHaveBeenCalledWith(5); }); - it('always returns a local NetworkingEngine', function() { + it('always returns a local NetworkingEngine', () => { // Set up the sender in casting mode: mockSender.isCasting.and.returnValue(true); mockSender.hasRemoteProperties.and.returnValue(true); @@ -442,8 +442,8 @@ describe('CastProxy', function() { }); }); - describe('local events', function() { - it('forward to the proxy when we are playing back locally', function() { + describe('local events', () => { + it('forward to the proxy when we are playing back locally', () => { const proxyListener = jasmine.createSpy('listener'); proxy.getPlayer().addEventListener( 'buffering', Util.spyFunc(proxyListener)); @@ -457,7 +457,7 @@ describe('CastProxy', function() { })); }); - it('are ignored when we are casting', function() { + it('are ignored when we are casting', () => { const proxyListener = jasmine.createSpy('listener'); proxy.getPlayer().addEventListener( 'buffering', Util.spyFunc(proxyListener)); @@ -473,8 +473,8 @@ describe('CastProxy', function() { }); }); - describe('remote events', function() { - it('forward to the proxy when we are casting', function() { + describe('remote events', () => { + it('forward to the proxy when we are casting', () => { const proxyListener = jasmine.createSpy('listener'); proxy.getPlayer().addEventListener( 'buffering', Util.spyFunc(proxyListener)); @@ -494,8 +494,8 @@ describe('CastProxy', function() { }); }); - describe('"caststatuschanged" event', function() { - it('is triggered by the sender', function() { + describe('"caststatuschanged" event', () => { + it('is triggered by the sender', () => { const listener = jasmine.createSpy('listener'); proxy.addEventListener('caststatuschanged', Util.spyFunc(listener)); expect(listener).not.toHaveBeenCalled(); @@ -506,8 +506,8 @@ describe('CastProxy', function() { }); }); - describe('synthetic video events from onFirstCastStateUpdate', function() { - it('sends a pause event if the video is paused', function() { + describe('synthetic video events from onFirstCastStateUpdate', () => { + it('sends a pause event if the video is paused', () => { mockVideo.paused = true; const proxyListener = jasmine.createSpy('listener'); proxy.getVideo().addEventListener('pause', Util.spyFunc(proxyListener)); @@ -516,7 +516,7 @@ describe('CastProxy', function() { expect(proxyListener).toHaveBeenCalled(); }); - it('sends a play event if the video is playing', function() { + it('sends a play event if the video is playing', () => { mockVideo.paused = false; const proxyListener = jasmine.createSpy('listener'); proxy.getVideo().addEventListener('play', Util.spyFunc(proxyListener)); @@ -526,10 +526,10 @@ describe('CastProxy', function() { }); }); - describe('resume local playback', function() { + describe('resume local playback', () => { let cache; - beforeEach(function() { + beforeEach(() => { // Simulate cached remote state: cache = { video: { @@ -541,7 +541,7 @@ describe('CastProxy', function() { isTextTrackVisisble: true, }, }; - mockSender.get.and.callFake(function(targetName, property) { + mockSender.get.and.callFake((targetName, property) => { if (targetName == 'player') { return function() { return cache[targetName][property]; }; } else { @@ -550,7 +550,7 @@ describe('CastProxy', function() { }); }); - it('transfers remote state back to local objects', function(done) { + it('transfers remote state back to local objects', (done) => { // Nothing has been set yet: expect(mockPlayer.configure).not.toHaveBeenCalled(); expect(mockPlayer.setTextTrackVisibility).not.toHaveBeenCalled(); @@ -569,7 +569,7 @@ describe('CastProxy', function() { expect(mockVideo.playbackRate).toBe(1); // The rest is done async: - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { expect(mockPlayer.setTextTrackVisibility).toHaveBeenCalledWith( cache.player.isTextTrackVisible); expect(mockVideo.loop).toEqual(cache.video.loop); @@ -577,7 +577,7 @@ describe('CastProxy', function() { }).catch(fail).then(done); }); - it('loads the manifest', function() { + it('loads the manifest', () => { cache.video.currentTime = 12; cache.player.getAssetUri = 'foo://bar'; expect(mockPlayer.load).not.toHaveBeenCalled(); @@ -587,7 +587,7 @@ describe('CastProxy', function() { expect(mockPlayer.load).toHaveBeenCalledWith('foo://bar', 12); }); - it('does not provide a start time if the video has ended', function() { + it('does not provide a start time if the video has ended', () => { cache.video.currentTime = 12; cache.video.ended = true; cache.player.getAssetUri = 'foo://bar'; @@ -598,7 +598,7 @@ describe('CastProxy', function() { expect(mockPlayer.load).toHaveBeenCalledWith('foo://bar', null); }); - it('plays the video after loading', function(done) { + it('plays the video after loading', (done) => { cache.player.getAssetUri = 'foo://bar'; // Should play even if the video was paused remotely. cache.video.paused = true; @@ -608,19 +608,19 @@ describe('CastProxy', function() { // Video autoplay inhibited: expect(mockVideo.autoplay).toBe(false); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { expect(mockVideo.play).toHaveBeenCalled(); // Video autoplay restored: expect(mockVideo.autoplay).toBe(true); }).catch(fail).then(done); }); - it('does not load or play without a manifest URI', function(done) { + it('does not load or play without a manifest URI', (done) => { cache.player.getAssetUri = null; mockSender.onResumeLocal(); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { // Nothing loaded or played: expect(mockPlayer.load).not.toHaveBeenCalled(); expect(mockVideo.play).not.toHaveBeenCalled(); @@ -633,7 +633,7 @@ describe('CastProxy', function() { }).catch(fail).then(done); }); - it('triggers an "error" event if load fails', function(done) { + it('triggers an "error" event if load fails', (done) => { cache.player.getAssetUri = 'foo://bar'; const fakeError = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, @@ -643,7 +643,7 @@ describe('CastProxy', function() { mockSender.onResumeLocal(); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { expect(mockPlayer.load).toHaveBeenCalled(); expect(mockPlayer.dispatchEvent).toHaveBeenCalledWith( jasmine.objectContaining({type: 'error', detail: fakeError})); @@ -651,8 +651,8 @@ describe('CastProxy', function() { }); }); - describe('destroy', function() { - it('destroys the local player and the sender', function(done) { + describe('destroy', () => { + it('destroys the local player and the sender', (done) => { expect(mockPlayer.destroy).not.toHaveBeenCalled(); expect(mockSender.destroy).not.toHaveBeenCalled(); expect(mockSender.forceDisconnect).not.toHaveBeenCalled(); @@ -664,7 +664,7 @@ describe('CastProxy', function() { expect(mockSender.forceDisconnect).not.toHaveBeenCalled(); }); - it('optionally forces the sender to disconnect', function(done) { + it('optionally forces the sender to disconnect', (done) => { expect(mockSender.destroy).not.toHaveBeenCalled(); expect(mockSender.forceDisconnect).not.toHaveBeenCalled(); diff --git a/test/cast/cast_receiver_integration.js b/test/cast/cast_receiver_integration.js index 07f92dd35..ff49826e5 100644 --- a/test/cast/cast_receiver_integration.js +++ b/test/cast/cast_receiver_integration.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('CastReceiver', function() { +describe('CastReceiver', () => { const CastReceiver = shaka.cast.CastReceiver; const CastUtils = shaka.cast.CastUtils; @@ -87,9 +87,9 @@ describe('CastReceiver', function() { return checkAndRun(test, /* checkKeySystems */ true); } - beforeAll(function(done) { + beforeAll((done) => { const supportTest = shaka.media.DrmEngine.probeSupport() - .then(function(result) { support = result; }) + .then((result) => { support = result; }) .catch(fail); // The receiver is only meant to run on the Chromecast, so we have the @@ -162,12 +162,12 @@ describe('CastReceiver', function() { }; })); - afterEach(function(done) { - toRestore.forEach(function(restoreCallback) { + afterEach((done) => { + toRestore.forEach((restoreCallback) => { restoreCallback(); }); - receiver.destroy().catch(fail).then(function() { + receiver.destroy().catch(fail).then(() => { document.body.removeChild(video); player = null; @@ -178,7 +178,7 @@ describe('CastReceiver', function() { }); }); - afterAll(function() { + afterAll(() => { if (originalUserAgent) { window['cast'] = originalCast; Object.defineProperty(window['navigator'], @@ -190,9 +190,9 @@ describe('CastReceiver', function() { // Use an encrypted asset, to make sure DRM info doesn't balloon the size. fakeInitState.manifest = 'test:sintel-enc'; - eventManager.listenOnce(video, 'loadeddata', function() { + eventManager.listenOnce(video, 'loadeddata', () => { // Wait for an update message. - waitForUpdateMessage().then(function(message) { + waitForUpdateMessage().then((message) => { // Check that the update message is of a reasonable size. From previous // testing we found that the socket would silently reject data that got // too big. 5KB is safely below the limit. @@ -214,7 +214,7 @@ describe('CastReceiver', function() { // Use an encrypted asset, to make sure DRM info doesn't balloon the size. fakeInitState.manifest = 'test:sintel-enc'; - eventManager.listenOnce(video, 'loadeddata', function() { + eventManager.listenOnce(video, 'loadeddata', () => { // Collect 50 update messages, and average their length. // Not all properties are passed along on every update message, so // the average length is expected to be lower than the length of the first @@ -222,13 +222,13 @@ describe('CastReceiver', function() { let totalLength = 0; let waitForUpdate = Promise.resolve(); for (let i = 0; i < 50; i++) { - waitForUpdate = waitForUpdate.then(function() { + waitForUpdate = waitForUpdate.then(() => { return waitForUpdateMessage(); - }).then(function(message) { + }).then((message) => { totalLength += message.length; }); } - waitForUpdate.then(function() { + waitForUpdate.then(() => { expect(totalLength / 50).toBeLessThan(3000); }).then(done); }); @@ -258,7 +258,7 @@ describe('CastReceiver', function() { waitForUpdateMessageWrapper( shaka.media.StreamingEngine.prototype, 'StreamingEngine', 'start'); - eventManager.listenOnce(video, 'loadeddata', function() { + eventManager.listenOnce(video, 'loadeddata', () => { // Make sure that each of the methods covered by // waitForUpdateMessageWrapper is called by this point. expect(pendingWaitWrapperCalls).toBe(0); @@ -295,11 +295,11 @@ describe('CastReceiver', function() { 'Waiting for update message before calling ' + name + '.' + methodName + '...'); const originalArguments = arguments; - return waitForUpdateMessage().then(function() { + return waitForUpdateMessage().then(() => { return original.apply(this, originalArguments); - }.bind(this)); + }); }; - toRestore.push(function() { + toRestore.push(() => { prototype[methodName] = original; }); } @@ -352,7 +352,7 @@ describe('CastReceiver', function() { getCastChannel: jasmine.createSpy('CastMessageBus.getCastChannel'), }; // For convenience, deserialize and store sent messages. - bus.broadcast.and.callFake(function(message) { + bus.broadcast.and.callFake((message) => { bus.messages.push(CastUtils.deserialize(message)); // Check to see if it's an update message. const parsed = CastUtils.deserialize(message); diff --git a/test/cast/cast_receiver_unit.js b/test/cast/cast_receiver_unit.js index cdea73798..3584c64da 100644 --- a/test/cast/cast_receiver_unit.js +++ b/test/cast/cast_receiver_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('CastReceiver', function() { +describe('CastReceiver', () => { const CastReceiver = shaka.cast.CastReceiver; const CastUtils = shaka.cast.CastUtils; const Util = shaka.test.Util; @@ -65,7 +65,7 @@ describe('CastReceiver', function() { return () => check(undefined); } - beforeAll(function() { + beforeAll(() => { // The receiver is only meant to run on the Chromecast, so we have the // ability to use modern APIs there that may not be available on all of the // browsers our library supports. Because of this, CastReceiver tests will @@ -108,7 +108,7 @@ describe('CastReceiver', function() { mockAppDataCallback = jasmine.createSpy('appDataCallback'); })); - afterEach(function(done) { + afterEach((done) => { if (receiver) { receiver.destroy().catch(fail).then(done); } else { @@ -116,7 +116,7 @@ describe('CastReceiver', function() { } }); - afterAll(function() { + afterAll(() => { if (originalUserAgent) { window['cast'] = originalCast; Object.defineProperty(window['navigator'], @@ -124,7 +124,7 @@ describe('CastReceiver', function() { } }); - describe('constructor', function() { + describe('constructor', () => { it('starts the receiver manager', checkAndRun(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); @@ -140,7 +140,7 @@ describe('CastReceiver', function() { it('limits streams to 1080p on Chromecast v1 and v2', checkAndRun(() => { // Simulate the canDisplayType reponse of Chromecast v1 or v2 - mockCanDisplayType.and.callFake(function(type) { + mockCanDisplayType.and.callFake((type) => { const matches = /height=(\d+)/.exec(type); const height = matches[1]; if (height && height > 1080) return false; @@ -155,7 +155,7 @@ describe('CastReceiver', function() { it('limits streams to 4k on Chromecast Ultra', checkAndRun(() => { // Simulate the canDisplayType reponse of Chromecast Ultra - mockCanDisplayType.and.callFake(function(type) { + mockCanDisplayType.and.callFake((type) => { const matches = /height=(\d+)/.exec(type); const height = matches[1]; if (height && height > 2160) return false; @@ -176,8 +176,8 @@ describe('CastReceiver', function() { })); }); - describe('isConnected', function() { - beforeEach(function() { + describe('isConnected', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); @@ -195,8 +195,8 @@ describe('CastReceiver', function() { })); }); - describe('"caststatuschanged" event', function() { - beforeEach(function() { + describe('"caststatuschanged" event', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); @@ -205,16 +205,16 @@ describe('CastReceiver', function() { const listener = jasmine.createSpy('listener'); receiver.addEventListener('caststatuschanged', Util.spyFunc(listener)); - shaka.test.Util.delay(0.2).then(function() { + shaka.test.Util.delay(0.2).then(() => { expect(listener).not.toHaveBeenCalled(); fakeConnectedSenders(1); return shaka.test.Util.delay(0.2); - }).then(function() { + }).then(() => { expect(listener).toHaveBeenCalled(); listener.calls.reset(); mockReceiverManager.onSenderDisconnected(); return shaka.test.Util.delay(0.2); - }).then(function() { + }).then(() => { expect(listener).toHaveBeenCalled(); }).catch(fail).then(done); })); @@ -228,20 +228,20 @@ describe('CastReceiver', function() { const fakeEndedEvent = {type: 'ended'}; const fakePlayingEvent = {type: 'playing'}; - shaka.test.Util.delay(0.2).then(function() { + shaka.test.Util.delay(0.2).then(() => { expect(listener).not.toHaveBeenCalled(); expect(receiver.isIdle()).toBe(true); mockPlayer.listeners['loading'](fakeLoadingEvent); return shaka.test.Util.delay(0.2); - }).then(function() { + }).then(() => { expect(listener).toHaveBeenCalled(); expect(receiver.isIdle()).toBe(false); listener.calls.reset(); mockPlayer.listeners['unloading'](fakeUnloadingEvent); return shaka.test.Util.delay(0.2); - }).then(function() { + }).then(() => { expect(listener).toHaveBeenCalled(); expect(receiver.isIdle()).toBe(true); listener.calls.reset(); @@ -249,22 +249,22 @@ describe('CastReceiver', function() { mockVideo.ended = true; mockVideo.on['ended'](fakeEndedEvent); return shaka.test.Util.delay(5.2); // There is a long delay for 'ended' - }).then(function() { + }).then(() => { expect(listener).toHaveBeenCalled(); listener.calls.reset(); expect(receiver.isIdle()).toBe(true); mockVideo.ended = false; mockVideo.on['playing'](fakePlayingEvent); - }).then(function() { + }).then(() => { expect(listener).toHaveBeenCalled(); expect(receiver.isIdle()).toBe(false); }).catch(fail).then(done); })); }); - describe('local events', function() { - beforeEach(function() { + describe('local events', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); @@ -292,14 +292,14 @@ describe('CastReceiver', function() { })); }); - describe('"init" message', function() { + describe('"init" message', () => { /** @const */ const fakeConfig = {key: 'value'}; /** @const */ const fakeAppData = {myFakeAppData: 1234}; let fakeInitState; - beforeEach(function() { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); @@ -338,7 +338,7 @@ describe('CastReceiver', function() { expect(mockVideo.playbackRate).toBe(1); // The rest is done async: - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { expect(mockPlayer.setTextTrackVisibility).toHaveBeenCalledWith( fakeInitState['playerAfterLoad'].setTextTrackVisibility); expect(mockVideo.loop).toEqual(fakeInitState.video.loop); @@ -431,7 +431,7 @@ describe('CastReceiver', function() { // Video autoplay inhibited: expect(mockVideo.autoplay).toBe(false); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { expect(mockVideo.play).toHaveBeenCalled(); // Video autoplay restored: expect(mockVideo.autoplay).toBe(true); @@ -447,7 +447,7 @@ describe('CastReceiver', function() { appData: fakeAppData, }, mockShakaMessageBus); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { // Nothing loaded or played: expect(mockPlayer.load).not.toHaveBeenCalled(); expect(mockVideo.play).not.toHaveBeenCalled(); @@ -479,7 +479,7 @@ describe('CastReceiver', function() { appData: fakeAppData, }, mockShakaMessageBus); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { expect(mockPlayer.load).toHaveBeenCalled(); expect(mockPlayer.dispatchEvent).toHaveBeenCalledWith( jasmine.objectContaining({type: 'error', detail: fakeError})); @@ -487,8 +487,8 @@ describe('CastReceiver', function() { })); }); - describe('"appData" message', function() { - beforeEach(function() { + describe('"appData" message', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); @@ -506,8 +506,8 @@ describe('CastReceiver', function() { })); }); - describe('"set" message', function() { - beforeEach(function() { + describe('"set" message', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); @@ -560,8 +560,8 @@ describe('CastReceiver', function() { })); }); - describe('"call" message', function() { - beforeEach(function() { + describe('"call" message', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); @@ -587,7 +587,7 @@ describe('CastReceiver', function() { })); }); - describe('"asyncCall" message', function() { + describe('"asyncCall" message', () => { /** @const */ const fakeSenderId = 'senderId'; /** @const */ @@ -595,7 +595,7 @@ describe('CastReceiver', function() { /** @type {!shaka.util.PublicPromise} */ let p; - beforeEach(function() { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); @@ -624,7 +624,7 @@ describe('CastReceiver', function() { expect(mockShakaMessageBus.getCastChannel).not.toHaveBeenCalled(); p.resolve(); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { // No broadcast messages have been sent, but a private message has // been sent to the sender who started the async call. expect(mockShakaMessageBus.broadcast).not.toHaveBeenCalled(); @@ -649,7 +649,7 @@ describe('CastReceiver', function() { shaka.util.Error.Category.MANIFEST, shaka.util.Error.Code.UNABLE_TO_GUESS_MANIFEST_TYPE); p.reject(fakeError); - shaka.test.Util.delay(0.1).then(function() { + shaka.test.Util.delay(0.1).then(() => { // No broadcast messages have been sent, but a private message has // been sent to the sender who started the async call. expect(mockShakaMessageBus.broadcast).not.toHaveBeenCalled(); @@ -669,7 +669,7 @@ describe('CastReceiver', function() { })); }); - describe('sends duration', function() { + describe('sends duration', () => { beforeEach(checkAndRun((done) => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); @@ -688,21 +688,21 @@ describe('CastReceiver', function() { }, mockShakaMessageBus); // The messages will show up asychronously: - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expectMediaInfo('URI A', 1); mockGenericMessageBus.messages = []; }).then(done); })); it('only once, if nothing else changes', checkAndRun((done) => { - Util.delay(0.5).then(function() { + Util.delay(0.5).then(() => { expect(mockGenericMessageBus.messages.length).toBe(0); }).then(done); })); it('after new sender connects', checkAndRun((done) => { fakeConnectedSenders(1); - Util.delay(0.5).then(function() { + Util.delay(0.5).then(() => { expectMediaInfo('URI A', 1); expect(mockGenericMessageBus.messages.length).toBe(0); }).then(done); @@ -711,7 +711,7 @@ describe('CastReceiver', function() { it('for correct manifest after loading new', checkAndRun((done) => { // Change media information, but only after half a second. mockPlayer.load = function() { - return Util.delay(0.5).then(function() { + return Util.delay(0.5).then(() => { mockVideo.duration = 2; mockPlayer.getAssetUri = function() { return 'URI B'; @@ -727,7 +727,7 @@ describe('CastReceiver', function() { }, mockShakaMessageBus, 'senderId'); // Wait for the mockPlayer to finish 'loading' before checking again. - Util.delay(1.0).then(function() { + Util.delay(1.0).then(() => { expectMediaInfo('URI B', 2); // pollAttributes_ expect(mockGenericMessageBus.messages.length).toBe(0); }).then(done); @@ -755,7 +755,7 @@ describe('CastReceiver', function() { }; fakeIncomingMessage(message, mockGenericMessageBus); - Util.delay(0.5).then(function() { + Util.delay(0.5).then(() => { expectMediaInfo('URI B', 2); expect(mockGenericMessageBus.messages.length).toBe(0); }).then(done); @@ -784,8 +784,8 @@ describe('CastReceiver', function() { } }); - describe('respects generic control messages', function() { - beforeEach(function() { + describe('respects generic control messages', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); fakeConnectedSenders(1); @@ -902,15 +902,15 @@ describe('CastReceiver', function() { })); }); - describe('destroy', function() { - beforeEach(function() { + describe('destroy', () => { + beforeEach(() => { receiver = new CastReceiver( mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback)); }); it('destroys the local player', checkAndRun((done) => { expect(mockPlayer.destroy).not.toHaveBeenCalled(); - receiver.destroy().then(function() { + receiver.destroy().then(() => { expect(mockPlayer.destroy).toHaveBeenCalled(); }).catch(fail).then(done); })); @@ -924,16 +924,16 @@ describe('CastReceiver', function() { }, mockShakaMessageBus); mockPlayer.getConfiguration.calls.reset(); - shaka.test.Util.delay(1).then(function() { + shaka.test.Util.delay(1).then(() => { // We have polled at least once, so this getter has been called. expect(mockPlayer.getConfiguration).toHaveBeenCalled(); mockPlayer.getConfiguration.calls.reset(); // Destroy the receiver. return receiver.destroy(); - }).then(function() { + }).then(() => { // Wait another second. return shaka.test.Util.delay(1); - }).then(function() { + }).then(() => { // We have not polled again since destruction. expect(mockPlayer.getConfiguration).not.toHaveBeenCalled(); }).catch(fail).then(done); @@ -941,7 +941,7 @@ describe('CastReceiver', function() { it('stops the receiver manager', checkAndRun((done) => { expect(mockReceiverManager.stop).not.toHaveBeenCalled(); - receiver.destroy().then(function() { + receiver.destroy().then(() => { expect(mockReceiverManager.stop).toHaveBeenCalled(); }).catch(fail).then(done); })); @@ -982,7 +982,7 @@ describe('CastReceiver', function() { getCastChannel: jasmine.createSpy('CastMessageBus.getCastChannel'), }; // For convenience, deserialize and store sent messages. - bus.broadcast.and.callFake(function(message) { + bus.broadcast.and.callFake((message) => { bus.messages.push(CastUtils.deserialize(message)); }); const channel = { @@ -1011,7 +1011,7 @@ describe('CastReceiver', function() { listeners: {}, }; - CastUtils.PlayerVoidMethods.forEach(function(name) { + CastUtils.PlayerVoidMethods.forEach((name) => { player[name] = jasmine.createSpy(name); }); for (const name in CastUtils.PlayerGetterMethods) { @@ -1020,7 +1020,7 @@ describe('CastReceiver', function() { for (const name in CastUtils.PlayerGetterMethodsThatRequireLive) { player[name] = jasmine.createSpy(name); } - CastUtils.PlayerPromiseMethods.forEach(function(name) { + CastUtils.PlayerPromiseMethods.forEach((name) => { player[name] = jasmine.createSpy(name).and.returnValue(Promise.resolve()); }); diff --git a/test/cast/cast_sender_unit.js b/test/cast/cast_sender_unit.js index 3a6c45743..e3de492af 100644 --- a/test/cast/cast_sender_unit.js +++ b/test/cast/cast_sender_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('CastSender', function() { +describe('CastSender', () => { const CastSender = shaka.cast.CastSender; const CastUtils = shaka.cast.CastUtils; const Util = shaka.test.Util; @@ -44,7 +44,7 @@ describe('CastSender', function() { /** @type {shaka.cast.CastSender} */ let sender; - beforeEach(function() { + beforeEach(() => { onStatusChanged = jasmine.createSpy('onStatusChanged'); onFirstCastStateUpdate = jasmine.createSpy('onFirstCastStateUpdate'); onRemoteEvent = jasmine.createSpy('onRemoteEvent'); @@ -66,17 +66,17 @@ describe('CastSender', function() { resetClassVariables(); }); - afterEach(function(done) { + afterEach((done) => { delete window.__onGCastApiAvailable; sender.destroy().catch(fail).then(done); }); - afterAll(function() { + afterAll(() => { window['chrome'] = originalChrome; }); - describe('init', function() { - it('installs a callback if the cast API is not available', function() { + describe('init', () => { + it('installs a callback if the cast API is not available', () => { // Remove the mock cast API. delete window['chrome'].cast; // This shouldn't exist yet. @@ -99,7 +99,7 @@ describe('CastSender', function() { expect(mockCastApi.initialize).toHaveBeenCalled(); }); - it('sets up cast API right away if it is available', function() { + it('sets up cast API right away if it is available', () => { sender.init(); // Expect the API to be ready and initialized. expect(sender.apiReady()).toBe(true); @@ -110,8 +110,8 @@ describe('CastSender', function() { }); }); - describe('hasReceivers', function() { - it('reflects the most recent receiver status', function() { + describe('hasReceivers', () => { + it('reflects the most recent receiver status', () => { sender.init(); expect(sender.hasReceivers()).toBe(false); @@ -122,10 +122,10 @@ describe('CastSender', function() { expect(sender.hasReceivers()).toBe(false); }); - it('remembers status from previous senders', function(done) { + it('remembers status from previous senders', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.destroy().then(function() { + sender.destroy().then(() => { sender = new CastSender( fakeAppId, Util.spyFunc(onStatusChanged), Util.spyFunc(onFirstCastStateUpdate), Util.spyFunc(onRemoteEvent), @@ -135,7 +135,7 @@ describe('CastSender', function() { expect(onStatusChanged).toHaveBeenCalledTimes(3); return Util.delay(0.25); - }).then(function() { + }).then(() => { // And then you get another call after it has 'discovered' the // existing receivers. expect(sender.hasReceivers()).toBe(true); @@ -144,28 +144,28 @@ describe('CastSender', function() { }); }); - describe('cast', function() { - it('fails when the cast API is not ready', function(done) { + describe('cast', () => { + it('fails when the cast API is not ready', (done) => { mockCastApi.isAvailable = false; sender.init(); expect(sender.apiReady()).toBe(false); - sender.cast(fakeInitState).then(fail).catch(function(error) { + sender.cast(fakeInitState).then(fail).catch((error) => { expect(error.category).toBe(shaka.util.Error.Category.CAST); expect(error.code).toBe(shaka.util.Error.Code.CAST_API_UNAVAILABLE); }).then(done); }); - it('fails when there are no receivers', function(done) { + it('fails when there are no receivers', (done) => { sender.init(); expect(sender.apiReady()).toBe(true); expect(sender.hasReceivers()).toBe(false); - sender.cast(fakeInitState).then(fail).catch(function(error) { + sender.cast(fakeInitState).then(fail).catch((error) => { expect(error.category).toBe(shaka.util.Error.Category.CAST); expect(error.code).toBe(shaka.util.Error.Code.NO_CAST_RECEIVERS); }).then(done); }); - it('creates a session and sends an "init" message', function(done) { + it('creates a session and sends an "init" message', (done) => { sender.init(); expect(sender.apiReady()).toBe(true); fakeReceiverAvailability(true); @@ -174,7 +174,7 @@ describe('CastSender', function() { const p = sender.cast(fakeInitState); fakeSessionConnection(); - p.then(function() { + p.then(() => { expect(onStatusChanged).toHaveBeenCalled(); expect(sender.isCasting()).toBe(true); expect(mockSession.messages).toContain(jasmine.objectContaining({ @@ -210,46 +210,46 @@ describe('CastSender', function() { }, ]; - connectionFailures.forEach(function(metadata) { - it('fails when ' + metadata.condition, function(done) { + connectionFailures.forEach((metadata) => { + it('fails when ' + metadata.condition, (done) => { sender.init(); fakeReceiverAvailability(true); const p = sender.cast(fakeInitState); fakeSessionConnectionFailure(metadata.castErrorCode); - p.then(fail).catch(function(error) { + p.then(fail).catch((error) => { expect(error.category).toBe(shaka.util.Error.Category.CAST); expect(error.code).toBe(metadata.shakaErrorCode); }).then(done); }); }); - it('fails when we are already casting', function(done) { + it('fails when we are already casting', (done) => { sender.init(); fakeReceiverAvailability(true); const p = sender.cast(fakeInitState); fakeSessionConnection(); - p.catch(fail).then(function() { + p.catch(fail).then(() => { return sender.cast(fakeInitState); - }).then(fail).catch(function(error) { + }).then(fail).catch((error) => { expect(error.category).toBe(shaka.util.Error.Category.CAST); expect(error.code).toBe(shaka.util.Error.Code.ALREADY_CASTING); }).then(done); }); }); - it('re-uses old sessions', function(done) { + it('re-uses old sessions', (done) => { sender.init(); fakeReceiverAvailability(true); const p = sender.cast(fakeInitState); fakeSessionConnection(); const oldMockSession = mockSession; - p.then(function() { + p.then(() => { return sender.destroy(); - }).then(function() { + }).then(() => { // Reset tracking variables. mockCastApi.ApiConfig.calls.reset(); onStatusChanged.calls.reset(); @@ -279,14 +279,14 @@ describe('CastSender', function() { }).catch(fail).then(done); }); - it('doesn\'t re-use stopped sessions', function(done) { + it('doesn\'t re-use stopped sessions', (done) => { sender.init(); fakeReceiverAvailability(true); const p = sender.cast(fakeInitState); fakeSessionConnection(); - p.then(function() { + p.then(() => { return sender.destroy(); - }).then(function() { + }).then(() => { mockCastApi.ApiConfig.calls.reset(); // The session is stopped in the meantime. @@ -302,12 +302,12 @@ describe('CastSender', function() { }).catch(fail).then(done); }); - it('joins existing sessions automatically', function(done) { + it('joins existing sessions automatically', (done) => { sender.init(); fakeReceiverAvailability(true); fakeJoinExistingSession(); - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(onStatusChanged).toHaveBeenCalled(); expect(sender.isCasting()).toBe(true); expect(onInitStateRequired).toHaveBeenCalled(); @@ -318,17 +318,17 @@ describe('CastSender', function() { }).catch(fail).then(done); }); - describe('setAppData', function() { + describe('setAppData', () => { const fakeAppData = { myKey1: 'myValue1', myKey2: 'myValue2', }; - it('sets "appData" for "init" message if not casting', function(done) { + it('sets "appData" for "init" message if not casting', (done) => { sender.init(); fakeReceiverAvailability(true); sender.setAppData(fakeAppData); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(mockSession.messages).toContain(jasmine.objectContaining({ type: 'init', appData: fakeAppData, @@ -337,10 +337,10 @@ describe('CastSender', function() { fakeSessionConnection(); }); - it('sends a special "appData" message if casting', function(done) { + it('sends a special "appData" message if casting', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { // init message has no appData expect(mockSession.messages).toContain(jasmine.objectContaining({ type: 'init', @@ -362,14 +362,14 @@ describe('CastSender', function() { }); }); - describe('onFirstCastStateUpdate', function() { - it('is triggered by an "update" message', function(done) { + describe('onFirstCastStateUpdate', () => { + it('is triggered by an "update" message', (done) => { // You have to join an existing session for it to work. sender.init(); fakeReceiverAvailability(true); fakeJoinExistingSession(); - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(onFirstCastStateUpdate).not.toHaveBeenCalled(); fakeSessionMessage({ @@ -380,10 +380,10 @@ describe('CastSender', function() { }).catch(fail).then(done); }); - it('is not triggered if making a new session', function(done) { + it('is not triggered if making a new session', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { fakeSessionMessage({ type: 'update', update: {video: {currentTime: 12}, player: {isLive: false}}, @@ -393,12 +393,12 @@ describe('CastSender', function() { fakeSessionConnection(); }); - it('is triggered once per existing session', function(done) { + it('is triggered once per existing session', (done) => { sender.init(); fakeReceiverAvailability(true); fakeJoinExistingSession(); - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { fakeSessionMessage({ type: 'update', update: {video: {currentTime: 12}, player: {isLive: false}}, @@ -416,7 +416,7 @@ describe('CastSender', function() { // Disconnect and then connect to another existing session. fakeJoinExistingSession(); return Util.delay(0.1); - }).then(function() { + }).then(() => { fakeSessionMessage({ type: 'update', update: {video: {currentTime: 12}, player: {isLive: false}}, @@ -426,11 +426,11 @@ describe('CastSender', function() { }); }); - describe('onRemoteEvent', function() { - it('is triggered by an "event" message', function(done) { + describe('onRemoteEvent', () => { + it('is triggered by an "event" message', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { const fakeEvent = { type: 'eventName', detail: {key1: 'value1'}, @@ -448,11 +448,11 @@ describe('CastSender', function() { }); }); - describe('onResumeLocal', function() { - it('is triggered when casting ends', function(done) { + describe('onResumeLocal', () => { + it('is triggered when casting ends', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(sender.isCasting()).toBe(true); expect(onResumeLocal).not.toHaveBeenCalled(); @@ -464,11 +464,11 @@ describe('CastSender', function() { }); }); - describe('showDisconnectDialog', function() { - it('opens the dialog if we are casting', function(done) { + describe('showDisconnectDialog', () => { + it('opens the dialog if we are casting', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(sender.isCasting()).toBe(true); expect(mockSession.leave).not.toHaveBeenCalled(); expect(mockSession.stop).not.toHaveBeenCalled(); @@ -488,11 +488,11 @@ describe('CastSender', function() { }); }); - describe('get', function() { - it('returns most recent properties from "update" messages', function(done) { + describe('get', () => { + it('returns most recent properties from "update" messages', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { const update = { video: { currentTime: 12, @@ -523,7 +523,7 @@ describe('CastSender', function() { fakeSessionConnection(); }); - it('returns functions for video and player methods', function() { + it('returns functions for video and player methods', () => { sender.init(); expect(sender.get('video', 'play')).toEqual(jasmine.any(Function)); expect(sender.get('player', 'isLive')).toEqual(jasmine.any(Function)); @@ -531,10 +531,10 @@ describe('CastSender', function() { expect(sender.get('player', 'load')).toEqual(jasmine.any(Function)); }); - it('simple methods trigger "call" messages', function(done) { + it('simple methods trigger "call" messages', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { const method = sender.get('video', 'play'); const retval = method(123, 'abc'); expect(retval).toBe(undefined); @@ -549,28 +549,28 @@ describe('CastSender', function() { fakeSessionConnection(); }); - describe('async player methods', function() { + describe('async player methods', () => { let method; - beforeEach(function(done) { + beforeEach((done) => { method = null; sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { method = sender.get('player', 'load'); }).catch(fail).then(done); fakeSessionConnection(); }); - it('return Promises', function() { + it('return Promises', () => { const p = method(); expect(p).toEqual(jasmine.any(Promise)); - p.catch(function() {}); // silence logs about uncaught rejections + p.catch(() => {}); // silence logs about uncaught rejections }); - it('trigger "asyncCall" messages', function() { + it('trigger "asyncCall" messages', () => { const p = method(123, 'abc'); - p.catch(function() {}); // silence logs about uncaught rejections + p.catch(() => {}); // silence logs about uncaught rejections expect(mockSession.messages).toContain(jasmine.objectContaining({ type: 'asyncCall', @@ -581,11 +581,11 @@ describe('CastSender', function() { })); }); - it('resolve when "asyncComplete" messages are received', function(done) { + it('resolve when "asyncComplete" messages are received', (done) => { const p = new shaka.test.StatusPromise(method(123, 'abc')); // Wait a tick for the Promise status to be set. - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(p.status).toBe('pending'); const id = mockSession.messages[mockSession.messages.length - 1].id; fakeSessionMessage({ @@ -596,12 +596,12 @@ describe('CastSender', function() { // Wait a tick for the Promise status to change. return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(p.status).toBe('resolved'); }).catch(fail).then(done); }); - it('reject when "asyncComplete" messages have an error', function(done) { + it('reject when "asyncComplete" messages have an error', (done) => { const originalError = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MANIFEST, @@ -610,7 +610,7 @@ describe('CastSender', function() { const p = new shaka.test.StatusPromise(method(123, 'abc')); // Wait a tick for the Promise status to be set. - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(p.status).toBe('pending'); const id = mockSession.messages[mockSession.messages.length - 1].id; fakeSessionMessage({ @@ -621,27 +621,27 @@ describe('CastSender', function() { // Wait a tick for the Promise status to change. return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(p.status).toBe('rejected'); - return p.catch(function(error) { + return p.catch((error) => { Util.expectToEqualError(error, originalError); }); }).catch(fail).then(done); }); - it('reject when disconnected remotely', function(done) { + it('reject when disconnected remotely', (done) => { const p = new shaka.test.StatusPromise(method(123, 'abc')); // Wait a tick for the Promise status to be set. - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(p.status).toBe('pending'); fakeRemoteDisconnect(); // Wait a tick for the Promise status to change. return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(p.status).toBe('rejected'); - return p.catch(function(error) { + return p.catch((error) => { Util.expectToEqualError(error, new shaka.util.Error( shaka.util.Error.Severity.RECOVERABLE, shaka.util.Error.Category.PLAYER, @@ -652,11 +652,11 @@ describe('CastSender', function() { }); }); - describe('set', function() { - it('overrides any cached properties', function(done) { + describe('set', () => { + it('overrides any cached properties', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { const update = { video: {muted: false}, }; @@ -672,10 +672,10 @@ describe('CastSender', function() { fakeSessionConnection(); }); - it('causes a "set" message to be sent', function(done) { + it('causes a "set" message to be sent', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { sender.set('video', 'muted', true); expect(mockSession.messages).toContain(jasmine.objectContaining({ type: 'set', @@ -687,10 +687,10 @@ describe('CastSender', function() { fakeSessionConnection(); }); - it('can be used before we have an "update" message', function(done) { + it('can be used before we have an "update" message', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(sender.get('video', 'muted')).toBe(undefined); sender.set('video', 'muted', true); expect(sender.get('video', 'muted')).toBe(true); @@ -699,11 +699,11 @@ describe('CastSender', function() { }); }); - describe('hasRemoteProperties', function() { - it('is true only after we have an "update" message', function(done) { + describe('hasRemoteProperties', () => { + it('is true only after we have an "update" message', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(sender.hasRemoteProperties()).toBe(false); fakeSessionMessage({ @@ -716,11 +716,11 @@ describe('CastSender', function() { }); }); - describe('forceDisconnect', function() { - it('disconnects and cancels all async operations', function(done) { + describe('forceDisconnect', () => { + it('disconnects and cancels all async operations', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(sender.isCasting()).toBe(true); expect(mockSession.leave).not.toHaveBeenCalled(); expect(mockSession.stop).not.toHaveBeenCalled(); @@ -731,7 +731,7 @@ describe('CastSender', function() { const p = new shaka.test.StatusPromise(method()); // Wait a tick for the Promise status to be set. - return Util.delay(0.1).then(function() { + return Util.delay(0.1).then(() => { expect(p.status).toBe('pending'); sender.forceDisconnect(); expect(mockSession.leave).not.toHaveBeenCalled(); @@ -741,9 +741,9 @@ describe('CastSender', function() { // Wait a tick for the Promise status to change. return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(p.status).toBe('rejected'); - return p.catch(function(error) { + return p.catch((error) => { Util.expectToEqualError(error, new shaka.util.Error( shaka.util.Error.Severity.RECOVERABLE, shaka.util.Error.Category.PLAYER, @@ -755,11 +755,11 @@ describe('CastSender', function() { }); }); - describe('destroy', function() { - it('cancels all async operations', function(done) { + describe('destroy', () => { + it('cancels all async operations', (done) => { sender.init(); fakeReceiverAvailability(true); - sender.cast(fakeInitState).then(function() { + sender.cast(fakeInitState).then(() => { expect(sender.isCasting()).toBe(true); expect(mockSession.stop).not.toHaveBeenCalled(); expect(mockSession.removeUpdateListener).not.toHaveBeenCalled(); @@ -769,7 +769,7 @@ describe('CastSender', function() { const p = new shaka.test.StatusPromise(method()); // Wait a tick for the Promise status to be set. - return Util.delay(0.1).then(function() { + return Util.delay(0.1).then(() => { expect(p.status).toBe('pending'); sender.destroy().catch(fail); expect(mockSession.leave).not.toHaveBeenCalled(); @@ -779,9 +779,9 @@ describe('CastSender', function() { // Wait a tick for the Promise status to change. return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(p.status).toBe('rejected'); - return p.catch(function(error) { + return p.catch((error) => { Util.expectToEqualError(error, new shaka.util.Error( shaka.util.Error.Severity.RECOVERABLE, shaka.util.Error.Category.PLAYER, @@ -820,7 +820,7 @@ describe('CastSender', function() { // For convenience, deserialize and store sent messages. session.sendMessage.and.callFake( - function(namespace, message, successCallback, errorCallback) { + (namespace, message, successCallback, errorCallback) => { session.messages.push(CastUtils.deserialize(message)); }); return session; diff --git a/test/cast/cast_utils_unit.js b/test/cast/cast_utils_unit.js index e78707254..e709a7381 100644 --- a/test/cast/cast_utils_unit.js +++ b/test/cast/cast_utils_unit.js @@ -15,11 +15,11 @@ * limitations under the License. */ -describe('CastUtils', function() { +describe('CastUtils', () => { const CastUtils = shaka.cast.CastUtils; const FakeEvent = shaka.util.FakeEvent; - it('includes every Player member', function() { + it('includes every Player member', () => { const ignoredMembers = [ 'constructor', // JavaScript added field 'getSharedConfiguration', // Handled specially @@ -51,25 +51,25 @@ describe('CastUtils', function() { castMembers.push(name); } const playerMembers = Object.keys(shaka.Player.prototype).filter( - function(name) { + (name) => { // Private members end with _. return !ignoredMembers.includes(name) && !name.endsWith('_'); }); // To make debugging easier, don't check that they are equal; instead check // that neither has any extra entries. - const extraCastMembers = castMembers.filter(function(name) { + const extraCastMembers = castMembers.filter((name) => { return !playerMembers.includes(name); }); - const extraPlayerMembers = playerMembers.filter(function(name) { + const extraPlayerMembers = playerMembers.filter((name) => { return !castMembers.includes(name); }); expect(extraCastMembers).toEqual([]); expect(extraPlayerMembers).toEqual([]); }); - describe('serialize/deserialize', function() { - it('transfers infinite values and NaN', function() { + describe('serialize/deserialize', () => { + it('transfers infinite values and NaN', () => { const orig = { 'nan': NaN, 'positive_infinity': Infinity, @@ -92,7 +92,7 @@ describe('CastUtils', function() { } }); - it('transfers real Events', function() { + it('transfers real Events', () => { // new Event() is not usable on IE11: const event = /** @type {!CustomEvent} */ (document.createEvent('CustomEvent')); @@ -127,7 +127,7 @@ describe('CastUtils', function() { const fakeEvent = new FakeEvent(deserialized['type'], deserialized); // The fake event has the same type and properties as the original. - nativeProperties.forEach(function(k) { + nativeProperties.forEach((k) => { expect(fakeEvent[k]).toEqual(event[k]); }); for (const k in extraProperties) { @@ -135,7 +135,7 @@ describe('CastUtils', function() { } }); - it('transfers dispatched FakeEvents', function(done) { + it('transfers dispatched FakeEvents', (done) => { const event = new FakeEvent('custom'); // Properties that can definitely be transferred. @@ -156,7 +156,7 @@ describe('CastUtils', function() { } const target = new shaka.util.FakeEventTarget(); - target.addEventListener(event.type, function() { + target.addEventListener(event.type, () => { try { // The event is turned into a string. const serialized = CastUtils.serialize(event); @@ -168,7 +168,7 @@ describe('CastUtils', function() { // The deserialized event has the same type and properties as the // original. - nativeProperties.forEach(function(k) { + nativeProperties.forEach((k) => { expect(deserialized[k]).toEqual(event[k]); }); for (const k in extraProperties) { @@ -182,7 +182,7 @@ describe('CastUtils', function() { target.dispatchEvent(event); }); - describe('TimeRanges', function() { + describe('TimeRanges', () => { /** @type {!HTMLVideoElement} */ let video; /** @type {!shaka.util.EventManager} */ @@ -190,12 +190,12 @@ describe('CastUtils', function() { /** @type {!shaka.media.MediaSourceEngine} */ let mediaSourceEngine; - beforeAll(function() { + beforeAll(() => { video = shaka.util.Dom.createVideoElement(); document.body.appendChild(video); }); - beforeEach(function(done) { + beforeEach((done) => { // The TimeRanges constructor cannot be used directly, so we load a clip // to get ranges to use. const fakeVideoStream = { @@ -223,14 +223,14 @@ describe('CastUtils', function() { const initObject = new Map(); initObject.set(ContentType.VIDEO, fakeVideoStream); - mediaSourceEngine.init(initObject, false).then(function() { + mediaSourceEngine.init(initObject, false).then(() => { return shaka.test.Util.fetch(initSegmentUrl); - }).then(function(data) { + }).then((data) => { return mediaSourceEngine.appendBuffer(ContentType.VIDEO, data, null, null, /* hasClosedCaptions */ false); - }).then(function() { + }).then(() => { return shaka.test.Util.fetch(videoSegmentUrl); - }).then(function(data) { + }).then((data) => { return mediaSourceEngine.appendBuffer(ContentType.VIDEO, data, null, null, /* hasClosedCaptions */ false); }).catch(fail).then(done); @@ -248,11 +248,11 @@ describe('CastUtils', function() { video.load(); }); - afterAll(function() { + afterAll(() => { document.body.removeChild(video); }); - quarantinedIt('deserialize into equivalent objects', function() { + quarantinedIt('deserialize into equivalent objects', () => { const buffered = video.buffered; // The test is less interesting if the ranges are empty. diff --git a/test/dash/dash_parser_content_protection_unit.js b/test/dash/dash_parser_content_protection_unit.js index 5590c3b57..fdd641e18 100644 --- a/test/dash/dash_parser_content_protection_unit.js +++ b/test/dash/dash_parser_content_protection_unit.js @@ -16,7 +16,7 @@ */ // Test DRM-related parsing. -describe('DashParser ContentProtection', function() { +describe('DashParser ContentProtection', () => { const Dash = shaka.test.Dash; /** @@ -52,7 +52,7 @@ describe('DashParser ContentProtection', function() { }; return dashParser.start('http://example.com', playerEvents) - .then(function(actual) { expect(actual).toEqual(expected); }); + .then((actual) => { expect(actual).toEqual(expected); }); } /** @@ -135,7 +135,7 @@ describe('DashParser ContentProtection', function() { */ function buildDrmInfo(keySystem, keyIds = [], base64Psshs = [], initDataKeyIds) { - const initData = base64Psshs.map(function(base64, index) { + const initData = base64Psshs.map((base64, index) => { /** @type {shaka.extern.InitDataOverride} */ const initData = { initDataType: 'cenc', @@ -155,7 +155,7 @@ describe('DashParser ContentProtection', function() { await testDashParser(source, expected); }); - describe('maps standard scheme IDs', function() { + describe('maps standard scheme IDs', () => { /** * @param {string} name A name for the test * @param {!Array.} uuids DRM scheme UUIDs @@ -163,12 +163,12 @@ describe('DashParser ContentProtection', function() { */ function testKeySystemMappings(name, uuids, keySystems) { it(name, async () => { - const adaptationSetLines = uuids.map(function(uri) { + const adaptationSetLines = uuids.map((uri) => { return sprintf('', uri); }); const source = buildManifestText(adaptationSetLines, [], []); - const drmInfos = keySystems.map(function(keySystem) { + const drmInfos = keySystems.map((keySystem) => { return buildDrmInfo(keySystem); }); const expected = buildExpectedManifest(drmInfos); @@ -737,15 +737,15 @@ describe('DashParser ContentProtection', function() { }); }); -describe('In-manifest PlayReady and Widevine', function() { +describe('In-manifest PlayReady and Widevine', () => { const ContentProtection = shaka.dash.ContentProtection; const strToXml = function(str) { const parser = new DOMParser(); return parser.parseFromString(str, 'application/xml').documentElement; }; - describe('getWidevineLicenseUrl', function() { - it('valid ms:laurl node', function() { + describe('getWidevineLicenseUrl', () => { + it('valid ms:laurl node', () => { const input = { init: null, keyId: null, @@ -761,7 +761,7 @@ describe('In-manifest PlayReady and Widevine', function() { expect(actual).toEqual(expected); }); - it('ms:laurl without license url', function() { + it('ms:laurl without license url', () => { const input = { init: null, keyId: null, @@ -777,7 +777,7 @@ describe('In-manifest PlayReady and Widevine', function() { expect(actual).toEqual(expected); }); - it('no ms:laurl node', function() { + it('no ms:laurl node', () => { const input = { init: null, keyId: null, @@ -790,8 +790,8 @@ describe('In-manifest PlayReady and Widevine', function() { }); }); - describe('getPlayReadyLicenseURL', function() { - it('mspro', function() { + describe('getPlayReadyLicenseURL', () => { + it('mspro', () => { const laurl = [ '', ' ', @@ -799,7 +799,7 @@ describe('In-manifest PlayReady and Widevine', function() { ' ', '', ].join('\n'); - const laurlCodes = laurl.split('').map(function(c) { + const laurlCodes = laurl.split('').map((c) => { return c.charCodeAt(); }); const prBytes = new Uint16Array([ @@ -833,7 +833,7 @@ describe('In-manifest PlayReady and Widevine', function() { expect(actual).toEqual(expected); }); - it('no mspro', function() { + it('no mspro', () => { const input = { init: null, keyId: null, diff --git a/test/dash/dash_parser_live_unit.js b/test/dash/dash_parser_live_unit.js index 72bdff99b..ffe9ffa70 100644 --- a/test/dash/dash_parser_live_unit.js +++ b/test/dash/dash_parser_live_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('DashParser Live', function() { +describe('DashParser Live', () => { const Util = shaka.test.Util; const ManifestParser = shaka.test.ManifestParser; @@ -32,7 +32,7 @@ describe('DashParser Live', function() { /** @type {shaka.extern.ManifestParser.PlayerInterface} */ let playerInterface; - beforeEach(function() { + beforeEach(() => { // First, fake the clock so we can control timers. // This does not mock Date.now, which must be done separately. jasmine.clock().install(); @@ -52,7 +52,7 @@ describe('DashParser Live', function() { }; }); - afterEach(function() { + afterEach(() => { // Dash parser stop is synchronous. parser.stop(); @@ -145,7 +145,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', firstManifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { const stream = manifest.periods[0].variants[0].video; ManifestParser.verifySegmentIndex(stream, firstReferences); expect(manifest.periods.length).toBe(1); @@ -161,16 +161,16 @@ describe('DashParser Live', function() { PromiseMock.flush(); } - it('basic support', function(done) { + it('basic support', (done) => { testBasicUpdate(done, basicLines, basicRefs, updateLines, updateRefs); }); - it('new manifests don\'t need to include old references', function(done) { + it('new manifests don\'t need to include old references', (done) => { testBasicUpdate( done, basicLines, basicRefs, partialUpdateLines, updateRefs); }); - it('evicts old references for single-period live stream', function(done) { + it('evicts old references for single-period live stream', (done) => { const template = [ ' { expect(manifest).toBeTruthy(); const stream = manifest.periods[0].variants[0].video; expect(stream).toBeTruthy(); @@ -215,7 +215,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('evicts old references for multi-period live stream', function(done) { + it('evicts old references for multi-period live stream', (done) => { const template = [ ' { return r.endTime - r.startTime; }); - const pStart = durs.reduce(function(p, d) { return p + d; }, 0); + const pStart = durs.reduce((p, d) => { return p + d; }, 0); const args = { updateTime: updateTime, pStart: pStart, @@ -255,7 +255,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', text); Date.now = function() { return 0; }; parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { const stream1 = manifest.periods[0].variants[0].video; const stream2 = manifest.periods[1].variants[0].video; ManifestParser.verifySegmentIndex(stream1, basicRefs); @@ -281,7 +281,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('sets infinite duration for single-period live streams', function(done) { + it('sets infinite duration for single-period live streams', (done) => { const template = [ ' { expect(manifest.periods.length).toBe(1); const timeline = manifest.presentationTimeline; expect(timeline.getDuration()).toBe(Infinity); @@ -311,7 +311,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('sets infinite duration for multi-period live streams', function(done) { + it('sets infinite duration for multi-period live streams', (done) => { const template = [ ' { expect(manifest.periods.length).toBe(2); expect(manifest.periods[1].startTime).toBe(60); const timeline = manifest.presentationTimeline; @@ -351,7 +351,7 @@ describe('DashParser Live', function() { }); } - it('can add Periods', function(done) { + it('can add Periods', (done) => { const lines = [ '', ]; @@ -381,7 +381,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', firstManifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest.periods.length).toBe(1); // Should call filterAllPeriods for parsing the first manifest expect(filterNewPeriod.calls.count()).toBe(0); @@ -399,7 +399,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('uses redirect URL for manifest BaseURL and updates', function(done) { + it('uses redirect URL for manifest BaseURL and updates', (done) => { const template = [ ' { // The manifest request was made to the original URL. // But includes a redirect expect(fakeNetEngine.request.calls.count()).toBe(1); @@ -447,7 +447,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('calls the error callback if an update fails', function(done) { + it('calls the error callback if an update fails', (done) => { const lines = [ '', ]; @@ -457,7 +457,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', manifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(fakeNetEngine.request.calls.count()).toBe(1); const error = new shaka.util.Error( @@ -473,7 +473,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('uses @minimumUpdatePeriod', function(done) { + it('uses @minimumUpdatePeriod', (done) => { const lines = [ '', ]; @@ -482,7 +482,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', manifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(fakeNetEngine.request.calls.count()).toBe(1); expect(manifest).toBeTruthy(); @@ -502,7 +502,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('still updates when @minimumUpdatePeriod is zero', function(done) { + it('still updates when @minimumUpdatePeriod is zero', (done) => { const lines = [ '', ]; @@ -511,7 +511,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', manifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest).toBeTruthy(); fakeNetEngine.request.calls.reset(); @@ -525,7 +525,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('does not update when @minimumUpdatePeriod is missing', function(done) { + it('does not update when @minimumUpdatePeriod is missing', (done) => { const lines = [ '', ]; @@ -534,7 +534,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', manifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest).toBeTruthy(); fakeNetEngine.request.calls.reset(); @@ -550,7 +550,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('delays subsequent updates when an update is slow', function(done) { + it('delays subsequent updates when an update is slow', (done) => { // For this test, we want Date.now() to follow the ticks of the fake clock. jasmine.clock().mockDate(); @@ -599,7 +599,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('uses Mpd.Location', function(done) { + it('uses Mpd.Location', (done) => { const manifestText = [ ' { expect(fakeNetEngine.request.calls.count()).toBe(1); fakeNetEngine.expectRequest('dummy://foo', manifestRequest); fakeNetEngine.request.calls.reset(); @@ -628,7 +628,7 @@ describe('DashParser Live', function() { // Create a mock so we can verify it gives two URIs. // The third location is a relative url, and should be resolved as an // absolute url. - fakeNetEngine.request.and.callFake(function(type, request) { + fakeNetEngine.request.and.callFake((type, request) => { expect(type).toBe(manifestRequest); expect(request.uris).toEqual( ['http://foobar', 'http://foobar2', 'dummy://foo/foobar3']); @@ -643,7 +643,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('uses @suggestedPresentationDelay', function(done) { + it('uses @suggestedPresentationDelay', (done) => { const manifest = [ ' { expect(manifest).toBeTruthy(); const timeline = manifest.presentationTimeline; expect(timeline).toBeTruthy(); @@ -681,8 +681,8 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - describe('availabilityWindowOverride', function() { - it('overrides @timeShiftBufferDepth', function(done) { + describe('availabilityWindowOverride', () => { + it('overrides @timeShiftBufferDepth', (done) => { const manifest = [ ' { expect(manifest).toBeTruthy(); const timeline = manifest.presentationTimeline; expect(timeline).toBeTruthy(); @@ -722,8 +722,8 @@ describe('DashParser Live', function() { }); }); - describe('maxSegmentDuration', function() { - it('uses @maxSegmentDuration', function(done) { + describe('maxSegmentDuration', () => { + it('uses @maxSegmentDuration', (done) => { const manifest = [ ' { expect(manifest).toBeTruthy(); const timeline = manifest.presentationTimeline; expect(timeline).toBeTruthy(); @@ -753,7 +753,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('derived from SegmentTemplate w/ SegmentTimeline', function(done) { + it('derived from SegmentTemplate w/ SegmentTimeline', (done) => { const lines = [ '', ' ', @@ -766,14 +766,14 @@ describe('DashParser Live', function() { testDerived(lines, done); }); - it('derived from SegmentTemplate w/ @duration', function(done) { + it('derived from SegmentTemplate w/ @duration', (done) => { const lines = [ '', ]; testDerived(lines, done); }); - it('derived from SegmentList', function(done) { + it('derived from SegmentList', (done) => { const lines = [ '', ' ', @@ -783,7 +783,7 @@ describe('DashParser Live', function() { testDerived(lines, done); }); - it('derived from SegmentList w/ SegmentTimeline', function(done) { + it('derived from SegmentList w/ SegmentTimeline', (done) => { const lines = [ '', ' ', @@ -819,7 +819,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', manifest); Date.now = function() { return 600000; /* 10 minutes */ }; parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest).toBeTruthy(); const timeline = manifest.presentationTimeline; expect(timeline).toBeTruthy(); @@ -831,13 +831,13 @@ describe('DashParser Live', function() { } }); // describe('maxSegmentDuration') - describe('stop', function() { + describe('stop', () => { const manifestRequestType = shaka.net.NetworkingEngine.RequestType.MANIFEST; const dateRequestType = shaka.net.NetworkingEngine.RequestType.TIMING; const manifestUri = 'dummy://foo'; const dateUri = 'http://foo.bar/date'; - beforeEach(function() { + beforeEach(() => { const manifest = [ '', @@ -861,9 +861,9 @@ describe('DashParser Live', function() { .setResponseText('dummy://foo', manifest); }); - it('stops updates', function(done) { + it('stops updates', (done) => { parser.start(manifestUri, playerInterface) - .then(function(manifest) { + .then((manifest) => { fakeNetEngine.expectRequest(manifestUri, manifestRequestType); fakeNetEngine.request.calls.reset(); @@ -874,9 +874,9 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('stops initial parsing', function(done) { + it('stops initial parsing', (done) => { parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest).toBe(null); fakeNetEngine.expectRequest(manifestUri, manifestRequestType); fakeNetEngine.request.calls.reset(); @@ -892,9 +892,9 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('interrupts manifest updates', function(done) { + it('interrupts manifest updates', (done) => { parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest).toBeTruthy(); fakeNetEngine.expectRequest(manifestUri, manifestRequestType); fakeNetEngine.request.calls.reset(); @@ -917,11 +917,11 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('interrupts UTCTiming requests', function(done) { + it('interrupts UTCTiming requests', (done) => { /** @type {!shaka.util.PublicPromise} */ let delay = fakeNetEngine.delayNextRequest(); - Util.delay(0.2, realTimeout).then(function() { + Util.delay(0.2, realTimeout).then(() => { // This is the initial manifest request. expect(fakeNetEngine.request.calls.count()).toBe(1); fakeNetEngine.expectRequest(manifestUri, manifestRequestType); @@ -930,7 +930,7 @@ describe('DashParser Live', function() { delay.resolve(); delay = fakeNetEngine.delayNextRequest(); return Util.delay(0.2, realTimeout); - }).then(function() { + }).then(() => { // This is the first UTCTiming request. expect(fakeNetEngine.request.calls.count()).toBe(1); fakeNetEngine.expectRequest(dateUri, dateRequestType); @@ -939,7 +939,7 @@ describe('DashParser Live', function() { parser.stop(); delay.reject(); return Util.delay(0.1, realTimeout); - }).then(function() { + }).then(() => { // Wait for another update period. delayForUpdatePeriod(); @@ -952,7 +952,7 @@ describe('DashParser Live', function() { }); }); - describe('SegmentTemplate w/ SegmentTimeline', function() { + describe('SegmentTemplate w/ SegmentTimeline', () => { const basicLines = [ '', ' ', @@ -996,7 +996,7 @@ describe('DashParser Live', function() { basicLines, basicRefs, updateLines, updateRefs, partialUpdateLines); }); - describe('SegmentList w/ SegmentTimeline', function() { + describe('SegmentList w/ SegmentTimeline', () => { const basicLines = [ '', ' ', @@ -1049,7 +1049,7 @@ describe('DashParser Live', function() { basicLines, basicRefs, updateLines, updateRefs, partialUpdateLines); }); - describe('SegmentList w/ @duration', function() { + describe('SegmentList w/ @duration', () => { const basicLines = [ '', ' ', @@ -1087,16 +1087,16 @@ describe('DashParser Live', function() { basicLines, basicRefs, updateLines, updateRefs, partialUpdateLines); }); - describe('SegmentTemplate w/ duration', function() { + describe('SegmentTemplate w/ duration', () => { const templateLines = [ '', ]; - it('produces sane references without assertions', function(done) { + it('produces sane references without assertions', (done) => { const manifest = makeSimpleLiveManifestText(templateLines, updateTime); fakeNetEngine.setResponseText('dummy://foo', manifest); - parser.start('dummy://foo', playerInterface).then(function(manifest) { + parser.start('dummy://foo', playerInterface).then((manifest) => { expect(manifest.periods.length).toBe(1); const stream = manifest.periods[0].variants[0].video; @@ -1109,7 +1109,7 @@ describe('DashParser Live', function() { }); }); - describe('EventStream', function() { + describe('EventStream', () => { const originalManifest = [ '', @@ -1131,16 +1131,16 @@ describe('DashParser Live', function() { /** @type {!jasmine.Spy} */ let onTimelineRegionAddedSpy; - beforeEach(function() { + beforeEach(() => { onTimelineRegionAddedSpy = jasmine.createSpy('onTimelineRegionAdded'); playerInterface.onTimelineRegionAdded = shaka.test.Util.spyFunc(onTimelineRegionAddedSpy); }); - it('will parse EventStream nodes', function(done) { + it('will parse EventStream nodes', (done) => { fakeNetEngine.setResponseText('dummy://foo', originalManifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(onTimelineRegionAddedSpy).toHaveBeenCalledTimes(2); expect(onTimelineRegionAddedSpy).toHaveBeenCalledWith({ @@ -1165,7 +1165,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('will add timeline regions on manifest update', function(done) { + it('will add timeline regions on manifest update', (done) => { const newManifest = [ '', @@ -1184,7 +1184,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', originalManifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(onTimelineRegionAddedSpy).toHaveBeenCalledTimes(2); onTimelineRegionAddedSpy.calls.reset(); @@ -1198,7 +1198,7 @@ describe('DashParser Live', function() { PromiseMock.flush(); }); - it('will not let an event exceed the Period duration', function(done) { + it('will not let an event exceed the Period duration', (done) => { const newManifest = [ '', ' ', @@ -1218,7 +1218,7 @@ describe('DashParser Live', function() { fakeNetEngine.setResponseText('dummy://foo', newManifest); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(onTimelineRegionAddedSpy).toHaveBeenCalledTimes(3); expect(onTimelineRegionAddedSpy) .toHaveBeenCalledWith( diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js index 83b07813b..0990585b2 100644 --- a/test/dash/dash_parser_manifest_unit.js +++ b/test/dash/dash_parser_manifest_unit.js @@ -16,7 +16,7 @@ */ // Test basic manifest parsing functionality. -describe('DashParser Manifest', function() { +describe('DashParser Manifest', () => { const ContentType = shaka.util.ManifestParserUtils.ContentType; const Dash = shaka.test.Dash; @@ -29,7 +29,7 @@ describe('DashParser Manifest', function() { /** @type {shaka.extern.ManifestParser.PlayerInterface} */ let playerInterface; - beforeEach(function() { + beforeEach(() => { fakeNetEngine = new shaka.test.FakeNetworkingEngine(); parser = shaka.test.Dash.makeDashParser(); onEventSpy = jasmine.createSpy('onEvent'); @@ -106,7 +106,7 @@ describe('DashParser Manifest', function() { }); } - describe('parses and inherits attributes', function() { + describe('parses and inherits attributes', () => { makeTestsForEach( [ '', @@ -305,9 +305,9 @@ describe('DashParser Manifest', function() { expect(stream.initSegmentReference).toBe(null); expect(stream.findSegmentPosition(0)).toBe(1); expect(stream.getSegmentReference(1)) - .toEqual(new shaka.media.SegmentReference(1, 0, 30, function() { + .toEqual(new shaka.media.SegmentReference(1, 0, 30, (() => { return ['http://example.com/de.vtt']; - }, 0, null)); + }), 0, null)); }); it('correctly parses closed captions with channels and languages', @@ -432,14 +432,14 @@ describe('DashParser Manifest', function() { expect(variant.language).toBe('\u2603'); }); - describe('supports UTCTiming', function() { + describe('supports UTCTiming', () => { const originalNow = Date.now; - beforeAll(function() { + beforeAll(() => { Date.now = function() { return 10 * 1000; }; }); - afterAll(function() { + afterAll(() => { Date.now = originalNow; }); @@ -516,7 +516,7 @@ describe('DashParser Manifest', function() { ' value="http://foo.bar/date" />', ]); - fakeNetEngine.request.and.callFake(function(type, request) { + fakeNetEngine.request.and.callFake((type, request) => { if (request.uris[0] == 'http://foo.bar/manifest') { const data = shaka.util.StringUtils.toUTF8(source); return shaka.util.AbortableOperation.completed({ @@ -597,7 +597,7 @@ describe('DashParser Manifest', function() { expect(period.variants[0].bandwidth).toBe(200); }); - describe('allows missing Segment* elements for text', function() { + describe('allows missing Segment* elements for text', () => { it('specified via AdaptationSet@contentType', async () => { const source = [ '', @@ -665,7 +665,7 @@ describe('DashParser Manifest', function() { }); }); - describe('fails for', function() { + describe('fails for', () => { it('invalid XML', async () => { const source = ' { /** * @param {?number} expectedNumChannels The expected number of channels * @param {!Object.} schemeMap A map where the map key is @@ -1052,7 +1052,7 @@ describe('DashParser Manifest', function() { fakeNetEngine.setResponseText('dummy://foo', source); return parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest.periods.length).toBe(1); expect(manifest.periods[0].variants.length).toBe(1); diff --git a/test/dash/dash_parser_segment_base_unit.js b/test/dash/dash_parser_segment_base_unit.js index 55447a13d..5b4a16f03 100644 --- a/test/dash/dash_parser_segment_base_unit.js +++ b/test/dash/dash_parser_segment_base_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('DashParser SegmentBase', function() { +describe('DashParser SegmentBase', () => { const Dash = shaka.test.Dash; const indexSegmentUri = '/base/test/test/assets/index-segment.mp4'; @@ -33,7 +33,7 @@ describe('DashParser SegmentBase', function() { indexSegment = await shaka.test.Util.fetch(indexSegmentUri); }); - beforeEach(function() { + beforeEach(() => { fakeNetEngine = new shaka.test.FakeNetworkingEngine(); parser = shaka.test.Dash.makeDashParser(); @@ -257,7 +257,7 @@ describe('DashParser SegmentBase', function() { expect(reference.endTime).toEqual(10); // would be 12 without PTO }); - describe('fails for', function() { + describe('fails for', () => { it('unsupported container', async () => { const source = [ '', diff --git a/test/dash/dash_parser_segment_list_unit.js b/test/dash/dash_parser_segment_list_unit.js index 0ab632743..df33b361a 100644 --- a/test/dash/dash_parser_segment_list_unit.js +++ b/test/dash/dash_parser_segment_list_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('DashParser SegmentList', function() { +describe('DashParser SegmentList', () => { const Dash = shaka.test.Dash; const ManifestParser = shaka.test.ManifestParser; const baseUri = 'http://example.com/'; @@ -60,7 +60,7 @@ describe('DashParser SegmentList', function() { await Dash.testSegmentIndex(source, references); }); - describe('duration', function() { + describe('duration', () => { it('basic support', async () => { const source = Dash.makeSimpleManifestText([ '', @@ -130,7 +130,7 @@ describe('DashParser SegmentList', function() { }); }); - describe('rejects streams with', function() { + describe('rejects streams with', () => { it('no @duration or SegmentTimeline', async () => { const source = Dash.makeSimpleManifestText([ '', @@ -175,7 +175,7 @@ describe('DashParser SegmentList', function() { }); }); - describe('inherits', function() { + describe('inherits', () => { it('attributes', async () => { const source = [ '', @@ -270,7 +270,7 @@ describe('DashParser SegmentList', function() { }); }); - describe('Segment start', function() { + describe('Segment start', () => { it('shoud be adjusted with presentationTimeOffset', async () => { const source = [ '', diff --git a/test/dash/dash_parser_segment_template_unit.js b/test/dash/dash_parser_segment_template_unit.js index 095b61002..540ef0af0 100644 --- a/test/dash/dash_parser_segment_template_unit.js +++ b/test/dash/dash_parser_segment_template_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('DashParser SegmentTemplate', function() { +describe('DashParser SegmentTemplate', () => { const Dash = shaka.test.Dash; const ManifestParser = shaka.test.ManifestParser; const baseUri = 'http://example.com/'; @@ -27,7 +27,7 @@ describe('DashParser SegmentTemplate', function() { /** @type {shaka.extern.ManifestParser.PlayerInterface} */ let playerInterface; - beforeEach(function() { + beforeEach(() => { fakeNetEngine = new shaka.test.FakeNetworkingEngine(); parser = shaka.test.Dash.makeDashParser(); @@ -44,7 +44,7 @@ describe('DashParser SegmentTemplate', function() { shaka.test.Dash.makeTimelineTests( 'SegmentTemplate', 'media="s$Number$.mp4"', []); - describe('duration', function() { + describe('duration', () => { it('basic support', async () => { const source = Dash.makeSimpleManifestText([ ' { const source = Dash.makeSimpleManifestText([ '', @@ -82,7 +82,7 @@ describe('DashParser SegmentTemplate', function() { fakeNetEngine.setResponseText('dummy://foo', source); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest.periods.length).toBe(1); expect(manifest.periods[0].variants.length).toBe(1); @@ -110,21 +110,21 @@ describe('DashParser SegmentTemplate', function() { await Dash.testSegmentIndex(source, references); }); - it('presentation start is parsed correctly', function(done) { + it('presentation start is parsed correctly', (done) => { const source = Dash.makeSimpleManifestText([ '', ], 30 /* duration */, /* startTime */ 30); fakeNetEngine.setResponseText('dummy://foo', source); parser.start('dummy://foo', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest.presentationTimeline.getSeekRangeStart()).toBe(30); }) .catch(fail).then(done); }); }); - describe('index', function() { + describe('index', () => { it('basic support', async () => { const source = Dash.makeSimpleManifestText([ ' { it('defaults to timeline when also has duration', async () => { const source = Dash.makeSimpleManifestText([ ' { it('bad container type', async () => { const source = [ '', diff --git a/test/dash/mpd_utils_unit.js b/test/dash/mpd_utils_unit.js index d46b76bc1..746bff09f 100644 --- a/test/dash/mpd_utils_unit.js +++ b/test/dash/mpd_utils_unit.js @@ -15,11 +15,11 @@ * limitations under the License. */ -describe('MpdUtils', function() { +describe('MpdUtils', () => { const MpdUtils = shaka.dash.MpdUtils; - describe('fillUriTemplate', function() { - it('handles a single RepresentationID identifier', function() { + describe('fillUriTemplate', () => { + it('handles a single RepresentationID identifier', () => { expect( MpdUtils.fillUriTemplate( '/example/$RepresentationID$.mp4', @@ -38,7 +38,7 @@ describe('MpdUtils', function() { .toBe('/example/$RepresentationID$.mp4'); }); - it('handles a single Number identifier', function() { + it('handles a single Number identifier', () => { expect( MpdUtils.fillUriTemplate( '/example/$Number$.mp4', @@ -56,7 +56,7 @@ describe('MpdUtils', function() { .toBe('/example/$Number$.mp4'); }); - it('handles a single Bandwidth identifier', function() { + it('handles a single Bandwidth identifier', () => { expect( MpdUtils.fillUriTemplate( '/example/$Bandwidth$.mp4', @@ -74,7 +74,7 @@ describe('MpdUtils', function() { .toBe('/example/$Bandwidth$.mp4'); }); - it('handles a single Time identifier', function() { + it('handles a single Time identifier', () => { expect( MpdUtils.fillUriTemplate( '/example/$Time$.mp4', @@ -92,7 +92,7 @@ describe('MpdUtils', function() { .toBe('/example/$Time$.mp4'); }); - it('handles rounding errors for calculated Times', function() { + it('handles rounding errors for calculated Times', () => { expect( MpdUtils.fillUriTemplate( '/example/$Time$.mp4', @@ -104,7 +104,7 @@ describe('MpdUtils', function() { null, null, null, 99.9999).toString()).toBe('/example/00100.mp4'); }); - it('handles multiple identifiers', function() { + it('handles multiple identifiers', () => { expect( MpdUtils.fillUriTemplate( '/example/$RepresentationID$_$Number$_$Bandwidth$_$Time$.mp4', @@ -141,7 +141,7 @@ describe('MpdUtils', function() { '1', 2, 3, 4).toString()).toBe('$/1$2$3$4$.$'); }); - it('handles invalid identifiers', function() { + it('handles invalid identifiers', () => { expect( MpdUtils.fillUriTemplate( '/example/$Garbage$.mp4', @@ -153,7 +153,7 @@ describe('MpdUtils', function() { '1', 2, 3, 4).toString()).toBe('/example/$Time.mp4'); }); - it('handles non-decimal format specifiers', function() { + it('handles non-decimal format specifiers', () => { expect( MpdUtils.fillUriTemplate( '/$Number%05x$_$Number%01X$_$Number%01u$_$Number%01o$.mp4', @@ -161,8 +161,8 @@ describe('MpdUtils', function() { }); }); - describe('createTimeline', function() { - it('works in normal case', function() { + describe('createTimeline', () => { + it('works in normal case', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, 0), @@ -176,7 +176,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles null start time', function() { + it('handles null start time', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(null, 10, 0), @@ -190,7 +190,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles gaps', function() { + it('handles gaps', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(15, 10, 0), @@ -202,7 +202,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles overlap', function() { + it('handles overlap', () => { const timePoints = [ createTimePoint(0, 15, 0), createTimePoint(10, 10, 0), @@ -214,7 +214,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles repetitions', function() { + it('handles repetitions', () => { const timePoints = [ createTimePoint(0, 10, 5), createTimePoint(60, 10, 0), @@ -231,7 +231,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles null repeat', function() { + it('handles null repeat', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, null), @@ -245,7 +245,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles repetitions with gap', function() { + it('handles repetitions with gap', () => { const timePoints = [ createTimePoint(0, 10, 2), createTimePoint(35, 10, 0), @@ -259,7 +259,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles negative repetitions', function() { + it('handles negative repetitions', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, -1), @@ -275,7 +275,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles negative repetitions with uneven border', function() { + it('handles negative repetitions with uneven border', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, -1), @@ -292,7 +292,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles negative repetitions w/ bad next start time', function() { + it('handles negative repetitions w/ bad next start time', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, -1), @@ -304,7 +304,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles negative repetitions w/ null next start time', function() { + it('handles negative repetitions w/ null next start time', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, -1), @@ -316,7 +316,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles negative repetitions at end', function() { + it('handles negative repetitions at end', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 5, -1), @@ -330,7 +330,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, 25); }); - it('handles negative repetitions at end w/o Period length', function() { + it('handles negative repetitions at end w/o Period length', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 5, -1), @@ -341,7 +341,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('handles negative repetitions at end w/ bad Period length', function() { + it('handles negative repetitions at end w/ bad Period length', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, 0), @@ -354,7 +354,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, 20); }); - it('ignores elements after null duration', function() { + it('ignores elements after null duration', () => { const timePoints = [ createTimePoint(0, 10, 0), createTimePoint(10, 10, 0), @@ -369,7 +369,7 @@ describe('MpdUtils', function() { checkTimePoints(timePoints, result, 1, 0, Infinity); }); - it('adjust start with presentationTimeOffset', function() { + it('adjust start with presentationTimeOffset', () => { const timePoints = [ createTimePoint(10, 10, 0), createTimePoint(20, 10, 0), @@ -438,7 +438,7 @@ describe('MpdUtils', function() { } }); - describe('processXlinks', function() { + describe('processXlinks', () => { const Error = shaka.util.Error; /** @type {!shaka.test.FakeNetworkingEngine} */ @@ -450,7 +450,7 @@ describe('MpdUtils', function() { /** @type {boolean} */ let failGracefully; - beforeEach(function() { + beforeEach(() => { failGracefully = false; retry = shaka.net.NetworkingEngine.defaultRetryParameters(); fakeNetEngine = new shaka.test.FakeNetworkingEngine(); @@ -649,7 +649,7 @@ describe('MpdUtils', function() { await testSucceeds(baseXMLString, desiredXMLString, 1); }); - it('interrupts requests on abort', function(done) { + it('interrupts requests on abort', (done) => { const baseXMLString = inBaseContainer( ''); // Create a few links. This is few enough that it would succeed if we @@ -709,7 +709,7 @@ describe('MpdUtils', function() { } function testFails(baseXMLString, desiredError, desiredNetCalls) { - return testRequest(baseXMLString).then(fail).catch(function(error) { + return testRequest(baseXMLString).then(fail).catch((error) => { expect(fakeNetEngine.request).toHaveBeenCalledTimes(desiredNetCalls); if (desiredError) { shaka.test.Util.expectToEqualError(error, desiredError); diff --git a/test/deprecate/version_unit.js b/test/deprecate/version_unit.js index ec8b6b36d..7cf0e245f 100644 --- a/test/deprecate/version_unit.js +++ b/test/deprecate/version_unit.js @@ -15,11 +15,11 @@ * limitations under the License. */ -describe('Version', function() { +describe('Version', () => { const Version = shaka.deprecate.Version; - describe('parse', function() { - it('can parse full tag', function() { + describe('parse', () => { + it('can parse full tag', () => { const versionString = 'v2.4.3-tag-and-other-words'; const version = Version.parse(versionString); @@ -28,38 +28,38 @@ describe('Version', function() { }); }); - describe('toString', function() { - it('converts version to string', function() { + describe('toString', () => { + it('converts version to string', () => { const version = new Version(2, 4); expect(version.toString()).toBe('v2.4'); }); }); - describe('compareTo', function() { - it('handles equals', function() { + describe('compareTo', () => { + it('handles equals', () => { const version = new Version(2, 4); expect(version.compareTo(version)).toBe(0); }); - it('handles less-than with minor', function() { + it('handles less-than with minor', () => { const smaller = new Version(2, 2); const larger = new Version(2, 4); expect(smaller.compareTo(larger)).toBeLessThan(0); }); - it('handles less-than with major', function() { + it('handles less-than with major', () => { const smaller = new Version(2, 2); const larger = new Version(3, 1); expect(smaller.compareTo(larger)).toBeLessThan(0); }); - it('handles greater-than with minor', function() { + it('handles greater-than with minor', () => { const smaller = new Version(2, 2); const larger = new Version(2, 4); expect(larger.compareTo(smaller)).toBeGreaterThan(0); }); - it('handles greater-than with major', function() { + it('handles greater-than with major', () => { const smaller = new Version(2, 2); const larger = new Version(3, 1); expect(larger.compareTo(smaller)).toBeGreaterThan(0); diff --git a/test/hls/hls_live_unit.js b/test/hls/hls_live_unit.js index 3c644d2fe..8b36c456f 100644 --- a/test/hls/hls_live_unit.js +++ b/test/hls/hls_live_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('HlsParser live', function() { +describe('HlsParser live', () => { const Util = shaka.test.Util; const ManifestParser = shaka.test.ManifestParser; @@ -50,7 +50,7 @@ describe('HlsParser live', function() { /** @type {number} */ let segmentDataStartTime; - beforeEach(function() { + beforeEach(() => { // TODO: use StreamGenerator? initSegmentData = new Uint8Array([ 0x00, 0x00, 0x00, 0x30, // size (48) @@ -130,7 +130,7 @@ describe('HlsParser live', function() { parser.configure(config); }); - afterEach(function() { + afterEach(() => { // HLS parser stop is synchronous. parser.stop(); }); @@ -164,7 +164,7 @@ describe('HlsParser live', function() { .setResponseValue('test:/selfInit.mp4', selfInitializingSegmentData); parser.start('test:/master', playerInterface) - .then(function(manifest) { + .then((manifest) => { const variants = manifest.periods[0].variants; for (let i = 0; i < variants.length; i++) { const video = variants[i].video; @@ -196,7 +196,7 @@ describe('HlsParser live', function() { } - describe('playlist type EVENT', function() { + describe('playlist type EVENT', () => { const media = [ '#EXTM3U\n', '#EXT-X-PLAYLIST-TYPE:EVENT\n', @@ -217,7 +217,7 @@ describe('HlsParser live', function() { 'main2.mp4\n', ].join(''); - it('treats already ended presentation like VOD', function(done) { + it('treats already ended presentation like VOD', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', media + '#EXT-X-ENDLIST') @@ -225,7 +225,7 @@ describe('HlsParser live', function() { .setResponseValue('test:/main.mp4', segmentData); parser.start('test:/master', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(manifest.presentationTimeline.isLive()).toBe(false); expect(manifest.presentationTimeline.isInProgress()).toBe(false); }) @@ -233,19 +233,19 @@ describe('HlsParser live', function() { .then(done); }); - describe('update', function() { - beforeAll(function() { + describe('update', () => { + beforeAll(() => { jasmine.clock().install(); // This mock is required for fakeEventLoop. PromiseMock.install(); }); - afterAll(function() { + afterAll(() => { jasmine.clock().uninstall(); PromiseMock.uninstall(); }); - it('adds new segments when they appear', function(done) { + it('adds new segments when they appear', (done) => { const ref1 = ManifestParser.makeReference('test:/main.mp4', 0, 2, 4); const ref2 = ManifestParser.makeReference('test:/main2.mp4', @@ -255,7 +255,7 @@ describe('HlsParser live', function() { mediaWithAdditionalSegment, [ref1, ref2]); }); - it('updates all variants', function(done) { + it('updates all variants', (done) => { const secondVariant = [ '#EXT-X-STREAM-INF:BANDWIDTH=300,CODECS="avc1",', 'RESOLUTION=1200x940,FRAME-RATE=60\n', @@ -272,7 +272,7 @@ describe('HlsParser live', function() { mediaWithAdditionalSegment, [ref1, ref2]); }); - it('updates all streams', function(done) { + it('updates all streams', (done) => { const audio = [ '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",', 'URI="audio"\n', @@ -288,7 +288,7 @@ describe('HlsParser live', function() { mediaWithAdditionalSegment, [ref1, ref2]); }); - it('handles multiple updates', function(done) { + it('handles multiple updates', (done) => { const newSegment1 = [ '#EXTINF:2,\n', 'main2.mp4\n', @@ -315,7 +315,7 @@ describe('HlsParser live', function() { .setResponseValue('test:/main.mp4', segmentData); parser.start('test:/master', playerInterface) - .then(function(manifest) { + .then((manifest) => { const video = manifest.periods[0].variants[0].video; ManifestParser.verifySegmentIndex(video, [ref1]); @@ -336,14 +336,14 @@ describe('HlsParser live', function() { PromiseMock.flush(); }); - it('converts presentation to VOD when it is finished', function(done) { + it('converts presentation to VOD when it is finished', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', media) .setResponseValue('test:/init.mp4', initSegmentData) .setResponseValue('test:/main.mp4', segmentData); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { expect(manifest.presentationTimeline.isLive()).toBe(true); fakeNetEngine .setResponseText('test:/master', master) @@ -356,14 +356,14 @@ describe('HlsParser live', function() { PromiseMock.flush(); }); - it('starts presentation as VOD when ENDLIST is present', function(done) { + it('starts presentation as VOD when ENDLIST is present', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', media + '#EXT-X-ENDLIST') .setResponseValue('test:/init.mp4', initSegmentData) .setResponseValue('test:/main.mp4', segmentData); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { expect(manifest.presentationTimeline.isLive()).toBe(false); }).catch(fail).then(done); PromiseMock.flush(); @@ -371,7 +371,7 @@ describe('HlsParser live', function() { }); // describe('update') }); // describe('playlist type EVENT') - describe('playlist type LIVE', function() { + describe('playlist type LIVE', () => { const media = [ '#EXTM3U\n', '#EXT-X-TARGETDURATION:5\n', @@ -433,19 +433,19 @@ describe('HlsParser live', function() { mediaWithManySegments += 'main.mp4\n'; } - it('starts presentation as VOD when ENDLIST is present', function(done) { + it('starts presentation as VOD when ENDLIST is present', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', media + '#EXT-X-ENDLIST') .setResponseValue('test:/init.mp4', initSegmentData) .setResponseValue('test:/main.mp4', segmentData); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { expect(manifest.presentationTimeline.isLive()).toBe(false); }).catch(fail).then(done); }); - it('does not fail on a missing sequence number', function(done) { + it('does not fail on a missing sequence number', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', mediaWithoutSequenceNumber) @@ -455,7 +455,7 @@ describe('HlsParser live', function() { parser.start('test:/master', playerInterface).catch(fail).then(done); }); - describe('availabilityWindowOverride', function() { + describe('availabilityWindowOverride', () => { async function testWindowOverride(expectedWindow) { fakeNetEngine .setResponseText('test:/master', master) @@ -485,7 +485,7 @@ describe('HlsParser live', function() { }); }); - it('offsets VTT text with rolled over TS timestamps', function(done) { + it('offsets VTT text with rolled over TS timestamps', (done) => { const masterWithVtt = [ '#EXTM3U\n', '#EXT-X-MEDIA:TYPE=SUBTITLES,LANGUAGE="fra",URI="text"\n', @@ -517,7 +517,7 @@ describe('HlsParser live', function() { .setResponseValue('test:/main.mp4', pastRolloverSegmentData) .setResponseText('test:/main.vtt', vtt); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { const textStream = manifest.periods[0].textStreams[0]; let ref = textStream.getSegmentReference(0); expect(ref).not.toBe(null); @@ -530,19 +530,19 @@ describe('HlsParser live', function() { }).catch(fail).then(done); }); - describe('update', function() { - beforeAll(function() { + describe('update', () => { + beforeAll(() => { jasmine.clock().install(); // This mock is required for fakeEventLoop. PromiseMock.install(); }); - afterAll(function() { + afterAll(() => { jasmine.clock().uninstall(); PromiseMock.uninstall(); }); - it('adds new segments when they appear', function(done) { + it('adds new segments when they appear', (done) => { const ref1 = ManifestParser.makeReference('test:/main.mp4', 0, 2, 4); const ref2 = ManifestParser.makeReference('test:/main2.mp4', @@ -552,7 +552,7 @@ describe('HlsParser live', function() { mediaWithAdditionalSegment, [ref1, ref2]); }); - it('evicts removed segments', function(done) { + it('evicts removed segments', (done) => { const ref1 = ManifestParser.makeReference('test:/main.mp4', 0, 2, 4); const ref2 = ManifestParser.makeReference('test:/main2.mp4', @@ -562,7 +562,7 @@ describe('HlsParser live', function() { mediaWithRemovedSegment, [ref2]); }); - it('handles updates with redirects', function(done) { + it('handles updates with redirects', (done) => { const oldRef1 = ManifestParser.makeReference('test:/main.mp4', 0, 2, 4); @@ -573,7 +573,7 @@ describe('HlsParser live', function() { let playlistFetchCount = 0; - fakeNetEngine.setResponseFilter(function(type, response) { + fakeNetEngine.setResponseFilter((type, response) => { // Simulate a redirect on the updated playlist by changing the // response URI on the second playlist fetch. if (response.uri == 'test:/video') { @@ -588,7 +588,7 @@ describe('HlsParser live', function() { mediaWithAdditionalSegment, [newRef1, newRef2]); }); - it('parses start time from mp4 segments', function(done) { + it('parses start time from mp4 segments', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', media) @@ -599,7 +599,7 @@ describe('HlsParser live', function() { 'test:/main.mp4', 0, segmentDataStartTime, segmentDataStartTime + 2); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { const video = manifest.periods[0].variants[0].video; ManifestParser.verifySegmentIndex(video, [ref]); @@ -609,7 +609,7 @@ describe('HlsParser live', function() { PromiseMock.flush(); }); - it('gets start time on update without segment request', function(done) { + it('gets start time on update without segment request', (done) => { fakeNetEngine .setResponseText('test:/master', master) .setResponseText('test:/video', mediaWithAdditionalSegment) @@ -624,7 +624,7 @@ describe('HlsParser live', function() { 'test:/main2.mp4', 1, segmentDataStartTime + 2, segmentDataStartTime + 4); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { const video = manifest.periods[0].variants[0].video; ManifestParser.verifySegmentIndex(video, [ref1, ref2]); @@ -651,7 +651,7 @@ describe('HlsParser live', function() { PromiseMock.flush(); }); - it('parses start time from ts segments', function(done) { + it('parses start time from ts segments', (done) => { const tsMediaPlaylist = mediaWithRemovedSegment.replace(/\.mp4/g, '.ts'); @@ -664,7 +664,7 @@ describe('HlsParser live', function() { 'test:/main2.ts', 1, segmentDataStartTime, segmentDataStartTime + 2); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { const video = manifest.periods[0].variants[0].video; ManifestParser.verifySegmentIndex(video, [ref]); // In live content, we do not set presentationTimeOffset. @@ -674,7 +674,7 @@ describe('HlsParser live', function() { PromiseMock.flush(); }); - it('gets start time of segments with byte range', function(done) { + it('gets start time of segments with byte range', (done) => { // Nit: this value is an implementation detail of the fix for #1106 const partialEndByte = expectedStartByte + 2048 - 1; @@ -693,7 +693,7 @@ describe('HlsParser live', function() { expectedStartByte, expectedEndByte); // Complete segment reference - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { const video = manifest.periods[0].variants[0].video; ManifestParser.verifySegmentIndex(video, [ref]); @@ -708,7 +708,7 @@ describe('HlsParser live', function() { PromiseMock.flush(); }); - it('handles rollover on update', function(done) { + it('handles rollover on update', (done) => { const masterWithVtt = [ '#EXTM3U\n', '#EXT-X-MEDIA:TYPE=SUBTITLES,LANGUAGE="fra",URI="text"\n', @@ -772,7 +772,7 @@ describe('HlsParser live', function() { /* startTime */ baseTime + 2, /* endTime */ baseTime + 4); - parser.start('test:/master', playerInterface).then(function(manifest) { + parser.start('test:/master', playerInterface).then((manifest) => { const text = manifest.periods[0].textStreams[0]; ManifestParser.verifySegmentIndex(text, [ref1]); diff --git a/test/hls/hls_parser_unit.js b/test/hls/hls_parser_unit.js index a0d3424ec..1c175b3dd 100644 --- a/test/hls/hls_parser_unit.js +++ b/test/hls/hls_parser_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('HlsParser', function() { +describe('HlsParser', () => { const ContentType = shaka.util.ManifestParserUtils.ContentType; const ManifestParser = shaka.test.ManifestParser; const TextStreamKind = shaka.util.ManifestParserUtils.TextStreamKind; @@ -43,7 +43,7 @@ describe('HlsParser', function() { /** @type {!ArrayBuffer} */ let selfInitializingSegmentData; - beforeEach(function() { + beforeEach(() => { // TODO: use StreamGenerator? initSegmentData = new Uint8Array([ 0x00, 0x00, 0x00, 0x30, // size (48) @@ -121,7 +121,7 @@ describe('HlsParser', function() { return actual; } - it('parses manifest attributes', function(done) { + it('parses manifest attributes', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",', @@ -195,11 +195,11 @@ describe('HlsParser', function() { .setResponseValue('test:/main.mp4', segmentData); parser.start('test:/master', playerInterface) - .then(function(actual) { expect(actual).toEqual(manifest); }) + .then((actual) => { expect(actual).toEqual(manifest); }) .catch(fail).then(done); }); - it('ignores duplicate CODECS', async function() { + it('ignores duplicate CODECS', async () => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1.4d001e,avc1.42000d",', @@ -227,7 +227,7 @@ describe('HlsParser', function() { await testHlsParser(master, media, manifest); }); - it('parses video-only variant', async function() { + it('parses video-only variant', async () => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1",', @@ -719,7 +719,7 @@ describe('HlsParser', function() { await testHlsParser(master, media, manifest); }); - it('should call filterAllPeriods for parsing', function(done) { + it('should call filterAllPeriods for parsing', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1",', @@ -747,7 +747,7 @@ describe('HlsParser', function() { playerInterface.filterAllPeriods = Util.spyFunc(filterAllPeriods); parser.start('test:/master', playerInterface) - .then(function(manifest) { + .then((manifest) => { expect(filterAllPeriods.calls.count()).toBe(1); }).catch(fail).then(done); }); @@ -1065,7 +1065,7 @@ describe('HlsParser', function() { expect(actual).toEqual(manifest); }); - it('allows init segments in text streams', function(done) { + it('allows init segments in text streams', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub1",LANGUAGE="eng",', @@ -1103,7 +1103,7 @@ describe('HlsParser', function() { .setResponseValue('test:/main.mp4', segmentData); parser.start('test:/master', playerInterface) - .then(function(actual) { expect(actual).toEqual(manifest); }) + .then((actual) => { expect(actual).toEqual(manifest); }) .catch(fail).then(done); }); @@ -1139,7 +1139,7 @@ describe('HlsParser', function() { await testHlsParser(master, media, manifest); }); - it('constructs relative URIs', function(done) { + it('constructs relative URIs', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",', @@ -1166,7 +1166,7 @@ describe('HlsParser', function() { .setResponseValue('test:/host/video/segment.mp4', segmentData); parser.start('test:/host/master.m3u8', playerInterface) - .then(function(actual) { + .then((actual) => { const video = actual.periods[0].variants[0].video; const audio = actual.periods[0].variants[0].audio; @@ -1326,7 +1326,7 @@ describe('HlsParser', function() { await testHlsParser(master, media, manifest); }); - describe('Errors out', function() { + describe('Errors out', () => { const Code = shaka.util.Error.Code; /** @@ -1346,13 +1346,13 @@ describe('HlsParser', function() { parser.start('test:/master', playerInterface) .then(fail) - .catch(function(e) { + .catch((e) => { shaka.test.Util.expectToEqualError(e, error); }) .then(done); } - it('if multiple init sections were provided', function(done) { + it('if multiple init sections were provided', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",', @@ -1379,7 +1379,7 @@ describe('HlsParser', function() { verifyError(master, media, error, done); }); - it('if unable to guess mime type', function(done) { + it('if unable to guess mime type', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",', @@ -1405,7 +1405,7 @@ describe('HlsParser', function() { verifyError(master, media, error, done); }); - it('if unable to guess codecs', function(done) { + it('if unable to guess codecs', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="aaa,bbb",', @@ -1433,7 +1433,7 @@ describe('HlsParser', function() { verifyError(master, media, error, done); }); - it('if all variants are encrypted with AES-128', function(done) { + it('if all variants are encrypted with AES-128', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1",', @@ -1461,7 +1461,7 @@ describe('HlsParser', function() { verifyError(master, media, error, done); }); - describe('if required attributes are missing', function() { + describe('if required attributes are missing', () => { /** * @param {string} master * @param {string} media @@ -1478,7 +1478,7 @@ describe('HlsParser', function() { verifyError(master, media, error, done); } - it('bandwidth', function(done) { + it('bandwidth', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:CODECS="avc1,mp4a",', @@ -1499,7 +1499,7 @@ describe('HlsParser', function() { verifyMissingAttribute(master, media, 'BANDWIDTH', done); }); - it('uri', function(done) { + it('uri', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:CODECS="avc1,mp4a",BANDWIDTH=200,', @@ -1521,7 +1521,7 @@ describe('HlsParser', function() { }); }); - describe('if required tags are missing', function() { + describe('if required tags are missing', () => { /** * @param {string} master * @param {string} media @@ -1538,7 +1538,7 @@ describe('HlsParser', function() { verifyError(master, media, error, done); } - it('EXTINF', function(done) { + it('EXTINF', (done) => { const master = [ '#EXTM3U\n', '#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",', @@ -1560,7 +1560,7 @@ describe('HlsParser', function() { }); }); // Errors out - describe('getStartTime_', function() { + describe('getStartTime_', () => { /** @type {number} */ let segmentDataStartTime; /** @type {!ArrayBuffer} */ @@ -1589,7 +1589,7 @@ describe('HlsParser', function() { // Nit: this value is an implementation detail of the fix for #1106 const partialEndByte = expectedStartByte + 2048 - 1; - beforeEach(function() { + beforeEach(() => { // TODO: use StreamGenerator? segmentData = new Uint8Array([ 0x00, 0x00, 0x00, 0x24, // size (36) @@ -1924,7 +1924,7 @@ describe('HlsParser', function() { .setResponseValue('http://foo/media/init.mp4', initSegmentData) .setResponseValue('http://foo/media/main.mp4', segmentData); - fakeNetEngine.setResponseFilter(function(type, response) { + fakeNetEngine.setResponseFilter((type, response) => { // Simulate support for relative URIs in the browser by setting the // absolute URI in response.uri. if (response.uri == 'media/master') { diff --git a/test/hls/manifest_text_parser_unit.js b/test/hls/manifest_text_parser_unit.js index 802f0af80..d68b5b52d 100644 --- a/test/hls/manifest_text_parser_unit.js +++ b/test/hls/manifest_text_parser_unit.js @@ -16,16 +16,16 @@ */ -describe('ManifestTextParser', function() { +describe('ManifestTextParser', () => { /** @type {!shaka.hls.ManifestTextParser} */ let parser; - beforeEach(function() { + beforeEach(() => { parser = new shaka.hls.ManifestTextParser(); }); - describe('parsePlaylist', function() { - it('rejects invalid playlists', function() { + describe('parsePlaylist', () => { + it('rejects invalid playlists', () => { verifyError('invalid playlist', shaka.util.Error.Code.HLS_PLAYLIST_HEADER_MISSING); @@ -37,7 +37,7 @@ describe('ManifestTextParser', function() { shaka.util.Error.Code.HLS_INVALID_PLAYLIST_HIERARCHY); }); - it('parses a Media Playlist', function() { + it('parses a Media Playlist', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, @@ -54,7 +54,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('parses a Master Playlist', function() { + it('parses a Master Playlist', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, @@ -78,7 +78,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('ignores comments', function() { + it('ignores comments', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, @@ -115,8 +115,8 @@ describe('ManifestTextParser', function() { } }); - describe('parseTag', function() { - it('parses tags with no attributes', function() { + describe('parseTag', () => { + it('parses tags with no attributes', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MASTER, @@ -163,7 +163,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('parses tags with attributes', function() { + it('parses tags with attributes', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MASTER, @@ -200,7 +200,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('parses tags with commas in attribute values', function() { + it('parses tags with commas in attribute values', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MASTER, @@ -259,7 +259,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('rejects invalid tags', function() { + it('rejects invalid tags', () => { const error = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MANIFEST, @@ -275,34 +275,34 @@ describe('ManifestTextParser', function() { }); }); - describe('tag.toString', function() { - it('recreates valid tag with attributes', function() { + describe('tag.toString', () => { + it('recreates valid tag with attributes', () => { const text = '#EXT-X-MEDIA:CODECS="avc1.64002a,mp4a.40.2",AUDIO="a1,a2"'; const tag = shaka.hls.ManifestTextParser.parseTag(0, text); expect(text).toEqual(tag.toString()); }); - it('recreates valid tag with value', function() { + it('recreates valid tag with value', () => { const text = '#EXT-X-PLAYLIST-TYPE:VOD'; const tag = shaka.hls.ManifestTextParser.parseTag(0, text); expect(text).toEqual(tag.toString()); }); - it('recreates valid tag with no value', function() { + it('recreates valid tag with no value', () => { const text = '#EXTM3U'; const tag = shaka.hls.ManifestTextParser.parseTag(0, text); expect(text).toEqual(tag.toString()); }); - it('recreates valid tag with both value and attributes', function() { + it('recreates valid tag with both value and attributes', () => { const text = '#EXTINF:5.99467,pid=180'; const tag = shaka.hls.ManifestTextParser.parseTag(0, text); expect(text).toEqual(tag.toString()); }); }); - describe('parseSegments', function() { - it('parses segments', function() { + describe('parseSegments', () => { + it('parses segments', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, @@ -327,7 +327,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('handles tags with both value and attributes', function() { + it('handles tags with both value and attributes', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, @@ -389,7 +389,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('tracks playlist URI', function() { + it('tracks playlist URI', () => { verifyPlaylist( { absoluteUri: 'https://test/manifest.m3u8', @@ -416,7 +416,7 @@ describe('ManifestTextParser', function() { }); }); - describe('parseSegments', function() { + describe('parseSegments', () => { const manifestText = '#EXTM3U\n' + '#EXT-X-TARGETDURATION:6\n' + '#EXTINF:5\n' + @@ -424,7 +424,7 @@ describe('ManifestTextParser', function() { '#EXTINF:4\n' + 'uri2\n'; - it('parses segments', function() { + it('parses segments', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, @@ -445,7 +445,7 @@ describe('ManifestTextParser', function() { 'https://test/manifest.m3u8'); }); - it('identifies playlist tags', function() { + it('identifies playlist tags', () => { verifyPlaylist( { type: shaka.hls.PlaylistType.MEDIA, diff --git a/test/media/adaptation_set_criteria_unit.js b/test/media/adaptation_set_criteria_unit.js index f86ffd58f..026472963 100644 --- a/test/media/adaptation_set_criteria_unit.js +++ b/test/media/adaptation_set_criteria_unit.js @@ -15,13 +15,13 @@ * limitations under the License. */ -describe('AdaptationSetCriteria', function() { - describe('preference based selection', function() { +describe('AdaptationSetCriteria', () => { + describe('preference based selection', () => { function variants(manifest) { return manifest.periods[0].variants; } - it('chooses variants in user\'s preferred language', function() { + it('chooses variants in user\'s preferred language', () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -41,7 +41,7 @@ describe('AdaptationSetCriteria', function() { ]); }); - it('prefers primary variants', function() { + it('prefers primary variants', () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -61,7 +61,7 @@ describe('AdaptationSetCriteria', function() { ]); }); - it('chooses variants in preferred language and role', function() { + it('chooses variants in preferred language and role', () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -83,7 +83,7 @@ describe('AdaptationSetCriteria', function() { ]); }); - it('chooses only one role, even if none is preferred', function() { + it('chooses only one role, even if none is preferred', () => { // Regression test for https://github.com/google/shaka-player/issues/949 const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) @@ -118,7 +118,7 @@ describe('AdaptationSetCriteria', function() { ]); }); - it('chooses only one role, even if all are primary', function() { + it('chooses only one role, even if all are primary', () => { // Regression test for https://github.com/google/shaka-player/issues/949 const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) @@ -153,7 +153,7 @@ describe('AdaptationSetCriteria', function() { ]); }); - it('chooses only one language, even if all are primary', function() { + it('chooses only one language, even if all are primary', () => { // Regression test for https://github.com/google/shaka-player/issues/918 const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) @@ -183,7 +183,7 @@ describe('AdaptationSetCriteria', function() { }); it('chooses a role from among primary variants without language match', - function() { + () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -219,7 +219,7 @@ describe('AdaptationSetCriteria', function() { }); it('chooses a role from best language match, in spite of primary', - function() { + () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -251,7 +251,7 @@ describe('AdaptationSetCriteria', function() { ]); }); - it('chooses variants with preferred audio channels count', function() { + it('chooses variants with preferred audio channels count', () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -272,7 +272,7 @@ describe('AdaptationSetCriteria', function() { }); it('chooses variants with largest audio channel count less than config' + - ' when no exact audio channel count match is possible', function() { + ' when no exact audio channel count match is possible', () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) @@ -293,7 +293,7 @@ describe('AdaptationSetCriteria', function() { }); it('chooses variants with fewest audio channels when none fit in the ' + - 'config', function() { + 'config', () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1) diff --git a/test/media/adaptation_set_unit.js b/test/media/adaptation_set_unit.js index fd4a5b988..393c5f886 100644 --- a/test/media/adaptation_set_unit.js +++ b/test/media/adaptation_set_unit.js @@ -15,13 +15,13 @@ * limitations under the License. */ -describe('AdaptationSet', function() { - describe('roles', function() { +describe('AdaptationSet', () => { + describe('roles', () => { const mimeType = 'mime-type'; const audioCodecs = ['a.35']; const videoCodecs = ['b.12']; - it('accepts matching roles', function() { + it('accepts matching roles', () => { const variants = [ makeVariant( 1, // variant id @@ -38,7 +38,7 @@ describe('AdaptationSet', function() { expect(set.canInclude(variants[1])).toBeTruthy(); }); - it('accepts matching empty roles', function() { + it('accepts matching empty roles', () => { const variants = [ makeVariant( 1, // variant id @@ -54,7 +54,7 @@ describe('AdaptationSet', function() { expect(set.canInclude(variants[1])).toBeTruthy(); }); - it('reject different roles', function() { + it('reject different roles', () => { const variants = [ makeVariant( 1, // variant id @@ -94,7 +94,7 @@ describe('AdaptationSet', function() { }); }); - it('rejects different mime types', function() { + it('rejects different mime types', () => { const variants = [ makeVariant( 1, // variant id @@ -113,7 +113,7 @@ describe('AdaptationSet', function() { expect(set.canInclude(variants[1])).toBeFalsy(); }); - it('rejects mis-aligned transmuxed streams', function() { + it('rejects mis-aligned transmuxed streams', () => { const variants = [ makeVariant( 1, // variant id diff --git a/test/media/drm_engine_integration.js b/test/media/drm_engine_integration.js index b576f55a0..8e350a8de 100644 --- a/test/media/drm_engine_integration.js +++ b/test/media/drm_engine_integration.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('DrmEngine', function() { +describe('DrmEngine', () => { const ContentType = shaka.util.ManifestParserUtils.ContentType; // These come from Axinom and use the Axinom license server. @@ -62,7 +62,7 @@ describe('DrmEngine', function() { beforeAll(async () => { const supportTest = shaka.media.DrmEngine.probeSupport() - .then(function(result) { support = result; }) + .then((result) => { support = result; }) .catch(fail); video = shaka.util.Dom.createVideoElement(); @@ -88,7 +88,7 @@ describe('DrmEngine', function() { onEventSpy = jasmine.createSpy('onEvent'); networkingEngine = new shaka.net.NetworkingEngine(); - networkingEngine.registerRequestFilter(function(type, request) { + networkingEngine.registerRequestFilter((type, request) => { if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) return; request.headers['X-AxDRM-Message'] = [ @@ -149,11 +149,11 @@ describe('DrmEngine', function() { await drmEngine.destroy(); }); - afterAll(function() { + afterAll(() => { document.body.removeChild(video); }); - describe('basic flow', function() { + describe('basic flow', () => { drmIt('gets a license and can play encrypted segments', checkAndRun((done) => { // The error callback should not be invoked. @@ -172,10 +172,10 @@ describe('DrmEngine', function() { networkingEngine.request = shaka.test.Util.spyFunc(requestSpy); const encryptedEventSeen = new shaka.util.PublicPromise(); - eventManager.listen(video, 'encrypted', function() { + eventManager.listen(video, 'encrypted', () => { encryptedEventSeen.resolve(); }); - eventManager.listen(video, 'error', function() { + eventManager.listen(video, 'error', () => { fail('MediaError code ' + video.error.code); let extended = video.error.msExtendedCode; if (extended) { @@ -187,7 +187,7 @@ describe('DrmEngine', function() { }); const keyStatusEventSeen = new shaka.util.PublicPromise(); - onKeyStatusSpy.and.callFake(function() { + onKeyStatusSpy.and.callFake(() => { keyStatusEventSeen.resolve(); }); @@ -195,22 +195,22 @@ describe('DrmEngine', function() { const variants = shaka.util.Periods.getAllVariantsFrom(periods); drmEngine.initForPlayback( - variants, manifest.offlineSessionIds).then(function() { + variants, manifest.offlineSessionIds).then(() => { return drmEngine.attach(video); - }).then(function() { + }).then(() => { return mediaSourceEngine.appendBuffer(ContentType.VIDEO, videoInitSegment, null, null, /* hasClosedCaptions */ false); - }).then(function() { + }).then(() => { return mediaSourceEngine.appendBuffer(ContentType.AUDIO, audioInitSegment, null, null, /* hasClosedCaptions */ false); - }).then(function() { + }).then(() => { return encryptedEventSeen; - }).then(function() { + }).then(() => { // With PlayReady, a persistent license policy can cause a different // chain of events. In particular, the request is bypassed and we // get a usable key right away. return Promise.race([requestMade, keyStatusEventSeen]); - }).then(function() { + }).then(() => { if (requestSpy.calls.count()) { // We made a license request. // Only one request should have been made. @@ -221,12 +221,12 @@ describe('DrmEngine', function() { } else { // This was probably a PlayReady persistent license. } - }).then(function() { + }).then(() => { // Some platforms (notably 2017 Tizen TVs) do not fire key status // events. const keyStatusTimeout = shaka.test.Util.delay(5); return Promise.race([keyStatusTimeout, keyStatusEventSeen]); - }).then(function() { + }).then(() => { const call = onKeyStatusSpy.calls.mostRecent(); if (call) { const map = /** @type {!Object} */ (call.args[0]); @@ -238,15 +238,15 @@ describe('DrmEngine', function() { return mediaSourceEngine.appendBuffer(ContentType.VIDEO, videoSegment, null, null, /* hasClosedCaptions */ false); - }).then(function() { + }).then(() => { return mediaSourceEngine.appendBuffer(ContentType.AUDIO, audioSegment, null, null, /* hasClosedCaptions */ false); - }).then(function() { + }).then(() => { expect(video.buffered.end(0)).toBeGreaterThan(0); video.play(); // Try to play for 5 seconds. return shaka.test.Util.delay(5); - }).then(function() { + }).then(() => { // Something should have played by now. expect(video.readyState).toBeGreaterThan(1); expect(video.currentTime).toBeGreaterThan(0); diff --git a/test/media/drm_engine_unit.js b/test/media/drm_engine_unit.js index 373fcc270..c3cd4893a 100644 --- a/test/media/drm_engine_unit.js +++ b/test/media/drm_engine_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('DrmEngine', function() { +describe('DrmEngine', () => { const Periods = shaka.util.Periods; const originalRequestMediaKeySystemAccess = @@ -55,7 +55,7 @@ describe('DrmEngine', function() { /** @type {!ArrayBuffer} */ let license; - beforeAll(function() { + beforeAll(() => { requestMediaKeySystemAccessSpy = jasmine.createSpy('requestMediaKeySystemAccess'); navigator.requestMediaKeySystemAccess = @@ -70,7 +70,7 @@ describe('DrmEngine', function() { onEventSpy = jasmine.createSpy('onEvent'); }); - beforeEach(function() { + beforeEach(() => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0) @@ -105,7 +105,7 @@ describe('DrmEngine', function() { mockMediaKeySystemAccess = createMockMediaKeySystemAccess(); mockMediaKeys = createMockMediaKeys(); - mockMediaKeys.createSession.and.callFake(function() { + mockMediaKeys.createSession.and.callFake(() => { const index = mockMediaKeys.createSession.calls.count() - 1; return [session1, session2, session3][index]; }); @@ -137,14 +137,14 @@ describe('DrmEngine', function() { await drmEngine.destroy(); }); - afterAll(function() { + afterAll(() => { navigator.requestMediaKeySystemAccess = originalRequestMediaKeySystemAccess; shaka.log.error = originalLogError; }); - describe('supportsVariants', function() { - it('supports all clear variants', async function() { + describe('supportsVariants', () => { + it('supports all clear variants', async () => { const manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0) @@ -160,7 +160,7 @@ describe('DrmEngine', function() { }); }); - describe('init', function() { + describe('init', () => { it('stops on first available key system', async () => { // Accept both drm.abc and drm.def. Only one can be chosen. requestMediaKeySystemAccessSpy.and.callFake( @@ -631,8 +631,8 @@ describe('DrmEngine', function() { }); }); // describe('init') - describe('attach', function() { - beforeEach(function() { + describe('attach', () => { + beforeEach(() => { // Both audio and video with the same key system: manifest = new shaka.test.ManifestGenerator() .addPeriod(0) @@ -685,7 +685,7 @@ describe('DrmEngine', function() { expect(mockMediaKeys.setServerCertificate).not.toHaveBeenCalled(); }); - it('creates sessions for init data overrides', function(done) { + it('creates sessions for init data overrides', (done) => { // Set up init data overrides in the manifest: const initData1 = new Uint8Array(5); const initData2 = new Uint8Array(0); @@ -696,7 +696,7 @@ describe('DrmEngine', function() { {initData: initData3, initDataType: 'cenc', keyId: null}, ]; - initAndAttach().then(function() { + initAndAttach().then(() => { expect(mockMediaKeys.createSession.calls.count()).toBe(3); expect(session1.generateRequest). toHaveBeenCalledWith('cenc', initData1.buffer); @@ -707,7 +707,7 @@ describe('DrmEngine', function() { }).catch(fail).then(done); }); - it('ignores duplicate init data overrides', function(done) { + it('ignores duplicate init data overrides', (done) => { // Set up init data overrides in the manifest; // The second initData has a different keyId from the first, // but the same initData. @@ -723,7 +723,7 @@ describe('DrmEngine', function() { {initData: initData3, initDataType: 'cenc', keyId: 'abc'}, ]; - initAndAttach().then(function() { + initAndAttach().then(() => { expect(mockMediaKeys.createSession.calls.count()).toBe(1); expect(session1.generateRequest). toHaveBeenCalledWith('cenc', initData1.buffer); @@ -745,7 +745,7 @@ describe('DrmEngine', function() { drmEngine.configure(config); const session = createMockSession(); - mockMediaKeys.createSession.and.callFake(function() { + mockMediaKeys.createSession.and.callFake(() => { expect(mockMediaKeys.createSession.calls.count()).toBe(1); return session; }); @@ -836,8 +836,8 @@ describe('DrmEngine', function() { }); }); // describe('attach') - describe('events', function() { - describe('encrypted', function() { + describe('events', () => { + describe('encrypted', () => { it('is listened for', async () => { await initAndAttach(); expect(mockVideo.addEventListener).toHaveBeenCalledWith( @@ -928,7 +928,7 @@ describe('DrmEngine', function() { }); }); // describe('encrypted') - describe('message', function() { + describe('message', () => { it('is listened for', async () => { await initAndAttach(); const initData = new Uint8Array(0); @@ -1031,7 +1031,7 @@ describe('DrmEngine', function() { } }); // describe('message') - describe('keystatuseschange', function() { + describe('keystatuseschange', () => { it('is listened for', async () => { await initAndAttach(); const initData = new Uint8Array(0); @@ -1042,8 +1042,8 @@ describe('DrmEngine', function() { 'keystatuseschange', jasmine.any(Function), false); }); - it('triggers callback', function(done) { - initAndAttach().then(function() { + it('triggers callback', (done) => { + initAndAttach().then(() => { const initData = new Uint8Array(0); mockVideo.on['encrypted']( {initDataType: 'webm', initData: initData, keyId: null}); @@ -1052,12 +1052,12 @@ describe('DrmEngine', function() { const keyId2 = (new Uint8Array(2)).buffer; const status1 = 'usable'; const status2 = 'expired'; - session1.keyStatuses.forEach.and.callFake(function(callback) { + session1.keyStatuses.forEach.and.callFake((callback) => { callback(keyId1, status1); callback(keyId2, status2); }); - onKeyStatusSpy.and.callFake(function(statusMap) { + onKeyStatusSpy.and.callFake((statusMap) => { expect(statusMap).toEqual({ '00': status1, '0000': status2, @@ -1081,7 +1081,7 @@ describe('DrmEngine', function() { const keyId2 = (new Uint8Array(2)).buffer; const status1 = 'usable'; const status2 = 'expired'; - session1.keyStatuses.forEach.and.callFake(function(callback) { + session1.keyStatuses.forEach.and.callFake((callback) => { callback(keyId1, status1); callback(keyId2, status2); }); @@ -1120,10 +1120,10 @@ describe('DrmEngine', function() { const keyId1 = (new Uint8Array(1)).buffer; const keyId2 = (new Uint8Array(2)).buffer; - session1.keyStatuses.forEach.and.callFake(function(callback) { + session1.keyStatuses.forEach.and.callFake((callback) => { callback(keyId1, 'usable'); }); - session2.keyStatuses.forEach.and.callFake(function(callback) { + session2.keyStatuses.forEach.and.callFake((callback) => { callback(keyId2, 'usable'); }); @@ -1143,10 +1143,10 @@ describe('DrmEngine', function() { expect(onKeyStatusSpy).toHaveBeenCalled(); }); - it('causes an EXPIRED error when all keys expire', function(done) { + it('causes an EXPIRED error when all keys expire', (done) => { onErrorSpy.and.stub(); - initAndAttach().then(function() { + initAndAttach().then(() => { expect(onErrorSpy).not.toHaveBeenCalled(); const initData = new Uint8Array(0); @@ -1157,22 +1157,22 @@ describe('DrmEngine', function() { const keyId2 = (new Uint8Array(2)).buffer; // Expire one key. - session1.keyStatuses.forEach.and.callFake(function(callback) { + session1.keyStatuses.forEach.and.callFake((callback) => { callback(keyId1, 'usable'); callback(keyId2, 'expired'); }); - onKeyStatusSpy.and.callFake(function(statusMap) { + onKeyStatusSpy.and.callFake((statusMap) => { // One key is still usable. expect(onErrorSpy).not.toHaveBeenCalled(); // Expire both keys. - session1.keyStatuses.forEach.and.callFake(function(callback) { + session1.keyStatuses.forEach.and.callFake((callback) => { callback(keyId1, 'expired'); callback(keyId2, 'expired'); }); - onKeyStatusSpy.and.callFake(function(statusMap) { + onKeyStatusSpy.and.callFake((statusMap) => { // Both keys are expired, so we should have an error. expect(onErrorSpy).toHaveBeenCalled(); // There should be exactly one error. @@ -1192,10 +1192,10 @@ describe('DrmEngine', function() { }).catch(fail); }); - it('causes only one error when two keys expire at once', function(done) { + it('causes only one error when two keys expire at once', (done) => { onErrorSpy.and.stub(); - initAndAttach().then(function() { + initAndAttach().then(() => { expect(onErrorSpy).not.toHaveBeenCalled(); const initData = new Uint8Array(0); @@ -1206,12 +1206,12 @@ describe('DrmEngine', function() { const keyId2 = (new Uint8Array(2)).buffer; // Expire both keys at once. - session1.keyStatuses.forEach.and.callFake(function(callback) { + session1.keyStatuses.forEach.and.callFake((callback) => { callback(keyId1, 'expired'); callback(keyId2, 'expired'); }); - onKeyStatusSpy.and.callFake(function(statusMap) { + onKeyStatusSpy.and.callFake((statusMap) => { // Both keys are expired, so we should have an error. expect(onErrorSpy).toHaveBeenCalled(); // There should be exactly one error. @@ -1225,7 +1225,7 @@ describe('DrmEngine', function() { // Ignore the next key status event, sleep for one second, then // check to see if another error fired. onKeyStatusSpy.and.stub(); - shaka.test.Util.delay(1).then(function() { + shaka.test.Util.delay(1).then(() => { // Still only one error. expect(onErrorSpy.calls.count()).toEqual(1); done(); @@ -1240,7 +1240,7 @@ describe('DrmEngine', function() { }); // describe('keystatuseschange') }); // describe('events') - describe('update', function() { + describe('update', () => { it('receives a license', async () => { const license = (new Uint8Array(0)).buffer; @@ -1273,7 +1273,7 @@ describe('DrmEngine', function() { // Not mocked. Run data through real data URI parser to ensure that it is // correctly formatted. - fakeNetEngine.request.and.callFake(function(type, request) { + fakeNetEngine.request.and.callFake((type, request) => { // eslint-disable-next-line new-cap return shaka.net.DataUriPlugin(request.uris[0], request); }); @@ -1339,7 +1339,7 @@ describe('DrmEngine', function() { }); }); // describe('update') - describe('destroy', function() { + describe('destroy', () => { it('tears down MediaKeys and active sessions', async () => { await initAndAttach(); const initData1 = new Uint8Array(1); @@ -1404,7 +1404,7 @@ describe('DrmEngine', function() { await drmEngine.destroy(); }); - it('interrupts failing MediaKeys queries', async function() { + it('interrupts failing MediaKeys queries', async () => { // Hold the MediaKeys query: /** @type {!shaka.util.PublicPromise} */ const p = new shaka.util.PublicPromise(); @@ -1428,7 +1428,7 @@ describe('DrmEngine', function() { expect(drmEngine.initialized()).toBe(false); }); - it('interrupts successful MediaKeys queries', async function() { + it('interrupts successful MediaKeys queries', async () => { // Hold the MediaKeys query: /** @type {!shaka.util.PublicPromise} */ const p = new shaka.util.PublicPromise(); @@ -1452,7 +1452,7 @@ describe('DrmEngine', function() { expect(drmEngine.initialized()).toBe(false); }); - it('interrupts successful calls to createMediaKeys', async function() { + it('interrupts successful calls to createMediaKeys', async () => { // Hold createMediaKeys: /** @type {!shaka.util.PublicPromise} */ const p = new shaka.util.PublicPromise(); @@ -1472,7 +1472,7 @@ describe('DrmEngine', function() { expect(drmEngine.initialized()).toBe(false); }); - it('interrupts failed calls to setMediaKeys', function(done) { + it('interrupts failed calls to setMediaKeys', (done) => { // Hold setMediaKeys: const p1 = new shaka.util.PublicPromise(); mockVideo.setMediaKeys.and.returnValue(p1); @@ -1480,7 +1480,7 @@ describe('DrmEngine', function() { // This chain should still return "success" when DrmEngine is destroyed. initAndAttach().catch(fail); - shaka.test.Util.delay(1.0).then(function() { + shaka.test.Util.delay(1.0).then(() => { // We are now blocked on setMediaKeys: expect(mockVideo.setMediaKeys.calls.count()).toBe(1); // DrmEngine.destroy also calls setMediaKeys. @@ -1493,7 +1493,7 @@ describe('DrmEngine', function() { }).catch(fail).then(done); }); - it('interrupts successful calls to setMediaKeys', function(done) { + it('interrupts successful calls to setMediaKeys', (done) => { // Hold setMediaKeys: const p1 = new shaka.util.PublicPromise(); mockVideo.setMediaKeys.and.returnValue(p1); @@ -1501,7 +1501,7 @@ describe('DrmEngine', function() { // This chain should still return "success" when DrmEngine is destroyed. initAndAttach().catch(fail); - shaka.test.Util.delay(1.0).then(function() { + shaka.test.Util.delay(1.0).then(() => { // We are now blocked on setMediaKeys: expect(mockVideo.setMediaKeys.calls.count()).toBe(1); // DrmEngine.destroy also calls setMediaKeys. @@ -1511,13 +1511,13 @@ describe('DrmEngine', function() { shaka.test.Util.delay(0.5).then(p1.resolve.bind(p1)); // Success shaka.test.Util.delay(1.0).then(p2.resolve.bind(p2)); // Success return drmEngine.destroy(); - }).then(function() { + }).then(() => { // Due to the interruption, we never listened for 'encrypted' events. expect(mockVideo.on['encrypted']).toBe(undefined); }).catch(fail).then(done); }); - it('interrupts failed calls to setServerCertificate', function(done) { + it('interrupts failed calls to setServerCertificate', (done) => { const cert = new Uint8Array(1); config.advanced['drm.abc'] = createAdvancedConfig(cert); drmEngine.configure(config); @@ -1529,17 +1529,17 @@ describe('DrmEngine', function() { // This chain should still return "success" when DrmEngine is destroyed. initAndAttach().catch(fail); - shaka.test.Util.delay(1.0).then(function() { + shaka.test.Util.delay(1.0).then(() => { // We are now blocked on setServerCertificate: expect(mockMediaKeys.setServerCertificate.calls.count()).toBe(1); return drmEngine.destroy(); - }).then(function() { + }).then(() => { p.reject(); // Fail setServerCertificate. return shaka.test.Util.delay(1.5); }).catch(fail).then(done); }); - it('interrupts successful calls to setServerCertificate', function(done) { + it('interrupts successful calls to setServerCertificate', (done) => { const cert = new Uint8Array(1); config.advanced['drm.abc'] = createAdvancedConfig(cert); drmEngine.configure(config); @@ -1551,24 +1551,24 @@ describe('DrmEngine', function() { // This chain should still return "success" when DrmEngine is destroyed. initAndAttach().catch(fail); - shaka.test.Util.delay(1.0).then(function() { + shaka.test.Util.delay(1.0).then(() => { // We are now blocked on setServerCertificate: expect(mockMediaKeys.setServerCertificate.calls.count()).toBe(1); return drmEngine.destroy(); - }).then(function() { + }).then(() => { p.resolve(); // Success for setServerCertificate. return shaka.test.Util.delay(1.5); - }).then(function() { + }).then(() => { // Due to the interruption, we never listened for 'encrypted' events. expect(mockVideo.on['encrypted']).toBe(undefined); }).catch(fail).then(done); }); - it('does not trigger errors if it fails generateRequest', function(done) { + it('does not trigger errors if it fails generateRequest', (done) => { const p = new shaka.util.PublicPromise(); session1.generateRequest.and.returnValue(p); - initAndAttach().then(function() { + initAndAttach().then(() => { const initData1 = new Uint8Array(1); mockVideo.on['encrypted']( {initDataType: 'webm', initData: initData1, keyId: null}); @@ -1577,18 +1577,18 @@ describe('DrmEngine', function() { expect(session1.generateRequest.calls.count()).toBe(1); return drmEngine.destroy(); - }).then(function() { + }).then(() => { p.reject(); // Fail generateRequest. }).catch(fail).then(done); // onError is a failure by default. }); - it('interrupts successful license requests', function(done) { + it('interrupts successful license requests', (done) => { const p = new shaka.util.PublicPromise(); const operation = shaka.util.AbortableOperation.notAbortable(p); fakeNetEngine.request.and.returnValue(operation); - initAndAttach().then(function() { + initAndAttach().then(() => { const initData1 = new Uint8Array(1); mockVideo.on['encrypted']( {initDataType: 'webm', initData: initData1, keyId: null}); @@ -1604,22 +1604,22 @@ describe('DrmEngine', function() { jasmine.anything()); return drmEngine.destroy(); - }).then(function() { + }).then(() => { // Unblock the license request. p.resolve({data: (new Uint8Array(0)).buffer}); - }).then(function() { + }).then(() => { // Due to the interruption, we never updated the session. expect(session1.update).not.toHaveBeenCalled(); }).catch(fail).then(done); // onError is a failure by default. }); - it('interrupts failed license requests', function(done) { + it('interrupts failed license requests', (done) => { const p = new shaka.util.PublicPromise(); const operation = shaka.util.AbortableOperation.notAbortable(p); fakeNetEngine.request.and.returnValue(operation); - initAndAttach().then(function() { + initAndAttach().then(() => { const initData1 = new Uint8Array(1); mockVideo.on['encrypted']( {initDataType: 'webm', initData: initData1, keyId: null}); @@ -1635,18 +1635,18 @@ describe('DrmEngine', function() { jasmine.anything()); return drmEngine.destroy(); - }).then(function() { + }).then(() => { // Fail the license request. p.reject(); }).catch(fail).then(done); // onError is a failure by default. }); - it('does not trigger errors if it fails update', function(done) { + it('does not trigger errors if it fails update', (done) => { const p = new shaka.util.PublicPromise(); session1.update.and.returnValue(p); - initAndAttach().then(function() { + initAndAttach().then(() => { const initData1 = new Uint8Array(1); mockVideo.on['encrypted']( {initDataType: 'webm', initData: initData1, keyId: null}); @@ -1655,11 +1655,11 @@ describe('DrmEngine', function() { session1.on['message']({target: session1, message: message}); return shaka.test.Util.delay(0.1); - }).then(function() { + }).then(() => { // We are now blocked on update: expect(session1.update.calls.count()).toBe(1); return drmEngine.destroy(); - }).then(function() { + }).then(() => { // Fail the update. p.reject(); }).catch(fail).then(done); @@ -1704,7 +1704,7 @@ describe('DrmEngine', function() { }); }); // describe('destroy') - describe('getDrmInfo', function() { + describe('getDrmInfo', () => { it('includes correct info', async () => { // Leave only one drmInfo manifest = new shaka.test.ManifestGenerator() @@ -1749,7 +1749,7 @@ describe('DrmEngine', function() { }); }); // describe('getDrmInfo') - describe('getCommonDrmInfos', function() { + describe('getCommonDrmInfos', () => { it('returns one array if the other is empty', () => { const drmInfo = { keySystem: 'drm.abc', @@ -1810,7 +1810,7 @@ describe('DrmEngine', function() { }); }); // describe('getCommonDrmInfos') - describe('configure', function() { + describe('configure', () => { it('delays initial license requests if configured to', async () => { config.delayLicenseRequestUntilPlayed = true; drmEngine.configure(config); @@ -1882,7 +1882,7 @@ describe('DrmEngine', function() { }); }); // describe('configure') - describe('removeSession', function() { + describe('removeSession', () => { /** @type {!shaka.util.PublicPromise} */ let updatePromise; @@ -1893,7 +1893,7 @@ describe('DrmEngine', function() { // 'message' event of type 'license-release'. The removeSessions method // should wait until update() is complete with the response. updatePromise = new shaka.util.PublicPromise(); - session1.remove.and.callFake(function() { + session1.remove.and.callFake(() => { // Raise the event synchronously, even though it doesn't normally. session1.on['message']({target: session1, message: new ArrayBuffer(0)}); session1.update.and.returnValue(updatePromise); @@ -1955,12 +1955,12 @@ describe('DrmEngine', function() { }); }); - describe('expiration', function() { - beforeAll(function() { + describe('expiration', () => { + beforeAll(() => { jasmine.clock().install(); }); - afterAll(function() { + afterAll(() => { jasmine.clock().uninstall(); }); @@ -1979,7 +1979,7 @@ describe('DrmEngine', function() { jasmine.clock().tick(1000); }); - it('calls the callback when the expiration changes', function() { + it('calls the callback when the expiration changes', () => { onExpirationSpy.calls.reset(); session1.expiration = 10000; @@ -2001,7 +2001,7 @@ describe('DrmEngine', function() { .toHaveBeenCalledWith(session1.sessionId, Infinity); }); - it('gets the current expiration times', function() { + it('gets the current expiration times', () => { session1.expiration = NaN; expect(drmEngine.getExpiration()).toEqual(Infinity); session1.expiration = 12345; @@ -2029,13 +2029,13 @@ describe('DrmEngine', function() { getConfiguration: jasmine.createSpy('getConfiguration'), createMediaKeys: jasmine.createSpy('createMediaKeys'), }; - mksa.getConfiguration.and.callFake(function() { + mksa.getConfiguration.and.callFake(() => { return { audioCapabilities: [{contentType: 'audio/webm'}], videoCapabilities: [{contentType: 'video/mp4; codecs="fake"'}], }; }); - mksa.createMediaKeys.and.callFake(function() { + mksa.createMediaKeys.and.callFake(() => { return Promise.resolve(mockMediaKeys); }); return mksa; @@ -2068,7 +2068,7 @@ describe('DrmEngine', function() { session.generateRequest.and.returnValue(Promise.resolve()); session.close.and.returnValue(Promise.resolve()); session.update.and.returnValue(Promise.resolve()); - session.addEventListener.and.callFake(function(name, callback) { + session.addEventListener.and.callFake((name, callback) => { session.on[name] = callback; }); return session; diff --git a/test/media/media_source_engine_integration.js b/test/media/media_source_engine_integration.js index 9d2f9756d..18439639b 100644 --- a/test/media/media_source_engine_integration.js +++ b/test/media/media_source_engine_integration.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('MediaSourceEngine', function() { +describe('MediaSourceEngine', () => { const ContentType = shaka.util.ManifestParserUtils.ContentType; const presentationDuration = 840; @@ -37,7 +37,7 @@ describe('MediaSourceEngine', function() { */ let textDisplayer; - beforeAll(function() { + beforeAll(() => { video = shaka.util.Dom.createVideoElement(); document.body.appendChild(video); }); @@ -66,7 +66,7 @@ describe('MediaSourceEngine', function() { await mediaSourceEngine.destroy(); }); - afterAll(function() { + afterAll(() => { document.body.removeChild(video); }); @@ -193,14 +193,14 @@ describe('MediaSourceEngine', function() { expect(mediaSource.duration).toBeCloseTo(30); }); - it('queues operations', function(done) { + it('queues operations', (done) => { const resolutionOrder = []; const requests = []; function checkOrder(p) { const nextIndex = requests.length; requests.push(p); - p.then(function() { resolutionOrder.push(nextIndex); }); + p.then(() => { resolutionOrder.push(nextIndex); }); } const initObject = new Map(); diff --git a/test/media/media_source_engine_unit.js b/test/media/media_source_engine_unit.js index ea23bc167..a5334c354 100644 --- a/test/media/media_source_engine_unit.js +++ b/test/media/media_source_engine_unit.js @@ -44,7 +44,7 @@ let MockTimeRanges; let MockSourceBuffer; -describe('MediaSourceEngine', function() { +describe('MediaSourceEngine', () => { const Util = shaka.test.Util; const ContentType = shaka.util.ManifestParserUtils.ContentType; @@ -84,7 +84,7 @@ describe('MediaSourceEngine', function() { /** @type {!shaka.media.MediaSourceEngine} */ let mediaSourceEngine; - beforeAll(function() { + beforeAll(() => { // Since this is not an integration test, we don't want MediaSourceEngine to // fail assertions based on browser support for types. Pretend that all // video and audio types are supported. @@ -99,7 +99,7 @@ describe('MediaSourceEngine', function() { }; }); - afterAll(function() { + afterAll(() => { window.MediaSource.isTypeSupported = originalIsTypeSupported; shaka.text.TextEngine = originalTextEngine; shaka.media.MediaSourceEngine.prototype.createMediaSource = @@ -107,17 +107,17 @@ describe('MediaSourceEngine', function() { shaka.media.Transmuxer.isSupported = originalTransmuxerIsSupported; }); - beforeEach(/** @suppress {invalidCasts} */ function() { + beforeEach(/** @suppress {invalidCasts} */ () => { audioSourceBuffer = createMockSourceBuffer(); videoSourceBuffer = createMockSourceBuffer(); mockMediaSource = createMockMediaSource(); - mockMediaSource.addSourceBuffer.and.callFake(function(mimeType) { + mockMediaSource.addSourceBuffer.and.callFake((mimeType) => { const type = mimeType.split('/')[0]; return type == 'audio' ? audioSourceBuffer : videoSourceBuffer; }); createMediaSourceSpy = jasmine.createSpy('createMediaSource'); - createMediaSourceSpy.and.callFake(function(p) { + createMediaSourceSpy.and.callFake((p) => { p.resolve(); return mockMediaSource; }); @@ -156,11 +156,11 @@ describe('MediaSourceEngine', function() { mockTextDisplayer); }); - afterEach(function() { + afterEach(() => { mockTextEngine = null; }); - describe('constructor', function() { + describe('constructor', () => { const originalCreateObjectURL = shaka.media.MediaSourceEngine.createObjectURL; const originalMediaSource = window.MediaSource; @@ -189,12 +189,12 @@ describe('MediaSourceEngine', function() { await mediaSourceEngine.destroy(); }); - afterAll(function() { + afterAll(() => { shaka.media.MediaSourceEngine.createObjectURL = originalCreateObjectURL; window.MediaSource = originalMediaSource; }); - it('creates a MediaSource object and sets video.src', function() { + it('creates a MediaSource object and sets video.src', () => { mediaSourceEngine = new shaka.media.MediaSourceEngine( video, new shaka.test.FakeClosedCaptionParser(), @@ -206,7 +206,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('init', function() { + describe('init', () => { it('creates SourceBuffers for the given types', async () => { const initObject = new Map(); initObject.set(ContentType.AUDIO, fakeAudioStream); @@ -226,7 +226,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('bufferStart and bufferEnd', function() { + describe('bufferStart and bufferEnd', () => { beforeEach(async () => { const initObject = new Map(); initObject.set(ContentType.AUDIO, fakeAudioStream); @@ -234,14 +234,14 @@ describe('MediaSourceEngine', function() { await mediaSourceEngine.init(initObject, false); }); - it('returns correct timestamps for one range', function() { + it('returns correct timestamps for one range', () => { audioSourceBuffer.buffered = createFakeBuffered([{start: 0, end: 10}]); expect(mediaSourceEngine.bufferStart(ContentType.AUDIO)).toBeCloseTo(0); expect(mediaSourceEngine.bufferEnd(ContentType.AUDIO)).toBeCloseTo(10); }); - it('returns correct timestamps for multiple ranges', function() { + it('returns correct timestamps for multiple ranges', () => { audioSourceBuffer.buffered = createFakeBuffered([{start: 5, end: 10}, {start: 20, end: 30}]); @@ -249,14 +249,14 @@ describe('MediaSourceEngine', function() { expect(mediaSourceEngine.bufferEnd(ContentType.AUDIO)).toBeCloseTo(30); }); - it('returns null if there are no ranges', function() { + it('returns null if there are no ranges', () => { audioSourceBuffer.buffered = createFakeBuffered([]); expect(mediaSourceEngine.bufferStart(ContentType.AUDIO)).toBeNull(); expect(mediaSourceEngine.bufferEnd(ContentType.AUDIO)).toBeNull(); }); - it('will forward to TextEngine', function() { + it('will forward to TextEngine', () => { mockTextEngine.bufferStart.and.returnValue(10); mockTextEngine.bufferEnd.and.returnValue(20); @@ -270,7 +270,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('bufferedAheadOf', function() { + describe('bufferedAheadOf', () => { beforeEach(async () => { const initObject = new Map(); initObject.set(ContentType.AUDIO, fakeAudioStream); @@ -278,7 +278,7 @@ describe('MediaSourceEngine', function() { await mediaSourceEngine.init(initObject, false); }); - it('returns the amount of data ahead of the given position', function() { + it('returns the amount of data ahead of the given position', () => { audioSourceBuffer.buffered = createFakeBuffered([{start: 0, end: 10}]); expect(mediaSourceEngine.bufferedAheadOf(ContentType.AUDIO, 0)) @@ -289,7 +289,7 @@ describe('MediaSourceEngine', function() { .toBeCloseTo(0.1); }); - it('returns zero when given an unbuffered time', function() { + it('returns zero when given an unbuffered time', () => { audioSourceBuffer.buffered = createFakeBuffered([{start: 5, end: 10}]); expect(mediaSourceEngine.bufferedAheadOf(ContentType.AUDIO, 10)) @@ -298,7 +298,7 @@ describe('MediaSourceEngine', function() { .toBeCloseTo(0); }); - it('returns the correct amount with multiple ranges', function() { + it('returns the correct amount with multiple ranges', () => { audioSourceBuffer.buffered = createFakeBuffered([{start: 1, end: 3}, {start: 6, end: 10}]); @@ -319,7 +319,7 @@ describe('MediaSourceEngine', function() { .toBeCloseTo(0.1); }); - it('will forward to TextEngine', function() { + it('will forward to TextEngine', () => { mockTextEngine.bufferedAheadOf.and.returnValue(10); expect(mockTextEngine.bufferedAheadOf).not.toHaveBeenCalled(); @@ -328,7 +328,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('appendBuffer', function() { + describe('appendBuffer', () => { beforeEach(async () => { captureEvents(audioSourceBuffer, ['updateend', 'error']); captureEvents(videoSourceBuffer, ['updateend', 'error']); @@ -367,7 +367,7 @@ describe('MediaSourceEngine', function() { it('rejects promise when op. throws QuotaExceededError', async () => { const fakeDOMException = {name: 'QuotaExceededError'}; - audioSourceBuffer.appendBuffer.and.callFake(function() { + audioSourceBuffer.appendBuffer.and.callFake(() => { throw fakeDOMException; }); mockVideo.error = {code: 5}; @@ -382,13 +382,13 @@ describe('MediaSourceEngine', function() { } }); - it('rejects the promise if this operation fails async', function(done) { + it('rejects the promise if this operation fails async', (done) => { mockVideo.error = {code: 5}; mediaSourceEngine.appendBuffer(ContentType.AUDIO, buffer, null, null, - /* hasClosedCaptions */ false).then(function() { + /* hasClosedCaptions */ false).then(() => { fail('not reached'); done(); - }, function(error) { + }, (error) => { expect(error.code).toBe( shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_FAILED); expect(error.data).toEqual([5]); @@ -455,13 +455,13 @@ describe('MediaSourceEngine', function() { }); it('continues if an operation throws', async () => { - audioSourceBuffer.appendBuffer.and.callFake(function(value) { + audioSourceBuffer.appendBuffer.and.callFake((value) => { if (value == 2) { // throw synchronously. throw new Error(); } else { // complete successfully asynchronously. - Promise.resolve().then(function() { + Promise.resolve().then(() => { audioSourceBuffer.updateend(); }); } @@ -498,7 +498,7 @@ describe('MediaSourceEngine', function() { data, 0, 10); }); - it('appends transmuxed data and captions', function(done) { + it('appends transmuxed data and captions', (done) => { const initObject = new Map(); initObject.set(ContentType.VIDEO, fakeTransportStream); @@ -515,12 +515,12 @@ describe('MediaSourceEngine', function() { // media source. We only append to the media source once transmuxing is // done. Since transmuxing is done using Promises, we need to delay the // event until MediaSourceEngine calls appendBuffer. - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { videoSourceBuffer.updateend(); }); }); - it('appends only transmuxed data without embedded text', function(done) { + it('appends only transmuxed data without embedded text', (done) => { const initObject = new Map(); initObject.set(ContentType.VIDEO, fakeTransportStream); @@ -536,7 +536,7 @@ describe('MediaSourceEngine', function() { // media source. We only append to the media source once transmuxing is // done. Since transmuxing is done using Promises, we need to delay the // event until MediaSourceEngine calls appendBuffer. - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { videoSourceBuffer.updateend(); }); }); @@ -603,7 +603,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('remove', function() { + describe('remove', () => { beforeEach(async () => { captureEvents(audioSourceBuffer, ['updateend', 'error']); captureEvents(videoSourceBuffer, ['updateend', 'error']); @@ -614,8 +614,8 @@ describe('MediaSourceEngine', function() { await mediaSourceEngine.init(initObject, false); }); - it('removes the given data', function(done) { - mediaSourceEngine.remove(ContentType.AUDIO, 1, 5).then(function() { + it('removes the given data', (done) => { + mediaSourceEngine.remove(ContentType.AUDIO, 1, 5).then(() => { expect(audioSourceBuffer.remove).toHaveBeenCalledWith(1, 5); done(); }); @@ -637,12 +637,12 @@ describe('MediaSourceEngine', function() { } }); - it('rejects the promise if this operation fails async', function(done) { + it('rejects the promise if this operation fails async', (done) => { mockVideo.error = {code: 5}; - mediaSourceEngine.remove(ContentType.AUDIO, 1, 5).then(function() { + mediaSourceEngine.remove(ContentType.AUDIO, 1, 5).then(() => { fail('not reached'); done(); - }, function(error) { + }, (error) => { expect(error.code).toBe( shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_FAILED); expect(error.data).toEqual([5]); @@ -703,13 +703,13 @@ describe('MediaSourceEngine', function() { }); it('continues if an operation throws', async () => { - audioSourceBuffer.remove.and.callFake(function(start, end) { + audioSourceBuffer.remove.and.callFake((start, end) => { if (start == 2) { // throw synchronously. throw new Error(); } else { // complete successfully asynchronously. - Promise.resolve().then(function() { + Promise.resolve().then(() => { audioSourceBuffer.updateend(); }); } @@ -741,7 +741,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('clear', function() { + describe('clear', () => { beforeEach(async () => { captureEvents(audioSourceBuffer, ['updateend', 'error']); captureEvents(videoSourceBuffer, ['updateend', 'error']); @@ -752,9 +752,9 @@ describe('MediaSourceEngine', function() { await mediaSourceEngine.init(initObject, false); }); - it('clears the given data', function(done) { + it('clears the given data', (done) => { mockMediaSource.durationGetter_.and.returnValue(20); - mediaSourceEngine.clear(ContentType.AUDIO).then(function() { + mediaSourceEngine.clear(ContentType.AUDIO).then(() => { expect(audioSourceBuffer.remove.calls.count()).toBe(1); expect(audioSourceBuffer.remove.calls.argsFor(0)[0]).toBe(0); expect(audioSourceBuffer.remove.calls.argsFor(0)[1] >= 20).toBeTruthy(); @@ -763,7 +763,7 @@ describe('MediaSourceEngine', function() { audioSourceBuffer.updateend(); }); - it('does not seek', function(done) { + it('does not seek', (done) => { // We had a bug in which we got into a seek loop. Seeking caused // StreamingEngine to call clear(). Clearing triggered a pipeline flush // which was implemented by seeking. See issue #569. @@ -790,7 +790,7 @@ describe('MediaSourceEngine', function() { mockVideo.currentTime = originalTime; mockMediaSource.durationGetter_.and.returnValue(20); - mediaSourceEngine.clear(ContentType.AUDIO).then(function() { + mediaSourceEngine.clear(ContentType.AUDIO).then(() => { expect(mockVideo.currentTime).toBe(originalTime); done(); }); @@ -809,7 +809,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('endOfStream', function() { + describe('endOfStream', () => { beforeEach(async () => { captureEvents(audioSourceBuffer, ['updateend', 'error']); captureEvents(videoSourceBuffer, ['updateend', 'error']); @@ -903,7 +903,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('setDuration', function() { + describe('setDuration', () => { beforeEach(async () => { mockMediaSource.durationGetter_.and.returnValue(0); captureEvents(audioSourceBuffer, ['updateend', 'error']); @@ -1000,7 +1000,7 @@ describe('MediaSourceEngine', function() { }); }); - describe('destroy', function() { + describe('destroy', () => { beforeEach(async () => { captureEvents(audioSourceBuffer, ['updateend', 'error']); captureEvents(videoSourceBuffer, ['updateend', 'error']); @@ -1116,7 +1116,7 @@ describe('MediaSourceEngine', function() { /* hasClosedCaptions */ false)); // The promise has already been rejected, but our capture requires 1 tick. - Promise.resolve().then(function() { + Promise.resolve().then(() => { expect(rejected.status).toBe('rejected'); expect(audioSourceBuffer.appendBuffer).not.toHaveBeenCalled(); }); @@ -1180,7 +1180,7 @@ describe('MediaSourceEngine', function() { function createMockTextEngineCtor() { const ctor = jasmine.createSpy('TextEngine'); ctor.isTypeSupported = function() { return true; }; - ctor.and.callFake(function() { + ctor.and.callFake(() => { expect(mockTextEngine).toBeFalsy(); mockTextEngine = jasmine.createSpyObj('TextEngine', [ 'initParser', 'destroy', 'appendBuffer', 'remove', 'setTimestampOffset', @@ -1198,12 +1198,12 @@ describe('MediaSourceEngine', function() { } function captureEvents(object, targetEventNames) { - object.addEventListener.and.callFake(function(eventName, listener) { + object.addEventListener.and.callFake((eventName, listener) => { if (targetEventNames.includes(eventName)) { object[eventName] = listener; } }); - object.removeEventListener.and.callFake(function(eventName, listener) { + object.removeEventListener.and.callFake((eventName, listener) => { if (targetEventNames.includes(eventName)) { expect(object[eventName]).toBe(listener); object[eventName] = null; diff --git a/test/media/mp4_segment_index_parser_unit.js b/test/media/mp4_segment_index_parser_unit.js index 3b120b262..809f67975 100644 --- a/test/media/mp4_segment_index_parser_unit.js +++ b/test/media/mp4_segment_index_parser_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Mp4SegmentIndexParser', function() { +describe('Mp4SegmentIndexParser', () => { const indexSegmentUri = '/base/test/test/assets/index-segment.mp4'; const mediaSegmentUri = '/base/test/test/assets/sintel-audio-segment.mp4'; @@ -31,7 +31,7 @@ describe('Mp4SegmentIndexParser', function() { mediaSegment = responses[1]; }); - it('rejects a non-index segment ', function() { + it('rejects a non-index segment ', () => { const error = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, @@ -45,7 +45,7 @@ describe('Mp4SegmentIndexParser', function() { } }); - it('parses index segment ', function() { + it('parses index segment ', () => { // eslint-disable-next-line new-cap const result = shaka.media.Mp4SegmentIndexParser(indexSegment, 0, [], 0); const references = @@ -68,7 +68,7 @@ describe('Mp4SegmentIndexParser', function() { } }); - it('takes a scaled presentationTimeOffset in seconds', function() { + it('takes a scaled presentationTimeOffset in seconds', () => { // eslint-disable-next-line new-cap const result = shaka.media.Mp4SegmentIndexParser(indexSegment, 0, [], 2); const references = diff --git a/test/media/playhead_unit.js b/test/media/playhead_unit.js index ad992a884..b89fd26e6 100644 --- a/test/media/playhead_unit.js +++ b/test/media/playhead_unit.js @@ -99,7 +99,7 @@ let PlayingTestInfo; let SeekTestInfo; -describe('Playhead', function() { +describe('Playhead', () => { const Util = shaka.test.Util; /** @type {!shaka.test.FakeVideo} */ @@ -121,15 +121,15 @@ describe('Playhead', function() { /** @type {!jasmine.Spy} */ let onEvent; - beforeAll(function() { + beforeAll(() => { jasmine.clock().install(); }); - afterAll(function() { + afterAll(() => { jasmine.clock().uninstall(); }); - beforeEach(function() { + beforeEach(() => { video = new shaka.test.FakeVideo(); timeline = new shaka.test.FakePresentationTimeline(); @@ -167,8 +167,8 @@ describe('Playhead', function() { jasmine.clock().mockDate(mockDate); } - describe('getTime', function() { - it('returns current time when the video is paused', function() { + describe('getTime', () => { + it('returns current time when the video is paused', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; playhead = new shaka.media.MediaSourcePlayhead( video, @@ -190,7 +190,7 @@ describe('Playhead', function() { expect(playhead.getTime()).toBe(5); }); - it('returns the correct time when readyState starts at 0', function() { + it('returns the correct time when readyState starts at 0', () => { playhead = new shaka.media.MediaSourcePlayhead( video, manifest, @@ -228,7 +228,7 @@ describe('Playhead', function() { expect(playhead.getTime()).toBe(5); }); - it('returns the correct time when readyState starts at 1', function() { + it('returns the correct time when readyState starts at 1', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; playhead = new shaka.media.MediaSourcePlayhead( @@ -246,7 +246,7 @@ describe('Playhead', function() { expect(playhead.getTime()).toBe(6); }); - it('allows using startTime of 0', function() { + it('allows using startTime of 0', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; timeline.isLive.and.returnValue(true); timeline.getDuration.and.returnValue(Infinity); @@ -260,7 +260,7 @@ describe('Playhead', function() { expect(playhead.getTime()).toBe(0); }); - it('bumps startTime back from duration', function() { + it('bumps startTime back from duration', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; timeline.isLive.and.returnValue(false); timeline.getSeekRangeStart.and.returnValue(0); @@ -275,7 +275,7 @@ describe('Playhead', function() { expect(video.currentTime).toBe(59); // duration - durationBackoff }); - it('playback from a certain offset from live edge for live', function() { + it('playback from a certain offset from live edge for live', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; timeline.isLive.and.returnValue(true); timeline.getDuration.and.returnValue(Infinity); @@ -289,7 +289,7 @@ describe('Playhead', function() { expect(playhead.getTime()).toBe(45); }); - it('playback from segment seek range start time', function() { + it('playback from segment seek range start time', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; timeline.isLive.and.returnValue(true); timeline.getDuration.and.returnValue(Infinity); @@ -304,7 +304,7 @@ describe('Playhead', function() { expect(playhead.getTime()).toBe(30); }); - it('does not change currentTime if it\'s not 0', function() { + it('does not change currentTime if it\'s not 0', () => { playhead = new shaka.media.MediaSourcePlayhead( video, manifest, @@ -331,7 +331,7 @@ describe('Playhead', function() { // This is important for recovering from drift. // See: https://github.com/google/shaka-player/issues/1105 // TODO: Re-evaluate after https://github.com/google/shaka-player/issues/999 - it('does not change once the initial position is set', function() { + it('does not change once the initial position is set', () => { timeline.isLive.and.returnValue(true); timeline.getDuration.and.returnValue(Infinity); timeline.getSeekRangeStart.and.returnValue(0); @@ -361,7 +361,7 @@ describe('Playhead', function() { }); }); // getTime - it('clamps playhead after seeking for live', function() { + it('clamps playhead after seeking for live', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; video.buffered = createFakeBuffered([{start: 25, end: 55}]); @@ -520,7 +520,7 @@ describe('Playhead', function() { expect(onSeek).toHaveBeenCalled(); }); // clamps playhead after seeking for live - it('clamps playhead after seeking for VOD', function() { + it('clamps playhead after seeking for VOD', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; video.buffered = createFakeBuffered([{start: 25, end: 55}]); @@ -569,7 +569,7 @@ describe('Playhead', function() { expect(onSeek).toHaveBeenCalled(); }); // clamps playhead after seeking for VOD - it('doesn\'t repeatedly re-seek', function() { + it('doesn\'t repeatedly re-seek', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; video.buffered = createFakeBuffered([{start: 25, end: 55}]); @@ -621,7 +621,7 @@ describe('Playhead', function() { expect(onSeek).not.toHaveBeenCalled(); }); // doesn't repeatedly re-seek - it('handles live manifests with no seek range', function() { + it('handles live manifests with no seek range', () => { video.buffered = createFakeBuffered([{start: 1000, end: 1030}]); video.readyState = HTMLMediaElement.HAVE_METADATA; @@ -674,14 +674,14 @@ describe('Playhead', function() { expect(seekCount).toBe(1); }); // handles live manifests with no seek range - describe('clamps playhead after resuming', function() { - beforeEach(function() { + describe('clamps playhead after resuming', () => { + beforeEach(() => { video.readyState = HTMLMediaElement.HAVE_METADATA; video.buffered = createFakeBuffered([{start: 5, end: 35}]); }); - it('(live case)', function() { + it('(live case)', () => { timeline.isLive.and.returnValue(true); timeline.getDuration.and.returnValue(Infinity); timeline.getSeekRangeStart.and.returnValue(5); @@ -712,7 +712,7 @@ describe('Playhead', function() { expect(onSeek).toHaveBeenCalled(); }); - it('(VOD case)', function() { + it('(VOD case)', () => { timeline.isLive.and.returnValue(false); timeline.getSeekRangeStart.and.returnValue(5); timeline.getSafeSeekRangeStart.and.returnValue(5); @@ -744,7 +744,7 @@ describe('Playhead', function() { }); }); // clamps playhead after resuming - it('clamps playhead even before seeking completes', function() { + it('clamps playhead even before seeking completes', () => { video.readyState = HTMLMediaElement.HAVE_METADATA; video.buffered = createFakeBuffered([{start: 25, end: 55}]); @@ -777,8 +777,8 @@ describe('Playhead', function() { expect(playhead.getTime()).not.toBeLessThan(5); }); // clamps playhead even before seeking completes - describe('gap jumping', function() { - beforeEach(function() { + describe('gap jumping', () => { + beforeEach(() => { timeline.isLive.and.returnValue(false); timeline.getSafeSeekRangeStart.and.returnValue(0); timeline.getSeekRangeStart.and.returnValue(0); @@ -788,8 +788,8 @@ describe('Playhead', function() { config.smallGapLimit = 1; }); - describe('when playing', function() { - describe('with small gaps', function() { + describe('when playing', () => { + describe('with small gaps', () => { playingTest('won\'t jump at end of single region', { buffered: [{start: 0, end: 10}], start: 3, @@ -833,7 +833,7 @@ describe('Playhead', function() { }); }); // with small gaps - describe('with large gaps', function() { + describe('with large gaps', () => { playingTest('will fire an event', { buffered: [{start: 0, end: 10}, {start: 30, end: 40}], start: 5, @@ -887,12 +887,12 @@ describe('Playhead', function() { * @param {PlayingTestInfo} data */ function playingTest(name, data) { - it(name, function() { + it(name, () => { video.buffered = createFakeBuffered(data.buffered); video.currentTime = data.start; video.readyState = HTMLMediaElement.HAVE_ENOUGH_DATA; - onEvent.and.callFake(function(event) { + onEvent.and.callFake((event) => { if (data.preventDefault) { event.preventDefault(); } @@ -939,8 +939,8 @@ describe('Playhead', function() { } }); // when playing - describe('with buffered seeks', function() { - describe('with small gaps', function() { + describe('with buffered seeks', () => { + describe('with small gaps', () => { seekTest('won\'t seek when past the end', { buffered: [{start: 0, end: 10}], start: 4, @@ -984,7 +984,7 @@ describe('Playhead', function() { }); }); // with small gaps - describe('with large gaps', function() { + describe('with large gaps', () => { seekTest('will raise event', { buffered: [{start: 0, end: 10}, {start: 30, end: 40}], start: 5, @@ -1014,8 +1014,8 @@ describe('Playhead', function() { }); // with large gaps }); // with buffered seeks - describe('with unbuffered seeks', function() { - describe('with small gaps', function() { + describe('with unbuffered seeks', () => { + describe('with small gaps', () => { seekTest('won\'t jump when seeking into buffered range', { // [0-10], [20-30], [31-40] buffered: [{start: 0, end: 10}], @@ -1099,7 +1099,7 @@ describe('Playhead', function() { }); }); // with small gaps - describe('with large gaps', function() { + describe('with large gaps', () => { seekTest('will jump large gap at beginning', { buffered: [{start: 20, end: 30}], newBuffered: [{start: 20, end: 30}], @@ -1145,7 +1145,7 @@ describe('Playhead', function() { }); // with large gaps }); // with unbuffered seeks - it('doesn\'t gap jump if the seeking event is late', function() { + it('doesn\'t gap jump if the seeking event is late', () => { const buffered = [{start: 10, end: 20}]; video.buffered = createFakeBuffered(buffered); video.currentTime = 12; @@ -1177,7 +1177,7 @@ describe('Playhead', function() { expect(video.currentTime).toBe(3); }); - it('works with rounding errors when seeking', function() { + it('works with rounding errors when seeking', () => { // If the browser sets the time to slightly before where we seek to, we // shouldn't get stuck in an infinite loop trying to jump the tiny gap. // https://github.com/google/shaka-player/issues/1309 @@ -1221,12 +1221,12 @@ describe('Playhead', function() { * @param {SeekTestInfo} data */ function seekTest(name, data) { - it(name, function() { + it(name, () => { video.buffered = createFakeBuffered(data.buffered); video.currentTime = data.start; video.readyState = HTMLMediaElement.HAVE_ENOUGH_DATA; - onEvent.and.callFake(function(event) { + onEvent.and.callFake((event) => { if (data.preventDefault) { event.preventDefault(); } diff --git a/test/media/presentation_timeline_unit.js b/test/media/presentation_timeline_unit.js index d4d2a905c..6f4b01fa7 100644 --- a/test/media/presentation_timeline_unit.js +++ b/test/media/presentation_timeline_unit.js @@ -15,18 +15,18 @@ * limitations under the License. */ -describe('PresentationTimeline', function() { +describe('PresentationTimeline', () => { const originalDateNow = Date.now; /** @type {!Date} */ let baseTime; - beforeEach(function() { + beforeEach(() => { baseTime = new Date(2015, 11, 30); Date.now = function() { return baseTime.getTime(); }; }); - afterEach(function() { + afterEach(() => { Date.now = originalDateNow; }); @@ -136,13 +136,13 @@ describe('PresentationTimeline', function() { /* position */ 0, startTime, endTime, - /* uris */ function() { return []; }, + /* uris */ (() => { return []; }), /* startByte */ 0, /* endByte */ null); } - describe('getSegmentAvailabilityStart', function() { - it('returns 0 for VOD and IPR', function() { + describe('getSegmentAvailabilityStart', () => { + it('returns 0 for VOD and IPR', () => { const timeline1 = makeVodTimeline(/* duration */ 60); const timeline2 = makeIprTimeline(/* duration */ 60); @@ -155,7 +155,7 @@ describe('PresentationTimeline', function() { expect(timeline2.getSegmentAvailabilityStart()).toBe(0); }); - it('calculates time for live with finite availability', function() { + it('calculates time for live with finite availability', () => { const timeline = makeLiveTimeline(/* availability */ 20); setElapsed(0); @@ -180,7 +180,7 @@ describe('PresentationTimeline', function() { expect(timeline.getSegmentAvailabilityStart()).toBe(41); }); - it('calculates time for live with infinite availability', function() { + it('calculates time for live with infinite availability', () => { const timeline = makeLiveTimeline(/* availability */ Infinity); setElapsed(0); @@ -235,8 +235,8 @@ describe('PresentationTimeline', function() { }); }); - describe('getSegmentAvailabilityEnd', function() { - it('returns duration for VOD', function() { + describe('getSegmentAvailabilityEnd', () => { + it('returns duration for VOD', () => { const timeline = makeVodTimeline(/* duration */ 60); setElapsed(0); @@ -246,7 +246,7 @@ describe('PresentationTimeline', function() { expect(timeline.getSegmentAvailabilityEnd()).toBe(60); }); - it('calculates time for IPR', function() { + it('calculates time for IPR', () => { const timeline = makeIprTimeline(/* duration */ 60); setElapsed(0); @@ -268,7 +268,7 @@ describe('PresentationTimeline', function() { expect(timeline.getSegmentAvailabilityEnd()).toBe(60); }); - it('calculates time for live', function() { + it('calculates time for live', () => { const timeline1 = makeLiveTimeline(/* availability */ 20); const timeline2 = makeLiveTimeline(/* availability */ Infinity); @@ -318,8 +318,8 @@ describe('PresentationTimeline', function() { }); }); - describe('getDuration', function() { - it('returns the timeline duration', function() { + describe('getDuration', () => { + it('returns the timeline duration', () => { setElapsed(0); const timeline1 = makeVodTimeline(/* duration */ 60); const timeline2 = makeIprTimeline(/* duration */ 60); @@ -332,8 +332,8 @@ describe('PresentationTimeline', function() { }); }); - describe('setDuration', function() { - it('affects availability end for VOD', function() { + describe('setDuration', () => { + it('affects availability end for VOD', () => { setElapsed(0); const timeline = makeVodTimeline(/* duration */ 60); expect(timeline.getSegmentAvailabilityEnd()).toBe(60); @@ -342,7 +342,7 @@ describe('PresentationTimeline', function() { expect(timeline.getSegmentAvailabilityEnd()).toBe(90); }); - it('affects availability end for IPR', function() { + it('affects availability end for IPR', () => { const timeline = makeIprTimeline(/* duration */ 60); setElapsed(85); @@ -353,8 +353,8 @@ describe('PresentationTimeline', function() { }); }); - describe('clockOffset', function() { - it('offsets availability calculations', function() { + describe('clockOffset', () => { + it('offsets availability calculations', () => { const timeline = makeLiveTimeline(/* availability */ 10); setElapsed(11); expect(timeline.getSegmentAvailabilityEnd()).toBe(1); @@ -364,15 +364,15 @@ describe('PresentationTimeline', function() { }); }); - describe('getSafeSeekRangeStart', function() { - it('ignores offset for VOD', function() { + describe('getSafeSeekRangeStart', () => { + it('ignores offset for VOD', () => { const timeline = makeVodTimeline(/* duration */ 60); expect(timeline.getSafeSeekRangeStart(0)).toBe(0); expect(timeline.getSafeSeekRangeStart(10)).toBe(0); expect(timeline.getSafeSeekRangeStart(25)).toBe(0); }); - it('offsets from live edge', function() { + it('offsets from live edge', () => { const timeline = makeLiveTimeline(/* availability */ 60, /* delay */ 0); setElapsed(120); @@ -383,7 +383,7 @@ describe('PresentationTimeline', function() { expect(timeline.getSafeSeekRangeStart(25)).toBe(75); }); - it('clamps to end', function() { + it('clamps to end', () => { const timeline = makeLiveTimeline(/* availability */ 60, /* delay */ 0); setElapsed(120); @@ -393,7 +393,7 @@ describe('PresentationTimeline', function() { expect(timeline.getSafeSeekRangeStart(200)).toBe(110); }); - it('will return 0 if safe', function() { + it('will return 0 if safe', () => { const timeline = makeLiveTimeline(/* availability */ 60, /* delay */ 0); setElapsed(50); @@ -420,8 +420,8 @@ describe('PresentationTimeline', function() { }); }); - describe('getSeekRangeEnd', function() { - it('accounts for delay for live and IPR', function() { + describe('getSeekRangeEnd', () => { + it('accounts for delay for live and IPR', () => { const timeline1 = makeIprTimeline(/* duration */ 60, /* delay */ 7); const timeline2 = makeLiveTimeline(/* duration */ 60, /* delay */ 7); diff --git a/test/media/segment_index_unit.js b/test/media/segment_index_unit.js index bc2e092ce..569a5b77b 100644 --- a/test/media/segment_index_unit.js +++ b/test/media/segment_index_unit.js @@ -15,13 +15,13 @@ * limitations under the License. */ -describe('SegmentIndex', /** @suppress {accessControls} */ function() { +describe('SegmentIndex', /** @suppress {accessControls} */ () => { const actual1 = makeReference(0, 0, 10, uri(0)); const actual2 = makeReference(1, 10, 20, uri(20)); const actual3 = makeReference(2, 20, 30, uri(20)); - describe('find', function() { - it('finds the correct references', function() { + describe('find', () => { + it('finds the correct references', () => { // One reference. let index = new shaka.media.SegmentIndex([actual1]); let pos1 = index.find(5); @@ -44,7 +44,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(pos3).toBe(actual3.position); }); - it('works if time == first start time', function() { + it('works if time == first start time', () => { const actual = makeReference(1, 10, 20, uri(10)); const index = new shaka.media.SegmentIndex([actual]); @@ -52,7 +52,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(pos).toBe(actual.position); }); - it('works with two references if time == second start time', function() { + it('works with two references if time == second start time', () => { const actual1 = makeReference(1, 10, 20, uri(10)); const actual2 = makeReference(2, 20, 30, uri(20)); const index = new shaka.media.SegmentIndex([actual1, actual2]); @@ -61,7 +61,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(pos).toBe(actual2.position); }); - it('returns the first segment if time < first start time', function() { + it('returns the first segment if time < first start time', () => { const actual = makeReference(1, 10, 20, uri(10)); const index = new shaka.media.SegmentIndex([actual]); @@ -69,7 +69,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(pos).toBe(actual.position); }); - it('returns null if time == last end time', function() { + it('returns null if time == last end time', () => { const actual = makeReference(1, 10, 20, uri(10)); const index = new shaka.media.SegmentIndex([actual]); @@ -77,7 +77,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(pos).toBeNull(); }); - it('returns null if time > last end time', function() { + it('returns null if time > last end time', () => { const actual = makeReference(1, 10, 20, uri(10)); const index = new shaka.media.SegmentIndex([actual]); @@ -85,7 +85,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(pos).toBeNull(); }); - it('returns null if time is within a gap', function() { + it('returns null if time is within a gap', () => { const actual1 = makeReference(1, 10, 20, uri(10)); const actual2 = makeReference(2, 25, 30, uri(25)); const index = new shaka.media.SegmentIndex([actual1, actual2]); @@ -95,8 +95,8 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { }); }); - describe('get', function() { - it('returns the correct references', function() { + describe('get', () => { + it('returns the correct references', () => { // One reference. let index = new shaka.media.SegmentIndex([actual1]); let r1 = index.get(0); @@ -131,17 +131,17 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(r3).toEqual(actual3); }); - it('returns null with zero references', function() { + it('returns null with zero references', () => { const index = new shaka.media.SegmentIndex([]); expect(index.get(0)).toBeNull(); }); - it('returns null if position < 0', function() { + it('returns null if position < 0', () => { const index = new shaka.media.SegmentIndex([actual1, actual2, actual3]); expect(index.get(-1)).toBeNull(); }); - it('returns null for unknown positions', function() { + it('returns null for unknown positions', () => { const index1 = new shaka.media.SegmentIndex([actual1, actual2, actual3]); expect(index1.get(3)).toBeNull(); @@ -150,8 +150,8 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { }); }); - describe('fit', function() { - it('drops references which are outside the period bounds', function() { + describe('fit', () => { + it('drops references which are outside the period bounds', () => { // These negative numbers can occur due to presentationTimeOffset in DASH. const references = [ makeReference(0, -10, -3, uri(0)), @@ -174,7 +174,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index.references_).toEqual(newReferences); }); - it('drops references which end exactly at zero', function() { + it('drops references which end exactly at zero', () => { // The end time is meant to be exclusive, so segments ending at zero // (after PTO adjustments) should be dropped. const references = [ @@ -193,8 +193,8 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { }); }); - describe('merge', function() { - it('three references into zero references', function() { + describe('merge', () => { + it('three references into zero references', () => { const index1 = new shaka.media.SegmentIndex([]); const references2 = [actual1, actual2, actual3]; @@ -204,7 +204,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_).toEqual(references2); }); - it('zero references into three references', function() { + it('zero references into three references', () => { const references1 = [actual1, actual2, actual3]; const index1 = new shaka.media.SegmentIndex(references1); @@ -213,7 +213,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_).toEqual(references1); }); - it('one reference into one reference at end', function() { + it('one reference into one reference at end', () => { const references1 = [makeReference(1, 10, 20, uri(10))]; const index1 = new shaka.media.SegmentIndex(references1); @@ -225,7 +225,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_[1]).toEqual(references2[0]); }); - it('one reference into two references at end', function() { + it('one reference into two references at end', () => { const references1 = [ makeReference(1, 10, 20, uri(10)), makeReference(2, 20, 30, uri(20)), @@ -241,7 +241,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_[2]).toEqual(references2[0]); }); - it('two references into one reference at end', function() { + it('two references into one reference at end', () => { const references1 = [makeReference(2, 20, 30, uri(20))]; const index1 = new shaka.media.SegmentIndex(references1); @@ -257,7 +257,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_[2]).toEqual(references2[1]); }); - it('last live stream reference when period change', function() { + it('last live stream reference when period change', () => { const references1 = [ makeReference(1, 10, 20, uri(10)), makeReference(2, 20, 30, uri(20)), @@ -283,7 +283,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { // Makes sure segment references from time-based template merge with correct // position numbers. // https://github.com/google/shaka-player/pull/838 - it('last live stream reference with corrected position', function() { + it('last live stream reference with corrected position', () => { const references1 = [ makeReference(1, 10, 20, uri(10)), makeReference(2, 20, 30, uri(20)), @@ -307,20 +307,20 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { }); }); - describe('evict', function() { + describe('evict', () => { /** @type {!shaka.media.SegmentIndex} */ let index1; - beforeEach(function() { + beforeEach(() => { index1 = new shaka.media.SegmentIndex([actual1, actual2, actual3]); }); - it('no segments', function() { + it('no segments', () => { index1.evict(5); expect(index1.references_.length).toBe(3); }); - it('one segment (edge)', function() { + it('one segment (edge)', () => { index1.evict(10); expect(index1.references_.length).toBe(2); @@ -328,7 +328,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_[1]).toEqual(actual3); }); - it('one segment', function() { + it('one segment', () => { index1.evict(11); expect(index1.references_.length).toBe(2); @@ -336,26 +336,26 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { expect(index1.references_[1]).toEqual(actual3); }); - it('two segments (edge)', function() { + it('two segments (edge)', () => { index1.evict(20); expect(index1.references_.length).toBe(1); expect(index1.references_[0]).toEqual(actual3); }); - it('two segments', function() { + it('two segments', () => { index1.evict(21); expect(index1.references_.length).toBe(1); expect(index1.references_[0]).toEqual(actual3); }); - it('three segments (edge)', function() { + it('three segments (edge)', () => { index1.evict(30); expect(index1.references_.length).toBe(0); }); - it('three segments', function() { + it('three segments', () => { index1.evict(31); expect(index1.references_.length).toBe(0); }); @@ -372,7 +372,7 @@ describe('SegmentIndex', /** @suppress {accessControls} */ function() { */ function makeReference(position, startTime, endTime, uri) { return new shaka.media.SegmentReference( - position, startTime, endTime, function() { return [uri]; }, 0, null); + position, startTime, endTime, (() => { return [uri]; }), 0, null); } /** diff --git a/test/media/segment_reference_unit.js b/test/media/segment_reference_unit.js index ebf841b26..aef2aba65 100644 --- a/test/media/segment_reference_unit.js +++ b/test/media/segment_reference_unit.js @@ -15,10 +15,10 @@ * limitations under the License. */ -describe('SegmentReference', function() { - it('returns in getters values from constructor parameters', function() { +describe('SegmentReference', () => { + it('returns in getters values from constructor parameters', () => { const reference = new shaka.media.SegmentReference(1, 2, 3, - function() { return ['x', 'y']; }, 4, 5); + (() => { return ['x', 'y']; }), 4, 5); expect(reference.getPosition()).toBe(1); expect(reference.getStartTime()).toBe(2); @@ -29,10 +29,10 @@ describe('SegmentReference', function() { }); }); -describe('InitSegmentReference', function() { - it('returns in getters values from constructor parameters', function() { +describe('InitSegmentReference', () => { + it('returns in getters values from constructor parameters', () => { const reference = new shaka.media.InitSegmentReference( - function() { return ['x', 'y']; }, 4, 5); + (() => { return ['x', 'y']; }), 4, 5); expect(reference.createUris()).toEqual(['x', 'y']); expect(reference.getStartByte()).toBe(4); diff --git a/test/media/streaming_engine_integration.js b/test/media/streaming_engine_integration.js index 14de3b165..bf2e82a12 100644 --- a/test/media/streaming_engine_integration.js +++ b/test/media/streaming_engine_integration.js @@ -213,7 +213,7 @@ describe('StreamingEngine', () => { // request a segment that does not exist. netEngine = shaka.test.StreamingEngineUtil.createFakeNetworkingEngine( // Init segment generator: - function(type, periodNumber) { + (type, periodNumber) => { expect(periodNumber).toBeLessThan(periodStartTimes.length + 1); const wallClockTime = Date.now() / 1000; const segment = generators[type].getInitSegment(wallClockTime); @@ -221,7 +221,7 @@ describe('StreamingEngine', () => { return segment; }, // Media segment generator: - function(type, periodNumber, position) { + (type, periodNumber, position) => { expect(boundsCheckPosition(type, periodNumber, position)) .not.toBeNull(); @@ -322,7 +322,7 @@ describe('StreamingEngine', () => { video.play(); }); - onBuffering.and.callFake(function(buffering) { + onBuffering.and.callFake((buffering) => { if (!buffering) { expect(startupComplete).toBeTruthy(); video.playbackRate = 10; @@ -526,7 +526,7 @@ describe('StreamingEngine', () => { expect(onEvent).toHaveBeenCalled(); }); - it('won\'t jump large gaps with preventDefault()', function(done) { + it('won\'t jump large gaps with preventDefault()', (done) => { config.jumpLargeGaps = true; setupGappyContent(/* gapAtStart */ 0, /* dropSegment */ true) .then(() => { @@ -535,7 +535,7 @@ describe('StreamingEngine', () => { video.play(); }); - onEvent.and.callFake(function(event) { + onEvent.and.callFake((event) => { event.preventDefault(); shaka.test.Util.delay(5).then(() => { // IE/Edge somehow plays inside the gap. Just make sure we diff --git a/test/media/streaming_engine_unit.js b/test/media/streaming_engine_unit.js index 677c90f1c..0702f1b71 100644 --- a/test/media/streaming_engine_unit.js +++ b/test/media/streaming_engine_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('StreamingEngine', function() { +describe('StreamingEngine', () => { const Util = shaka.test.Util; const ContentType = shaka.util.ManifestParserUtils.ContentType; const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils; @@ -98,7 +98,7 @@ describe('StreamingEngine', function() { Util.fakeEventLoop(60, onTick); } - beforeAll(function() { + beforeAll(() => { jasmine.clock().install(); jasmine.clock().mockDate(); // This mock is required for fakeEventLoop. @@ -318,12 +318,12 @@ describe('StreamingEngine', function() { // request a segment that does not exist. netEngine = shaka.test.StreamingEngineUtil.createFakeNetworkingEngine( // Init segment generator: - function(type, periodNumber) { + (type, periodNumber) => { expect((periodNumber == 1) || (periodNumber == 2)); return segmentData[type].initSegments[periodNumber - 1]; }, // Media segment generator: - function(type, periodNumber, position) { + (type, periodNumber, position) => { expect(position).toBeGreaterThan(0); expect((periodNumber == 1 && position <= segmentsInFirstPeriod) || (periodNumber == 2 && position <= segmentsInSecondPeriod)); @@ -355,35 +355,35 @@ describe('StreamingEngine', function() { // Create InitSegmentReferences. manifest.periods[0].variants[0].audio.initSegmentReference = new shaka.media.InitSegmentReference( - function() { return ['1_audio_init']; }, + (() => { return ['1_audio_init']; }), initSegmentRanges[ContentType.AUDIO][0], initSegmentRanges[ContentType.AUDIO][1]); manifest.periods[0].variants[0].video.initSegmentReference = new shaka.media.InitSegmentReference( - function() { return ['1_video_init']; }, + (() => { return ['1_video_init']; }), initSegmentRanges[ContentType.VIDEO][0], initSegmentRanges[ContentType.VIDEO][1]); if (manifest.periods[0].variants[0].video.trickModeVideo) { manifest.periods[0].variants[0].video.trickModeVideo .initSegmentReference = new shaka.media.InitSegmentReference( - function() { return ['1_trickvideo_init']; }, + (() => { return ['1_trickvideo_init']; }), initSegmentRanges[ContentType.VIDEO][0], initSegmentRanges[ContentType.VIDEO][1]); } manifest.periods[1].variants[0].audio.initSegmentReference = new shaka.media.InitSegmentReference( - function() { return ['2_audio_init']; }, + (() => { return ['2_audio_init']; }), initSegmentRanges[ContentType.AUDIO][0], initSegmentRanges[ContentType.AUDIO][1]); manifest.periods[1].variants[0].video.initSegmentReference = new shaka.media.InitSegmentReference( - function() { return ['2_video_init']; }, + (() => { return ['2_video_init']; }), initSegmentRanges[ContentType.VIDEO][0], initSegmentRanges[ContentType.VIDEO][1]); if (manifest.periods[1].variants[0].video.trickModeVideo) { manifest.periods[1].variants[0].video.trickModeVideo .initSegmentReference = new shaka.media.InitSegmentReference( - function() { return ['2_trickvideo_init']; }, + (() => { return ['2_trickvideo_init']; }), initSegmentRanges[ContentType.VIDEO][0], initSegmentRanges[ContentType.VIDEO][1]); } @@ -461,12 +461,12 @@ describe('StreamingEngine', function() { streamingEngine.configure(config); } - afterEach(function(done) { + afterEach((done) => { streamingEngine.destroy().catch(fail).then(done); PromiseMock.flush(); }); - afterAll(function() { + afterAll(() => { PromiseMock.uninstall(); jasmine.clock().uninstall(); }); @@ -493,12 +493,12 @@ describe('StreamingEngine', function() { // both segments within the second Period. At this point the playhead // should not be at the end of the presentation, but the test will be // effectively over since SE will have nothing else to do. - it('initializes and plays VOD', function() { + it('initializes and plays VOD', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { // Verify buffers. expect(mediaSourceEngine.initSegments).toEqual({ audio: [true, false], @@ -516,10 +516,10 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.reinitText).not.toHaveBeenCalled(); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onCanSwitch.and.callFake(function() { + onCanSwitch.and.callFake(() => { expect(alternateVideoStream1.createSegmentIndex).toHaveBeenCalled(); expect(mediaSourceEngine.reinitText).not.toHaveBeenCalled(); mediaSourceEngine.reinitText.calls.reset(); @@ -527,7 +527,7 @@ describe('StreamingEngine', function() { }); // For second Period. - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Verify buffers. @@ -544,7 +544,7 @@ describe('StreamingEngine', function() { verifyNetworkingEngineRequestCalls(1); - onCanSwitch.and.callFake(function() { + onCanSwitch.and.callFake(() => { expect(audioStream2.createSegmentIndex).toHaveBeenCalled(); expect(videoStream2.createSegmentIndex).toHaveBeenCalled(); expect(textStream2.createSegmentIndex).toHaveBeenCalled(); @@ -561,7 +561,7 @@ describe('StreamingEngine', function() { return defaultOnChooseStreams(period); }); - onInitialStreamsSetup.and.callFake(function() { + onInitialStreamsSetup.and.callFake(() => { const expectedObject = new Map(); expectedObject.set(ContentType.AUDIO, audioStream1); expectedObject.set(ContentType.VIDEO, videoStream1); @@ -603,17 +603,17 @@ describe('StreamingEngine', function() { verifyNetworkingEngineRequestCalls(2); }); - describe('loadNewTextStream', function() { - it('clears MediaSourceEngine', function() { + describe('loadNewTextStream', () => { + it('clears MediaSourceEngine', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(function() { setupFakeGetTime(0); }); + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); onChooseStreams.and.callFake(onChooseStreamsWithUnloadedText); streamingEngine.start(); - runTest(function() { + runTest(() => { if (presentationTimeInSeconds == 20) { mediaSourceEngine.clear.calls.reset(); mediaSourceEngine.init.calls.reset(); @@ -630,12 +630,12 @@ describe('StreamingEngine', function() { }); }); - describe('unloadTextStream', function() { - it('doesn\'t send requests for text after calling unload', function() { + describe('unloadTextStream', () => { + it('doesn\'t send requests for text after calling unload', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(function() { setupFakeGetTime(0); }); + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); onChooseStreams.and.callFake(onChooseStreamsWithUnloadedText); streamingEngine.start(); @@ -643,7 +643,7 @@ describe('StreamingEngine', function() { // Verify that after unloading text stream, no network request for text // is sent. - runTest(function() { + runTest(() => { if (presentationTimeInSeconds == 1) { netEngine.expectRequest('1_text_1', segmentType); netEngine.request.calls.reset(); @@ -658,14 +658,14 @@ describe('StreamingEngine', function() { }); }); - it('initializes and plays live', function() { + it('initializes and plays live', () => { setupLive(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); presentationTimeInSeconds = 100; - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(100); }); @@ -701,26 +701,26 @@ describe('StreamingEngine', function() { // Start the playhead in the first Period but pass start() Streams from the // second Period. - it('plays from 1st Period when passed Streams from 2nd', function() { + it('plays from 1st Period when passed Streams from 2nd', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); // Start with Streams from the second Period even though the playhead is // in the first Period. onChooseStreams() should be called again for the // first Period and then eventually for the second Period. - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); return defaultOnChooseStreams(period); @@ -750,24 +750,24 @@ describe('StreamingEngine', function() { // Start the playhead in the second Period but pass start() Streams from the // first Period. - it('plays from 2nd Period when passed Streams from 1st', function() { + it('plays from 2nd Period when passed Streams from 1st', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); presentationTimeInSeconds = 20; - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(20); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Start with Streams from the first Period even though the playhead is // in the second Period. onChooseStreams() should be called again for the // second Period. - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); onChooseStreams.and.throwError(new Error()); @@ -794,7 +794,7 @@ describe('StreamingEngine', function() { }); }); - it('plays when a small gap is present at the beginning', function() { + it('plays when a small gap is present at the beginning', () => { const drift = 0.050; // 50 ms setupVod(); @@ -810,7 +810,7 @@ describe('StreamingEngine', function() { expect(onStartupComplete).toHaveBeenCalled(); }); - it('plays when 1st Period doesn\'t have text streams', function() { + it('plays when 1st Period doesn\'t have text streams', () => { setupVod(); manifest.periods[0].textStreams = []; @@ -818,7 +818,7 @@ describe('StreamingEngine', function() { createStreamingEngine(); onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0)); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { const chosen = defaultOnChooseStreams(period); if (period == manifest.periods[0]) { chosen.text = null; @@ -837,7 +837,7 @@ describe('StreamingEngine', function() { }); }); - it('doesn\'t get stuck when 2nd Period isn\'t available yet', function() { + it('doesn\'t get stuck when 2nd Period isn\'t available yet', () => { // See: https://github.com/google/shaka-player/pull/839 setupVod(); manifest.periods[0].textStreams = []; @@ -858,7 +858,7 @@ describe('StreamingEngine', function() { createStreamingEngine(); onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0)); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { const chosen = defaultOnChooseStreams(period); if (period == manifest.periods[0]) { chosen.text = null; @@ -877,7 +877,7 @@ describe('StreamingEngine', function() { }); }); - it('only reinitializes text when switching streams', function() { + it('only reinitializes text when switching streams', () => { // See: https://github.com/google/shaka-player/issues/910 setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); @@ -887,8 +887,8 @@ describe('StreamingEngine', function() { onChooseStreams.and.callFake(defaultOnChooseStreams); // When we can switch in the second Period, switch to the playing stream. - onCanSwitch.and.callFake(function() { - onCanSwitch.and.callFake(function() { + onCanSwitch.and.callFake(() => { + onCanSwitch.and.callFake(() => { expect(streamingEngine.getBufferingText()).toBe(textStream2); mediaSourceEngine.reinitText.calls.reset(); @@ -903,7 +903,7 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.reinitText).not.toHaveBeenCalled(); }); - it('plays when 2nd Period doesn\'t have text streams', function() { + it('plays when 2nd Period doesn\'t have text streams', () => { setupVod(); manifest.periods[1].textStreams = []; @@ -911,7 +911,7 @@ describe('StreamingEngine', function() { createStreamingEngine(); onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0)); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { const chosen = defaultOnChooseStreams(period); if (period == manifest.periods[1]) { chosen.text = null; @@ -930,7 +930,7 @@ describe('StreamingEngine', function() { }); }); - it('updates the timeline duration to match media duration', function() { + it('updates the timeline duration to match media duration', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); @@ -938,7 +938,7 @@ describe('StreamingEngine', function() { onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0)); onChooseStreams.and.callFake(defaultOnChooseStreams); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { expect(mediaSourceEngine.setDuration).toHaveBeenCalledWith(40); expect(mediaSourceEngine.setDuration).toHaveBeenCalledTimes(1); mediaSourceEngine.setDuration.calls.reset(); @@ -956,7 +956,7 @@ describe('StreamingEngine', function() { }); // https://github.com/google/shaka-player/issues/979 - it('does not expand the timeline duration', function() { + it('does not expand the timeline duration', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); @@ -964,7 +964,7 @@ describe('StreamingEngine', function() { onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0)); onChooseStreams.and.callFake(defaultOnChooseStreams); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { expect(mediaSourceEngine.setDuration).toHaveBeenCalledWith(40); expect(mediaSourceEngine.setDuration).toHaveBeenCalledTimes(1); mediaSourceEngine.setDuration.calls.reset(); @@ -981,7 +981,7 @@ describe('StreamingEngine', function() { expect(timeline.setDuration).not.toHaveBeenCalled(); }); - it('applies fudge factor for appendWindowStart', function() { + it('applies fudge factor for appendWindowStart', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); @@ -1004,7 +1004,7 @@ describe('StreamingEngine', function() { .toHaveBeenCalledWith('video', 20, lt20, 40); }); - it('does not buffer one media type ahead of another', function() { + it('does not buffer one media type ahead of another', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); @@ -1051,13 +1051,13 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.appendBuffer).toHaveBeenCalled(); }); - describe('switchVariant/switchTextStream', function() { + describe('switchVariant/switchTextStream', () => { let initialVariant; let sameAudioVariant; let sameVideoVariant; let initialTextStream; - beforeEach(function() { + beforeEach(() => { // Set up a manifest with multiple variants and a text stream. manifest = new shaka.test.ManifestGenerator() .addPeriod(0) @@ -1099,17 +1099,17 @@ describe('StreamingEngine', function() { const bufferEnd = {audio: 0, video: 0, text: 0}; mediaSourceEngine.appendBuffer.and.callFake( - function(type, data, start, end) { + (type, data, start, end) => { bufferEnd[type] = end; return Promise.resolve(); }); - mediaSourceEngine.bufferEnd.and.callFake(function(type) { + mediaSourceEngine.bufferEnd.and.callFake((type) => { return bufferEnd[type]; }); - mediaSourceEngine.bufferedAheadOf.and.callFake(function(type, start) { + mediaSourceEngine.bufferedAheadOf.and.callFake((type, start) => { return Math.max(0, bufferEnd[type] - start); }); - mediaSourceEngine.isBuffered.and.callFake(function(type, time) { + mediaSourceEngine.isBuffered.and.callFake((type, time) => { return time >= 0 && time < bufferEnd[type]; }); @@ -1117,13 +1117,13 @@ describe('StreamingEngine', function() { createStreamingEngine(); onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 0)); - onChooseStreams.and.callFake(function() { + onChooseStreams.and.callFake(() => { return {variant: initialVariant, text: initialTextStream}; }); }); - it('will not clear buffers if streams have not changed', function() { - onCanSwitch.and.callFake(function() { + it('will not clear buffers if streams have not changed', () => { + onCanSwitch.and.callFake(() => { mediaSourceEngine.clear.calls.reset(); streamingEngine.switchVariant( sameAudioVariant, /* clearBuffer */ true, /* safeMargin */ 0); @@ -1154,11 +1154,11 @@ describe('StreamingEngine', function() { }); }); - describe('handles seeks (VOD)', function() { + describe('handles seeks (VOD)', () => { /** @type {!jasmine.Spy} */ let onTick; - beforeEach(function() { + beforeEach(() => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); @@ -1169,11 +1169,11 @@ describe('StreamingEngine', function() { onTick.and.stub(); }); - it('into buffered regions', function() { - onChooseStreams.and.callFake(function(period) { + it('into buffered regions', () => { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Seek backwards to a buffered region in the first Period. Note that @@ -1211,18 +1211,18 @@ describe('StreamingEngine', function() { }); }); - it('into partially buffered regions in the same period', function() { + it('into partially buffered regions in the same period', () => { // When seeking into a region within the same period, or changing // resolution, and after the seek some states are buffered and some // are unbuffered, StreamingEngine should only clear the unbuffered // states. - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { // Should have the first Period entirely buffered. expect(mediaSourceEngine.initSegments).toEqual({ audio: [false, true], @@ -1281,11 +1281,11 @@ describe('StreamingEngine', function() { }); - it('into buffered regions across Periods', function() { - onChooseStreams.and.callFake(function(period) { + it('into buffered regions across Periods', () => { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); onChooseStreams.and.throwError(new Error()); @@ -1294,7 +1294,7 @@ describe('StreamingEngine', function() { return defaultOnChooseStreams(period); }); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { // Seek backwards to a buffered region in the first Period. Note // that since the buffering goal is 5 seconds and each segment is // 10 seconds long, the last segment should be required at 26 seconds. @@ -1330,8 +1330,8 @@ describe('StreamingEngine', function() { }); }); - it('into unbuffered regions', function() { - onChooseStreams.and.callFake(function(period) { + it('into unbuffered regions', () => { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); onChooseStreams.and.throwError(new Error()); @@ -1340,7 +1340,7 @@ describe('StreamingEngine', function() { return defaultOnChooseStreams(period); }); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); // Seek forward to an unbuffered region in the first Period. @@ -1348,7 +1348,7 @@ describe('StreamingEngine', function() { presentationTimeInSeconds += 15; streamingEngine.seeked(); - onTick.and.callFake(function() { + onTick.and.callFake(() => { // Verify that all buffers have been cleared. expect(mediaSourceEngine.clear) .toHaveBeenCalledWith(ContentType.AUDIO); @@ -1359,7 +1359,7 @@ describe('StreamingEngine', function() { onTick.and.stub(); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Verify buffers. @@ -1398,13 +1398,13 @@ describe('StreamingEngine', function() { }); }); - it('into unbuffered regions across Periods', function() { + it('into unbuffered regions across Periods', () => { // Start from the second Period. presentationTimeInSeconds = 20; onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 20)); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); onChooseStreams.and.throwError(new Error()); @@ -1413,7 +1413,7 @@ describe('StreamingEngine', function() { return defaultOnChooseStreams(period); }); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { // Verify buffers. expect(mediaSourceEngine.initSegments).toEqual({ audio: [false, true], @@ -1434,7 +1434,7 @@ describe('StreamingEngine', function() { presentationTimeInSeconds -= 20; streamingEngine.seeked(); - onTick.and.callFake(function() { + onTick.and.callFake(() => { // Verify that all buffers have been cleared. expect(mediaSourceEngine.clear) .toHaveBeenCalledWith(ContentType.AUDIO); @@ -1445,10 +1445,10 @@ describe('StreamingEngine', function() { onTick.and.stub(); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Verify buffers. @@ -1494,8 +1494,8 @@ describe('StreamingEngine', function() { }); }); - it('into unbuffered regions when nothing is buffered', function() { - onChooseStreams.and.callFake(function(period) { + it('into unbuffered regions when nothing is buffered', () => { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); onChooseStreams.and.throwError(new Error()); @@ -1504,19 +1504,19 @@ describe('StreamingEngine', function() { return defaultOnChooseStreams(period); }); - onInitialStreamsSetup.and.callFake(function() { + onInitialStreamsSetup.and.callFake(() => { // Seek forward to an unbuffered region in the first Period. expect(presentationTimeInSeconds).toBe(0); presentationTimeInSeconds = 15; streamingEngine.seeked(); - onTick.and.callFake(function() { + onTick.and.callFake(() => { // Nothing should have been cleared. expect(mediaSourceEngine.clear).not.toHaveBeenCalled(); onTick.and.stub(); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Verify buffers. @@ -1561,20 +1561,20 @@ describe('StreamingEngine', function() { // If we seek back into an unbuffered region but do not called seeked(), // StreamingEngine should wait for seeked() to be called. - it('back into unbuffered regions without seeked() ', function() { + it('back into unbuffered regions without seeked() ', () => { // Start from the second segment in the second Period. presentationTimeInSeconds = 30; onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 20)); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Init the second Period. return defaultOnChooseStreams(period); }); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { // Seek backwards to an unbuffered region in the second Period. Do not // call seeked(). expect(presentationTimeInSeconds).toBe(26); @@ -1604,22 +1604,22 @@ describe('StreamingEngine', function() { // StreamingEngine should continue buffering. This test also exercises the // case where the playhead moves past the end of the buffer, which may // occur on some browsers depending on the playback rate. - it('forward into unbuffered regions without seeked()', function() { - onChooseStreams.and.callFake(function(period) { + it('forward into unbuffered regions without seeked()', () => { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); // Init the first Period. return defaultOnChooseStreams(period); }); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); // Seek forward to an unbuffered region in the first Period. Do not // call seeked(). presentationTimeInSeconds += 15; - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Switch to the second Period. @@ -1644,20 +1644,20 @@ describe('StreamingEngine', function() { }); }); - it('into partially buffered regions across periods', function() { + it('into partially buffered regions across periods', () => { // Seeking into a region where some buffers (text) are buffered and some // are not should work despite the media states requiring different // periods. - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); // Should get another call for the unbuffered Period transition. onChooseStreams.and.callFake(defaultOnChooseStreams); - mediaSourceEngine.endOfStream.and.callFake(function() { + mediaSourceEngine.endOfStream.and.callFake(() => { // Should have the first Period entirely buffered. expect(mediaSourceEngine.initSegments).toEqual({ audio: [false, true], @@ -1717,8 +1717,8 @@ describe('StreamingEngine', function() { }); }); - describe('handles seeks (live)', function() { - beforeEach(function() { + describe('handles seeks (live)', () => { + beforeEach(() => { setupLive(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData, 0); createStreamingEngine(); @@ -1726,13 +1726,13 @@ describe('StreamingEngine', function() { onStartupComplete.and.callFake(setupFakeGetTime.bind(null, 100)); }); - it('outside segment availability window', function() { + it('outside segment availability window', () => { timeline.segmentAvailabilityStart = 90; timeline.segmentAvailabilityEnd = 110; presentationTimeInSeconds = 90; - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); onChooseStreams.and.throwError(new Error()); @@ -1741,7 +1741,7 @@ describe('StreamingEngine', function() { return defaultOnChooseStreams(period); }); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(90); // Seek forward to an unbuffered and unavailable region in the second @@ -1753,7 +1753,7 @@ describe('StreamingEngine', function() { playing = false; streamingEngine.seeked(); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[1]); onChooseStreams.and.throwError(new Error()); @@ -1768,7 +1768,7 @@ describe('StreamingEngine', function() { const originalAppendBuffer = shaka.test.FakeMediaSourceEngine.prototype.appendBufferImpl; mediaSourceEngine.appendBuffer.and.callFake( - function(type, data, startTime, endTime) { + (type, data, startTime, endTime) => { expect(presentationTimeInSeconds).toBe(125); expect(timeline.getSegmentAvailabilityStart()).toBe(100); expect(timeline.getSegmentAvailabilityEnd()).toBe(120); @@ -1807,19 +1807,19 @@ describe('StreamingEngine', function() { }); }); - describe('handles errors', function() { - beforeEach(function() { + describe('handles errors', () => { + beforeEach(() => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); }); - it('from initial Stream setup', function() { + it('from initial Stream setup', () => { videoStream1.createSegmentIndex.and.returnValue( Promise.reject('FAKE_ERROR')); const onInitError = jasmine.createSpy('onInitError'); - onInitError.and.callFake(function(error) { + onInitError.and.callFake((error) => { expect(onInitialStreamsSetup).not.toHaveBeenCalled(); expect(onStartupComplete).not.toHaveBeenCalled(); expect(error).toBe('FAKE_ERROR'); @@ -1834,7 +1834,7 @@ describe('StreamingEngine', function() { expect(onError).not.toHaveBeenCalled(); }); - it('from post startup Stream setup', function() { + it('from post startup Stream setup', () => { const expectedError = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.NETWORK, @@ -1842,7 +1842,7 @@ describe('StreamingEngine', function() { alternateVideoStream1.createSegmentIndex.and.returnValue( Promise.reject(expectedError)); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(onInitialStreamsSetup).toHaveBeenCalled(); expect(onStartupComplete).toHaveBeenCalled(); expect(error).toBe(expectedError); @@ -1855,19 +1855,19 @@ describe('StreamingEngine', function() { expect(onError).toHaveBeenCalled(); }); - it('from failed init segment append during startup', function() { + it('from failed init segment append during startup', () => { const expectedError = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_FAILED); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(onInitialStreamsSetup).toHaveBeenCalled(); expect(onStartupComplete).not.toHaveBeenCalled(); Util.expectToEqualError(error, expectedError); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); const streamsByType = defaultOnChooseStreams(period); @@ -1875,7 +1875,7 @@ describe('StreamingEngine', function() { const originalAppendBuffer = shaka.test.FakeMediaSourceEngine.prototype.appendBufferImpl; mediaSourceEngine.appendBuffer.and.callFake( - function(type, data, startTime, endTime) { + (type, data, startTime, endTime) => { // Reject the first video init segment. if (data == segmentData[ContentType.VIDEO].initSegments[0]) { return Promise.reject(expectedError); @@ -1894,19 +1894,19 @@ describe('StreamingEngine', function() { expect(onError).toHaveBeenCalled(); }); - it('from failed media segment append during startup', function() { + it('from failed media segment append during startup', () => { const expectedError = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_FAILED); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(onInitialStreamsSetup).toHaveBeenCalled(); expect(onStartupComplete).not.toHaveBeenCalled(); Util.expectToEqualError(error, expectedError); }); - onChooseStreams.and.callFake(function(period) { + onChooseStreams.and.callFake((period) => { expect(period).toBe(manifest.periods[0]); const streamsByType = defaultOnChooseStreams(period); @@ -1914,7 +1914,7 @@ describe('StreamingEngine', function() { const originalAppendBuffer = shaka.test.FakeMediaSourceEngine.prototype.appendBufferImpl; mediaSourceEngine.appendBuffer.and.callFake( - function(type, data, startTime, endTime) { + (type, data, startTime, endTime) => { // Reject the first audio segment. if (data == segmentData[ContentType.AUDIO].segments[0]) { return Promise.reject(expectedError); @@ -1934,15 +1934,15 @@ describe('StreamingEngine', function() { }); }); - describe('handles network errors', function() { - it('ignores text stream failures if configured to', function() { + describe('handles network errors', () => { + it('ignores text stream failures if configured to', () => { setupVod(); const textUri = '1_text_1'; const originalNetEngine = netEngine; netEngine = { request: jasmine.createSpy('request'), }; - netEngine.request.and.callFake(function(requestType, request) { + netEngine.request.and.callFake((requestType, request) => { if (request.uris[0] == textUri) { return shaka.util.AbortableOperation.failed(new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, @@ -1956,7 +1956,7 @@ describe('StreamingEngine', function() { config.ignoreTextStreamFailures = true; createStreamingEngine(config); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); @@ -1969,7 +1969,7 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.endOfStream).toHaveBeenCalled(); }); - it('retries if configured to', function() { + it('retries if configured to', () => { setupLive(); // Wrap the NetworkingEngine to cause errors. @@ -1984,11 +1984,11 @@ describe('StreamingEngine', function() { createStreamingEngine(config); presentationTimeInSeconds = 100; - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(100); }); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(error.severity).toBe(shaka.util.Error.Severity.CRITICAL); expect(error.category).toBe(shaka.util.Error.Category.NETWORK); expect(error.code).toBe(shaka.util.Error.Code.BAD_HTTP_STATUS); @@ -2004,7 +2004,7 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.endOfStream).toHaveBeenCalledTimes(1); }); - it('does not retry if configured not to', function() { + it('does not retry if configured not to', () => { setupLive(); // Wrap the NetworkingEngine to cause errors. @@ -2019,11 +2019,11 @@ describe('StreamingEngine', function() { createStreamingEngine(config); presentationTimeInSeconds = 100; - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(100); }); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(error.severity).toBe(shaka.util.Error.Severity.CRITICAL); expect(error.category).toBe(shaka.util.Error.Category.NETWORK); expect(error.code).toBe(shaka.util.Error.Code.BAD_HTTP_STATUS); @@ -2039,7 +2039,7 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.endOfStream).toHaveBeenCalledTimes(0); }); - it('does not invoke the callback if the error is handled', function() { + it('does not invoke the callback if the error is handled', () => { setupLive(); // Wrap the NetworkingEngine to cause errors. @@ -2056,11 +2056,11 @@ describe('StreamingEngine', function() { createStreamingEngine(config); presentationTimeInSeconds = 100; - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(100); }); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { error.handled = true; }); @@ -2073,7 +2073,7 @@ describe('StreamingEngine', function() { expect(failureCallback).not.toHaveBeenCalled(); }); - it('waits to invoke the failure callback', function() { + it('waits to invoke the failure callback', () => { setupLive(); // Wrap the NetworkingEngine to cause errors. @@ -2086,7 +2086,7 @@ describe('StreamingEngine', function() { // Configure with a failure callback that records the callback time. let callbackTime = null; const failureCallback = jasmine.createSpy('failureCallback'); - failureCallback.and.callFake(function() { callbackTime = Date.now(); }); + failureCallback.and.callFake(() => { callbackTime = Date.now(); }); const config = shaka.util.PlayerConfiguration.createDefault().streaming; config.failureCallback = shaka.test.Util.spyFunc(failureCallback); @@ -2096,7 +2096,7 @@ describe('StreamingEngine', function() { createStreamingEngine(config); presentationTimeInSeconds = 100; - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(100); }); onError.and.stub(); @@ -2112,8 +2112,8 @@ describe('StreamingEngine', function() { }); }); - describe('retry()', function() { - it('resumes streaming after failure', function() { + describe('retry()', () => { + it('resumes streaming after failure', () => { setupVod(); // Wrap the NetworkingEngine to cause errors. @@ -2125,11 +2125,11 @@ describe('StreamingEngine', function() { mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { // Restore the original fake request function. netEngine.request = originalNetEngineRequest; netEngine.request.calls.reset(); @@ -2152,13 +2152,13 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.endOfStream).toHaveBeenCalledTimes(1); }); - it('does not resume streaming after quota error', function() { + it('does not resume streaming after quota error', () => { setupVod(); const appendBufferSpy = jasmine.createSpy('appendBuffer'); // Throw QuotaExceededError on every segment to quickly trigger the quota // error. - appendBufferSpy.and.callFake(function(type, data, startTime, endTime) { + appendBufferSpy.and.callFake((type, data, startTime, endTime) => { throw new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, @@ -2170,11 +2170,11 @@ describe('StreamingEngine', function() { mediaSourceEngine.appendBuffer = appendBufferSpy; createStreamingEngine(); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(error.code).toBe(shaka.util.Error.Code.QUOTA_EXCEEDED_ERROR); // Retry streaming, which should fail and return false. @@ -2197,13 +2197,13 @@ describe('StreamingEngine', function() { expect(mediaSourceEngine.endOfStream).not.toHaveBeenCalled(); }); - it('does not resume streaming after destruction', function() { + it('does not resume streaming after destruction', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(function() { + onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); @@ -2212,7 +2212,7 @@ describe('StreamingEngine', function() { // Here we go! let count = 0; - runTest(function() { + runTest(() => { if (++count == 3) { streamingEngine.destroy(); @@ -2229,10 +2229,10 @@ describe('StreamingEngine', function() { }); }); - describe('eviction', function() { + describe('eviction', () => { let config; - beforeEach(function() { + beforeEach(() => { setupVod(); manifest.minBufferTime = 1; @@ -2243,7 +2243,7 @@ describe('StreamingEngine', function() { config.bufferBehind = 10; }); - it('evicts media to meet the max buffer tail limit', function() { + it('evicts media to meet the max buffer tail limit', () => { // Create StreamingEngine. mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(config); @@ -2254,13 +2254,13 @@ describe('StreamingEngine', function() { shaka.test.FakeMediaSourceEngine.prototype.removeImpl .bind(mediaSourceEngine); - mediaSourceEngine.remove.and.callFake(function(type, start, end) { + mediaSourceEngine.remove.and.callFake((type, start, end) => { expect(presentationTimeInSeconds).toBe(20); expect(start).toBe(0); expect(end).toBe(10); if (mediaSourceEngine.remove.calls.count() == 3) { - mediaSourceEngine.remove.and.callFake(function(type, start, end) { + mediaSourceEngine.remove.and.callFake((type, start, end) => { expect(presentationTimeInSeconds).toBe(30); expect(start).toBe(10); expect(end).toBe(20); @@ -2311,7 +2311,7 @@ describe('StreamingEngine', function() { }); }); - it('doesn\'t evict too much when bufferBehind is very low', function() { + it('doesn\'t evict too much when bufferBehind is very low', () => { // Set the bufferBehind to a value significantly below the segment size. config.bufferBehind = 0.1; @@ -2340,8 +2340,8 @@ describe('StreamingEngine', function() { }); }); - describe('QuotaExceededError', function() { - it('does not fail immediately', function() { + describe('QuotaExceededError', () => { + it('does not fail immediately', () => { setupVod(); manifest.minBufferTime = 1; @@ -2365,7 +2365,7 @@ describe('StreamingEngine', function() { // Throw two QuotaExceededErrors at different times. let numErrorsThrown = 0; appendBufferSpy.and.callFake( - function(type, data, startTime, endTime) { + (type, data, startTime, endTime) => { const throwError = (numErrorsThrown == 0 && startTime == 10) || (numErrorsThrown == 1 && startTime == 20); if (throwError) { @@ -2402,7 +2402,7 @@ describe('StreamingEngine', function() { }); }); - it('fails after multiple QuotaExceededError', function() { + it('fails after multiple QuotaExceededError', () => { setupVod(); manifest.minBufferTime = 1; @@ -2425,7 +2425,7 @@ describe('StreamingEngine', function() { // Throw QuotaExceededError multiple times after at least one segment of // each type has been appended. appendBufferSpy.and.callFake( - function(type, data, startTime, endTime) { + (type, data, startTime, endTime) => { if (startTime >= 10) { throw new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, @@ -2439,7 +2439,7 @@ describe('StreamingEngine', function() { } }); - onError.and.callFake(function(error) { + onError.and.callFake((error) => { expect(error.code).toBe(shaka.util.Error.Code.QUOTA_EXCEEDED_ERROR); expect(error.data[0] == ContentType.AUDIO || error.data[0] == ContentType.VIDEO || @@ -2460,8 +2460,8 @@ describe('StreamingEngine', function() { }); }); - describe('VOD drift', function() { - beforeEach(function() { + describe('VOD drift', () => { + beforeEach(() => { setupVod(); }); @@ -2530,8 +2530,8 @@ describe('StreamingEngine', function() { it('is handled for small - values', testNegativeDrift.bind(null, -3)); }); - describe('live drift', function() { - beforeEach(function() { + describe('live drift', () => { + beforeEach(() => { setupLive(); }); @@ -2577,8 +2577,8 @@ describe('StreamingEngine', function() { it('is handled for large - values', testNegativeDrift.bind(null, -12)); }); - describe('setTrickPlay', function() { - it('uses trick mode track when requested', function() { + describe('setTrickPlay', () => { + it('uses trick mode track when requested', () => { setupVod(/* trickMode */ true); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); @@ -2595,7 +2595,7 @@ describe('StreamingEngine', function() { onChooseStreams.and.callFake(defaultOnChooseStreams.bind(null)); streamingEngine.start(); - runTest(function() { + runTest(() => { if (presentationTimeInSeconds == 1) { expect(mediaSourceEngine.initSegments).toEqual({ audio: [true, false], @@ -2677,7 +2677,7 @@ describe('StreamingEngine', function() { }); }); - describe('embedded emsg boxes', function() { + describe('embedded emsg boxes', () => { const emsgSegment = Uint8ArrayUtils.fromHex( '0000003b656d736700000000666f6f3a6261723a637573746f6d646174617363' + '68656d6500310000000001000000080000ffff0000000174657374'); @@ -2693,7 +2693,7 @@ describe('StreamingEngine', function() { messageData: new Uint8Array([0x74, 0x65, 0x73, 0x74]), }; - beforeEach(function() { + beforeEach(() => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); @@ -2702,7 +2702,7 @@ describe('StreamingEngine', function() { onChooseStreams.and.callFake(defaultOnChooseStreams.bind(null)); }); - it('raises an event for registered embedded emsg boxes', function() { + it('raises an event for registered embedded emsg boxes', () => { segmentData[ContentType.VIDEO].segments[0] = emsgSegment.buffer; videoStream1.emsgSchemeIdUris = [emsgObj.schemeIdUri]; @@ -2716,7 +2716,7 @@ describe('StreamingEngine', function() { expect(event.detail).toEqual(emsgObj); }); - it('raises multiple events', function() { + it('raises multiple events', () => { const dummyBox = shaka.util.Uint8ArrayUtils.fromHex('0000000c6672656501020304'); segmentData[ContentType.VIDEO].segments[0] = @@ -2731,7 +2731,7 @@ describe('StreamingEngine', function() { expect(onEvent).toHaveBeenCalledTimes(2); }); - it('won\'t raise an event without stream field set', function() { + it('won\'t raise an event without stream field set', () => { segmentData[ContentType.VIDEO].segments[0] = emsgSegment.buffer; // Here we go! @@ -2741,7 +2741,7 @@ describe('StreamingEngine', function() { expect(onEvent).not.toHaveBeenCalled(); }); - it('won\'t raise an event when no emsg boxes present', function() { + it('won\'t raise an event when no emsg boxes present', () => { videoStream1.emsgSchemeIdUris = [emsgObj.schemeIdUri]; // Here we go! @@ -2751,7 +2751,7 @@ describe('StreamingEngine', function() { expect(onEvent).not.toHaveBeenCalled(); }); - it('won\'t raise an event for an unregistered emsg box', function() { + it('won\'t raise an event for an unregistered emsg box', () => { segmentData[ContentType.VIDEO].segments[0] = emsgSegment.buffer; // Here we go! @@ -2761,7 +2761,7 @@ describe('StreamingEngine', function() { expect(onEvent).not.toHaveBeenCalled(); }); - it('triggers manifest updates', function() { + it('triggers manifest updates', () => { // This is an 'emsg' box that contains a scheme of // urn:mpeg:dash:event:2012 to indicate a manifest update. segmentData[ContentType.VIDEO].segments[0] = @@ -2783,7 +2783,7 @@ describe('StreamingEngine', function() { }); }); - describe('network downgrading', function() { + describe('network downgrading', () => { /** @type {shaka.extern.Variant} */ let newVariant; /** @type {!Array.} */ @@ -2795,7 +2795,7 @@ describe('StreamingEngine', function() { /** @type {boolean} */ let shouldDelayRequests; - beforeEach(function() { + beforeEach(() => { manifest = new shaka.test.ManifestGenerator() .setPresentationDuration(60) .addPeriod(0) @@ -3093,7 +3093,7 @@ describe('StreamingEngine', function() { netEngine.attempts = 0; netEngine.request = jasmine.createSpy('request').and.callFake( - function(requestType, request) { + (requestType, request) => { if (request.uris[0] == targetUri) { if (++netEngine.attempts == 1) { const data = [targetUri]; diff --git a/test/media/time_ranges_utils_unit.js b/test/media/time_ranges_utils_unit.js index 76c1f736e..bcabdc7b1 100644 --- a/test/media/time_ranges_utils_unit.js +++ b/test/media/time_ranges_utils_unit.js @@ -15,25 +15,25 @@ * limitations under the License. */ -describe('TimeRangesUtils', function() { +describe('TimeRangesUtils', () => { const TimeRangesUtils = shaka.media.TimeRangesUtils; - describe('isBuffered', function() { - it('still works when passed null', function() { + describe('isBuffered', () => { + it('still works when passed null', () => { expect(TimeRangesUtils.isBuffered(null, 10)).toBe(false); }); - it('still works with nothing buffered', function() { + it('still works with nothing buffered', () => { const b = createFakeBuffered([]); expect(TimeRangesUtils.isBuffered(b, 10)).toBe(false); }); - it('returns buffered when inside a single range', function() { + it('returns buffered when inside a single range', () => { const b = createFakeBuffered([{start: 10, end: 20}]); expect(TimeRangesUtils.isBuffered(b, 13)).toBe(true); }); - it('returns buffered when having a small gap', function() { + it('returns buffered when having a small gap', () => { const b = createFakeBuffered([{start: 10, end: 20}]); expect(TimeRangesUtils.isBuffered(b, 9, 1)).toBe(true); }); @@ -52,7 +52,7 @@ describe('TimeRangesUtils', function() { * @param {{time: number, expected: boolean}} data */ function defineTest(name, data) { - it(name, function() { + it(name, () => { const b = createFakeBuffered( [{start: 10, end: 20}, {start: 30, end: 40}, {start: 50, end: 60}]); expect(TimeRangesUtils.isBuffered(b, data.time)).toBe(data.expected); @@ -60,12 +60,12 @@ describe('TimeRangesUtils', function() { } }); - describe('bufferedAheadOf', function() { - it('still works when passed null', function() { + describe('bufferedAheadOf', () => { + it('still works when passed null', () => { expect(TimeRangesUtils.bufferedAheadOf(null, 10)).toBe(0); }); - it('still works when nothing is buffered', function() { + it('still works when nothing is buffered', () => { const b = createFakeBuffered([]); expect(TimeRangesUtils.bufferedAheadOf(b, 10)).toBe(0); }); @@ -88,7 +88,7 @@ describe('TimeRangesUtils', function() { * @param {{time: number, expected: number}} data */ function defineTest(name, data) { - it(name, function() { + it(name, () => { const b = createFakeBuffered( [{start: 10, end: 20}, {start: 30, end: 40}, {start: 50, end: 60}]); expect(TimeRangesUtils.bufferedAheadOf( @@ -97,12 +97,12 @@ describe('TimeRangesUtils', function() { } }); - describe('getGapIndex', function() { - it('still works when passed null', function() { + describe('getGapIndex', () => { + it('still works when passed null', () => { expect(TimeRangesUtils.getGapIndex(null, 10)).toBe(null); }); - it('still works whith nothing buffered', function() { + it('still works whith nothing buffered', () => { const b = createFakeBuffered([]); expect(TimeRangesUtils.getGapIndex(b, 10)).toBe(null); }); @@ -128,7 +128,7 @@ describe('TimeRangesUtils', function() { * @param {{time: number, expected: ?number}} data */ function defineTest(name, data) { - it(name, function() { + it(name, () => { const b = createFakeBuffered( [{start: 10, end: 20}, {start: 30, end: 40}, {start: 50, end: 60}]); expect(TimeRangesUtils.getGapIndex(b, data.time)).toBe(data.expected); diff --git a/test/media/transmuxer_integration.js b/test/media/transmuxer_integration.js index c852c3c4c..2fa5f8dad 100644 --- a/test/media/transmuxer_integration.js +++ b/test/media/transmuxer_integration.js @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -describe('Transmuxer', function() { +describe('Transmuxer', () => { const ContentType = shaka.util.ManifestParserUtils.ContentType; const videoSegmentUri = '/base/test/test/assets/video.ts'; @@ -44,7 +44,7 @@ describe('Transmuxer', function() { emptySegment = new ArrayBuffer(0); }); - beforeEach(function() { + beforeEach(() => { transmuxer = new shaka.media.Transmuxer(); }); @@ -52,19 +52,19 @@ describe('Transmuxer', function() { await transmuxer.destroy(); }); - describe('isSupported', function() { + describe('isSupported', () => { const isSupported = shaka.media.Transmuxer.isSupported; - it('returns whether the content type is supported', function() { + it('returns whether the content type is supported', () => { expect(isSupported(mp4MimeType, ContentType.VIDEO)).toBeFalsy(); expect(isSupported(transportStreamVideoMimeType, ContentType.VIDEO)) .toBe(true); }); }); - describe('convertTsCodecs', function() { + describe('convertTsCodecs', () => { const convertTsCodecs = shaka.media.Transmuxer.convertTsCodecs; - it('returns converted codecs', function() { + it('returns converted codecs', () => { const convertedVideoCodecs = convertTsCodecs(ContentType.VIDEO, transportStreamVideoMimeType); const convertedAudioCodecs = @@ -75,7 +75,7 @@ describe('Transmuxer', function() { expect(convertedAudioCodecs).toEqual(expectedAudioCodecs); }); - it('converts legacy avc1 codec strings', function() { + it('converts legacy avc1 codec strings', () => { expect(convertTsCodecs(ContentType.VIDEO, 'video/mp2t; codecs="avc1.100.42"')).toEqual( 'video/mp4; codecs="avc1.64002a"'); @@ -88,7 +88,7 @@ describe('Transmuxer', function() { }); }); - describe('transmuxing', function() { + describe('transmuxing', () => { it('transmux video from TS to MP4', async () => { let sawMDAT = false; @@ -97,7 +97,7 @@ describe('Transmuxer', function() { expect(transmuxedData.data.length).toBeGreaterThan(0); expect(transmuxedData.captions).toEqual(jasmine.any(Array)); new shaka.util.Mp4Parser() - .box('mdat', shaka.util.Mp4Parser.allData(function(data) { + .box('mdat', shaka.util.Mp4Parser.allData((data) => { sawMDAT = true; expect(data.buffer.byteLength).toBeGreaterThan(0); })) @@ -112,7 +112,7 @@ describe('Transmuxer', function() { expect(transmuxedData.data.length).toBeGreaterThan(0); expect(transmuxedData.captions).toEqual(jasmine.any(Array)); new shaka.util.Mp4Parser() - .box('mdat', shaka.util.Mp4Parser.allData(function(data) { + .box('mdat', shaka.util.Mp4Parser.allData((data) => { sawMDAT = true; expect(data.buffer.byteLength).toBeGreaterThan(0); })) @@ -127,7 +127,7 @@ describe('Transmuxer', function() { expect(transmuxedData.data.length).toBeGreaterThan(0); expect(transmuxedData.captions).toEqual(jasmine.any(Array)); new shaka.util.Mp4Parser() - .box('mdat', shaka.util.Mp4Parser.allData(function(data) { + .box('mdat', shaka.util.Mp4Parser.allData((data) => { sawMDAT = true; })) .parse(transmuxedData.data.buffer); @@ -145,7 +145,7 @@ describe('Transmuxer', function() { new Mp4Parser() .box('moof', Mp4Parser.children) .box('traf', Mp4Parser.children) - .fullBox('tfdt', function(box) { + .fullBox('tfdt', (box) => { goog.asserts.assert( box.version == 0 || box.version == 1, 'TFDT version can only be 0 or 1'); diff --git a/test/media/webm_segment_index_parser_unit.js b/test/media/webm_segment_index_parser_unit.js index 9c13f7601..187439659 100644 --- a/test/media/webm_segment_index_parser_unit.js +++ b/test/media/webm_segment_index_parser_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('WebmSegmentIndexParser', function() { +describe('WebmSegmentIndexParser', () => { const indexSegmentUri = '/base/test/test/assets/index-segment.webm'; const initSegmentUri = '/base/test/test/assets/init-segment.webm'; @@ -32,7 +32,7 @@ describe('WebmSegmentIndexParser', function() { initSegment = responses[1]; }); - it('rejects a non-index segment ', function() { + it('rejects a non-index segment ', () => { const error = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, @@ -45,7 +45,7 @@ describe('WebmSegmentIndexParser', function() { } }); - it('rejects an invalid init segment ', function() { + it('rejects an invalid init segment ', () => { const error = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, @@ -58,7 +58,7 @@ describe('WebmSegmentIndexParser', function() { } }); - it('parses index segment ', function() { + it('parses index segment ', () => { const result = parser.parse(indexSegment, initSegment, [], 0); const references = [ @@ -80,7 +80,7 @@ describe('WebmSegmentIndexParser', function() { } }); - it('takes a scaled presentationTimeOffset in seconds', function() { + it('takes a scaled presentationTimeOffset in seconds', () => { const result = parser.parse(indexSegment, initSegment, [], 2); const references = [ diff --git a/test/net/data_uri_plugin_unit.js b/test/net/data_uri_plugin_unit.js index 6c072e708..3a37b98cb 100644 --- a/test/net/data_uri_plugin_unit.js +++ b/test/net/data_uri_plugin_unit.js @@ -15,14 +15,14 @@ * limitations under the License. */ -describe('DataUriPlugin', function() { +describe('DataUriPlugin', () => { const retryParameters = shaka.net.NetworkingEngine.defaultRetryParameters(); - it('supports MIME types', function(done) { + it('supports MIME types', (done) => { testSucceeds('data:text/plain,Hello', 'text/plain', 'Hello', done); }); - it('supports URI encoded text', function(done) { + it('supports URI encoded text', (done) => { testSucceeds( 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', 'text/html', @@ -30,37 +30,37 @@ describe('DataUriPlugin', function() { done); }); - it('supports base64 encoded text', function(done) { + it('supports base64 encoded text', (done) => { testSucceeds( 'data:;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', '', 'Hello, World!', done); }); - it('supports extra colin', function(done) { + it('supports extra colin', (done) => { testSucceeds('data:,Hello:', '', 'Hello:', done); }); - it('supports extra semi-colin', function(done) { + it('supports extra semi-colin', (done) => { testSucceeds('data:,Hello;', '', 'Hello;', done); }); - it('supports extra comma', function(done) { + it('supports extra comma', (done) => { testSucceeds('data:,Hello,', '', 'Hello,', done); }); - it('fails for empty URI', function(done) { + it('fails for empty URI', (done) => { testFails('', done, shaka.util.Error.Code.MALFORMED_DATA_URI); }); - it('fails for non-data URIs', function(done) { + it('fails for non-data URIs', (done) => { testFails('http://google.com/', done, shaka.util.Error.Code.MALFORMED_DATA_URI); }); - it('fails for decoding errors', function(done) { + it('fails for decoding errors', (done) => { testFails('data:Bad%', done, shaka.util.Error.Code.MALFORMED_DATA_URI); }); - it('fails if missing comma', function(done) { + it('fails if missing comma', (done) => { testFails('data:Bad', done, shaka.util.Error.Code.MALFORMED_DATA_URI); }); @@ -69,7 +69,7 @@ describe('DataUriPlugin', function() { shaka.net.NetworkingEngine.makeRequest([uri], retryParameters); // eslint-disable-next-line new-cap shaka.net.DataUriPlugin(uri, request).promise - .then(function(response) { + .then((response) => { expect(response).toBeTruthy(); expect(response.uri).toBe(uri); expect(response.data).toBeTruthy(); @@ -88,8 +88,8 @@ describe('DataUriPlugin', function() { // eslint-disable-next-line new-cap shaka.net.DataUriPlugin(uri, request).promise .then(fail) - .catch(function(error) { expect(error.code).toBe(code); }) - .then(function() { + .catch((error) => { expect(error.code).toBe(code); }) + .then(() => { done(); }); } diff --git a/test/net/http_plugin_unit.js b/test/net/http_plugin_unit.js index b29d01bf7..dfe88d457 100644 --- a/test/net/http_plugin_unit.js +++ b/test/net/http_plugin_unit.js @@ -31,7 +31,7 @@ function httpPluginTests(usingFetch) { /** @type {shaka.extern.SchemePlugin} */ let plugin; - beforeAll(function() { + beforeAll(() => { plugin = usingFetch ? shaka.net.HttpFetchPlugin : shaka.net.HttpXHRPlugin; PromiseMock.install(); @@ -149,7 +149,7 @@ function httpPluginTests(usingFetch) { retryParameters.timeout = 4000; }); - afterAll(function() { + afterAll(() => { if (usingFetch) { shaka.net.HttpFetchPlugin['fetch_'] = window.fetch; shaka.net.HttpFetchPlugin['AbortController_'] = window.AbortController; @@ -162,7 +162,7 @@ function httpPluginTests(usingFetch) { PromiseMock.uninstall(); }); - it('sets the correct fields', function(done) { + it('sets the correct fields', (done) => { const request = shaka.net.NetworkingEngine.makeRequest( ['https://foo.bar/'], retryParameters); request.allowCrossSiteCredentials = true; @@ -170,7 +170,7 @@ function httpPluginTests(usingFetch) { request.headers['BAZ'] = '123'; plugin(request.uris[0], request, requestType).promise - .then(function() { + .then(() => { const actual = mostRecentRequest(); expect(actual).toBeTruthy(); expect(actual.url).toBe(request.uris[0]); @@ -187,14 +187,14 @@ function httpPluginTests(usingFetch) { if (usingFetch) { // Regression test for an issue with Edge, where Fetch fails if the body // is set to null but succeeds on undefined. - it('sets a request\'s null body to undefined', function(done) { + it('sets a request\'s null body to undefined', (done) => { const request = shaka.net.NetworkingEngine.makeRequest( ['https://foo.bar/'], retryParameters); request.body = null; request.method = 'GET'; plugin(request.uris[0], request, requestType).promise - .then(function() { + .then(() => { const actual = jasmine.Fetch.requests.mostRecent(); expect(actual).toBeTruthy(); expect(actual.body).toBeUndefined(); @@ -205,45 +205,45 @@ function httpPluginTests(usingFetch) { }); } - it('fails with 202 status', function(done) { + it('fails with 202 status', (done) => { testFails('https://foo.bar/202', done); PromiseMock.flush(); }); - it('succeeds with 204 status', function(done) { + it('succeeds with 204 status', (done) => { testSucceeds('https://foo.bar/204', done); PromiseMock.flush(); }); - it('succeeds with empty line in response', function(done) { + it('succeeds with empty line in response', (done) => { testSucceedsWithEmptyLine('https://foo.bar/withemptyline', done); PromiseMock.flush(); }); - it('gets redirect URLs with 302 status', function(done) { + it('gets redirect URLs with 302 status', (done) => { testSucceeds('https://foo.bar/302', done, 'https://foo.bar/after/302'); PromiseMock.flush(); }); - it('fails with CRITICAL for 401 status', function(done) { + it('fails with CRITICAL for 401 status', (done) => { testFails('https://foo.bar/401', done, shaka.util.Error.Severity.CRITICAL); PromiseMock.flush(); }); - it('fails with CRITICAL for 403 status', function(done) { + it('fails with CRITICAL for 403 status', (done) => { testFails('https://foo.bar/403', done, shaka.util.Error.Severity.CRITICAL); PromiseMock.flush(); }); - it('fails if non-2xx status', function(done) { + it('fails if non-2xx status', (done) => { const uri = 'https://foo.bar/404'; testFails(uri, done, undefined, shaka.util.Error.Code.BAD_HTTP_STATUS, [uri, 404, 'ABC', {'foo': 'BAR'}, requestType]); PromiseMock.flush(); }); - it('fails on timeout', function(done) { + it('fails on timeout', (done) => { const uri = 'https://foo.bar/timeout'; testFails(uri, done, shaka.util.Error.Severity.RECOVERABLE, shaka.util.Error.Code.TIMEOUT, [uri, requestType]); @@ -256,7 +256,7 @@ function httpPluginTests(usingFetch) { PromiseMock.flush(); }); - it('fails on error', function(done) { + it('fails on error', (done) => { const uri = 'https://foo.bar/error'; testFails(uri, done, shaka.util.Error.Severity.RECOVERABLE, shaka.util.Error.Code.HTTP_ERROR, @@ -264,12 +264,12 @@ function httpPluginTests(usingFetch) { PromiseMock.flush(); }); - it('detects cache headers', function(done) { + it('detects cache headers', (done) => { const request = shaka.net.NetworkingEngine.makeRequest( ['https://foo.bar/cache'], retryParameters); plugin(request.uris[0], request, requestType).promise .catch(fail) - .then(function(response) { + .then((response) => { expect(response).toBeTruthy(); expect(response.fromCache).toBe(true); }) @@ -277,7 +277,7 @@ function httpPluginTests(usingFetch) { PromiseMock.flush(); }); - it('aborts the request when the operation is aborted', function(done) { + it('aborts the request when the operation is aborted', (done) => { let abortPromise; let requestPromise; const oldXHRMock = shaka.net.HttpXHRPlugin['Xhr_']; @@ -314,12 +314,12 @@ function httpPluginTests(usingFetch) { this.send = function() { // Delay the effects of send until after operation is defined. - Promise.resolve().then(function() { + Promise.resolve().then(() => { expect(this.abort).not.toHaveBeenCalled(); operation.abort(); expect(this.abort).toHaveBeenCalled(); this.onabort(); - }.bind(this)); + }); }; }; shaka.net.HttpXHRPlugin['Xhr_'] = NewXHRMock; @@ -361,7 +361,7 @@ function httpPluginTests(usingFetch) { [uri], retryParameters); plugin(uri, request, requestType).promise .catch(fail) - .then(function(response) { + .then((response) => { expect(mostRecentRequest().url).toBe(uri); expect(response).toBeTruthy(); expect(response.uri).toBe(overrideUri || uri); @@ -387,7 +387,7 @@ function httpPluginTests(usingFetch) { [uri], retryParameters); plugin(uri, request, requestType).promise .then(fail) - .catch(function(error) { + .catch((error) => { expect(error).toBeTruthy(); expect(error.severity) .toBe(severity || shaka.util.Error.Severity.RECOVERABLE); @@ -416,7 +416,7 @@ function httpPluginTests(usingFetch) { [uri], retryParameters); plugin(uri, request, requestType).promise .catch(fail) - .then(function(response) { + .then((response) => { expect(mostRecentRequest().url).toBe(uri); expect(response).toBeTruthy(); expect(response.uri).toBe(overrideUri || uri); diff --git a/test/net/networking_engine_unit.js b/test/net/networking_engine_unit.js index e274992b9..fad2a3ee1 100644 --- a/test/net/networking_engine_unit.js +++ b/test/net/networking_engine_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('NetworkingEngine', /** @suppress {accessControls} */ function() { +describe('NetworkingEngine', /** @suppress {accessControls} */ () => { const StatusPromise = shaka.test.StatusPromise; const Util = shaka.test.Util; const requestType = shaka.net.NetworkingEngine.RequestType.SEGMENT; @@ -35,19 +35,19 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { /** @type {!shaka.util.Error} */ let error; - beforeAll(function() { + beforeAll(() => { shaka.net.NetworkingEngine.getLocationProtocol_ = function() { return fakeProtocol; }; }); function makeResolveScheme(spyName) { - return jasmine.createSpy(spyName).and.callFake(function() { + return jasmine.createSpy(spyName).and.callFake(() => { return shaka.util.AbortableOperation.completed(createResponse()); }); } - beforeEach(function() { + beforeEach(() => { fakeProtocol = 'http:'; error = new shaka.util.Error( shaka.util.Error.Severity.RECOVERABLE, @@ -67,18 +67,18 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { shaka.net.NetworkingEngine.PluginPriority.FALLBACK); }); - afterEach(function() { + afterEach(() => { shaka.net.NetworkingEngine.unregisterScheme('resolve'); shaka.net.NetworkingEngine.unregisterScheme('reject'); }); - afterAll(function() { + afterAll(() => { shaka.net.NetworkingEngine.getLocationProtocol_ = originalGetLocationProtocol; }); - describe('retry', function() { - it('will retry', function(done) { + describe('retry', () => { + it('will retry', (done) => { const request = createRequest('reject://foo', { maxAttempts: 2, baseDelay: 0, @@ -86,7 +86,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { fuzzFactor: 0, timeout: 0, }); - rejectScheme.and.callFake(function() { + rejectScheme.and.callFake(() => { if (rejectScheme.calls.count() == 1) { return shaka.util.AbortableOperation.failed(error); } else { @@ -95,13 +95,13 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); networkingEngine.request(requestType, request).promise .catch(fail) - .then(function() { + .then(() => { expect(rejectScheme.calls.count()).toBe(2); done(); }); }); - it('will retry twice', function(done) { + it('will retry twice', (done) => { const request = createRequest('reject://foo', { maxAttempts: 3, baseDelay: 0, @@ -109,7 +109,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { fuzzFactor: 0, timeout: 0, }); - rejectScheme.and.callFake(function() { + rejectScheme.and.callFake(() => { if (rejectScheme.calls.count() < 3) { return shaka.util.AbortableOperation.failed(error); } else { @@ -118,13 +118,13 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); networkingEngine.request(requestType, request).promise .catch(fail) - .then(function() { + .then(() => { expect(rejectScheme.calls.count()).toBe(3); done(); }); }); - it('will fail overall', function(done) { + it('will fail overall', (done) => { const request = createRequest('reject://foo', { maxAttempts: 3, baseDelay: 0, @@ -134,14 +134,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); networkingEngine.request(requestType, request).promise .then(fail) - .catch(function(error) { + .catch((error) => { // It is expected to fail with the most recent error. expect(error).toEqual(jasmine.any(shaka.util.Error)); expect(rejectScheme.calls.count()).toBe(3); }).then(done); }); - describe('backoff', function() { + describe('backoff', () => { const baseDelay = 200; const originalDefer = shaka.net.Backoff.defer; const realRandom = Math.random; @@ -225,7 +225,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); // describe('backoff') - it('uses multiple URIs', function(done) { + it('uses multiple URIs', (done) => { const request = createRequest('', { maxAttempts: 3, baseDelay: 0, @@ -236,14 +236,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { request.uris = ['reject://foo', 'resolve://foo']; networkingEngine.request(requestType, request).promise .catch(fail) - .then(function() { + .then(() => { expect(rejectScheme.calls.count()).toBe(1); expect(resolveScheme.calls.count()).toBe(1); done(); }); }); - it('won\'t retry for CRITICAL error', function(done) { + it('won\'t retry for CRITICAL error', (done) => { const request = createRequest('reject://foo', { maxAttempts: 5, baseDelay: 0, @@ -255,28 +255,28 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { error.severity = shaka.util.Error.Severity.CRITICAL; networkingEngine.request(requestType, request).promise .then(fail) - .catch(function() { + .catch(() => { expect(rejectScheme.calls.count()).toBe(1); done(); }); }); }); // describe('retry') - describe('request', function() { + describe('request', () => { function testResolve(schemeSpy) { return networkingEngine.request( requestType, createRequest('resolve://foo')).promise .catch(fail) - .then(function() { + .then(() => { expect(schemeSpy).toHaveBeenCalled(); }); } - it('uses registered schemes', function(done) { + it('uses registered schemes', (done) => { testResolve(resolveScheme).then(done); }); - it('uses registered scheme plugins in order of priority', function(done) { + it('uses registered scheme plugins in order of priority', (done) => { const applicationResolveScheme = makeResolveScheme('application resolve scheme'); shaka.net.NetworkingEngine.registerScheme( @@ -291,7 +291,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { testResolve(applicationResolveScheme).then(done); }); - it('uses newest scheme plugin in case of tie in priority', function(done) { + it('uses newest scheme plugin in case of tie in priority', (done) => { const secondResolveScheme = makeResolveScheme('second resolve scheme'); shaka.net.NetworkingEngine.registerScheme( 'resolve', Util.spyFunc(secondResolveScheme), @@ -300,7 +300,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { testResolve(secondResolveScheme).then(done); }); - it('defaults new scheme plugins to application priority', function(done) { + it('defaults new scheme plugins to application priority', (done) => { const secondResolveScheme = makeResolveScheme('second resolve scheme'); shaka.net.NetworkingEngine.registerScheme( 'resolve', Util.spyFunc(secondResolveScheme)); @@ -313,16 +313,16 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { testResolve(secondResolveScheme).then(done); }); - it('can unregister scheme', function(done) { + it('can unregister scheme', (done) => { shaka.net.NetworkingEngine.unregisterScheme('resolve'); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .then(fail) - .catch(function() { expect(resolveScheme).not.toHaveBeenCalled(); }) + .catch(() => { expect(resolveScheme).not.toHaveBeenCalled(); }) .then(done); }); - it('unregister removes all plugins for scheme at once', function(done) { + it('unregister removes all plugins for scheme at once', (done) => { const preferredResolveScheme = makeResolveScheme('preferred resolve scheme'); shaka.net.NetworkingEngine.registerScheme( @@ -333,25 +333,25 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .then(fail) - .catch(function() { + .catch(() => { expect(resolveScheme).not.toHaveBeenCalled(); expect(preferredResolveScheme).not.toHaveBeenCalled(); }).then(done); }); - it('rejects if scheme does not exist', function(done) { + it('rejects if scheme does not exist', (done) => { networkingEngine.request(requestType, createRequest('foo://foo')) .promise .then(fail) - .catch(function() { expect(resolveScheme).not.toHaveBeenCalled(); }) + .catch(() => { expect(resolveScheme).not.toHaveBeenCalled(); }) .then(done); }); - it('returns the response object', function(done) { + it('returns the response object', (done) => { networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .catch(fail) - .then(function(response) { + .then((response) => { expect(response).toBeTruthy(); expect(response.data).toBeTruthy(); expect(response.data.byteLength).toBe(5); @@ -360,12 +360,12 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('passes correct arguments to plugin', function(done) { + it('passes correct arguments to plugin', (done) => { const request = createRequest('resolve://foo'); request.method = 'POST'; resolveScheme.and.callFake( - function(uri, requestPassed, requestTypePassed) { + (uri, requestPassed, requestTypePassed) => { expect(uri).toBe(request.uris[0]); expect(requestPassed).toEqual(request); expect(requestTypePassed).toEqual(requestType); @@ -375,23 +375,23 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { .promise.catch(fail).then(done); }); - it('infers a scheme for // URIs', function(done) { + it('infers a scheme for // URIs', (done) => { fakeProtocol = 'resolve:'; networkingEngine.request(requestType, createRequest('//foo')).promise .catch(fail) - .then(function() { + .then(() => { expect(resolveScheme).toHaveBeenCalled(); expect(resolveScheme.calls.argsFor(0)[0]).toBe('resolve://foo'); done(); }); }); - it('fills in defaults for partial request objects', function(done) { + it('fills in defaults for partial request objects', (done) => { const originalRequest = /** @type {shaka.extern.Request} */ ({ uris: ['resolve://foo'], }); - resolveScheme.and.callFake(function(uri, request, requestTypePassed) { + resolveScheme.and.callFake((uri, request, requestTypePassed) => { // NetworkingEngine should have filled in these values: expect(request.method).toBeTruthy(); expect(request.headers).toBeTruthy(); @@ -404,42 +404,42 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); // describe('request') - describe('request filter', function() { + describe('request filter', () => { /** @type {!jasmine.Spy} */ let filter; - beforeEach(function() { + beforeEach(() => { filter = jasmine.createSpy('request filter'); networkingEngine.registerRequestFilter(Util.spyFunc(filter)); }); - afterEach(function() { + afterEach(() => { networkingEngine.unregisterRequestFilter(Util.spyFunc(filter)); }); - it('can be called', function(done) { + it('can be called', (done) => { networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .catch(fail) - .then(function() { + .then(() => { expect(filter).toHaveBeenCalled(); done(); }); }); - it('called on failure', function(done) { + it('called on failure', (done) => { networkingEngine.request(requestType, createRequest('reject://foo')) .promise .then(fail) - .catch(function() { expect(filter).toHaveBeenCalled(); }) + .catch(() => { expect(filter).toHaveBeenCalled(); }) .then(done); }); - it('is given correct arguments', function(done) { + it('is given correct arguments', (done) => { const request = createRequest('resolve://foo'); networkingEngine.request(requestType, request).promise .catch(fail) - .then(function() { + .then(() => { expect(filter.calls.argsFor(0)[0]).toBe(requestType); expect(filter.calls.argsFor(0)[1]).toBe(request); expect(filter.calls.argsFor(0)[1].uris[0]).toBe(request.uris[0]); @@ -447,7 +447,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('waits for asynchronous filters', function(done) { + it('waits for asynchronous filters', (done) => { const responseFilter = jasmine.createSpy('response filter'); networkingEngine.registerResponseFilter(Util.spyFunc(responseFilter)); @@ -459,7 +459,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { const r = new StatusPromise( networkingEngine.request(requestType, request).promise); - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(filter).toHaveBeenCalled(); expect(resolveScheme).not.toHaveBeenCalled(); expect(responseFilter).not.toHaveBeenCalled(); @@ -467,28 +467,28 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { p.resolve(); return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(resolveScheme).toHaveBeenCalled(); expect(responseFilter).toHaveBeenCalled(); expect(r.status).toBe('pending'); p2.resolve(); return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(r.status).toBe('resolved'); done(); }).catch(fail); }); - it('turns errors into shaka errors', function(done) { + it('turns errors into shaka errors', (done) => { const fakeError = 'fake error'; - filter.and.callFake(function() { + filter.and.callFake(() => { throw fakeError; }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .then(fail) - .catch(function(e) { + .catch((e) => { expect(e.severity).toBe(shaka.util.Error.Severity.CRITICAL); expect(e.code).toBe(shaka.util.Error.Code.REQUEST_FILTER_ERROR); expect(e.data).toEqual([fakeError]); @@ -496,29 +496,29 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('can modify uris', function(done) { - filter.and.callFake(function(type, request) { + it('can modify uris', (done) => { + filter.and.callFake((type, request) => { request.uris = ['resolve://foo']; }); networkingEngine.request(requestType, createRequest('reject://foo')) .promise .catch(fail) - .then(function() { + .then(() => { expect(filter).toHaveBeenCalled(); done(); }); }); - it('applies request filters sequentially', function(done) { + it('applies request filters sequentially', (done) => { const secondFilter = jasmine.createSpy('second request filter'); networkingEngine.registerRequestFilter(Util.spyFunc(secondFilter)); let order = 0; - filter.and.callFake(function() { + filter.and.callFake(() => { expect(order).toBe(0); order += 1; }); - secondFilter.and.callFake(function() { + secondFilter.and.callFake(() => { expect(order).toBe(1); order += 1; }); @@ -529,10 +529,10 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { .then(done); }); - it('can modify requests asynchronously', function(done) { + it('can modify requests asynchronously', (done) => { const p = new shaka.util.PublicPromise(); - filter.and.callFake(function(type, request) { - return p.then(function() { + filter.and.callFake((type, request) => { + return p.then(() => { request.uris = ['resolve://foo']; request.allowCrossSiteCredentials = true; }); @@ -540,14 +540,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { networkingEngine.request(requestType, createRequest('reject://foo')) .promise .catch(fail) - .then(function() { + .then(() => { expect(resolveScheme).toHaveBeenCalled(); expect(resolveScheme.calls.argsFor(0)[1].allowCrossSiteCredentials) .toBe(true); done(); }); - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(filter).toHaveBeenCalled(); expect(resolveScheme).not.toHaveBeenCalled(); @@ -555,14 +555,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('can modify allowCrossSiteCredentials', function(done) { - filter.and.callFake(function(type, request) { + it('can modify allowCrossSiteCredentials', (done) => { + filter.and.callFake((type, request) => { request.allowCrossSiteCredentials = true; }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .catch(fail) - .then(function() { + .then(() => { expect(filter).toHaveBeenCalled(); expect(resolveScheme).toHaveBeenCalled(); expect(resolveScheme.calls.argsFor(0)[1].allowCrossSiteCredentials) @@ -571,7 +571,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('if rejects will stop requests', function(done) { + it('if rejects will stop requests', (done) => { const request = createRequest('resolve://foo', { maxAttempts: 3, baseDelay: 0, @@ -582,14 +582,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { filter.and.returnValue(Promise.reject()); networkingEngine.request(requestType, request).promise .then(fail) - .catch(function() { + .catch(() => { expect(resolveScheme).not.toHaveBeenCalled(); expect(filter.calls.count()).toBe(1); }) .then(done); }); - it('if throws will stop requests', function(done) { + it('if throws will stop requests', (done) => { const request = createRequest('resolve://foo', { maxAttempts: 3, baseDelay: 0, @@ -600,59 +600,59 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { filter.and.throwError(error); networkingEngine.request(requestType, request).promise .then(fail) - .catch(function() { + .catch(() => { expect(resolveScheme).not.toHaveBeenCalled(); expect(filter.calls.count()).toBe(1); }) .then(done); }); - it('causes no errors to remove an unused filter', function() { + it('causes no errors to remove an unused filter', () => { const unusedFilter = jasmine.createSpy('unused filter'); networkingEngine.unregisterRequestFilter(Util.spyFunc(unusedFilter)); }); }); // describe('request filter') - describe('response filter', function() { + describe('response filter', () => { /** @type {!jasmine.Spy} */ let filter; - beforeEach(function() { + beforeEach(() => { filter = jasmine.createSpy('response filter'); networkingEngine.registerResponseFilter(Util.spyFunc(filter)); - resolveScheme.and.callFake(function(request) { + resolveScheme.and.callFake((request) => { return shaka.util.AbortableOperation.completed(createResponse()); }); }); - afterEach(function() { + afterEach(() => { networkingEngine.unregisterResponseFilter(Util.spyFunc(filter)); }); - it('can be called', function(done) { + it('can be called', (done) => { networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .catch(fail) - .then(function() { + .then(() => { expect(filter).toHaveBeenCalled(); done(); }); }); - it('not called on failure', function(done) { + it('not called on failure', (done) => { networkingEngine.request(requestType, createRequest('reject://foo')) .promise .then(fail) - .catch(function() { expect(filter).not.toHaveBeenCalled(); }) + .catch(() => { expect(filter).not.toHaveBeenCalled(); }) .then(done); }); - it('is given correct arguments', function(done) { + it('is given correct arguments', (done) => { const request = createRequest('resolve://foo'); networkingEngine.request(requestType, request) .promise .catch(fail) - .then(function() { + .then(() => { expect(filter.calls.argsFor(0)[0]).toBe(requestType); expect(filter.calls.argsFor(0)[1]).toBeTruthy(); expect(filter.calls.argsFor(0)[1].data).toBeTruthy(); @@ -661,14 +661,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('can modify data', function(done) { - filter.and.callFake(function(type, response) { + it('can modify data', (done) => { + filter.and.callFake((type, response) => { response.data = new ArrayBuffer(5); }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .catch(fail) - .then(function(response) { + .then((response) => { expect(filter).toHaveBeenCalled(); expect(response).toBeTruthy(); expect(response.data.byteLength).toBe(5); @@ -676,15 +676,15 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('can modify headers', function(done) { - filter.and.callFake(function(type, response) { + it('can modify headers', (done) => { + filter.and.callFake((type, response) => { expect(response.headers).toBeTruthy(); response.headers['DATE'] = 'CAT'; }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .catch(fail) - .then(function(response) { + .then((response) => { expect(filter).toHaveBeenCalled(); expect(response).toBeTruthy(); expect(response.headers['DATE']).toBe('CAT'); @@ -692,16 +692,16 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('applies response filters sequentially', function(done) { + it('applies response filters sequentially', (done) => { const secondFilter = jasmine.createSpy('second response filter'); networkingEngine.registerResponseFilter(Util.spyFunc(secondFilter)); let order = 0; - filter.and.callFake(function() { + filter.and.callFake(() => { expect(order).toBe(0); order += 1; }); - secondFilter.and.callFake(function() { + secondFilter.and.callFake(() => { expect(order).toBe(1); order += 1; }); @@ -712,25 +712,25 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { .then(done); }); - it('turns errors into shaka errors', function(done) { + it('turns errors into shaka errors', (done) => { const fakeError = 'fake error'; - filter.and.callFake(function() { + filter.and.callFake(() => { throw fakeError; }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .then(fail) - .catch(function(e) { + .catch((e) => { expect(e.code).toBe(shaka.util.Error.Code.RESPONSE_FILTER_ERROR); expect(e.data).toEqual([fakeError]); done(); }); }); - it('can modify responses asynchronously', function(done) { + it('can modify responses asynchronously', (done) => { const p = new shaka.util.PublicPromise(); - filter.and.callFake(function(type, response) { - return p.then(function() { + filter.and.callFake((type, response) => { + return p.then(() => { expect(response.headers).toBeTruthy(); response.headers['DATE'] = 'CAT'; response.data = new ArrayBuffer(5); @@ -741,14 +741,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { const r = new StatusPromise(networkingEngine.request(requestType, request) .promise .catch(fail) - .then(function(response) { + .then((response) => { expect(response).toBeTruthy(); expect(response.headers['DATE']).toBe('CAT'); expect(response.data.byteLength).toBe(5); done(); })); - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(filter).toHaveBeenCalled(); expect(r.status).toBe('pending'); @@ -756,23 +756,23 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('if throws will stop requests', function(done) { - filter.and.callFake(function() { throw error; }); + it('if throws will stop requests', (done) => { + filter.and.callFake(() => { throw error; }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .then(fail) - .catch(function() { expect(filter).toHaveBeenCalled(); }) + .catch(() => { expect(filter).toHaveBeenCalled(); }) .then(done); }); - it('causes no errors to remove an unused filter', function() { + it('causes no errors to remove an unused filter', () => { const unusedFilter = jasmine.createSpy('unused filter'); networkingEngine.unregisterResponseFilter(Util.spyFunc(unusedFilter)); }); }); // describe('response filter') - describe('destroy', function() { - it('waits for all operations to complete', function(done) { + describe('destroy', () => { + it('waits for all operations to complete', (done) => { const request = createRequest('resolve://foo'); const p = new shaka.util.PublicPromise(); resolveScheme.and.returnValue( @@ -788,26 +788,26 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { /** @type {!shaka.test.StatusPromise} */ let d; - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { d = new StatusPromise(networkingEngine.destroy()); expect(d.status).toBe('pending'); expect(r1.status).toBe('pending'); expect(r2.status).toBe('pending'); return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(d.status).toBe('pending'); p.resolve({}); return d; - }).then(function() { + }).then(() => { return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(r1.status).not.toBe('pending'); expect(r2.status).not.toBe('pending'); expect(d.status).toBe('resolved'); }).catch(fail).then(done); }); - it('causes requests to reject if called while filtering', function(done) { + it('causes requests to reject if called while filtering', (done) => { const filter = jasmine.createSpy('request filter'); networkingEngine.registerRequestFilter(Util.spyFunc(filter)); const p = new shaka.util.PublicPromise(); @@ -825,7 +825,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { /** @type {!shaka.test.StatusPromise} */ let d; - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(filter).toHaveBeenCalled(); expect(r.status).toBe('pending'); @@ -833,14 +833,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { p.resolve(); return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(d.status).toBe('resolved'); expect(r.status).toBe('rejected'); expect(resolveScheme).not.toHaveBeenCalled(); }).catch(fail).then(done); }); - it('resolves even when a request fails', function(done) { + it('resolves even when a request fails', (done) => { const request = createRequest('reject://foo'); const p = new shaka.util.PublicPromise(); rejectScheme.and.returnValue( @@ -856,25 +856,25 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { /** @type {!shaka.test.StatusPromise} */ let d; - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { d = new StatusPromise(networkingEngine.destroy()); expect(d.status).toBe('pending'); return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(d.status).toBe('pending'); p.reject(error); return d; - }).then(function() { + }).then(() => { return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(r1.status).toBe('rejected'); expect(r2.status).toBe('rejected'); expect(d.status).toBe('resolved'); }).catch(fail).then(done); }); - it('prevents new requests', function(done) { + it('prevents new requests', (done) => { const request = createRequest('resolve://foo'); const d = new StatusPromise(networkingEngine.destroy()); @@ -893,7 +893,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - it('does not allow further retries', function(done) { + it('does not allow further retries', (done) => { const request = createRequest('reject://foo', { maxAttempts: 3, baseDelay: 0, @@ -904,7 +904,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { const p1 = new shaka.util.PublicPromise(); const p2 = new shaka.util.PublicPromise(); - rejectScheme.and.callFake(function() { + rejectScheme.and.callFake(() => { // Return p1 the first time, then p2 the second time. return (rejectScheme.calls.count() == 1) ? shaka.util.AbortableOperation.notAbortable(p1) : @@ -915,14 +915,14 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { networkingEngine.request(requestType, request).promise); /** @type {shaka.test.StatusPromise} */ let d; - Util.delay(0.1).then(function() { + Util.delay(0.1).then(() => { expect(rejectScheme.calls.count()).toBe(1); d = new StatusPromise(networkingEngine.destroy()); expect(d.status).toBe('pending'); return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(d.status).toBe('pending'); expect(rejectScheme.calls.count()).toBe(1); // Reject the initial request. @@ -931,9 +931,9 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { // promise should not be used. p2.resolve(); return d; - }).then(function() { + }).then(() => { return Util.delay(0.1); - }).then(function() { + }).then(() => { expect(d.status).toBe('resolved'); // The request was never retried. expect(r.status).toBe('rejected'); @@ -942,31 +942,31 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); // describe('destroy') - it('ignores cache hits', function(done) { + it('ignores cache hits', (done) => { const onSegmentDownloaded = jasmine.createSpy('onSegmentDownloaded'); networkingEngine = new shaka.net.NetworkingEngine(Util.spyFunc(onSegmentDownloaded)); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise - .then(function() { + .then(() => { expect(onSegmentDownloaded).toHaveBeenCalled(); onSegmentDownloaded.calls.reset(); - resolveScheme.and.callFake(function() { + resolveScheme.and.callFake(() => { return shaka.util.AbortableOperation.completed(createResponse()); }); return networkingEngine.request( requestType, createRequest('resolve://foo')); }) - .then(function() { + .then(() => { expect(onSegmentDownloaded).not.toHaveBeenCalled(); }) .catch(fail) .then(done); }); - describe('\'retry\' event', function() { + describe('\'retry\' event', () => { /** @type {shaka.extern.Request} */ let request; /** @type {jasmine.Spy} */ @@ -1026,18 +1026,18 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }); }); - describe('abort', function() { + describe('abort', () => { /** @type {!shaka.util.Error} */ let abortError; - beforeEach(function() { + beforeEach(() => { abortError = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.PLAYER, shaka.util.Error.Code.OPERATION_ABORTED); }); - it('interrupts request filters', function(done) { + it('interrupts request filters', (done) => { const filter1Promise = new shaka.util.PublicPromise(); const filter1Spy = jasmine.createSpy('filter 1') .and.returnValue(filter1Promise); @@ -1082,7 +1082,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }).catch(fail).then(done); }); - it('interrupts scheme plugins', function(done) { + it('interrupts scheme plugins', (done) => { const p = new shaka.util.PublicPromise(); const abortSpy = jasmine.createSpy('abort'); const abort = Util.spyFunc(abortSpy); @@ -1114,7 +1114,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }).catch(fail).then(done); }); - it('interrupts response filters', function(done) { + it('interrupts response filters', (done) => { const filter1Promise = new shaka.util.PublicPromise(); const filter1Spy = jasmine.createSpy('filter 1') .and.returnValue(filter1Promise); @@ -1158,7 +1158,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() { }).catch(fail).then(done); }); - it('is called by destroy', function(done) { + it('is called by destroy', (done) => { const p = new shaka.util.PublicPromise(); const abortSpy = jasmine.createSpy('abort'); const abort = Util.spyFunc(abortSpy); diff --git a/test/offline/indexeddb_storage_unit.js b/test/offline/indexeddb_storage_unit.js index 2b0f3b79d..fd277201a 100644 --- a/test/offline/indexeddb_storage_unit.js +++ b/test/offline/indexeddb_storage_unit.js @@ -16,7 +16,7 @@ */ -describe('IndexeddbStorageCell', function() { +describe('IndexeddbStorageCell', () => { const IndexedDBUtils = shaka.test.IndexedDBUtils; const OfflineUtils = shaka.test.OfflineUtils; @@ -33,12 +33,12 @@ describe('IndexeddbStorageCell', function() { /** @type {!Array.} */ let connections = []; - beforeEach(function() { + beforeEach(() => { cells = []; connections = []; }); - afterEach(async function() { + afterEach(async () => { // If the test did not run, then there will be no cells and no connections, // so we don't need to worry about checking if indexeddb is supported here. @@ -47,7 +47,7 @@ describe('IndexeddbStorageCell', function() { connections.forEach((connection) => connection.close()); }); - it('can add, get, and remove segments', checkAndRun(function(done) { + it('can add, get, and remove segments', checkAndRun((done) => { /** @type {shaka.extern.StorageCell} */ let cell; @@ -90,7 +90,7 @@ describe('IndexeddbStorageCell', function() { }).catch(fail).then(done); })); - it('can add, get, and remove manifests', checkAndRun(function(done) { + it('can add, get, and remove manifests', checkAndRun((done) => { /** @type {shaka.extern.StorageCell} */ let cell; @@ -133,7 +133,7 @@ describe('IndexeddbStorageCell', function() { }).catch(fail).then(done); })); - it('can add and get all manifests', checkAndRun(function(done) { + it('can add and get all manifests', checkAndRun((done) => { /** @type {shaka.extern.StorageCell} */ let cell; @@ -169,7 +169,7 @@ describe('IndexeddbStorageCell', function() { }).catch(fail).then(done); })); - it('can add, get, and update manifests', checkAndRun(function(done) { + it('can add, get, and update manifests', checkAndRun((done) => { /** @type {shaka.extern.StorageCell} */ let cell; diff --git a/test/offline/manifest_convert_unit.js b/test/offline/manifest_convert_unit.js index db7d8005a..11319752f 100644 --- a/test/offline/manifest_convert_unit.js +++ b/test/offline/manifest_convert_unit.js @@ -15,12 +15,12 @@ * limitations under the License. */ -describe('ManifestConverter', function() { - describe('createVariants', function() { +describe('ManifestConverter', () => { + describe('createVariants', () => { const audioType = 'audio'; const videoType = 'video'; - it('will create variants with variant ids', function() { + it('will create variants with variant ids', () => { /** @type {!Array.} */ const audios = [ createStreamDB(0, audioType, [0]), @@ -45,7 +45,7 @@ describe('ManifestConverter', function() { expect(variants.get(1).video.id).toBe(3); }); - it('will create variants when there is only audio', function() { + it('will create variants when there is only audio', () => { /** @type {!Array.} */ const audios = [ createStreamDB(0, audioType, [0]), @@ -59,7 +59,7 @@ describe('ManifestConverter', function() { expect(variants.size).toBe(2); }); - it('will create variants when there is only video', function() { + it('will create variants when there is only video', () => { /** @type {!Array.} */ const audios = []; /** @type {!Array.} */ @@ -74,8 +74,8 @@ describe('ManifestConverter', function() { }); }); // describe('createVariants') - describe('fromPeriodDB', function() { - it('will reconstruct Periods correctly', function() { + describe('fromPeriodDB', () => { + it('will reconstruct Periods correctly', () => { /** @type {shaka.extern.PeriodDB} */ const periodDb = { startTime: 60, @@ -102,7 +102,7 @@ describe('ManifestConverter', function() { verifyStream(variant.audio, periodDb.streams[1]); }); - it('supports video-only content', function() { + it('supports video-only content', () => { /** @type {shaka.extern.PeriodDB} */ const periodDb = { startTime: 60, @@ -118,7 +118,7 @@ describe('ManifestConverter', function() { expect(period.variants[0].video).toBeTruthy(); }); - it('supports audio-only content', function() { + it('supports audio-only content', () => { /** @type {shaka.extern.PeriodDB} */ const periodDb = { startTime: 60, @@ -134,7 +134,7 @@ describe('ManifestConverter', function() { expect(period.variants[0].video).toBe(null); }); - it('supports text streams', function() { + it('supports text streams', () => { /** @type {shaka.extern.PeriodDB} */ const periodDb = { startTime: 60, @@ -154,7 +154,7 @@ describe('ManifestConverter', function() { verifyStream(period.textStreams[0], periodDb.streams[1]); }); - it('combines Variants according to variantIds field', function() { + it('combines Variants according to variantIds field', () => { const audio1 = 0; const audio2 = 1; const video1 = 2; @@ -420,7 +420,7 @@ describe('ManifestConverter', function() { // Assume that we don't have to call createSegmentIndex. - streamDb.segments.forEach(function(segmentDb, i) { + streamDb.segments.forEach((segmentDb, i) => { const uri = shaka.offline.OfflineUri.segment( 'mechanism', 'cell', segmentDb.dataKey); @@ -449,7 +449,7 @@ describe('ManifestConverter', function() { /** @type {?shaka.extern.Variant} */ let found = null; - variants.forEach(function(variant) { + variants.forEach((variant) => { /** @type {?shaka.extern.Stream} */ const audio = variant.audio; /** @type {?shaka.extern.Stream} */ diff --git a/test/offline/offline_integration.js b/test/offline/offline_integration.js index 54119ffea..f1c2bc107 100644 --- a/test/offline/offline_integration.js +++ b/test/offline/offline_integration.js @@ -25,16 +25,16 @@ describe('Offline', () => { /** @type {!shaka.util.EventManager} */ let eventManager; - beforeAll(function() { + beforeAll(() => { video = shaka.util.Dom.createVideoElement(); document.body.appendChild(video); }); - afterAll(function() { + afterAll(() => { document.body.removeChild(video); }); - beforeEach(async function() { + beforeEach(async () => { player = new shaka.Player(video); player.addEventListener('error', fail); @@ -47,7 +47,7 @@ describe('Offline', () => { } }); - afterEach(async function() { + afterEach(async () => { eventManager.release(); if (storage) { @@ -64,7 +64,7 @@ describe('Offline', () => { } }); - it('stores, plays, and deletes clear content', async function() { + it('stores, plays, and deletes clear content', async () => { if (!supportsStorage()) { pending('Storage is not supported.'); return; @@ -88,7 +88,7 @@ describe('Offline', () => { // TODO: Add a PlayReady version once Edge supports offline. drmIt( 'stores, plays, and deletes protected content with a persistent license', - async function() { + async () => { if (!supportsStorage()) { pending('Storage is not supported on this platform.'); return; @@ -128,7 +128,7 @@ describe('Offline', () => { drmIt( 'stores, plays, and deletes protected content with a temporary license', - async function() { + async () => { if (!supportsStorage()) { pending('Storage is not supported.'); return; diff --git a/test/offline/offline_manifest_parser_unit.js b/test/offline/offline_manifest_parser_unit.js index cd598cb29..2c731b546 100644 --- a/test/offline/offline_manifest_parser_unit.js +++ b/test/offline/offline_manifest_parser_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('OfflineManifestParser', function() { +describe('OfflineManifestParser', () => { // The offline manifest parser does not need the player interface, so // this is a work around to avoid creating one. const playerInterface = @@ -27,19 +27,19 @@ describe('OfflineManifestParser', function() { /** @type {!shaka.offline.OfflineManifestParser} */ let parser; - beforeEach(checkAndRun(async function() { + beforeEach(checkAndRun(async () => { // Make sure we start with a clean slate. await clearStorage(); parser = new shaka.offline.OfflineManifestParser(); })); - afterEach(checkAndRun(async function() { + afterEach(checkAndRun(async () => { parser.stop(); // Make sure that we don't waste storage by leaving stuff in storage. await clearStorage(); })); - it('returns manifest from storage', checkAndRun(async function() { + it('returns manifest from storage', checkAndRun(async () => { const inputManifest = makeManifest(); /** @type {!shaka.offline.OfflineUri} */ @@ -63,7 +63,7 @@ describe('OfflineManifestParser', function() { expect(outputManifest).toBeTruthy(); })); - it('updates expiration', checkAndRun(async function() { + it('updates expiration', checkAndRun(async () => { const newExpiration = 1000; const inputManifest = makeManifest(); @@ -94,7 +94,7 @@ describe('OfflineManifestParser', function() { } })); - it('fails if manifest was not found', checkAndRun(async function() { + it('fails if manifest was not found', checkAndRun(async () => { const inputManifest = makeManifest(); /** @type {!shaka.offline.OfflineUri} */ @@ -125,7 +125,7 @@ describe('OfflineManifestParser', function() { } })); - it('fails for invalid URI', checkAndRun(async function() { + it('fails for invalid URI', checkAndRun(async () => { const uri = 'this-is-an-invalid-uri'; try { @@ -137,7 +137,7 @@ describe('OfflineManifestParser', function() { })); it('ignores update expiration when data is deleted', - checkAndRun(async function() { + checkAndRun(async () => { const newExpiration = 1000; const inputManifest = makeManifest(); @@ -165,7 +165,7 @@ describe('OfflineManifestParser', function() { })); it('ignores update expiration with unknown session', - checkAndRun(async function() { + checkAndRun(async () => { const wrongSession = 'this-session-wont-be-found'; const newExpiration = 1000; diff --git a/test/offline/offline_scheme_unit.js b/test/offline/offline_scheme_unit.js index 408102c75..9f6ff0723 100644 --- a/test/offline/offline_scheme_unit.js +++ b/test/offline/offline_scheme_unit.js @@ -15,19 +15,19 @@ * limitations under the License. */ -describe('OfflineScheme', function() { - beforeEach(checkAndRun(async function() { +describe('OfflineScheme', () => { + beforeEach(checkAndRun(async () => { // Make sure we start with a clean slate. await clearStorage(); })); - afterEach(checkAndRun(async function() { + afterEach(checkAndRun(async () => { // Make sure that we don't waste storage by leaving stuff in storage. await clearStorage(); })); it('returns special content-type header for manifests', - checkAndRun(async function() { + checkAndRun(async () => { const expectedContentType = 'application/x-offline-manifest'; const request = createRequest(); /** @type {!shaka.offline.OfflineUri} */ @@ -43,7 +43,7 @@ describe('OfflineScheme', function() { expect(response.headers['content-type']).toBe(expectedContentType); })); - it('returns segment data from storage', checkAndRun(async function() { + it('returns segment data from storage', checkAndRun(async () => { const request = createRequest(); const segment = createSegment(); @@ -71,7 +71,7 @@ describe('OfflineScheme', function() { expect(response.data.byteLength).toBe(segment.data.byteLength); })); - it('fails if segment not found', checkAndRun(async function() { + it('fails if segment not found', checkAndRun(async () => { const request = createRequest(); /** @type {!shaka.offline.OfflineUri} */ @@ -102,7 +102,7 @@ describe('OfflineScheme', function() { } })); - it('fails for invalid URI', checkAndRun(async function() { + it('fails for invalid URI', checkAndRun(async () => { const request = createRequest(); const uri = 'this-in-an-invalid-uri'; diff --git a/test/offline/offline_uri_unit.js b/test/offline/offline_uri_unit.js index 6a3c8a4c6..007e9b9c0 100644 --- a/test/offline/offline_uri_unit.js +++ b/test/offline/offline_uri_unit.js @@ -15,10 +15,10 @@ * limitations under the License. */ -describe('OfflineUri', function() { +describe('OfflineUri', () => { const OfflineUri = shaka.offline.OfflineUri; - it('creates uri from manifest id', function() { + it('creates uri from manifest id', () => { /** @type {number} */ const id = 123; /** @type {string} */ @@ -27,7 +27,7 @@ describe('OfflineUri', function() { expect(uri).toBe('offline:manifest/mech/cell/123'); }); - it('creates uri from segment id', function() { + it('creates uri from segment id', () => { /** @type {number} */ const id = 123; /** @type {string} */ @@ -36,7 +36,7 @@ describe('OfflineUri', function() { expect(uri).toBe('offline:segment/mech/cell/123'); }); - it('creates null from invalid uri', function() { + it('creates null from invalid uri', () => { /** @type {string} */ const uri = 'invalid-uri'; const parsed = OfflineUri.parse(uri); @@ -44,7 +44,7 @@ describe('OfflineUri', function() { expect(parsed).toBeNull(); }); - it('parse manifest uri', function() { + it('parse manifest uri', () => { /** @type {string} */ const uri = 'offline:manifest/mech/cell/123'; const parsed = OfflineUri.parse(uri); @@ -56,7 +56,7 @@ describe('OfflineUri', function() { expect(parsed.key()).toBe(123); }); - it('parse segment uri', function() { + it('parse segment uri', () => { /** @type {string} */ const uri = 'offline:segment/mech/cell/123'; const parsed = OfflineUri.parse(uri); diff --git a/test/offline/storage_unit.js b/test/offline/storage_unit.js index 7ae7e5dbe..176bc9311 100644 --- a/test/offline/storage_unit.js +++ b/test/offline/storage_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Storage', function() { +describe('Storage', () => { const englishUS = 'en-us'; const frenchCanadian= 'fr-ca'; @@ -45,22 +45,22 @@ describe('Storage', function() { await eraseStorage(); }); - describe('storage delete all', function() { + describe('storage delete all', () => { /** @type {!shaka.Player} */ let player; - beforeEach(function() { + beforeEach(() => { // Use a real Player since Storage only uses the configuration and // networking engine. This allows us to use Player.configure in these // tests. player = new shaka.Player(); }); - afterEach(async function() { + afterEach(async () => { await player.destroy(); }); - it('removes all content from storage', checkAndRun(async function() { + it('removes all content from storage', checkAndRun(async () => { const TestManifestParser = shaka.test.TestScheme.ManifestParser; const manifestUri = 'test:sintel'; @@ -104,13 +104,13 @@ describe('Storage', function() { } }); - describe('persistent license', function() { + describe('persistent license', () => { /** @type {!shaka.Player} */ let player; /** @type {!shaka.offline.Storage} */ let storage; - beforeEach(function() { + beforeEach(() => { // Use a real Player since Storage only uses the configuration and // networking engine. This allows us to use Player.configure in these // tests. @@ -118,7 +118,7 @@ describe('Storage', function() { storage = new shaka.offline.Storage(player); }); - afterEach(async function() { + afterEach(async () => { await storage.destroy(); await player.destroy(); }); @@ -130,7 +130,7 @@ describe('Storage', function() { // http://crbug.com/887635 // http://crbug.com/883895 quarantinedIt('removes persistent license', - drmCheckAndRun(async function() { + drmCheckAndRun(async () => { const TestManifestParser = shaka.test.TestScheme.ManifestParser; // PART 1 - Download and store content that has a persistent license @@ -198,7 +198,7 @@ describe('Storage', function() { // http://crbug.com/887635 // http://crbug.com/883895 quarantinedIt('defers removing licenses on error', - drmCheckAndRun(async function() { + drmCheckAndRun(async () => { const TestManifestParser = shaka.test.TestScheme.ManifestParser; const getEmeSessions = async () => { /** @type {!shaka.offline.StorageMuxer} */ @@ -279,10 +279,10 @@ describe('Storage', function() { })); }); - describe('default track selection callback', function() { + describe('default track selection callback', () => { const PlayerConfiguration = shaka.util.PlayerConfiguration; - it('selects the largest SD video with middle quality audio', function() { + it('selects the largest SD video with middle quality audio', () => { const tracks = [ variantTrack(0, 360, englishUS, 1 * kbps), variantTrack(1, 480, englishUS, 2.0 * kbps), @@ -302,7 +302,7 @@ describe('Storage', function() { expect(selected[0].bandwidth).toBe(2.1 * kbps); }); - it('selects all text tracks', function() { + it('selects all text tracks', () => { const tracks = [ textTrack(0, englishUS), textTrack(1, frenchCanadian), @@ -317,8 +317,8 @@ describe('Storage', function() { }); }); - describe('language matching', function() { - it('finds exact match', function() { + describe('language matching', () => { + it('finds exact match', () => { const tracks = [ variantTrack(0, 480, 'eng-us', 1 * kbps), variantTrack(1, 480, 'fr-ca', 1 * kbps), @@ -333,7 +333,7 @@ describe('Storage', function() { expect(selected[0].language).toBe('eng-us'); }); - it('finds exact match with only base', function() { + it('finds exact match with only base', () => { const tracks = [ variantTrack(0, 480, 'eng-us', 1 * kbps), variantTrack(1, 480, 'fr-ca', 1 * kbps), @@ -348,7 +348,7 @@ describe('Storage', function() { expect(selected[0].language).toBe('eng'); }); - it('finds base match when exact match is not found', function() { + it('finds base match when exact match is not found', () => { const tracks = [ variantTrack(0, 480, 'eng-us', 1 * kbps), variantTrack(1, 480, 'fr-ca', 1 * kbps), @@ -362,7 +362,7 @@ describe('Storage', function() { expect(selected[0].language).toBe('fr-ca'); }); - it('finds common base when exact match is not found', function() { + it('finds common base when exact match is not found', () => { const tracks = [ variantTrack(0, 480, 'eng-us', 1 * kbps), variantTrack(1, 480, 'fr-ca', 1 * kbps), @@ -377,7 +377,7 @@ describe('Storage', function() { expect(selected[0].language).toBe('fr-ca'); }); - it('finds primary track when no match is found', function() { + it('finds primary track when no match is found', () => { const tracks = [ variantTrack(0, 480, 'eng-us', 1 * kbps), variantTrack(1, 480, 'fr-ca', 1 * kbps), @@ -396,27 +396,27 @@ describe('Storage', function() { }); // describe('default track selection callback') - describe('no support', function() { + describe('no support', () => { /** @type {!shaka.Player} */ let player; /** @type {!shaka.offline.Storage} */ let storage; - beforeEach(function() { + beforeEach(() => { shaka.offline.StorageMuxer.overrideSupport(new Map()); player = new shaka.Player(); storage = new shaka.offline.Storage(player); }); - afterEach(async function() { + afterEach(async () => { await storage.destroy(); await player.destroy(); shaka.offline.StorageMuxer.clearOverride(); }); - it('throws error using list', async function() { + it('throws error using list', async () => { try { await storage.list(); fail(); @@ -425,7 +425,7 @@ describe('Storage', function() { } }); - it('throws error using store', async function() { + it('throws error using store', async () => { try { await storage.store('the-uri-wont-matter'); fail(); @@ -434,7 +434,7 @@ describe('Storage', function() { } }); - it('throws error using remove', async function() { + it('throws error using remove', async () => { try { await storage.remove('the-uri-wont-matter'); fail(); @@ -456,7 +456,7 @@ describe('Storage', function() { // // To allow us to control the network order, our manifests for these tests // could not repeat/reuse segments uris. - describe('reports progress on store', function() { + describe('reports progress on store', () => { const audioSegment1Uri = 'audio-segment-1'; const audioSegment2Uri = 'audio-segment-2'; const audioSegment3Uri = 'audio-segment-3'; @@ -472,7 +472,7 @@ describe('Storage', function() { /** @type {!shaka.offline.Storage} */ let storage; - beforeEach(function() { + beforeEach(() => { // Use these promises to ensure that the data from networking // engine arrives in the correct order. const delays = {}; @@ -529,12 +529,12 @@ describe('Storage', function() { }); }); - afterEach(async function() { + afterEach(async () => { await storage.destroy(); await player.destroy(); }); - it('uses stream bandwidth', checkAndRun(async function() { + it('uses stream bandwidth', checkAndRun(async () => { /** * These numbers are the overall progress based on the segment sizes * per stream. We assume a specific download order for the content @@ -553,7 +553,7 @@ describe('Storage', function() { })); it('uses variant bandwidth when stream bandwidth is unavailable', - checkAndRun(async function() { + checkAndRun(async () => { /** * These numbers are the overall progress based on the segment sizes * per stream. We assume a specific download order for the content @@ -691,7 +691,7 @@ describe('Storage', function() { } }); - describe('basic function', function() { + describe('basic function', () => { /** * Keep a reference to the networking engine so that we can interrupt * networking calls. @@ -704,25 +704,25 @@ describe('Storage', function() { /** @type {!shaka.offline.Storage} */ let storage; - beforeEach(function() { + beforeEach(() => { netEngine = makeNetworkEngine(); // Use a real Player since Storage only uses the configuration and // networking engine. This allows us to use Player.configure in these // tests. - player = new shaka.Player(null, function(player) { + player = new shaka.Player(null, ((player) => { player.createNetworkingEngine = () => netEngine; - }); + })); storage = new shaka.offline.Storage(player); }); - afterEach(async function() { + afterEach(async () => { await storage.destroy(); await player.destroy(); }); - it('stores and lists content', checkAndRun(async function() { + it('stores and lists content', checkAndRun(async () => { // Just use any three manifests as we don't care about the manifests // right now. const manifestUris = [ @@ -749,7 +749,7 @@ describe('Storage', function() { }); })); - it('only stores chosen tracks', checkAndRun(async function() { + it('only stores chosen tracks', checkAndRun(async () => { // Change storage to only store one track so that it will be easy // for use to ensure that only the one track was stored. const selectTrack = (tracks) => { @@ -807,7 +807,7 @@ describe('Storage', function() { } })); - it('stores drm info without license', checkAndRun(async function() { + it('stores drm info without license', checkAndRun(async () => { const drmInfo = makeDrmInfo(); const session1 = 'session-1'; const session2 = 'session-2'; @@ -857,7 +857,7 @@ describe('Storage', function() { // Make sure that when we configure storage to NOT store persistent // licenses that we don't store the sessions. it('stores drm info with no license', - checkAndRun(async function() { + checkAndRun(async () => { const drmInfo = makeDrmInfo(); const session1 = 'session-1'; const session2 = 'session-2'; @@ -907,7 +907,7 @@ describe('Storage', function() { // TODO(vaage): Remove the need to limit the number of store commands. With // all the changes, it should be very easy to do now. it('throws an error if another store is in progress', - checkAndRun(async function() { + checkAndRun(async () => { // Block the network so that we won't finish the first store command. /** @type {!shaka.util.PublicPromise} */ const hangingPromise = netEngine.delayNextRequest(); @@ -934,7 +934,7 @@ describe('Storage', function() { })); it('throws an error if the content is a live stream', - checkAndRun(async function() { + checkAndRun(async () => { try { await storage.store( manifestWithLiveTimelineUri, @@ -947,7 +947,7 @@ describe('Storage', function() { })); it('throws an error if DRM sessions are not ready', - checkAndRun(async function() { + checkAndRun(async () => { const drmInfo = makeDrmInfo(); const noSessions = []; @@ -970,7 +970,7 @@ describe('Storage', function() { } })); - it('throws an error if destroyed mid-store', checkAndRun(async function() { + it('throws an error if destroyed mid-store', checkAndRun(async () => { const manifest = makeManifestWithPerStreamBandwidth(); /** @@ -1002,7 +1002,7 @@ describe('Storage', function() { } })); - it('stops for networking errors', checkAndRun(async function() { + it('stops for networking errors', checkAndRun(async () => { // Force all network requests to fail. netEngine.request.and.callFake(() => { return shaka.util.AbortableOperation.failed(new shaka.util.Error( @@ -1024,7 +1024,7 @@ describe('Storage', function() { })); it('throws an error if removing malformed uri', - checkAndRun(async function() { + checkAndRun(async () => { const badUri = 'this-is-an-invalid-uri'; try { await storage.remove(badUri); @@ -1035,7 +1035,7 @@ describe('Storage', function() { })); it('throws an error if removing missing manifest', - checkAndRun(async function() { + checkAndRun(async () => { // Store a piece of content, but then change the uri slightly so that // it won't be found when we try to remove it (with the wrong uri). const stored = await storage.store( @@ -1054,14 +1054,14 @@ describe('Storage', function() { } })); - it('removes manifest', checkAndRun(async function() { + it('removes manifest', checkAndRun(async () => { const stored = await storage.store( manifestWithPerStreamBandwidthUri, noMetadata, FakeManifestParser); await storage.remove(stored.offlineUri); })); - it('removes manifest with missing segments', checkAndRun(async function() { + it('removes manifest with missing segments', checkAndRun(async () => { const stored = await storage.store( manifestWithPerStreamBandwidthUri, noMetadata, FakeManifestParser); @@ -1098,7 +1098,7 @@ describe('Storage', function() { await storage.remove(uri.toString()); })); - it('tracks progress on remove', checkAndRun(async function() { + it('tracks progress on remove', checkAndRun(async () => { const selectOneTrack = (tracks) => { const allVariants = tracks.filter((t) => { return t.type == 'variant'; @@ -1150,11 +1150,11 @@ describe('Storage', function() { })); }); - describe('storage without player', function() { + describe('storage without player', () => { const TestManifestParser = shaka.test.TestScheme.ManifestParser; const manifestUri = 'test:sintel'; - it('stores content', checkAndRun(async function() { + it('stores content', checkAndRun(async () => { /** @type {shaka.offline.Storage} */ const storage = new shaka.offline.Storage(); try { diff --git a/test/offline/v1_indexeddb_storage_unit.js b/test/offline/v1_indexeddb_storage_unit.js index 24a4419d3..72d4cf7dc 100644 --- a/test/offline/v1_indexeddb_storage_unit.js +++ b/test/offline/v1_indexeddb_storage_unit.js @@ -16,7 +16,7 @@ */ -describe('V1IndexeddbStorageCell', function() { +describe('V1IndexeddbStorageCell', () => { const dbImagePath = '/base/test/test/assets/db-dump-v1.json'; const dbName = 'shaka-storage-cell-test'; @@ -32,17 +32,17 @@ describe('V1IndexeddbStorageCell', function() { /** @type {!Array.} */ let connections = []; - beforeAll(async function() { + beforeAll(async () => { const data = await shaka.test.Util.fetch(dbImagePath); dbImageAsString = shaka.util.StringUtils.fromUTF8(data); }); - beforeEach(function() { + beforeEach(() => { cells = []; connections = []; }); - afterEach(async function() { + afterEach(async () => { // If the test did not run, then there will be no cells and no connections, // so we don't need to worry about checking if indexeddb is supported here. @@ -51,7 +51,7 @@ describe('V1IndexeddbStorageCell', function() { connections.forEach((connection) => connection.close()); }); - it('cannot add new manifests', checkAndRun(async function() { + it('cannot add new manifests', checkAndRun(async () => { const expectedErrorCode = shaka.util.Error.Code.NEW_KEY_OPERATION_NOT_SUPPORTED; @@ -72,7 +72,7 @@ describe('V1IndexeddbStorageCell', function() { } })); - it('cannot add new segment', checkAndRun(async function() { + it('cannot add new segment', checkAndRun(async () => { const expectedErrorCode = shaka.util.Error.Code.NEW_KEY_OPERATION_NOT_SUPPORTED; @@ -91,7 +91,7 @@ describe('V1IndexeddbStorageCell', function() { } })); - it('can get all manifests', checkAndRun(async function() { + it('can get all manifests', checkAndRun(async () => { const connection = await makeConnection(); const cell = makeCell(connection); @@ -102,7 +102,7 @@ describe('V1IndexeddbStorageCell', function() { expect(map.get(0)).toBeTruthy(); })); - it('can get manifest and all segments', checkAndRun(async function() { + it('can get manifest and all segments', checkAndRun(async () => { const connection = await makeConnection(); const cell = makeCell(connection); @@ -123,7 +123,7 @@ describe('V1IndexeddbStorageCell', function() { }); })); - it('can update expiration', checkAndRun(async function() { + it('can update expiration', checkAndRun(async () => { // Keys and old values are pulled directly from the db image. const manifestKey = 0; const oldExpiration = Infinity; @@ -145,7 +145,7 @@ describe('V1IndexeddbStorageCell', function() { expect(updated[0].expiration).toBe(newExpiration); })); - it('can remove manifests and segments', checkAndRun(async function() { + it('can remove manifests and segments', checkAndRun(async () => { const connection = await makeConnection(); const cell = makeCell(connection); diff --git a/test/player_integration.js b/test/player_integration.js index bfea0a420..679dd3a91 100644 --- a/test/player_integration.js +++ b/test/player_integration.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Player', function() { +describe('Player', () => { const Util = shaka.test.Util; const waitUntilPlayheadReaches = Util.waitUntilPlayheadReaches; @@ -39,14 +39,14 @@ describe('Player', function() { await shaka.test.TestScheme.createManifests(compiledShaka, '_compiled'); }); - beforeEach(function() { + beforeEach(() => { player = new compiledShaka.Player(video); // Grab event manager from the uncompiled library: eventManager = new shaka.util.EventManager(); onErrorSpy = jasmine.createSpy('onError'); - onErrorSpy.and.callFake(function(event) { fail(event.detail); }); + onErrorSpy.and.callFake((event) => { fail(event.detail); }); eventManager.listen(player, 'error', Util.spyFunc(onErrorSpy)); }); @@ -56,12 +56,12 @@ describe('Player', function() { await player.destroy(); }); - afterAll(function() { + afterAll(() => { document.body.removeChild(video); }); - describe('attach', function() { - beforeEach(async function() { + describe('attach', () => { + beforeEach(async () => { // To test attach, we want to construct a player without a video element // attached in advance. To do that, we destroy the player that was // constructed in the outermost beforeEach(), then construct a new one @@ -70,13 +70,13 @@ describe('Player', function() { player = new compiledShaka.Player(); }); - it('can be used before load()', async function() { + it('can be used before load()', async () => { await player.attach(video); await player.load('test:sintel_compiled'); }); }); - describe('getStats', function() { + describe('getStats', () => { it('gives stats about current stream', async () => { // This is tested more in player_unit.js. This is here to test the public // API and to check for renaming. @@ -119,7 +119,7 @@ describe('Player', function() { }); }); - describe('setTextTrackVisibility', function() { + describe('setTextTrackVisibility', () => { // Using mode='disabled' on TextTrack causes cues to go null, which leads // to a crash in TextEngine. This validates that we do not trigger this // behavior when changing visibility of text. @@ -252,7 +252,7 @@ describe('Player', function() { }); }); - describe('plays', function() { + describe('plays', () => { it('with external text tracks', async () => { await player.load('test:sintel_no_text_compiled'); @@ -313,7 +313,7 @@ describe('Player', function() { * @return {string} */ function getActiveLanguage() { - const tracks = player.getVariantTracks().filter(function(t) { + const tracks = player.getVariantTracks().filter((t) => { return t.active; }); expect(tracks.length).toBeGreaterThan(0); @@ -321,11 +321,11 @@ describe('Player', function() { } }); - describe('TextDisplayer plugin', function() { + describe('TextDisplayer plugin', () => { // Simulate the use of an external TextDisplayer plugin. /** @type {shaka.test.FakeTextDisplayer} */ let textDisplayer; - beforeEach(function() { + beforeEach(() => { textDisplayer = new shaka.test.FakeTextDisplayer(); textDisplayer.isTextVisibleSpy.and.callFake(() => { @@ -354,7 +354,7 @@ describe('Player', function() { }); }); - describe('TextAndRoles', function() { + describe('TextAndRoles', () => { // Regression Test. Makes sure that the language and role fields have been // properly exported from the player. it('exports language and roles fields', async () => { @@ -368,13 +368,13 @@ describe('Player', function() { }); }); - describe('streaming event', function() { + describe('streaming event', () => { // Calling switch early during load() caused a failed assertion in Player // and the track selection was ignored. Because this bug involved // interactions between Player and StreamingEngine, it is an integration // test and not a unit test. // https://github.com/google/shaka-player/issues/1119 - it('allows early selection of specific tracks', function(done) { + it('allows early selection of specific tracks', (done) => { const streamingListener = jasmine.createSpy('listener'); // Because this is an issue with failed assertions, destroy the existing @@ -409,7 +409,7 @@ describe('Player', function() { // between Player and StreamingEngine, it is an integration test and not a // unit test. // https://github.com/google/shaka-player/issues/1119 - it('allows selection of tracks in subsequent loads', function(done) { + it('allows selection of tracks in subsequent loads', (done) => { const streamingListener = jasmine.createSpy('listener'); // Because this is an issue with failed assertions, destroy the existing @@ -479,7 +479,7 @@ describe('Player Stats', () => { // // TODO: Any call to |load|, |attach|, etc. should abort manifest retries. // Add the missing tests for |load| and |attach|. -describe('Player Manifest Retries', function() { +describe('Player Manifest Retries', () => { /** @type {!HTMLVideoElement} */ let video; /** @type {shaka.Player} */ @@ -654,7 +654,7 @@ describe('Player Load Path', () => { expect(video.src).toBeTruthy(); }); - it('does not set video.src when no video is provided', async function() { + it('does not set video.src when no video is provided', async () => { expect(video.src).toBeFalsy(); createPlayer(/* attachedTo= */ null); diff --git a/test/player_unit.js b/test/player_unit.js index 0cc6ae8f0..e0aa7f29c 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Player', function() { +describe('Player', () => { const ContentType = shaka.util.ManifestParserUtils.ContentType; const Util = shaka.test.Util; @@ -61,7 +61,7 @@ describe('Player', function() { /** @type {!shaka.test.FakeVideo} */ let video; - beforeAll(function() { + beforeAll(() => { logErrorSpy = jasmine.createSpy('shaka.log.error'); shaka.log.error = shaka.test.Util.spyFunc(logErrorSpy); logWarnSpy = jasmine.createSpy('shaka.log.warning'); @@ -69,7 +69,7 @@ describe('Player', function() { shaka.log.alwaysWarn = shaka.test.Util.spyFunc(logWarnSpy); }); - beforeEach(function() { + beforeEach(() => { // By default, errors are a failure. logErrorSpy.calls.reset(); logErrorSpy.and.callFake(fail); @@ -141,24 +141,24 @@ describe('Player', function() { }); onError = jasmine.createSpy('error event'); - onError.and.callFake(function(event) { + onError.and.callFake((event) => { fail(event.detail); }); player.addEventListener('error', shaka.test.Util.spyFunc(onError)); }); - afterEach(function(done) { + afterEach((done) => { player.destroy().catch(fail).then(done); }); - afterAll(function() { + afterAll(() => { shaka.log.error = originalLogError; shaka.log.warning = originalLogWarn; shaka.log.alwaysWarn = originalLogAlwaysWarn; window.MediaSource.isTypeSupported = originalIsTypeSupported; }); - describe('destroy', function() { + describe('destroy', () => { it('cleans up all dependencies', async () => { goog.asserts.assert(manifest, 'Manifest should be non-null'); const parser = new shaka.test.FakeManifestParser(manifest); @@ -196,19 +196,19 @@ describe('Player', function() { // TODO(vaage): Re-enable once the parser is integrated into the load graph // better. - xit('destroys parser first when interrupting load', function(done) { + xit('destroys parser first when interrupting load', (done) => { const p = shaka.test.Util.delay(0.3); const parser = new shaka.test.FakeManifestParser(manifest); parser.start.and.returnValue(p); - parser.stop.and.callFake(function() { + parser.stop.and.callFake(() => { expect(abrManager.stop).not.toHaveBeenCalled(); expect(networkingEngine.destroy).not.toHaveBeenCalled(); }); const factory = function() { return parser; }; player.load(fakeManifestUri, 0, factory).then(fail).catch(() => {}); - shaka.test.Util.delay(0.1).then(function() { - player.destroy().catch(fail).then(function() { + shaka.test.Util.delay(0.1).then(() => { + player.destroy().catch(fail).then(() => { expect(abrManager.stop).toHaveBeenCalled(); expect(networkingEngine.destroy).toHaveBeenCalled(); expect(parser.stop).toHaveBeenCalled(); @@ -217,7 +217,7 @@ describe('Player', function() { }); }); - describe('load/unload', function() { + describe('load/unload', () => { /** @type {!shaka.test.FakeManifestParser} */ let parser1; /** @type {!Function} */ @@ -225,22 +225,22 @@ describe('Player', function() { /** @type {!jasmine.Spy} */ let checkError; - beforeEach(function() { + beforeEach(() => { goog.asserts.assert(manifest, 'manifest must be non-null'); parser1 = new shaka.test.FakeManifestParser(manifest); factory1 = function() { return parser1; }; checkError = jasmine.createSpy('checkError'); - checkError.and.callFake(function(error) { + checkError.and.callFake((error) => { expect(error.code).toBe(shaka.util.Error.Code.LOAD_INTERRUPTED); }); }); - describe('streaming event', function() { + describe('streaming event', () => { /** @type {jasmine.Spy} */ let streamingListener; - beforeEach(function() { + beforeEach(() => { streamingListener = jasmine.createSpy('listener'); player.addEventListener('streaming', Util.spyFunc(streamingListener)); @@ -265,7 +265,7 @@ describe('Player', function() { } it('fires after tracks exist', async () => { - streamingListener.and.callFake(function() { + streamingListener.and.callFake(() => { const tracks = player.getVariantTracks(); expect(tracks).toBeDefined(); expect(tracks.length).toBeGreaterThan(0); @@ -274,7 +274,7 @@ describe('Player', function() { }); it('fires before any tracks are active', async () => { - streamingListener.and.callFake(function() { + streamingListener.and.callFake(() => { const activeTracks = player.getVariantTracks().filter((t) => t.active); expect(activeTracks.length).toEqual(0); @@ -287,7 +287,7 @@ describe('Player', function() { // later be removed during filtering. // https://github.com/google/shaka-player/issues/1119 it('fires after tracks have been filtered', async () => { - streamingListener.and.callFake(function() { + streamingListener.and.callFake(() => { const tracks = player.getVariantTracks(); // Either WebM, or MP4, but not both. expect(tracks.length).toEqual(1); @@ -296,8 +296,8 @@ describe('Player', function() { }); }); - describe('setTextTrackVisibility', function() { - beforeEach(function() { + describe('setTextTrackVisibility', () => { + beforeEach(() => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0) @@ -342,8 +342,8 @@ describe('Player', function() { }); }); // describe('load/unload') - describe('getConfiguration', function() { - it('returns a copy of the configuration', function() { + describe('getConfiguration', () => { + it('returns a copy of the configuration', () => { const config1 = player.getConfiguration(); config1.streaming.bufferBehind = -99; const config2 = player.getConfiguration(); @@ -352,8 +352,8 @@ describe('Player', function() { }); }); - describe('configure', function() { - it('overwrites defaults', function() { + describe('configure', () => { + it('overwrites defaults', () => { const defaultConfig = player.getConfiguration(); // Make sure the default differs from our test value: expect(defaultConfig.drm.retryParameters.backoffFactor).not.toBe(5); @@ -371,7 +371,7 @@ describe('Player', function() { expect(newConfig.manifest.retryParameters.backoffFactor).not.toBe(5); }); - it('reverts to defaults when undefined is given', function() { + it('reverts to defaults when undefined is given', () => { player.configure({ streaming: { retryParameters: {backoffFactor: 5}, @@ -398,7 +398,7 @@ describe('Player', function() { expect(newConfig.streaming.bufferBehind).not.toBe(7); }); - it('restricts the types of config values', function() { + it('restricts the types of config values', () => { logErrorSpy.and.stub(); const defaultConfig = player.getConfiguration(); @@ -424,7 +424,7 @@ describe('Player', function() { stringContaining('.streaming')); }); - it('expands dictionaries that allow arbitrary keys', function() { + it('expands dictionaries that allow arbitrary keys', () => { player.configure({ drm: {servers: {'com.widevine.alpha': 'http://foo/widevine'}}, }); @@ -445,7 +445,7 @@ describe('Player', function() { }); }); - it('expands dictionaries but still restricts their values', function() { + it('expands dictionaries but still restricts their values', () => { // Try a bogus server value (number instead of string) logErrorSpy.and.stub(); player.configure({ @@ -481,7 +481,7 @@ describe('Player', function() { stringContaining('.drm.advanced.ks1.bogus')); }); - it('removes dictionary entries when undefined is given', function() { + it('removes dictionary entries when undefined is given', () => { player.configure({ drm: { servers: { @@ -514,7 +514,7 @@ describe('Player', function() { expect(newConfig.drm.servers).toEqual({}); }); - it('checks the number of arguments to functions', function() { + it('checks the number of arguments to functions', () => { const goodCustomScheme = function(node) {}; const badCustomScheme1 = function() {}; // too few args const badCustomScheme2 = function(x, y) {}; // too many args @@ -562,7 +562,7 @@ describe('Player', function() { }); // Regression test for https://github.com/google/shaka-player/issues/784 - it('does not throw when overwriting serverCertificate', function() { + it('does not throw when overwriting serverCertificate', () => { player.configure({ drm: { advanced: { @@ -584,7 +584,7 @@ describe('Player', function() { }); }); - it('checks the type of serverCertificate', function() { + it('checks the type of serverCertificate', () => { logErrorSpy.and.stub(); player.configure({ @@ -615,7 +615,7 @@ describe('Player', function() { stringContaining('.serverCertificate')); }); - it('does not throw when null appears instead of an object', function() { + it('does not throw when null appears instead of an object', () => { logErrorSpy.and.stub(); player.configure({ @@ -662,7 +662,7 @@ describe('Player', function() { expect(switchVariantSpy).not.toHaveBeenCalled(); }); - it('accepts parameters in a (fieldName, value) format', function() { + it('accepts parameters in a (fieldName, value) format', () => { const oldConfig = player.getConfiguration(); const oldDelayLicense = oldConfig.drm.delayLicenseRequestUntilPlayed; const oldSwitchInterval = oldConfig.abr.switchInterval; @@ -687,7 +687,7 @@ describe('Player', function() { }); it('accepts escaped "." in names', - /** @suppress {accessControls} */ (function() { + /** @suppress {accessControls} */ (() => { expect(player.convertToConfigObject_('foo', 1)).toEqual({foo: 1}); expect(player.convertToConfigObject_('foo.bar', 1)) .toEqual({foo: {bar: 1}}); @@ -709,13 +709,13 @@ describe('Player', function() { .toEqual({'.foo': 1}); })); - it('returns whether the config was valid', function() { + it('returns whether the config was valid', () => { logErrorSpy.and.stub(); expect(player.configure({streaming: {bufferBehind: '77'}})).toBe(false); expect(player.configure({streaming: {bufferBehind: 77}})).toBe(true); }); - it('still sets other fields when there are errors', function() { + it('still sets other fields when there are errors', () => { logErrorSpy.and.stub(); const changes = { @@ -745,7 +745,7 @@ describe('Player', function() { }); }); - describe('resetConfiguration', function() { + describe('resetConfiguration', () => { it('resets configurations to default', () => { const default_ = player.getConfiguration().streaming.bufferingGoal; expect(default_).not.toBe(100); @@ -771,13 +771,13 @@ describe('Player', function() { }); }); - describe('AbrManager', function() { + describe('AbrManager', () => { /** @type {!shaka.test.FakeManifestParser} */ let parser; /** @type {!Function} */ let parserFactory; - beforeEach(function() { + beforeEach(() => { goog.asserts.assert(manifest, 'manifest must be non-null'); parser = new shaka.test.FakeManifestParser(manifest); parserFactory = function() { return parser; }; @@ -865,8 +865,8 @@ describe('Player', function() { }); }); - describe('filterTracks', function() { - it('retains only video+audio variants if they exist', function(done) { + describe('filterTracks', () => { + it('retains only video+audio variants if they exist', (done) => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(10) @@ -909,7 +909,7 @@ describe('Player', function() { expect(actualVariantTracks1).toEqual(variantTracks1); // Check the second period's variant tracks. - playhead.getTime.and.callFake(function() { + playhead.getTime.and.callFake(() => { return 100; }); const actualVariantTracks2 = player.getVariantTracks(); @@ -918,7 +918,7 @@ describe('Player', function() { }); }); - describe('tracks', function() { + describe('tracks', () => { /** @type {!Array.} */ let variantTracks; /** @type {!Array.} */ @@ -1326,7 +1326,7 @@ describe('Player', function() { await player.load(fakeManifestUri, 0, parserFactory); }); - it('returns the correct tracks', function() { + it('returns the correct tracks', () => { streamingEngine.onCanSwitch(); expect(player.getVariantTracks()).toEqual(variantTracks); @@ -1336,7 +1336,7 @@ describe('Player', function() { it('returns empty arrays before tracks can be determined', async () => { const parser = new shaka.test.FakeManifestParser(manifest); const parserFactory = function() { return parser; }; - parser.start.and.callFake(function(manifestUri, playerInterface) { + parser.start.and.callFake((manifestUri, playerInterface) => { // The player does not yet have a manifest. expect(player.getVariantTracks()).toEqual([]); expect(player.getTextTracks()).toEqual([]); @@ -1360,7 +1360,7 @@ describe('Player', function() { expect(player.getTextTracks()).toEqual(textTracks); }); - it('doesn\'t disable AbrManager if switching variants', function() { + it('doesn\'t disable AbrManager if switching variants', () => { streamingEngine.onCanSwitch(); let config = player.getConfiguration(); @@ -1373,7 +1373,7 @@ describe('Player', function() { expect(config.abr.enabled).toBe(true); }); - it('doesn\'t disable AbrManager if switching text', function() { + it('doesn\'t disable AbrManager if switching text', () => { streamingEngine.onCanSwitch(); let config = player.getConfiguration(); @@ -1386,7 +1386,7 @@ describe('Player', function() { expect(config.abr.enabled).toBe(true); }); - it('switches streams', function() { + it('switches streams', () => { streamingEngine.onCanSwitch(); const newTrack = player.getVariantTracks().filter((t) => !t.active)[0]; @@ -1397,7 +1397,7 @@ describe('Player', function() { expect(variant.id).toEqual(newTrack.id); }); - it('still switches streams if called during startup', function() { + it('still switches streams if called during startup', () => { // startup is not complete until onCanSwitch is called. // pick a track @@ -1414,7 +1414,7 @@ describe('Player', function() { expect(variant.id).toEqual(newTrack.id); }); - it('still switches streams if called while switching Periods', function() { + it('still switches streams if called while switching Periods', () => { // startup is complete after onCanSwitch. streamingEngine.onCanSwitch(); @@ -1438,7 +1438,7 @@ describe('Player', function() { expect(variant.id).toEqual(newTrack.id); }); - it('switching audio doesn\'t change selected text track', function() { + it('switching audio doesn\'t change selected text track', () => { streamingEngine.onCanSwitch(); player.configure({ preferredTextLanguage: 'es', @@ -1464,7 +1464,7 @@ describe('Player', function() { }); it('selectAudioLanguage() takes precedence over ' + - 'preferredAudioLanguage', function() { + 'preferredAudioLanguage', () => { streamingEngine.onCanSwitch(); // This preference is set in beforeEach, before load(). @@ -1481,7 +1481,7 @@ describe('Player', function() { expect(getActiveVariantTrack().language).toBe('es'); }); - it('selectAudioLanguage() respects selected role', function() { + it('selectAudioLanguage() respects selected role', () => { streamingEngine.onCanSwitch(); expect(getActiveVariantTrack().roles).not.toContain('commentary'); @@ -1495,7 +1495,7 @@ describe('Player', function() { expect(getActiveVariantTrack().roles).toContain('commentary'); }); - it('selectAudioLanguage() does not change selected text track', function() { + it('selectAudioLanguage() does not change selected text track', () => { // This came up in a custom application that allows to select // from all tracks regardless of selected language. // We imitate this behavior by calling selectTextLanguage() @@ -1523,7 +1523,7 @@ describe('Player', function() { }); it('selectTextLanguage() takes precedence over ' + - 'preferredTextLanguage', function() { + 'preferredTextLanguage', () => { streamingEngine.onCanSwitch(); // This preference is set in beforeEach, before load(). @@ -1539,7 +1539,7 @@ describe('Player', function() { expect(getActiveTextTrack().language).toBe('en'); }); - it('selectTextLanguage() respects selected role', function() { + it('selectTextLanguage() respects selected role', () => { streamingEngine.onCanSwitch(); expect(getActiveTextTrack().roles).not.toContain('commentary'); @@ -1552,7 +1552,7 @@ describe('Player', function() { expect(getActiveTextTrack().roles).toContain('commentary'); }); - it('changing current audio language changes active stream', function() { + it('changing current audio language changes active stream', () => { streamingEngine.onCanSwitch(); expect(getActiveVariantTrack().language).not.toBe('es'); @@ -1566,7 +1566,7 @@ describe('Player', function() { expect(getActiveVariantTrack().language).toBe('es'); }); - it('changing current text language changes active stream', function() { + it('changing current text language changes active stream', () => { streamingEngine.onCanSwitch(); expect(getActiveTextTrack().language).not.toBe('en'); @@ -1661,7 +1661,7 @@ describe('Player', function() { }); }); // describe('tracks') - describe('languages', function() { + describe('languages', () => { it('chooses the first as default', async () => { await runTest(['en', 'es'], 'pt', 0); }); @@ -1777,14 +1777,14 @@ describe('Player', function() { const parser = new shaka.test.FakeManifestParser(manifest); const factory = function() { return parser; }; - return player.load(fakeManifestUri, 0, factory).then(function() { + return player.load(fakeManifestUri, 0, factory).then(() => { expect(getActiveVariantTrack().id).toBe(expectedIndex); }); } }); - describe('getStats', function() { - beforeAll(function() { + describe('getStats', () => { + beforeAll(() => { jasmine.clock().install(); jasmine.clock().mockDate(); }); @@ -1823,17 +1823,17 @@ describe('Player', function() { streamingEngine.onCanSwitch(); }); - afterAll(function() { + afterAll(() => { jasmine.clock().uninstall(); }); - it('tracks estimated bandwidth', function() { + it('tracks estimated bandwidth', () => { abrManager.getBandwidthEstimate.and.returnValue(25); const stats = player.getStats(); expect(stats.estimatedBandwidth).toBe(25); }); - it('tracks info about current stream', function() { + it('tracks info about current stream', () => { const stats = player.getStats(); // Should have chosen the first of each type of stream. expect(stats.width).toBe(100); @@ -1841,7 +1841,7 @@ describe('Player', function() { expect(stats.streamBandwidth).toBe(200); }); - it('tracks frame info', function() { + it('tracks frame info', () => { // getVideoPlaybackQuality does not exist yet. let stats = player.getStats(); expect(stats.decodedFrames).toBeNaN(); @@ -1863,8 +1863,8 @@ describe('Player', function() { expect(stats.droppedFrames).toBe(125); }); - describe('buffer/play times', function() { - it('tracks play time', function() { + describe('buffer/play times', () => { + it('tracks play time', () => { let stats = player.getStats(); expect(stats.playTime).toBeCloseTo(0); expect(stats.bufferingTime).toBeCloseTo(0); @@ -1878,7 +1878,7 @@ describe('Player', function() { expect(stats.bufferingTime).toBeCloseTo(0); }); - it('tracks buffering time', function() { + it('tracks buffering time', () => { let stats = player.getStats(); expect(stats.playTime).toBeCloseTo(0); expect(stats.bufferingTime).toBeCloseTo(0); @@ -1891,7 +1891,7 @@ describe('Player', function() { expect(stats.bufferingTime).toBeCloseTo(5); }); - it('tracks correct time when switching states', function() { + it('tracks correct time when switching states', () => { forceBufferingTo(false); jasmine.clock().tick(3000); forceBufferingTo(true); @@ -1907,13 +1907,13 @@ describe('Player', function() { }); }); - describe('.switchHistory', function() { - it('includes original choices', function() { + describe('.switchHistory', () => { + it('includes original choices', () => { // checkHistory prepends the initial stream selections. checkHistory([]); }); - it('includes selectVariantTrack choices', function() { + it('includes selectVariantTrack choices', () => { const track = player.getVariantTracks()[3]; const variants = manifest.periods[0].variants; @@ -1931,7 +1931,7 @@ describe('Player', function() { }]); }); - it('includes adaptation choices', function() { + it('includes adaptation choices', () => { const variant = manifest.periods[0].variants[3]; switch_(variant); @@ -1974,14 +1974,14 @@ describe('Player', function() { } }); - describe('.stateHistory', function() { + describe('.stateHistory', () => { function history() { return player.getStats().stateHistory; } // We expect that the player will start us in the buffering state after // loading. We should see that the only entry is a buffering entry. - it('begins with buffering state', function() { + it('begins with buffering state', () => { expect(history()).toEqual([ { timestamp: jasmine.any(Number), @@ -1994,7 +1994,7 @@ describe('Player', function() { // We expect that the player will start us in the buffering state, but // when the media element is paused, we should see that we change to the // paused state. - it('transitions to paused if the video is paused', function() { + it('transitions to paused if the video is paused', () => { // Start playback, we must be playing in order to be paused. The // buffering state takes precedent over other states, so if we are // buffering and then paused, it will only report buffering. @@ -2025,7 +2025,7 @@ describe('Player', function() { // We expect that the player will start us in the buffering state, but // once we leave that state, we should be playing. - it('transitions to playing if the video is playing', function() { + it('transitions to playing if the video is playing', () => { // Leave buffering (and enter playing). forceBufferingTo(false); @@ -2047,7 +2047,7 @@ describe('Player', function() { // expect that once we reach the end, we will enter the ended state. Since // we must be first playing before reaching the end, this test will // reflect that. - it('transitions to ended when the video ends', function() { + it('transitions to ended when the video ends', () => { // Stop buffering (and start playing); forceBufferingTo(false); @@ -2094,8 +2094,8 @@ describe('Player', function() { } }); - describe('unplayable periods', function() { - beforeEach(function() { + describe('unplayable periods', () => { + beforeEach(() => { // overriding for good / bad codecs. window.MediaSource.isTypeSupported = function(mimeType) { return mimeType.includes('good'); @@ -2211,7 +2211,7 @@ describe('Player', function() { .build(); const parser = new shaka.test.FakeManifestParser(manifest); const factory = function() { return parser; }; - player.load(fakeManifestUri, 0, factory).catch(fail).then(function() { + player.load(fakeManifestUri, 0, factory).catch(fail).then(() => { const manifest2 = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0).bandwidth(500) @@ -2233,7 +2233,7 @@ describe('Player', function() { }); }); - describe('restrictions', function() { + describe('restrictions', () => { it('switches if active is restricted by application', async () => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) @@ -2643,7 +2643,7 @@ describe('Player', function() { await setupPlayer(); expect(player.getVariantTracks().length).toBe(3); - onError.and.callFake(function(e) { + onError.and.callFake((e) => { const error = e.detail; shaka.test.Util.expectToEqualError( error, @@ -2691,7 +2691,7 @@ describe('Player', function() { expect(variants[2].video.codecs).toEqual('good'); }); - it('updates AbrManager about restricted variants', function(done) { + it('updates AbrManager about restricted variants', (done) => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(0) @@ -2702,7 +2702,7 @@ describe('Player', function() { const abrManager = new shaka.test.FakeAbrManager(); player.configure({abrFactory: function() { return abrManager; }}); - setupPlayer().then(function() { + setupPlayer().then(() => { expect(player.getVariantTracks().length).toBe(2); // We have some key statuses, but not for the key IDs we know. @@ -2746,14 +2746,14 @@ describe('Player', function() { function setupPlayer() { const parser = new shaka.test.FakeManifestParser(manifest); const parserFactory = function() { return parser; }; - return player.load(fakeManifestUri, 0, parserFactory).then(function() { + return player.load(fakeManifestUri, 0, parserFactory).then(() => { // Initialize the fake streams. streamingEngine.onCanSwitch(); }); } }); - describe('getPlayheadTimeAsDate()', function() { + describe('getPlayheadTimeAsDate()', () => { beforeEach(async () => { const timeline = new shaka.media.PresentationTimeline(300, 0); timeline.setStatic(false); @@ -2769,13 +2769,13 @@ describe('Player', function() { await player.load(fakeManifestUri, 0, factory); }); - it('gets current wall clock time in UTC', function() { + it('gets current wall clock time in UTC', () => { const liveTimeUtc = player.getPlayheadTimeAsDate(); expect(liveTimeUtc).toEqual(new Date(320000)); }); }); - it('rejects empty manifests', function(done) { + it('rejects empty manifests', (done) => { manifest = new shaka.test.ManifestGenerator().build(); const emptyParser = new shaka.test.FakeManifestParser(manifest); const emptyFactory = function() { return emptyParser; }; @@ -2820,19 +2820,19 @@ describe('Player', function() { abrManager.switchCallback(manifest.periods[0].variants[2]); }); - describe('isTextTrackVisible', function() { - it('does not throw before load', function() { + describe('isTextTrackVisible', () => { + it('does not throw before load', () => { player.isTextTrackVisible(); }); }); - describe('setTextTrackVisibility', function() { - it('does not throw before load', function() { + describe('setTextTrackVisibility', () => { + it('does not throw before load', () => { player.setTextTrackVisibility(true); }); }); - describe('isAudioOnly', function() { + describe('isAudioOnly', () => { it('detects audio-only content', async () => { // This factory recreates the parser each time, so updates to |manifest| // affect the next load() call. @@ -2877,7 +2877,7 @@ describe('Player', function() { }); }); - describe('load', function() { + describe('load', () => { it('tolerates bandwidth of NaN, undefined, or 0', async () => { // Regression test for https://github.com/google/shaka-player/issues/938 manifest = new shaka.test.ManifestGenerator() @@ -2945,13 +2945,13 @@ describe('Player', function() { }); }); - describe('language methods', function() { + describe('language methods', () => { let videoOnlyManifest; const parserFactory = function() { return new shaka.test.FakeManifestParser(manifest); }; - beforeEach(function() { + beforeEach(() => { manifest = new shaka.test.ManifestGenerator() .addPeriod(0) .addVariant(1).language('fr') @@ -2989,7 +2989,7 @@ describe('Player', function() { .build(); }); - describe('get*Languages', function() { + describe('get*Languages', () => { it('returns a list of languages', async () => { await player.load(fakeManifestUri, 0, parserFactory); expect(player.getAudioLanguages()).toEqual(['fr', 'en', 'de']); @@ -3046,7 +3046,7 @@ describe('Player', function() { }); }); - describe('getTextLanguageAndRoles', function() { + describe('getTextLanguageAndRoles', () => { it('lists all language-role combinations', async () => { await player.load(fakeManifestUri, 0, parserFactory); expect(player.getTextLanguagesAndRoles()).toEqual([ @@ -3065,7 +3065,7 @@ describe('Player', function() { * @return {shaka.extern.Track} */ function getActiveVariantTrack() { - const activeTracks = player.getVariantTracks().filter(function(track) { + const activeTracks = player.getVariantTracks().filter((track) => { return track.active; }); @@ -3078,7 +3078,7 @@ describe('Player', function() { * @return {shaka.extern.Track} */ function getActiveTextTrack() { - const activeTracks = player.getTextTracks().filter(function(track) { + const activeTracks = player.getTextTracks().filter((track) => { return track.active; }); diff --git a/test/test/boot.js b/test/test/boot.js index abb3e7b47..7f54ce896 100644 --- a/test/test/boot.js +++ b/test/test/boot.js @@ -100,7 +100,7 @@ function getClientArg(name) { // seems to be OK. I suspect Edge's Promise implementation is actually not in // native code, but rather something like a polyfill that binds to timer calls // the first time it needs to schedule something. - Promise.resolve().then(function() {}); + Promise.resolve().then(() => {}); // Set the default timeout to 120s for all asynchronous tests. jasmine.DEFAULT_TIMEOUT_INTERVAL = 120 * 1000; diff --git a/test/test/util/dash_parser_util.js b/test/test/util/dash_parser_util.js index 8da5465cc..f6cf09c0e 100644 --- a/test/test/util/dash_parser_util.js +++ b/test/test/util/dash_parser_util.js @@ -163,7 +163,7 @@ shaka.test.Dash.makeManifestFromInit = function( createSegmentIndex: jasmine.any(Function), findSegmentPosition: jasmine.any(Function), initSegmentReference: new shaka.media.InitSegmentReference( - function() { return ['http://example.com/' + uri]; }, + (() => { return ['http://example.com/' + uri]; }), startByte, endByte), }), })]); @@ -180,7 +180,7 @@ shaka.test.Dash.makeManifestFromInit = function( */ shaka.test.Dash.callCreateSegmentIndex = function(manifest) { const stream = manifest.periods[0].variants[0].video; - return stream.createSegmentIndex().then(fail).catch(function() {}); + return stream.createSegmentIndex().then(fail).catch(() => {}); }; @@ -194,7 +194,7 @@ shaka.test.Dash.callCreateSegmentIndex = function(manifest) { * @param {!Array.} extraChildren */ shaka.test.Dash.makeTimelineTests = function(type, extraAttrs, extraChildren) { - describe('SegmentTimeline', function() { + describe('SegmentTimeline', () => { const Dash = shaka.test.Dash; const ManifestParser = shaka.test.ManifestParser; const baseUri = 'http://example.com/'; diff --git a/test/test/util/jasmine_fetch.js b/test/test/util/jasmine_fetch.js index 00da35020..bce6c2879 100644 --- a/test/test/util/jasmine_fetch.js +++ b/test/test/util/jasmine_fetch.js @@ -102,7 +102,7 @@ jasmine.Fetch.impl_ = function(url, init) { const headers = {}; const initHeaders = new jasmine.Fetch.Headers(init.headers); - initHeaders.forEach(function(value, key) { + initHeaders.forEach((value, key) => { headers[key] = value; }); @@ -165,8 +165,8 @@ jasmine.Fetch.impl_ = function(url, init) { } else if (stubbed.timeout) { // Fetch does not time out yet, so just return a promise that rejects when // the user aborts. - return new Promise(function(resolve, reject) { - const interval = setInterval(function() { + return new Promise(((resolve, reject) => { + const interval = setInterval(() => { if (init['signal'] && init['signal']()) { // TODO: This assumes that this request is still the most recent. // If you have multiple requests at once, this could be incorrect. @@ -175,7 +175,7 @@ jasmine.Fetch.impl_ = function(url, init) { reject(jasmine.Fetch.makeAbortError_()); } }, 200); - }); + })); } throw new Error('no known action'); }; @@ -262,13 +262,13 @@ jasmine.Fetch.Headers = function(headers) { headers = headers.contents; } if (Array.isArray(headers)) { - headers.forEach(function(header) { + headers.forEach((header) => { this.append(header[0], header[1]); - }.bind(this)); + }); } else { - Object.getOwnPropertyNames(headers).forEach(function(name) { + Object.getOwnPropertyNames(headers).forEach((name) => { this.append(name, headers[name]); - }.bind(this)); + }); } } }; diff --git a/test/test/util/manifest_generator.js b/test/test/util/manifest_generator.js index 02f5e4438..917728cca 100644 --- a/test/test/util/manifest_generator.js +++ b/test/test/util/manifest_generator.js @@ -528,7 +528,7 @@ shaka.test.ManifestGenerator.prototype.createStream_ = } const create = - jasmine.createSpy('createSegmentIndex').and.callFake(function() { + jasmine.createSpy('createSegmentIndex').and.callFake(() => { return Promise.resolve(); }); const find = jasmine.createSpy('findSegmentPosition').and.returnValue(null); diff --git a/test/test/util/offline_utils.js b/test/test/util/offline_utils.js index f3d689be1..8c59d25ad 100644 --- a/test/test/util/offline_utils.js +++ b/test/test/util/offline_utils.js @@ -85,7 +85,7 @@ shaka.test.OfflineUtils.createSegmentData = function(data) { */ shaka.test.OfflineUtils.expectSegmentsToContain = function(segments, expected) { - const actualData = segments.map(function(segment) { + const actualData = segments.map((segment) => { expect(segment.data).toBeTruthy(); return new Uint8Array(segment.data); }); diff --git a/test/test/util/simple_fakes.js b/test/test/util/simple_fakes.js index 765144de5..054b1e7d8 100644 --- a/test/test/util/simple_fakes.js +++ b/test/test/util/simple_fakes.js @@ -52,11 +52,11 @@ shaka.test.FakeAbrManager = function() { ret.chooseIndex = 0; - ret.init.and.callFake(function(switchCallback) { + ret.init.and.callFake((switchCallback) => { ret.switchCallback = switchCallback; }); - ret.setVariants.and.callFake(function(arg) { ret.variants = arg; }); - ret.chooseVariant.and.callFake(function() { + ret.setVariants.and.callFake((arg) => { ret.variants = arg; }); + ret.chooseVariant.and.callFake(() => { return ret.variants[ret.chooseIndex]; }); @@ -137,19 +137,19 @@ shaka.test.FakeStreamingEngine = function(onChooseStreams, onCanSwitch) { ]); ret.destroy.and.callFake(resolve); ret.getBufferingPeriod.and.returnValue(null); - ret.getBufferingAudio.and.callFake(function() { return activeAudio; }); - ret.getBufferingVideo.and.callFake(function() { return activeVideo; }); - ret.getBufferingText.and.callFake(function() { return activeText; }); - ret.loadNewTextStream.and.callFake(function(stream) { + ret.getBufferingAudio.and.callFake(() => { return activeAudio; }); + ret.getBufferingVideo.and.callFake(() => { return activeVideo; }); + ret.getBufferingText.and.callFake(() => { return activeText; }); + ret.loadNewTextStream.and.callFake((stream) => { activeText = stream; return Promise.resolve(); }); - ret.unloadTextStream.and.callFake(function() { + ret.unloadTextStream.and.callFake(() => { activeText = null; }); - ret.start.and.callFake(function() { + ret.start.and.callFake(() => { const chosen = onChooseStreams(); - return Promise.resolve().then(function() { + return Promise.resolve().then(() => { if (chosen.variant && chosen.variant.audio) { activeAudio = chosen.variant.audio; } @@ -161,11 +161,11 @@ shaka.test.FakeStreamingEngine = function(onChooseStreams, onCanSwitch) { } }); }); - ret.switchVariant.and.callFake(function(variant) { + ret.switchVariant.and.callFake((variant) => { activeAudio = variant.audio || activeAudio; activeVideo = variant.video || activeVideo; }); - ret.switchTextStream.and.callFake(function(textStream) { + ret.switchTextStream.and.callFake((textStream) => { activeText = textStream; }); ret.onChooseStreams = onChooseStreams; @@ -207,9 +207,9 @@ shaka.test.FakeManifestParser = function(manifest) { const ret = jasmine.createSpyObj('FakeManifestParser', [ 'start', 'stop', 'configure', 'update', 'onExpirationUpdated', ]); - ret.start.and.callFake(function(manifestUri, playerInterface) { + ret.start.and.callFake((manifestUri, playerInterface) => { ret.playerInterface = playerInterface; - return Promise.resolve().then(function() { + return Promise.resolve().then(() => { return manifest; }); }); @@ -280,12 +280,12 @@ shaka.test.FakeVideo = function(currentTime) { on: {}, // event listeners }; video.setMediaKeys.and.returnValue(Promise.resolve()); - video.addTextTrack.and.callFake(function(kind, id) { + video.addTextTrack.and.callFake((kind, id) => { const track = new shaka.test.FakeTextTrack(); video.textTracks.push(track); return track; }); - video.addEventListener.and.callFake(function(name, callback) { + video.addEventListener.and.callFake((name, callback) => { video.on[name] = callback; }); @@ -338,7 +338,7 @@ shaka.test.FakePresentationTimeline = function() { const getStart = jasmine.createSpy('getSeekRangeStart'); const getEnd = jasmine.createSpy('getSeekRangeEnd'); const getSafeStart = jasmine.createSpy('getSafeSeekRangeStart'); - getSafeStart.and.callFake(function(delay) { + getSafeStart.and.callFake((delay) => { const end = shaka.test.Util.invokeSpy(getEnd); return Math.min(shaka.test.Util.invokeSpy(getStart) + delay, end); }); @@ -522,10 +522,10 @@ shaka.test.FakeTextTrack = function() { removeCue: jasmine.createSpy('removeCue'), cues: [], }; - track.addCue.and.callFake(function(cue) { + track.addCue.and.callFake((cue) => { track.cues.push(cue); }); - track.removeCue.and.callFake(function(cue) { + track.removeCue.and.callFake((cue) => { const idx = track.cues.indexOf(cue); expect(idx).not.toBeLessThan(0); track.cues.splice(idx, 1); diff --git a/test/test/util/stream_generator.js b/test/test/util/stream_generator.js index 6c673682e..887495e6a 100644 --- a/test/test/util/stream_generator.js +++ b/test/test/util/stream_generator.js @@ -186,14 +186,14 @@ shaka.test.Mp4VodStreamGenerator.prototype.init = function() { ]; return Promise.all(async).then( - function(results) { + (results) => { goog.asserts.assert(results.length == 2, 'did not load both segments'); this.initSegment_ = results[0]; this.segmentTemplate_ = results[1]; this.timescale_ = shaka.test.StreamGenerator.getTimescale_( /** @type {!ArrayBuffer} */ (this.initSegment_), this.mdhdOffset_); - }.bind(this)); + }); }; @@ -323,14 +323,14 @@ shaka.test.Mp4LiveStreamGenerator.prototype.init = function() { ]; return Promise.all(async).then( - function(results) { + (results) => { goog.asserts.assert(results.length == 2, 'did not load both segments'); this.initSegment_ = results[0]; this.segmentTemplate_ = results[1]; this.timescale_ = shaka.test.StreamGenerator.getTimescale_( /** @type {!ArrayBuffer} */ (this.initSegment_), this.mdhdOffset_); - }.bind(this)); + }); }; diff --git a/test/test/util/streaming_engine_util.js b/test/test/util/streaming_engine_util.js index d9a2dc427..416310a46 100644 --- a/test/test/util/streaming_engine_util.js +++ b/test/test/util/streaming_engine_util.js @@ -49,7 +49,7 @@ shaka.test.StreamingEngineUtil.createFakeNetworkingEngine = function( }, }; - netEngine.request.and.callFake(function(requestType, request) { + netEngine.request.and.callFake((requestType, request) => { expect(requestType).toBeTruthy(); expect(request.uris.length).toBe(1); @@ -144,32 +144,32 @@ shaka.test.StreamingEngineUtil.createFakePresentationTimeline = function( timeline.getMaxSegmentDuration.and.returnValue(maxSegmentDuration); - timeline.isLive.and.callFake(function() { + timeline.isLive.and.callFake(() => { return isLive; }); - timeline.getEarliestStart.and.callFake(function() { + timeline.getEarliestStart.and.callFake(() => { return timeline.segmentAvailabilityStart; }); - timeline.getSegmentAvailabilityStart.and.callFake(function() { + timeline.getSegmentAvailabilityStart.and.callFake(() => { return timeline.segmentAvailabilityStart; }); - timeline.getSegmentAvailabilityEnd.and.callFake(function() { + timeline.getSegmentAvailabilityEnd.and.callFake(() => { return timeline.segmentAvailabilityEnd; }); - timeline.getSafeSeekRangeStart.and.callFake(function(delay) { + timeline.getSafeSeekRangeStart.and.callFake((delay) => { return shaka.test.Util.invokeSpy(timeline.getSegmentAvailabilityStart) + delay; }); - timeline.getSeekRangeStart.and.callFake(function() { + timeline.getSeekRangeStart.and.callFake(() => { return shaka.test.Util.invokeSpy(timeline.getSegmentAvailabilityStart); }); - timeline.getSeekRangeEnd.and.callFake(function() { + timeline.getSeekRangeEnd.and.callFake(() => { return shaka.test.Util.invokeSpy(timeline.getSegmentAvailabilityEnd); }); diff --git a/test/test/util/test_scheme.js b/test/test/util/test_scheme.js index 88f9e9e87..15ef36d61 100644 --- a/test/test/util/test_scheme.js +++ b/test/test/util/test_scheme.js @@ -367,7 +367,7 @@ shaka.test.TestScheme.setupPlayer = function(player, name) { if (asset.licenseRequestHeaders) { const netEngine = player.getNetworkingEngine(); netEngine.registerRequestFilter( - function(type, request) { + (type, request) => { if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) return; for (const header in asset.licenseRequestHeaders) { @@ -466,7 +466,7 @@ shaka.test.TestScheme.createManifests = function(shaka, suffix) { for (const name in DATA) { GENERATORS[name + suffix] = GENERATORS[name + suffix] || {}; const data = DATA[name]; - [ContentType.VIDEO, ContentType.AUDIO].forEach(function(type) { + [ContentType.VIDEO, ContentType.AUDIO].forEach((type) => { if (data[type]) { const streamGen = createStreamGenerator(data[type]); GENERATORS[name + suffix][type] = streamGen; @@ -572,7 +572,7 @@ shaka.test.TestScheme.createManifests = function(shaka, suffix) { }; -beforeAll(function(done) { +beforeAll((done) => { shaka.test.TestScheme.createManifests(shaka, '').catch(fail).then(done); }); @@ -608,7 +608,7 @@ shaka.test.TestScheme.ManifestParser.prototype.start = // This makes sure the filtering functions are covered implicitly by tests. // This covers regression https://github.com/google/shaka-player/issues/988 playerInterface.filterAllPeriods(manifest.periods); - manifest.periods.forEach(function(period) { + manifest.periods.forEach((period) => { playerInterface.filterNewPeriod(period); }); diff --git a/test/test/util/util.js b/test/test/util/util.js index 66b8bccf2..0c6fe1bef 100644 --- a/test/test/util/util.js +++ b/test/test/util/util.js @@ -29,9 +29,9 @@ goog.provide('shaka.test.Util'); shaka.test.StatusPromise = function(p) { // TODO: investigate using PromiseMock for this when possible. p.status = 'pending'; - p.then(function() { + p.then(() => { p.status = 'resolved'; - }, function() { + }, () => { p.status = 'rejected'; }); return /** @type {!shaka.test.StatusPromise} */(p); @@ -78,16 +78,16 @@ shaka.test.Util.fakeEventLoop = function(duration, onTick) { * @return {!Promise} */ shaka.test.Util.delay = function(seconds, realSetTimeout) { - return new Promise(function(resolve, reject) { + return new Promise(((resolve, reject) => { const timeout = realSetTimeout || setTimeout; - timeout(function() { + timeout(() => { resolve(); // Play nicely with PromiseMock by flushing automatically. if (window.Promise == PromiseMock) { PromiseMock.flush(); } }, seconds * 1000.0); - }); + })); }; @@ -203,7 +203,7 @@ shaka.test.Util.compareReferences = function(first, second) { return false; } if (a.length != b.length || - !a.every(function(x, i) { return x == b[i]; })) { + !a.every((x, i) => { return x == b[i]; })) { return false; } } @@ -228,7 +228,7 @@ shaka.test.Util.compareReferences = function(first, second) { * @return {!Promise.} */ shaka.test.Util.fetch = function(uri) { - return new Promise(function(resolve, reject) { + return new Promise(((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('GET', uri, true /* asynchronous */); xhr.responseType = 'arraybuffer'; @@ -248,7 +248,7 @@ shaka.test.Util.fetch = function(uri) { }; xhr.send(null /* body */); - }); + })); }; @@ -439,8 +439,8 @@ shaka.test.Util.waitUntilPlayheadReaches = let goalMet = false; // TODO: Refactor all the wait utils into a class that avoids repeated args - return new Promise(function(resolve, reject) { - eventManager.listen(target, 'timeupdate', function() { + return new Promise(((resolve, reject) => { + eventManager.listen(target, 'timeupdate', () => { if (target.currentTime >= playheadTime) { goalMet = true; eventManager.unlisten(target, 'timeupdate'); @@ -448,7 +448,7 @@ shaka.test.Util.waitUntilPlayheadReaches = } }); - shaka.test.Util.delay(timeout).then(function() { + shaka.test.Util.delay(timeout).then(() => { if (!goalMet) { const buffered = []; for (let i = 0; i < target.buffered.length; ++i) { @@ -469,7 +469,7 @@ shaka.test.Util.waitUntilPlayheadReaches = reject(new Error('Timeout waiting for time ' + playheadTime)); } }); - }); + })); }; /** @@ -557,7 +557,7 @@ shaka.test.Util.customMatchers_ = { }; -beforeEach(function() { +beforeEach(() => { jasmine.addCustomEqualityTester(shaka.test.Util.compareReferences); jasmine.addMatchers(shaka.test.Util.customMatchers_); }); diff --git a/test/text/cue_integration.js b/test/text/cue_integration.js index a5636f436..3ac43ea48 100644 --- a/test/text/cue_integration.js +++ b/test/text/cue_integration.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Cue', function() { +describe('Cue', () => { // This integration test checks platform support for various cue scenarios // that have caused platform-specific issues. The unit tests for each parser // use a mocked VTTCue implementation, so they do not find platform issues. @@ -23,7 +23,7 @@ describe('Cue', function() { // The scenarios under test are not specific to WebVTT, but WebVTT is used to // exercise the platform's native cues and ensure that no errors occur. - it('handles offsets', function() { + it('handles offsets', () => { // Offsets must be handled early. // See issue #502 const cues = parseVtt( @@ -36,7 +36,7 @@ describe('Cue', function() { expect(cues[0].endTime).toBe(47); }); - it('does not object to extra settings', function() { + it('does not object to extra settings', () => { // To simplify refactoring, we are no longer checking for VTTCue before // setting properties that only exist on VTTCue. So we want to ensure that // errors are not thrown when the extra settings are assigned. diff --git a/test/text/mp4_ttml_parser_unit.js b/test/text/mp4_ttml_parser_unit.js index 300f2734e..c5478f5d5 100644 --- a/test/text/mp4_ttml_parser_unit.js +++ b/test/text/mp4_ttml_parser_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Mp4TtmlParser', function() { +describe('Mp4TtmlParser', () => { const ttmlInitSegmentUri = '/base/test/test/assets/ttml-init.mp4'; const ttmlSegmentUri = '/base/test/test/assets/ttml-segment.mp4'; const ttmlSegmentMultipleMDATUri = @@ -31,13 +31,13 @@ describe('Mp4TtmlParser', function() { /** @type {!Uint8Array} */ let audioInitSegment; - beforeAll(function(done) { + beforeAll((done) => { Promise.all([ shaka.test.Util.fetch(ttmlInitSegmentUri), shaka.test.Util.fetch(ttmlSegmentUri), shaka.test.Util.fetch(ttmlSegmentMultipleMDATUri), shaka.test.Util.fetch(audioInitSegmentUri), - ]).then(function(responses) { + ]).then((responses) => { ttmlInitSegment = new Uint8Array(responses[0]); ttmlSegment = new Uint8Array(responses[1]); ttmlSegmentMultipleMDAT = new Uint8Array(responses[2]); @@ -45,11 +45,11 @@ describe('Mp4TtmlParser', function() { }).catch(fail).then(done); }); - it('parses init segment', function() { + it('parses init segment', () => { new shaka.text.Mp4TtmlParser().parseInit(ttmlInitSegment); }); - it('parses media segment', function() { + it('parses media segment', () => { const parser = new shaka.text.Mp4TtmlParser(); parser.parseInit(ttmlInitSegment); const time = {periodStart: 0, segmentStart: 0, segmentEnd: 0}; @@ -57,7 +57,7 @@ describe('Mp4TtmlParser', function() { expect(ret.length).toBe(10); }); - it('handles media segments with multiple mdats', function() { + it('handles media segments with multiple mdats', () => { const parser = new shaka.text.Mp4TtmlParser(); parser.parseInit(ttmlInitSegment); const time = {periodStart: 0, segmentStart: 0, segmentEnd: 0}; @@ -65,7 +65,7 @@ describe('Mp4TtmlParser', function() { expect(ret.length).toBe(20); }); - it('accounts for offset', function() { + it('accounts for offset', () => { const time1 = {periodStart: 0, segmentStart: 0, segmentEnd: 0}; const time2 = {periodStart: 7, segmentStart: 0, segmentEnd: 0}; @@ -82,7 +82,7 @@ describe('Mp4TtmlParser', function() { expect(ret2[0].endTime).toEqual(ret1[0].endTime + 7); }); - it('rejects init segment with no ttml', function() { + it('rejects init segment with no ttml', () => { const error = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, diff --git a/test/text/mp4_vtt_parser_unit.js b/test/text/mp4_vtt_parser_unit.js index 03d389fa1..228c744fb 100644 --- a/test/text/mp4_vtt_parser_unit.js +++ b/test/text/mp4_vtt_parser_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('Mp4VttParser', function() { +describe('Mp4VttParser', () => { const vttInitSegmentUri = '/base/test/test/assets/vtt-init.mp4'; const vttSegmentUri = '/base/test/test/assets/vtt-segment.mp4'; const vttSegmentMultiPayloadUri = @@ -38,7 +38,7 @@ describe('Mp4VttParser', function() { /** @type {!Uint8Array} */ let audioInitSegment; - beforeAll(function(done) { + beforeAll((done) => { Promise.all([ shaka.test.Util.fetch(vttInitSegmentUri), shaka.test.Util.fetch(vttSegmentUri), @@ -46,7 +46,7 @@ describe('Mp4VttParser', function() { shaka.test.Util.fetch(vttSegSettingsUri), shaka.test.Util.fetch(vttSegNoDurationUri), shaka.test.Util.fetch(audioInitSegmentUri), - ]).then(function(responses) { + ]).then((responses) => { vttInitSegment = new Uint8Array(responses[0]); vttSegment = new Uint8Array(responses[1]); vttSegmentMultiPayload = new Uint8Array(responses[2]); @@ -56,11 +56,11 @@ describe('Mp4VttParser', function() { }).catch(fail).then(done); }); - it('parses init segment', function() { + it('parses init segment', () => { new shaka.text.Mp4VttParser().parseInit(vttInitSegment); }); - it('parses media segment', function() { + it('parses media segment', () => { const cues = [ { start: 111.8, @@ -110,7 +110,7 @@ describe('Mp4VttParser', function() { verifyHelper(cues, result); }); - it('parses media segment containing settings', function() { + it('parses media segment containing settings', () => { const Cue = shaka.text.Cue; const cues = [ { @@ -138,7 +138,7 @@ describe('Mp4VttParser', function() { verifyHelper(cues, result); }); - it('parses media segments without a sample duration', function() { + it('parses media segments without a sample duration', () => { // Regression test for https://github.com/google/shaka-player/issues/919 const cues = [ {start: 10, end: 11, payload: 'cue 10'}, @@ -160,7 +160,7 @@ describe('Mp4VttParser', function() { verifyHelper(cues, result); }); - it('accounts for offset', function() { + it('accounts for offset', () => { const cues = [ { start: 121.8, @@ -182,7 +182,7 @@ describe('Mp4VttParser', function() { verifyHelper(cues, result); }); - it('rejects init segment with no vtt', function() { + it('rejects init segment with no vtt', () => { const error = new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, diff --git a/test/text/simple_text_displayer_unit.js b/test/text/simple_text_displayer_unit.js index 0d037c0ae..f4511c172 100644 --- a/test/text/simple_text_displayer_unit.js +++ b/test/text/simple_text_displayer_unit.js @@ -16,7 +16,7 @@ */ -describe('SimpleTextDisplayer', function() { +describe('SimpleTextDisplayer', () => { const originalVTTCue = window.VTTCue; const Cue = shaka.text.Cue; const SimpleTextDisplayer = shaka.text.SimpleTextDisplayer; @@ -28,7 +28,7 @@ describe('SimpleTextDisplayer', function() { /** @type {!shaka.text.SimpleTextDisplayer} */ let displayer; - beforeEach(function() { + beforeEach(() => { video = new shaka.test.FakeVideo(); displayer = new SimpleTextDisplayer(video); @@ -50,12 +50,12 @@ describe('SimpleTextDisplayer', function() { window.VTTCue = /** @type {?} */(FakeVTTCue); }); - afterAll(function() { + afterAll(() => { window.VTTCue = originalVTTCue; }); - describe('append', function() { - it('sorts cues before inserting', function() { + describe('append', () => { + it('sorts cues before inserting', () => { // See: https://bit.ly/2K9VX3s verifyHelper( [ @@ -70,7 +70,7 @@ describe('SimpleTextDisplayer', function() { ]); }); - it('appends equal time cues in reverse order', function() { + it('appends equal time cues in reverse order', () => { // Regression test for https://github.com/google/shaka-player/issues/848 verifyHelper( [ @@ -86,8 +86,8 @@ describe('SimpleTextDisplayer', function() { }); }); - describe('remove', function() { - it('removes cues which overlap the range', function() { + describe('remove', () => { + it('removes cues which overlap the range', () => { const cue1 = new shaka.text.Cue(0, 1, 'Test'); const cue2 = new shaka.text.Cue(1, 2, 'Test'); const cue3 = new shaka.text.Cue(2, 3, 'Test'); @@ -116,14 +116,14 @@ describe('SimpleTextDisplayer', function() { mockTrack.removeCue.calls.reset(); }); - it('does nothing when nothing is buffered', function() { + it('does nothing when nothing is buffered', () => { displayer.remove(0, 1); expect(mockTrack.removeCue).not.toHaveBeenCalled(); }); }); - describe('convertToTextTrackCue', function() { - it('converts shaka.text.Cues to VttCues', function() { + describe('convertToTextTrackCue', () => { + it('converts shaka.text.Cues to VttCues', () => { verifyHelper( [ {start: 20, end: 40, text: 'Test'}, @@ -234,7 +234,7 @@ describe('SimpleTextDisplayer', function() { ], [cue5]); }); - it('works around browsers not supporting align=center', function() { + it('works around browsers not supporting align=center', () => { /** * @constructor * @param {number} start @@ -270,7 +270,7 @@ describe('SimpleTextDisplayer', function() { [cue1]); }); - it('ignores cues with startTime >= endTime', function() { + it('ignores cues with startTime >= endTime', () => { const cue1 = new shaka.text.Cue(60, 40, 'Test'); const cue2 = new shaka.text.Cue(40, 40, 'Test'); displayer.append([cue1, cue2]); diff --git a/test/text/text_engine_unit.js b/test/text/text_engine_unit.js index 88f737592..91dfe206c 100644 --- a/test/text/text_engine_unit.js +++ b/test/text/text_engine_unit.js @@ -15,7 +15,7 @@ * limitations under the License. */ -describe('TextEngine', function() { +describe('TextEngine', () => { const TextEngine = shaka.text.TextEngine; const dummyData = new ArrayBuffer(0); @@ -36,7 +36,7 @@ describe('TextEngine', function() { /** @type {!shaka.text.TextEngine} */ let textEngine; - beforeEach(function() { + beforeEach(() => { mockParseInit = jasmine.createSpy('mockParseInit'); mockParseMedia = jasmine.createSpy('mockParseMedia'); mockParserPlugIn = function() { @@ -54,12 +54,12 @@ describe('TextEngine', function() { textEngine.initParser(dummyMimeType); }); - afterEach(function() { + afterEach(() => { TextEngine.unregisterParser(dummyMimeType); }); - describe('isTypeSupported', function() { - it('reports support only when a parser is installed', function() { + describe('isTypeSupported', () => { + it('reports support only when a parser is installed', () => { TextEngine.unregisterParser(dummyMimeType); expect(TextEngine.isTypeSupported(dummyMimeType)).toBe(false); TextEngine.registerParser(dummyMimeType, mockParserPlugIn); @@ -69,7 +69,7 @@ describe('TextEngine', function() { }); it('reports support when it\'s closed captions and muxjs is available', - function() { + () => { const closedCaptionsType = shaka.util.MimeUtils.CLOSED_CAPTION_MIMETYPE; const originalMuxjs = window.muxjs; @@ -83,8 +83,8 @@ describe('TextEngine', function() { }); }); - describe('appendBuffer', function() { - it('works asynchronously', function(done) { + describe('appendBuffer', () => { + it('works asynchronously', (done) => { mockParseMedia.and.returnValue([1, 2, 3]); textEngine.appendBuffer(dummyData, 0, 3).catch(fail).then(done); expect(mockDisplayer.appendSpy).not.toHaveBeenCalled(); @@ -123,15 +123,15 @@ describe('TextEngine', function() { ]); }); - it('does not throw if called right before destroy', function(done) { + it('does not throw if called right before destroy', (done) => { mockParseMedia.and.returnValue([1, 2, 3]); textEngine.appendBuffer(dummyData, 0, 3).catch(fail).then(done); textEngine.destroy(); }); }); - describe('storeAndAppendClosedCaptions', function() { - it('appends closed captions with selected id', function() { + describe('storeAndAppendClosedCaptions', () => { + it('appends closed captions with selected id', () => { const caption = { startPts: 0, endPts: 100, @@ -147,7 +147,7 @@ describe('TextEngine', function() { expect(mockDisplayer.appendSpy).toHaveBeenCalled(); }); - it('does not append closed captions without selected id', function() { + it('does not append closed captions without selected id', () => { const caption = { startPts: 0, endPts: 100, @@ -163,7 +163,7 @@ describe('TextEngine', function() { expect(mockDisplayer.appendSpy).not.toHaveBeenCalled(); }); - it('stores closed captions', function() { + it('stores closed captions', () => { const caption0 = { startPts: 0, endPts: 100, @@ -212,7 +212,7 @@ describe('TextEngine', function() { expect(textEngine.getNumberOfClosedCaptionChannels()).toEqual(2); }); - it('offsets closed captions to account for video offset', function() { + it('offsets closed captions to account for video offset', () => { const caption = { startPts: 0, endPts: 100, @@ -235,39 +235,39 @@ describe('TextEngine', function() { }); - describe('remove', function() { + describe('remove', () => { let cue1; let cue2; let cue3; - beforeEach(function() { + beforeEach(() => { cue1 = createFakeCue(0, 1); cue2 = createFakeCue(1, 2); cue3 = createFakeCue(2, 3); mockParseMedia.and.returnValue([cue1, cue2, cue3]); }); - it('works asynchronously', function(done) { - textEngine.appendBuffer(dummyData, 0, 3).then(function() { + it('works asynchronously', (done) => { + textEngine.appendBuffer(dummyData, 0, 3).then(() => { const p = textEngine.remove(0, 1); expect(mockDisplayer.removeSpy).not.toHaveBeenCalled(); return p; }).catch(fail).then(done); }); - it('calls displayer.remove()', function(done) { - textEngine.remove(0, 1).then(function() { + it('calls displayer.remove()', (done) => { + textEngine.remove(0, 1).then(() => { expect(mockDisplayer.removeSpy).toHaveBeenCalledWith(0, 1); }).catch(fail).then(done); }); - it('does not throw if called right before destroy', function(done) { + it('does not throw if called right before destroy', (done) => { textEngine.remove(0, 1).catch(fail).then(done); textEngine.destroy(); }); }); - describe('setTimestampOffset', function() { + describe('setTimestampOffset', () => { it('passes the offset to the parser', async () => { mockParseMedia.and.callFake((data, time) => { return [ @@ -307,67 +307,67 @@ describe('TextEngine', function() { }); }); - describe('bufferStart/bufferEnd', function() { - beforeEach(function() { - mockParseMedia.and.callFake(function() { + describe('bufferStart/bufferEnd', () => { + beforeEach(() => { + mockParseMedia.and.callFake(() => { return [createFakeCue(0, 1), createFakeCue(1, 2), createFakeCue(2, 3)]; }); }); - it('return null when there are no cues', function() { + it('return null when there are no cues', () => { expect(textEngine.bufferStart()).toBe(null); expect(textEngine.bufferEnd()).toBe(null); }); - it('reflect newly-added cues', function(done) { - textEngine.appendBuffer(dummyData, 0, 3).then(function() { + it('reflect newly-added cues', (done) => { + textEngine.appendBuffer(dummyData, 0, 3).then(() => { expect(textEngine.bufferStart()).toBe(0); expect(textEngine.bufferEnd()).toBe(3); return textEngine.appendBuffer(dummyData, 3, 6); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(0); expect(textEngine.bufferEnd()).toBe(6); return textEngine.appendBuffer(dummyData, 6, 10); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(0); expect(textEngine.bufferEnd()).toBe(10); }).catch(fail).then(done); }); - it('reflect newly-removed cues', function(done) { - textEngine.appendBuffer(dummyData, 0, 3).then(function() { + it('reflect newly-removed cues', (done) => { + textEngine.appendBuffer(dummyData, 0, 3).then(() => { return textEngine.appendBuffer(dummyData, 3, 6); - }).then(function() { + }).then(() => { return textEngine.appendBuffer(dummyData, 6, 10); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(0); expect(textEngine.bufferEnd()).toBe(10); return textEngine.remove(0, 3); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(3); expect(textEngine.bufferEnd()).toBe(10); return textEngine.remove(8, 11); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(3); expect(textEngine.bufferEnd()).toBe(8); return textEngine.remove(11, 20); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(3); expect(textEngine.bufferEnd()).toBe(8); return textEngine.remove(0, Infinity); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(null); expect(textEngine.bufferEnd()).toBe(null); }).catch(fail).then(done); }); - it('does not use timestamp offset', async function() { + it('does not use timestamp offset', async () => { // The start and end times passed to appendBuffer are now absolute, so // they already account for timestampOffset and period offset. // See https://github.com/google/shaka-player/issues/1562 @@ -382,38 +382,38 @@ describe('TextEngine', function() { }); }); - describe('bufferedAheadOf', function() { - beforeEach(function() { - mockParseMedia.and.callFake(function() { + describe('bufferedAheadOf', () => { + beforeEach(() => { + mockParseMedia.and.callFake(() => { return [createFakeCue(0, 1), createFakeCue(1, 2), createFakeCue(2, 3)]; }); }); - it('returns 0 when there are no cues', function() { + it('returns 0 when there are no cues', () => { expect(textEngine.bufferedAheadOf(0)).toBe(0); }); - it('returns 0 if |t| is not buffered', function(done) { - textEngine.appendBuffer(dummyData, 3, 6).then(function() { + it('returns 0 if |t| is not buffered', (done) => { + textEngine.appendBuffer(dummyData, 3, 6).then(() => { expect(textEngine.bufferedAheadOf(6.1)).toBe(0); }).catch(fail).then(done); }); - it('ignores gaps in the content', function(done) { - textEngine.appendBuffer(dummyData, 3, 6).then(function() { + it('ignores gaps in the content', (done) => { + textEngine.appendBuffer(dummyData, 3, 6).then(() => { expect(textEngine.bufferedAheadOf(2)).toBe(3); }).catch(fail).then(done); }); - it('returns the distance to the end if |t| is buffered', function(done) { - textEngine.appendBuffer(dummyData, 0, 3).then(function() { + it('returns the distance to the end if |t| is buffered', (done) => { + textEngine.appendBuffer(dummyData, 0, 3).then(() => { expect(textEngine.bufferedAheadOf(0)).toBe(3); expect(textEngine.bufferedAheadOf(1)).toBe(2); expect(textEngine.bufferedAheadOf(2.5)).toBeCloseTo(0.5); }).catch(fail).then(done); }); - it('does not use timestamp offset', async function() { + it('does not use timestamp offset', async () => { // The start and end times passed to appendBuffer are now absolute, so // they already account for timestampOffset and period offset. // See https://github.com/google/shaka-player/issues/1562 @@ -424,9 +424,9 @@ describe('TextEngine', function() { }); }); - describe('setAppendWindow', function() { - beforeEach(function() { - mockParseMedia.and.callFake(function() { + describe('setAppendWindow', () => { + beforeEach(() => { + mockParseMedia.and.callFake(() => { return [createFakeCue(0, 1), createFakeCue(1, 2), createFakeCue(2, 3)]; }); }); @@ -453,33 +453,33 @@ describe('TextEngine', function() { ]); }); - it('limits bufferStart', function(done) { + it('limits bufferStart', (done) => { textEngine.setAppendWindow(1, 9); - textEngine.appendBuffer(dummyData, 0, 3).then(function() { + textEngine.appendBuffer(dummyData, 0, 3).then(() => { expect(textEngine.bufferStart()).toBe(1); return textEngine.remove(0, 9); - }).then(function() { + }).then(() => { textEngine.setAppendWindow(2.1, 9); return textEngine.appendBuffer(dummyData, 0, 3); - }).then(function() { + }).then(() => { expect(textEngine.bufferStart()).toBe(2.1); }).catch(fail).then(done); }); - it('limits bufferEnd', function(done) { + it('limits bufferEnd', (done) => { textEngine.setAppendWindow(0, 1.9); - textEngine.appendBuffer(dummyData, 0, 3).then(function() { + textEngine.appendBuffer(dummyData, 0, 3).then(() => { expect(textEngine.bufferEnd()).toBe(1.9); textEngine.setAppendWindow(0, 2.1); return textEngine.appendBuffer(dummyData, 0, 3); - }).then(function() { + }).then(() => { expect(textEngine.bufferEnd()).toBe(2.1); textEngine.setAppendWindow(0, 4.1); return textEngine.appendBuffer(dummyData, 0, 3); - }).then(function() { + }).then(() => { expect(textEngine.bufferEnd()).toBe(3); }).catch(fail).then(done); }); diff --git a/test/text/text_track_integration.js b/test/text/text_track_integration.js index e26d6a491..acd2c6770 100644 --- a/test/text/text_track_integration.js +++ b/test/text/text_track_integration.js @@ -22,7 +22,7 @@ // track's current mode. // 3. Regardless of mode, we can use removeCue to remove cues regardless // of the track's current mode. -describe('TextTrackIntegration', function() { +describe('TextTrackIntegration', () => { /** @type {HTMLVideoElement} */ let video; @@ -32,7 +32,7 @@ describe('TextTrackIntegration', function() { /** @type {TextTrackCueList} */ let trackCues; - beforeEach(function() { + beforeEach(() => { video = shaka.util.Dom.createVideoElement(); document.body.appendChild(video); @@ -50,7 +50,7 @@ describe('TextTrackIntegration', function() { trackCues = track.cues; }); - afterEach(function() { + afterEach(() => { document.body.removeChild(video); video = null; track = null; @@ -61,18 +61,18 @@ describe('TextTrackIntegration', function() { // else. Edge and IE will always return a valid list of cues regardless of // what the mode is set to. Everyone else will return null for cues when // mode is set to "disabled". - describe('cues', function() { - it('is not null when mode is showing', function() { + describe('cues', () => { + it('is not null when mode is showing', () => { track.mode = 'showing'; expect(track.cues).not.toBe(null); }); - it('is not null when mode is hidden', function() { + it('is not null when mode is hidden', () => { track.mode = 'hidden'; expect(track.cues).not.toBe(null); }); - it('does not change references', function() { + it('does not change references', () => { // Flip to the mode from showing to hidden and back. The value // of cues should not change. track.mode = 'hidden'; @@ -88,13 +88,13 @@ describe('TextTrackIntegration', function() { }); - describe('addCue', function() { + describe('addCue', () => { const cues = [ new VTTCue(0, 1000, 'Cue 1 message'), new VTTCue(2000, 3000, 'Cue 2 message'), ]; - it('adds cues when showing', function() { + it('adds cues when showing', () => { track.mode = 'showing'; track.addCue(cues[0]); @@ -105,7 +105,7 @@ describe('TextTrackIntegration', function() { expect(trackCues[1]).toBe(cues[1]); }); - it('adds cues when hidden', function() { + it('adds cues when hidden', () => { track.mode = 'hidden'; track.addCue(cues[0]); @@ -116,7 +116,7 @@ describe('TextTrackIntegration', function() { expect(trackCues[1]).toBe(cues[1]); }); - it('adds cues when disabled', function() { + it('adds cues when disabled', () => { track.mode = 'disabled'; track.addCue(cues[0]); @@ -128,13 +128,13 @@ describe('TextTrackIntegration', function() { }); }); - describe('removeCue', function() { + describe('removeCue', () => { const cues = [ new VTTCue(0, 1000, 'Cue 1 message'), new VTTCue(2000, 3000, 'Cue 2 message'), ]; - it('removes cues when showing', function() { + it('removes cues when showing', () => { track.mode = 'showing'; track.addCue(cues[0]); @@ -148,7 +148,7 @@ describe('TextTrackIntegration', function() { expect(trackCues.length).toBe(0); }); - it('removes cues when hidden', function() { + it('removes cues when hidden', () => { track.mode = 'showing'; track.addCue(cues[0]); @@ -164,7 +164,7 @@ describe('TextTrackIntegration', function() { expect(trackCues.length).toBe(0); }); - it('removes cues when disabled', function() { + it('removes cues when disabled', () => { track.mode = 'showing'; track.addCue(cues[0]); diff --git a/test/text/ttml_text_parser_unit.js b/test/text/ttml_text_parser_unit.js index f4f386c1b..6a5d6fb55 100644 --- a/test/text/ttml_text_parser_unit.js +++ b/test/text/ttml_text_parser_unit.js @@ -15,24 +15,24 @@ * limitations under the License. */ -describe('TtmlTextParser', function() { +describe('TtmlTextParser', () => { const Cue = shaka.text.Cue; const CueRegion = shaka.text.CueRegion; - it('supports no cues', function() { + it('supports no cues', () => { verifyHelper([], '', {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports div with no cues but whitespace', function() { + it('supports div with no cues but whitespace', () => { verifyHelper( [], '
\r\n
', {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports xml:space', function() { + it('supports xml:space', () => { const ttBody = '\n' + ' \n' + '

\n' + @@ -66,19 +66,19 @@ describe('TtmlTextParser', function() { '' + ttBody + ''); }); - it('rejects invalid ttml', function() { + it('rejects invalid ttml', () => { errorHelper(shaka.util.Error.Code.INVALID_XML, ''); errorHelper(shaka.util.Error.Code.INVALID_XML, ''); }); - it('rejects invalid time format', function() { + it('rejects invalid time format', () => { errorHelper(shaka.util.Error.Code.INVALID_TEXT_CUE, '

'); errorHelper(shaka.util.Error.Code.INVALID_TEXT_CUE, '

'); }); - it('supports colon formatted time', function() { + it('supports colon formatted time', () => { verifyHelper( [ {start: 62.05, end: 3723.2, payload: 'Test'}, @@ -88,7 +88,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('accounts for offset', function() { + it('accounts for offset', () => { verifyHelper( [ {start: 69.05, end: 3730.2, payload: 'Test'}, @@ -98,7 +98,7 @@ describe('TtmlTextParser', function() { {periodStart: 7, segmentStart: 0, segmentEnd: 0}); }); - it('supports time in 0.00h 0.00m 0.00s format', function() { + it('supports time in 0.00h 0.00m 0.00s format', () => { verifyHelper( [ {start: 3567.03, end: 5402.3, payload: 'Test'}, @@ -108,7 +108,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports time with frame rate', function() { + it('supports time with frame rate', () => { verifyHelper( [ {start: 615.5, end: 663, payload: 'Test'}, @@ -122,7 +122,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports time with frame rate multiplier', function() { + it('supports time with frame rate multiplier', () => { verifyHelper( [ {start: 615.5, end: 663, payload: 'Test'}, @@ -137,7 +137,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports time with subframes', function() { + it('supports time with subframes', () => { verifyHelper( [ {start: 615.517, end: 663, payload: 'Test'}, @@ -152,7 +152,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports time in frame format', function() { + it('supports time in frame format', () => { verifyHelper( [ {start: 2.5, end: 10.01, payload: 'Test'}, @@ -167,7 +167,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports time in tick format', function() { + it('supports time in tick format', () => { verifyHelper( [ {start: 5, end: 6.02, payload: 'Test'}, @@ -182,7 +182,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('supports time with duration', function() { + it('supports time with duration', () => { verifyHelper( [ {start: 62.05, end: 67.05, payload: 'Test'}, @@ -192,7 +192,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('parses alignment from textAlign attribute of a region', function() { + it('parses alignment from textAlign attribute of a region', () => { verifyHelper( [ { @@ -213,7 +213,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('allows non-standard namespace names', function() { + it('allows non-standard namespace names', () => { verifyHelper( [ { @@ -234,7 +234,7 @@ describe('TtmlTextParser', function() { {periodStart: 0, segmentStart: 0, segmentEnd: 0}); }); - it('parses alignment from