Blame view

node_modules/videojs-contrib-media-sources/test/videojs-contrib-media-sources.js 2.87 KB
2a09d1a4   liuqimichale   添加宜春 天水 宣化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  import document from 'global/document';
  import window from 'global/window';
  import QUnit from 'qunit';
  import sinon from 'sinon';
  import videojs from 'video.js';
  import FlashMediaSource from '../src/flash-media-source';
  import HtmlMediaSource from '../src/html-media-source';
  
  // we disable this because browserify needs to include these files
  // but the exports are not important
  /* eslint-disable no-unused-vars */
  import {MediaSource, URL} from '../src/videojs-contrib-media-sources.js';
  /* eslint-disable no-unused-vars */
  
  QUnit.test('the environment is sane', function(assert) {
    assert.strictEqual(typeof Array.isArray, 'function', 'es5 exists');
    assert.strictEqual(typeof sinon, 'object', 'sinon exists');
    assert.strictEqual(typeof videojs, 'function', 'videojs exists');
    assert.strictEqual(typeof videojs.MediaSource, 'function', 'plugin is a function');
  });
  
  QUnit.module('videojs-contrib-media-sources - General', {
    beforeEach() {
      this.fixture = document.getElementById('qunit-fixture');
      this.video = document.createElement('video');
      this.fixture.appendChild(this.video);
      this.player = videojs(this.video);
  
      // Mock the environment's timers because certain things - particularly
      // player readiness - are asynchronous in video.js 5.
      this.clock = sinon.useFakeTimers();
      this.oldMediaSource = window.MediaSource || window.WebKitMediaSource;
    },
  
    afterEach() {
  
      // The clock _must_ be restored before disposing the player; otherwise,
      // certain timeout listeners that happen inside video.js may throw errors.
      this.clock.restore();
      this.player.dispose();
      window.MediaSource = window.WebKitMediaSource = this.oldMediaSource;
    }
  });
  
  QUnit.test('Plugin is registered', function(assert) {
    assert.strictEqual(
      typeof videojs.MediaSource,
      'function',
      'MediaSource plugin is attached to videojs'
    );
    assert.strictEqual(
      typeof videojs.URL,
      'object',
      'URL plugin is attached to player'
    );
  });
  
  QUnit.test('implementation selection is overridable', function() {
    // mock native MediaSources
    window.MediaSource = videojs.extend(videojs.EventTarget, {
      addSourceBuffer() {
        throw new Error('Testing Mock');
      }
    });
  
    window.MediaSource.isTypeSupported = function(mime) {
      return true;
    };
  
    QUnit.ok(
      new videojs.MediaSource({ mode: 'flash' }) instanceof FlashMediaSource,
      'forced flash'
    );
  
    QUnit.ok(
        new videojs.MediaSource({ mode: 'html5' }) instanceof HtmlMediaSource,
      'forced html5'
    );
  
    // 'auto' should use native mediasources when they're available
    QUnit.ok(
      new videojs.MediaSource() instanceof HtmlMediaSource,
      'used html5'
    );
  
    window.MediaSource.isTypeSupported = function(mime) {
      return false;
    };
  
    // 'auto' should use flash when native mediasources are not available
    QUnit.ok(
      new videojs.MediaSource() instanceof FlashMediaSource,
        'used flash'
    );
  });