summaryrefslogtreecommitdiffstats
path: root/dom/media/test/can_play_type_ogg.js
blob: 79bf8a554c7244715a0fff44518ad2a8d1e205db (plain)
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
function check_ogg(v, enabled, finish) {
  function check(type, expected) {
    is(v.canPlayType(type), enabled ? expected : "", type);
  }

  function basic_test() {
    return new Promise(function (resolve, reject) {
      // Ogg types
      check("video/ogg", "maybe");
      check("audio/ogg", "maybe");
      check("application/ogg", "maybe");

      // Supported Ogg codecs
      check("audio/ogg; codecs=vorbis", "probably");
      check("video/ogg; codecs=vorbis", "probably");
      check("video/ogg; codecs=vorbis,theora", "probably");
      check('video/ogg; codecs="vorbis, theora"', "probably");
      check("video/ogg; codecs=theora", "probably");

      resolve();
    });
  }

  // Verify Opus support
  function verify_opus_support() {
    return new Promise(function (resolve, reject) {
      var OpusEnabled = SpecialPowers.getBoolPref(
        "media.opus.enabled",
        undefined
      );
      if (OpusEnabled != undefined) {
        resolve();
      } else {
        console.log(
          "media.opus.enabled pref not found; skipping Opus validation"
        );
        reject();
      }
    });
  }

  function opus_enable() {
    return SpecialPowers.pushPrefEnv({
      set: [["media.opus.enabled", true]],
    }).then(function () {
      check("audio/ogg; codecs=opus", "probably");
    });
  }

  function opus_disable() {
    return SpecialPowers.pushPrefEnv({
      set: [["media.opus.enabled", false]],
    }).then(function () {
      check("audio/ogg; codecs=opus", "");
    });
  }

  function unspported_ogg() {
    // Unsupported Ogg codecs
    check("video/ogg; codecs=xyz", "");
    check("video/ogg; codecs=xyz,vorbis", "");
    check("video/ogg; codecs=vorbis,xyz", "");

    finish.call();
  }

  basic_test()
    .then(verify_opus_support)
    .then(opus_enable)
    .then(opus_disable)
    .then(unspported_ogg, unspported_ogg);
}