shaka-player 3.3.11 → 3.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.github/workflows/build-and-test.yaml +11 -6
  2. package/.github/workflows/compute-incremental-coverage.py +14 -3
  3. package/.github/workflows/demo-version-index.yaml +9 -1
  4. package/.github/workflows/nightly-demo.yaml +1 -1
  5. package/.github/workflows/release-please.yaml +4 -4
  6. package/.github/workflows/report-incremental-coverage.yaml +1 -1
  7. package/.github/workflows/selenium-lab-tests.yaml +8 -6
  8. package/CHANGELOG.md +26 -0
  9. package/dist/deps.js +5 -5
  10. package/dist/locales.js +31 -31
  11. package/dist/shaka-player.compiled.d.ts +2 -1
  12. package/dist/shaka-player.compiled.debug.d.ts +2 -1
  13. package/dist/shaka-player.compiled.debug.externs.js +3 -1
  14. package/dist/shaka-player.compiled.debug.js +104 -101
  15. package/dist/shaka-player.compiled.debug.map +4 -4
  16. package/dist/shaka-player.compiled.externs.js +3 -1
  17. package/dist/shaka-player.compiled.js +725 -722
  18. package/dist/shaka-player.compiled.map +4 -4
  19. package/dist/shaka-player.ui.d.ts +2 -1
  20. package/dist/shaka-player.ui.debug.d.ts +2 -1
  21. package/dist/shaka-player.ui.debug.externs.js +3 -1
  22. package/dist/shaka-player.ui.debug.js +122 -119
  23. package/dist/shaka-player.ui.debug.map +4 -4
  24. package/dist/shaka-player.ui.externs.js +3 -1
  25. package/dist/shaka-player.ui.js +843 -840
  26. package/dist/shaka-player.ui.map +4 -4
  27. package/docs/tutorials/welcome.md +2 -2
  28. package/lib/ads/client_side_ad_manager.js +5 -2
  29. package/lib/cast/cast_proxy.js +2 -1
  30. package/lib/cast/cast_receiver.js +19 -5
  31. package/lib/cast/cast_sender.js +2 -1
  32. package/lib/cast/cast_utils.js +16 -6
  33. package/lib/hls/hls_parser.js +9 -2
  34. package/lib/media/drm_engine.js +4 -2
  35. package/lib/media/playhead.js +23 -1
  36. package/lib/media/streaming_engine.js +3 -12
  37. package/lib/offline/indexeddb/storage_mechanism.js +24 -0
  38. package/lib/player.js +24 -11
  39. package/lib/polyfill/media_capabilities.js +1 -0
  40. package/lib/text/ttml_text_parser.js +69 -93
  41. package/lib/util/error.js +7 -0
  42. package/lib/util/manifest_parser_utils.js +4 -0
  43. package/lib/util/periods.js +9 -9
  44. package/lib/util/xml_utils.js +45 -6
  45. package/package.json +1 -1
  46. package/test/cast/cast_receiver_integration.js +97 -16
  47. package/test/cast/cast_receiver_unit.js +17 -12
  48. package/test/cast/cast_utils_unit.js +1 -0
  49. package/test/media/playhead_unit.js +41 -0
  50. package/test/media/streaming_engine_integration.js +13 -0
  51. package/test/media/streaming_engine_unit.js +23 -8
  52. package/test/offline/storage_integration.js +30 -0
  53. package/test/player_unit.js +87 -0
  54. package/test/test/util/simple_fakes.js +3 -0
  55. package/test/util/periods_unit.js +149 -11
  56. package/test/util/xml_utils_unit.js +64 -0
  57. package/ui/controls.js +4 -1
  58. package/ui/settings_menu.js +11 -2
@@ -1180,15 +1180,6 @@ shaka.util.PeriodCombiner = class {
1180
1180
  return false;
1181
1181
  }
1182
1182
 
1183
- // If the language doesn't match, but the candidate is the "primary"
1184
- // language, then that should be preferred as a fallback.
1185
- if (!best.primary && candidate.primary) {
1186
- return true;
1187
- }
1188
- if (best.primary && !candidate.primary) {
1189
- return false;
1190
- }
1191
-
1192
1183
  // If language-based differences haven't decided this, look at roles. If
1193
1184
  // the candidate has more roles in common with the output, upgrade to the
1194
1185
  // candidate.
@@ -1222,6 +1213,15 @@ shaka.util.PeriodCombiner = class {
1222
1213
  return false;
1223
1214
  }
1224
1215
 
1216
+ // If the language doesn't match, but the candidate is the "primary"
1217
+ // language, then that should be preferred as a fallback.
1218
+ if (!best.primary && candidate.primary) {
1219
+ return true;
1220
+ }
1221
+ if (best.primary && !candidate.primary) {
1222
+ return false;
1223
+ }
1224
+
1225
1225
  // If language-based and role-based features are equivalent, take the audio
1226
1226
  // with the closes channel count to the output.
1227
1227
  const channelsBetterOrWorse =
@@ -8,6 +8,7 @@ goog.provide('shaka.util.XmlUtils');
8
8
 
9
9
  goog.require('goog.asserts');
10
10
  goog.require('shaka.log');
11
+ goog.require('shaka.util.Lazy');
11
12
  goog.require('shaka.util.StringUtils');
12
13
 
13
14
 
@@ -348,19 +349,21 @@ shaka.util.XmlUtils = class {
348
349
  */
349
350
  static parseXmlString(xmlString, expectedRootElemName) {
350
351
  const parser = new DOMParser();
351
- let xml = null;
352
+ const unsafeXmlString =
353
+ shaka.util.XmlUtils.trustedHTMLFromString_.value()(xmlString);
354
+ let unsafeXml = null;
352
355
  try {
353
- xml = parser.parseFromString(xmlString, 'text/xml');
356
+ unsafeXml = parser.parseFromString(unsafeXmlString, 'text/xml');
354
357
  } catch (exception) {
355
358
  shaka.log.error('XML parsing exception:', exception);
356
359
  return null;
357
360
  }
358
361
 
359
362
  // According to MDN, parseFromString never returns null.
360
- goog.asserts.assert(xml, 'Parsed XML document cannot be null!');
363
+ goog.asserts.assert(unsafeXml, 'Parsed XML document cannot be null!');
361
364
 
362
365
  // Check for empty documents.
363
- const rootElem = xml.documentElement;
366
+ const rootElem = unsafeXml.documentElement;
364
367
  if (!rootElem) {
365
368
  shaka.log.error('XML document was empty!');
366
369
  return null;
@@ -374,13 +377,28 @@ shaka.util.XmlUtils = class {
374
377
  }
375
378
 
376
379
  // The top-level element in the loaded XML should have the name we expect.
377
- if (xml.documentElement.tagName != expectedRootElemName) {
380
+ if (rootElem.tagName != expectedRootElemName) {
378
381
  shaka.log.error(
379
382
  `XML tag name does not match expected "${expectedRootElemName}":`,
380
- xml.documentElement.tagName);
383
+ rootElem.tagName);
381
384
  return null;
382
385
  }
383
386
 
387
+ // SECURITY: Verify that the document does not contain elements from the
388
+ // HTML or SVG namespaces, which could trigger script execution and XSS.
389
+ const iterator = document.createNodeIterator(
390
+ unsafeXml,
391
+ NodeFilter.SHOW_ALL,
392
+ );
393
+ let currentNode;
394
+ while (currentNode = iterator.nextNode()) {
395
+ if (currentNode instanceof HTMLElement ||
396
+ currentNode instanceof SVGElement) {
397
+ shaka.log.error('XML document embeds unsafe content!');
398
+ return null;
399
+ }
400
+ }
401
+
384
402
  return rootElem;
385
403
  }
386
404
 
@@ -402,3 +420,24 @@ shaka.util.XmlUtils = class {
402
420
  }
403
421
  }
404
422
  };
423
+
424
+ /**
425
+ * Promote a string to TrustedHTML. This function is security-sensitive and
426
+ * should only be used with security approval where the string is guaranteed not
427
+ * to cause an XSS vulnerability.
428
+ *
429
+ * @private {!shaka.util.Lazy.<function(!string): (!TrustedHTML|!string)>}
430
+ */
431
+ shaka.util.XmlUtils.trustedHTMLFromString_ = new shaka.util.Lazy(() => {
432
+ if (typeof trustedTypes !== 'undefined') {
433
+ // Create a Trusted Types policy for promoting the string to TrustedHTML.
434
+ // The Lazy wrapper ensures this policy is only created once.
435
+ const policy = trustedTypes.createPolicy('shaka-player#xml', {
436
+ createHTML: (s) => s,
437
+ });
438
+ return (s) => policy.createHTML(s);
439
+ }
440
+ // Fall back to strings in environments that don't support Trusted Types.
441
+ return (s) => s;
442
+ });
443
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shaka-player",
3
3
  "description": "DASH/EME video player library",
4
- "version": "3.3.11",
4
+ "version": "3.3.13",
5
5
  "homepage": "https://github.com/shaka-project/shaka-player",
6
6
  "author": "Google",
7
7
  "maintainers": [
@@ -34,6 +34,8 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
34
34
 
35
35
  /** @type {shaka.util.PublicPromise} */
36
36
  let messageWaitPromise;
37
+ /** @type {Array.<string>} */
38
+ let pendingMessages = null;
37
39
 
38
40
  /** @type {!Array.<function()>} */
39
41
  let toRestore;
@@ -91,6 +93,9 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
91
93
  toRestore = [];
92
94
  pendingWaitWrapperCalls = 0;
93
95
 
96
+ messageWaitPromise = null;
97
+ pendingMessages = null;
98
+
94
99
  fakeInitState = {
95
100
  player: {
96
101
  configure: {},
@@ -118,6 +123,12 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
118
123
  player = null;
119
124
  video = null;
120
125
  receiver = null;
126
+
127
+ if (messageWaitPromise) {
128
+ messageWaitPromise.resolve([]);
129
+ }
130
+ messageWaitPromise = null;
131
+ pendingMessages = null;
121
132
  });
122
133
 
123
134
  afterAll(() => {
@@ -128,6 +139,66 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
128
139
  }
129
140
  });
130
141
 
142
+ describe('without drm', () => {
143
+ it('sends reasonably-sized updates', async () => {
144
+ // Use an unencrypted asset.
145
+ fakeInitState.manifest = 'test:sintel';
146
+
147
+ const p = waitForLoadedData();
148
+
149
+ // Start the process of loading by sending a fake init message.
150
+ fakeConnectedSenders(1);
151
+ fakeIncomingMessage({
152
+ type: 'init',
153
+ initState: fakeInitState,
154
+ appData: {},
155
+ }, mockShakaMessageBus);
156
+
157
+ await p;
158
+ // Wait for an update message.
159
+ const messages = await waitForUpdateMessages();
160
+ for (const message of messages) {
161
+ // Check that the update message is of a reasonable size. From previous
162
+ // testing we found that the socket would silently reject data that got
163
+ // too big. 6KB is safely below the limit.
164
+ expect(message.length).toBeLessThan(6000);
165
+ }
166
+ });
167
+
168
+ it('has reasonable average message size', async () => {
169
+ // Use an unencrypted asset.
170
+ fakeInitState.manifest = 'test:sintel';
171
+
172
+ const p = waitForLoadedData();
173
+
174
+ // Start the process of loading by sending a fake init message.
175
+ fakeConnectedSenders(1);
176
+ fakeIncomingMessage({
177
+ type: 'init',
178
+ initState: fakeInitState,
179
+ appData: {},
180
+ }, mockShakaMessageBus);
181
+
182
+ await p;
183
+
184
+ // Collect messages over 50 update cycles, and average their length.
185
+ // Not all properties are passed along on every update message, so
186
+ // the average length is expected to be lower than the length of the first
187
+ // update message.
188
+ let totalLength = 0;
189
+ let totalMessages = 0;
190
+ for (let i = 0; i < 50; i++) {
191
+ // eslint-disable-next-line no-await-in-loop
192
+ const messages = await waitForUpdateMessages();
193
+ for (const message of messages) {
194
+ totalLength += message.length;
195
+ totalMessages += 1;
196
+ }
197
+ }
198
+ expect(totalLength / totalMessages).toBeLessThan(2000);
199
+ });
200
+ });
201
+
131
202
  filterDescribe('with drm', () => support['com.widevine.alpha'], () => {
132
203
  drmIt('sends reasonably-sized updates', async () => {
133
204
  // Use an encrypted asset, to make sure DRM info doesn't balloon the size.
@@ -150,11 +221,13 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
150
221
 
151
222
  await p;
152
223
  // Wait for an update message.
153
- const message = await waitForUpdateMessage();
154
- // Check that the update message is of a reasonable size. From previous
155
- // testing we found that the socket would silently reject data that got
156
- // too big. 6KB is safely below the limit.
157
- expect(message.length).toBeLessThan(7 * 1024);
224
+ const messages = await waitForUpdateMessages();
225
+ for (const message of messages) {
226
+ // Check that the update message is of a reasonable size. From previous
227
+ // testing we found that the socket would silently reject data that got
228
+ // too big. 6KB is safely below the limit.
229
+ expect(message.length).toBeLessThan(6000);
230
+ }
158
231
  });
159
232
 
160
233
  drmIt('has reasonable average message size', async () => {
@@ -177,17 +250,22 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
177
250
  }, mockShakaMessageBus);
178
251
 
179
252
  await p;
180
- // Collect 50 update messages, and average their length.
253
+
254
+ // Collect messages over 50 update cycles, and average their length.
181
255
  // Not all properties are passed along on every update message, so
182
256
  // the average length is expected to be lower than the length of the first
183
257
  // update message.
184
258
  let totalLength = 0;
259
+ let totalMessages = 0;
185
260
  for (let i = 0; i < 50; i++) {
186
261
  // eslint-disable-next-line no-await-in-loop
187
- const message = await waitForUpdateMessage();
188
- totalLength += message.length;
262
+ const messages = await waitForUpdateMessages();
263
+ for (const message of messages) {
264
+ totalLength += message.length;
265
+ totalMessages += 1;
266
+ }
189
267
  }
190
- expect(totalLength / 50).toBeLessThan(3000);
268
+ expect(totalLength / totalMessages).toBeLessThan(2000);
191
269
  });
192
270
  });
193
271
 
@@ -227,12 +305,12 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
227
305
  expect(pendingWaitWrapperCalls).toBe(0);
228
306
 
229
307
  // Wait for a final update message before proceeding.
230
- await waitForUpdateMessage();
308
+ await waitForUpdateMessages();
231
309
  });
232
310
 
233
311
  /**
234
312
  * Creates a wrapper around a method on a given prototype, which makes it
235
- * wait on waitForUpdateMessage before returning, and registers that wrapper
313
+ * wait on waitForUpdateMessages before returning, and registers that wrapper
236
314
  * to be uninstalled afterwards.
237
315
  * The replaced method is expected to be a method that returns a promise.
238
316
  * @param {!Object} prototype
@@ -249,7 +327,7 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
249
327
  'Waiting for update message before calling ' +
250
328
  name + '.' + methodName + '...');
251
329
  const originalArguments = Array.from(arguments);
252
- await waitForUpdateMessage();
330
+ await waitForUpdateMessages();
253
331
  // eslint-disable-next-line no-restricted-syntax
254
332
  return original.apply(this, originalArguments);
255
333
  };
@@ -265,7 +343,8 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
265
343
  });
266
344
  }
267
345
 
268
- function waitForUpdateMessage() {
346
+ function waitForUpdateMessages() {
347
+ pendingMessages = [];
269
348
  messageWaitPromise = new shaka.util.PublicPromise();
270
349
  return messageWaitPromise;
271
350
  }
@@ -316,10 +395,12 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
316
395
  bus.messages.push(CastUtils.deserialize(message));
317
396
  // Check to see if it's an update message.
318
397
  const parsed = CastUtils.deserialize(message);
319
- if (parsed.type == 'update' && messageWaitPromise) {
398
+ if (parsed.type == 'update' && pendingMessages) {
320
399
  shaka.log.debug('Received update message. Proceeding...');
321
- messageWaitPromise.resolve(message);
322
- messageWaitPromise = null;
400
+ // The code waiting on this Promise will get an array of all of the
401
+ // messages processed within this tick.
402
+ pendingMessages.push(message);
403
+ messageWaitPromise.resolve(pendingMessages);
323
404
  }
324
405
  });
325
406
  const channel = {
@@ -245,18 +245,20 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
245
245
  const fakeEvent = {type: 'timeupdate'};
246
246
  mockVideo.on['timeupdate'](fakeEvent);
247
247
 
248
- // There are now "update" and "event" messages, in that order.
249
- expect(mockShakaMessageBus.messages).toEqual([
250
- {
251
- type: 'update',
252
- update: jasmine.any(Object),
253
- },
254
- {
255
- type: 'event',
256
- targetName: 'video',
257
- event: jasmine.objectContaining(fakeEvent),
258
- },
259
- ]);
248
+ // There are now some number of "update" and "event" messages, in that
249
+ // order.
250
+ expect(mockShakaMessageBus.messages).toContain({
251
+ type: 'update',
252
+ update: jasmine.any(Object),
253
+ });
254
+ expect(mockShakaMessageBus.messages).toContain({
255
+ type: 'event',
256
+ targetName: 'video',
257
+ event: jasmine.objectContaining(fakeEvent),
258
+ });
259
+ const eventIndex = mockShakaMessageBus.messages.findIndex(
260
+ (message) => message.type == 'event');
261
+ expect(eventIndex).toBe(mockShakaMessageBus.messages.length - 1);
260
262
  });
261
263
  });
262
264
 
@@ -1105,6 +1107,9 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
1105
1107
  for (const name in CastUtils.PlayerGetterMethods) {
1106
1108
  player[name] = jasmine.createSpy(name);
1107
1109
  }
1110
+ for (const name in CastUtils.LargePlayerGetterMethods) {
1111
+ player[name] = jasmine.createSpy(name);
1112
+ }
1108
1113
  for (const name in CastUtils.PlayerGetterMethodsThatRequireLive) {
1109
1114
  player[name] = jasmine.createSpy(name);
1110
1115
  }
@@ -34,6 +34,7 @@ describe('CastUtils', () => {
34
34
  const castMembers = CastUtils.PlayerVoidMethods
35
35
  .concat(CastUtils.PlayerPromiseMethods)
36
36
  .concat(Object.keys(CastUtils.PlayerGetterMethods))
37
+ .concat(Object.keys(CastUtils.LargePlayerGetterMethods))
37
38
  .concat(Object.keys(CastUtils.PlayerGetterMethodsThatRequireLive));
38
39
  // eslint-disable-next-line no-restricted-syntax
39
40
  const allPlayerMembers = Object.getOwnPropertyNames(shaka.Player.prototype);
@@ -171,6 +171,8 @@ describe('Playhead', () => {
171
171
  Util.spyFunc(onSeek),
172
172
  Util.spyFunc(onEvent));
173
173
 
174
+ playhead.ready();
175
+
174
176
  expect(video.currentTime).toBe(5);
175
177
  expect(playhead.getTime()).toBe(5);
176
178
 
@@ -192,6 +194,8 @@ describe('Playhead', () => {
192
194
  Util.spyFunc(onSeek),
193
195
  Util.spyFunc(onEvent));
194
196
 
197
+ playhead.ready();
198
+
195
199
  expect(video.addEventListener).toHaveBeenCalledWith(
196
200
  'loadedmetadata', jasmine.any(Function), jasmine.anything());
197
201
  expect(video.addEventListener).not.toHaveBeenCalledWith(
@@ -233,6 +237,8 @@ describe('Playhead', () => {
233
237
  Util.spyFunc(onSeek),
234
238
  Util.spyFunc(onEvent));
235
239
 
240
+ playhead.ready();
241
+
236
242
  video.on['seeking']();
237
243
  expect(playhead.getTime()).toBe(5);
238
244
  expect(video.currentTime).toBe(5);
@@ -266,6 +272,8 @@ describe('Playhead', () => {
266
272
  video, manifest, config, /* startTime= */ 60, Util.spyFunc(onSeek),
267
273
  Util.spyFunc(onEvent));
268
274
 
275
+ playhead.ready();
276
+
269
277
  expect(playhead.getTime()).toBe(59); // duration - durationBackoff
270
278
  expect(video.currentTime).toBe(59); // duration - durationBackoff
271
279
  });
@@ -296,6 +304,8 @@ describe('Playhead', () => {
296
304
  video, manifest, config, /* startTime= */ -40, Util.spyFunc(onSeek),
297
305
  Util.spyFunc(onEvent));
298
306
 
307
+ playhead.ready();
308
+
299
309
  expect(playhead.getTime()).toBe(30);
300
310
  });
301
311
 
@@ -308,6 +318,8 @@ describe('Playhead', () => {
308
318
  Util.spyFunc(onSeek),
309
319
  Util.spyFunc(onEvent));
310
320
 
321
+ playhead.ready();
322
+
311
323
  expect(video.addEventListener).toHaveBeenCalledWith(
312
324
  'loadedmetadata', jasmine.any(Function), jasmine.anything());
313
325
 
@@ -341,6 +353,8 @@ describe('Playhead', () => {
341
353
  Util.spyFunc(onSeek),
342
354
  Util.spyFunc(onEvent));
343
355
 
356
+ playhead.ready();
357
+
344
358
  expect(video.addEventListener).toHaveBeenCalledWith(
345
359
  'loadedmetadata', jasmine.any(Function), jasmine.anything());
346
360
 
@@ -374,6 +388,8 @@ describe('Playhead', () => {
374
388
  Util.spyFunc(onSeek),
375
389
  Util.spyFunc(onEvent));
376
390
 
391
+ playhead.ready();
392
+
377
393
  // This has to periodically increment the mock date to allow the onSeeking_
378
394
  // handler to seek, if appropriate.
379
395
 
@@ -646,6 +662,8 @@ describe('Playhead', () => {
646
662
  expect(currentTime).toBe(1000);
647
663
  seekCount = 0;
648
664
 
665
+ playhead.ready();
666
+
649
667
  // The availability window slips ahead.
650
668
  timeline.getSeekRangeStart.and.returnValue(1030);
651
669
  timeline.getSeekRangeEnd.and.returnValue(1030);
@@ -690,6 +708,8 @@ describe('Playhead', () => {
690
708
  Util.spyFunc(onSeek),
691
709
  Util.spyFunc(onEvent));
692
710
 
711
+ playhead.ready();
712
+
693
713
  video.on['seeking']();
694
714
  expect(video.currentTime).toBe(5);
695
715
  expect(playhead.getTime()).toBe(5);
@@ -722,6 +742,8 @@ describe('Playhead', () => {
722
742
  Util.spyFunc(onSeek),
723
743
  Util.spyFunc(onEvent));
724
744
 
745
+ playhead.ready();
746
+
725
747
  video.on['seeking']();
726
748
  expect(video.currentTime).toBe(5);
727
749
  expect(playhead.getTime()).toBe(5);
@@ -759,6 +781,9 @@ describe('Playhead', () => {
759
781
 
760
782
  video.currentTime = 0;
761
783
  video.seeking = true;
784
+
785
+ playhead.ready();
786
+
762
787
  // "video.seeking" stays true until the buffered range intersects with
763
788
  // "video.currentTime". Playhead should correct anyway.
764
789
  video.on['seeking']();
@@ -803,6 +828,8 @@ describe('Playhead', () => {
803
828
  Util.spyFunc(onSeek),
804
829
  Util.spyFunc(onEvent));
805
830
 
831
+ playhead.ready();
832
+
806
833
  /**
807
834
  * Prevent retries on the initial start time seek. This will ensure that
808
835
  * only one call is made for the initial seek, and that any additional calls
@@ -955,6 +982,8 @@ describe('Playhead', () => {
955
982
  Util.spyFunc(onSeek),
956
983
  Util.spyFunc(onEvent));
957
984
 
985
+ playhead.ready();
986
+
958
987
  jasmine.clock().tick(500);
959
988
  for (let time = data.start; time < data.waitingAt; time++) {
960
989
  // We don't want to run tick() for 1 second because it will trigger
@@ -1208,6 +1237,8 @@ describe('Playhead', () => {
1208
1237
  Util.spyFunc(onSeek),
1209
1238
  Util.spyFunc(onEvent));
1210
1239
 
1240
+ playhead.ready();
1241
+
1211
1242
  jasmine.clock().tick(500);
1212
1243
  expect(onEvent).not.toHaveBeenCalled();
1213
1244
 
@@ -1257,6 +1288,8 @@ describe('Playhead', () => {
1257
1288
  Util.spyFunc(onSeek),
1258
1289
  Util.spyFunc(onEvent));
1259
1290
 
1291
+ playhead.ready();
1292
+
1260
1293
  playhead.notifyOfBufferingChange();
1261
1294
  jasmine.clock().tick(500);
1262
1295
 
@@ -1280,6 +1313,8 @@ describe('Playhead', () => {
1280
1313
  Util.spyFunc(onSeek),
1281
1314
  Util.spyFunc(onEvent));
1282
1315
 
1316
+ playhead.ready();
1317
+
1283
1318
  playhead.notifyOfBufferingChange();
1284
1319
  jasmine.clock().tick(500);
1285
1320
 
@@ -1305,6 +1340,8 @@ describe('Playhead', () => {
1305
1340
  Util.spyFunc(onSeek),
1306
1341
  Util.spyFunc(onEvent));
1307
1342
 
1343
+ playhead.ready();
1344
+
1308
1345
  playhead.notifyOfBufferingChange();
1309
1346
  jasmine.clock().tick(500);
1310
1347
 
@@ -1330,6 +1367,8 @@ describe('Playhead', () => {
1330
1367
  Util.spyFunc(onSeek),
1331
1368
  Util.spyFunc(onEvent));
1332
1369
 
1370
+ playhead.ready();
1371
+
1333
1372
  playhead.notifyOfBufferingChange();
1334
1373
  jasmine.clock().tick(500);
1335
1374
 
@@ -1362,6 +1401,8 @@ describe('Playhead', () => {
1362
1401
  Util.spyFunc(onSeek),
1363
1402
  Util.spyFunc(onEvent));
1364
1403
 
1404
+ playhead.ready();
1405
+
1365
1406
  jasmine.clock().tick(500);
1366
1407
  expect(onEvent).not.toHaveBeenCalled();
1367
1408
 
@@ -154,6 +154,19 @@ describe('StreamingEngine', () => {
154
154
  /* presentationDuration= */ Infinity);
155
155
  setupPlayhead();
156
156
 
157
+ // Retry on failure for live streams.
158
+ config.failureCallback = () => streamingEngine.retry(0.1);
159
+
160
+ // Ignore 404 errors in live stream tests.
161
+ onError.and.callFake((error) => {
162
+ if (error.code == shaka.util.Error.Code.BAD_HTTP_STATUS &&
163
+ error.data[1] == 404) {
164
+ // 404 error
165
+ } else {
166
+ fail(error);
167
+ }
168
+ });
169
+
157
170
  createStreamingEngine();
158
171
  }
159
172
 
@@ -857,7 +857,7 @@ describe('StreamingEngine', () => {
857
857
 
858
858
  const config = shaka.util.PlayerConfiguration.createDefault().streaming;
859
859
  config.bufferingGoal = 60;
860
- config.failureCallback = () => streamingEngine.retry();
860
+ config.failureCallback = () => streamingEngine.retry(0.1);
861
861
  createStreamingEngine(config);
862
862
 
863
863
  // Make requests for different types take different amounts of time.
@@ -1716,8 +1716,23 @@ describe('StreamingEngine', () => {
1716
1716
  beforeEach(() => {
1717
1717
  setupLive();
1718
1718
  mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData, 0);
1719
- createStreamingEngine();
1719
+
1720
+ // Retry on failure for live streams.
1721
+ const config = shaka.util.PlayerConfiguration.createDefault().streaming;
1722
+ config.failureCallback = () => streamingEngine.retry(0.1);
1723
+
1724
+ createStreamingEngine(config);
1720
1725
  presentationTimeInSeconds = 100;
1726
+
1727
+ // Ignore 404 errors in live stream tests.
1728
+ onError.and.callFake((error) => {
1729
+ if (error.code == shaka.util.Error.Code.BAD_HTTP_STATUS &&
1730
+ error.data[1] == 404) {
1731
+ // 404 error
1732
+ } else {
1733
+ fail(error);
1734
+ }
1735
+ });
1721
1736
  });
1722
1737
 
1723
1738
  it('outside segment availability window', async () => {
@@ -1753,9 +1768,9 @@ describe('StreamingEngine', () => {
1753
1768
  if (startTime >= 100) {
1754
1769
  // Ignore a possible call for the first Period.
1755
1770
  expect(Util.invokeSpy(timeline.getSegmentAvailabilityStart))
1756
- .toBe(100);
1771
+ .not.toBeLessThan(100);
1757
1772
  expect(Util.invokeSpy(timeline.getSegmentAvailabilityEnd))
1758
- .toBe(120);
1773
+ .not.toBeLessThan(120);
1759
1774
  playing = true;
1760
1775
  mediaSourceEngine.appendBuffer.and.callFake(
1761
1776
  originalAppendBuffer);
@@ -1980,7 +1995,7 @@ describe('StreamingEngine', () => {
1980
1995
  mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData);
1981
1996
 
1982
1997
  const config = shaka.util.PlayerConfiguration.createDefault().streaming;
1983
- config.failureCallback = () => streamingEngine.retry();
1998
+ config.failureCallback = () => streamingEngine.retry(0.1);
1984
1999
  createStreamingEngine(config);
1985
2000
 
1986
2001
  presentationTimeInSeconds = 100;
@@ -2141,7 +2156,7 @@ describe('StreamingEngine', () => {
2141
2156
  netEngine.request.calls.reset();
2142
2157
 
2143
2158
  // Retry streaming.
2144
- expect(streamingEngine.retry()).toBe(true);
2159
+ expect(streamingEngine.retry(0.1)).toBe(true);
2145
2160
  });
2146
2161
 
2147
2162
  // Here we go!
@@ -2171,7 +2186,7 @@ describe('StreamingEngine', () => {
2171
2186
 
2172
2187
  // Retry streaming, which should fail and return false.
2173
2188
  netEngine.request.calls.reset();
2174
- expect(streamingEngine.retry()).toBe(false);
2189
+ expect(streamingEngine.retry(0.1)).toBe(false);
2175
2190
  });
2176
2191
 
2177
2192
  // Here we go!
@@ -2223,7 +2238,7 @@ describe('StreamingEngine', () => {
2223
2238
 
2224
2239
  // Retry streaming, which should fail and return false.
2225
2240
  netEngine.request.calls.reset();
2226
- expect(streamingEngine.retry()).toBe(false);
2241
+ expect(streamingEngine.retry(0.1)).toBe(false);
2227
2242
  }
2228
2243
  });
2229
2244