|
2 | 2 | import Flash from '../../../src/js/tech/flash.js'; |
3 | 3 | import { createTimeRange } from '../../../src/js/utils/time-ranges.js'; |
4 | 4 | import document from 'global/document'; |
| 5 | +import window from 'global/window'; |
5 | 6 | import sinon from 'sinon'; |
6 | 7 |
|
7 | 8 | // fake out the <object> interaction but leave all the other logic intact |
@@ -261,3 +262,81 @@ QUnit.test('duration returns NaN, Infinity or duration according to the HTML sta |
261 | 262 | 'duration returns duration property when readyState' + |
262 | 263 | ' and duration property are both higher than 0'); |
263 | 264 | }); |
| 265 | + |
| 266 | +QUnit.test('getVideoPlaybackQuality API exists', function(assert) { |
| 267 | + const propertyCalls = []; |
| 268 | + const videoPlaybackQuality = { test: 'test' }; |
| 269 | + const mockFlash = { |
| 270 | + el_: { |
| 271 | + /* eslint-disable camelcase */ |
| 272 | + vjs_getProperty(attr) { |
| 273 | + propertyCalls.push(attr); |
| 274 | + return videoPlaybackQuality; |
| 275 | + } |
| 276 | + /* eslint-enable camelcase */ |
| 277 | + } |
| 278 | + }; |
| 279 | + |
| 280 | + assert.equal(typeof Flash.prototype.getVideoPlaybackQuality, |
| 281 | + 'function', |
| 282 | + 'getVideoPlaybackQuality is a function'); |
| 283 | + assert.deepEqual(Flash.prototype.getVideoPlaybackQuality.call(mockFlash), |
| 284 | + videoPlaybackQuality, |
| 285 | + 'called to get property from flash'); |
| 286 | + assert.equal(propertyCalls.length, 1, 'only one property call'); |
| 287 | + assert.equal(propertyCalls[0], |
| 288 | + 'getVideoPlaybackQuality', |
| 289 | + 'called for getVideoPlaybackQuality'); |
| 290 | +}); |
| 291 | + |
| 292 | +QUnit.test('getVideoPlaybackQuality uses best available creationTime', function(assert) { |
| 293 | + const origPerformance = window.performance; |
| 294 | + const origDate = window.Date; |
| 295 | + const videoPlaybackQuality = {}; |
| 296 | + const mockFlash = { |
| 297 | + el_: { |
| 298 | + /* eslint-disable camelcase */ |
| 299 | + vjs_getProperty(attr) { |
| 300 | + return videoPlaybackQuality; |
| 301 | + } |
| 302 | + /* eslint-enable camelcase */ |
| 303 | + } |
| 304 | + }; |
| 305 | + |
| 306 | + window.performance = void 0; |
| 307 | + assert.notOk(Flash.prototype.getVideoPlaybackQuality.call(mockFlash).creationTime, |
| 308 | + 'no creationTime when no performance API available'); |
| 309 | + |
| 310 | + window.performance = { |
| 311 | + timing: {} |
| 312 | + }; |
| 313 | + assert.notOk(Flash.prototype.getVideoPlaybackQuality.call(mockFlash).creationTime, |
| 314 | + 'no creationTime when performance API insufficient'); |
| 315 | + |
| 316 | + window.performance = { |
| 317 | + now: () => 4 |
| 318 | + }; |
| 319 | + assert.equal(Flash.prototype.getVideoPlaybackQuality.call(mockFlash).creationTime, |
| 320 | + 4, |
| 321 | + 'creationTime is performance.now when available'); |
| 322 | + |
| 323 | + window.Date = { |
| 324 | + now: () => 10 |
| 325 | + }; |
| 326 | + window.performance = { |
| 327 | + timing: { |
| 328 | + navigationStart: 3 |
| 329 | + } |
| 330 | + }; |
| 331 | + assert.equal(Flash.prototype.getVideoPlaybackQuality.call(mockFlash).creationTime, |
| 332 | + 7, |
| 333 | + 'creationTime uses Date.now() - navigationStart when available'); |
| 334 | + |
| 335 | + window.performance.now = () => 4; |
| 336 | + assert.equal(Flash.prototype.getVideoPlaybackQuality.call(mockFlash).creationTime, |
| 337 | + 4, |
| 338 | + 'creationTime prioritizes performance.now when available'); |
| 339 | + |
| 340 | + window.Date = origDate; |
| 341 | + window.performance = origPerformance; |
| 342 | +}); |
0 commit comments