Blame view

node_modules/videojs-contrib-hls/test/xhr.test.js 1.18 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
  import QUnit from 'qunit';
  import xhrFactory from '../src/xhr';
  import { useFakeEnvironment } from './test-helpers.js';
  import videojs from 'video.js';
  
  QUnit.module('xhr', {
    beforeEach(assert) {
      this.env = useFakeEnvironment(assert);
      this.clock = this.env.clock;
      this.requests = this.env.requests;
      this.xhr = xhrFactory();
    },
    afterEach() {
      this.env.restore();
    }
  });
  
  QUnit.test('xhr respects beforeRequest', function(assert) {
    let defaultOptions = {
      url: 'default'
    };
  
    this.xhr(defaultOptions);
    assert.equal(this.requests.shift().url, 'default', 'url the same without override');
  
    this.xhr.beforeRequest = (options) => {
      options.url = 'player';
      return options;
    };
  
    this.xhr(defaultOptions);
    assert.equal(this.requests.shift().url, 'player', 'url changed with player override');
  
    videojs.Hls.xhr.beforeRequest = (options) => {
      options.url = 'global';
      return options;
    };
  
    this.xhr(defaultOptions);
    assert.equal(this.requests.shift().url, 'player', 'prioritizes player override');
  
    delete this.xhr.beforeRequest;
  
    this.xhr(defaultOptions);
    assert.equal(this.requests.shift().url, 'global', 'url changed with global override');
  });