summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webcodecs/video-decoder.https.any.js
blob: 77a610bd4ea2ca090ba029cdf1239e83184873b8 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// META: global=window,dedicatedworker
// META: script=/webcodecs/utils.js

const invalidConfigs = [
  {
    comment: 'Missing codec',
    config: {},
  },
  {
    comment: 'Empty codec',
    config: {codec: ''},
  },
];  // invalidConfigs

invalidConfigs.forEach(entry => {
  promise_test(
      t => {
        return promise_rejects_js(
            t, TypeError, VideoDecoder.isConfigSupported(entry.config));
      },
      'Test that VideoDecoder.isConfigSupported() rejects invalid config:' +
          entry.comment);
});

invalidConfigs.forEach(entry => {
  async_test(
      t => {
        let codec = new VideoDecoder(getDefaultCodecInit(t));
        assert_throws_js(TypeError, () => {
          codec.configure(entry.config);
        });
        t.done();
      },
      'Test that VideoDecoder.configure() rejects invalid config:' +
          entry.comment);
});

const arrayBuffer = new ArrayBuffer(12583);
const arrayBufferView = new DataView(arrayBuffer);

const validButUnsupportedConfigs = [
  {
    comment: 'Unrecognized codec',
    config: {codec: 'bogus'},
  },
  {
    comment: 'Unrecognized codec with dataview description',
    config: {
      codec: '7󠎢ﷺ۹.9',
      description: arrayBufferView,
    },
  },
  {
    comment: 'Audio codec',
    config: {codec: 'vorbis'},
  },
  {
    comment: 'Ambiguous codec',
    config: {codec: 'vp9'},
  },
  {
    comment: 'Codec with bad casing',
    config: {codec: 'Vp09.00.10.08'},
  },
  {
    comment: 'Codec with MIME type',
    config: {codec: 'video/webm; codecs="vp8"'},
  },
  {
    comment: 'Possible future H264 codec string',
    config: {codec: 'avc1.FF000b'},
  },
  {
    comment: 'Possible future HEVC codec string',
    config: {codec: 'hvc1.C99.6FFFFFF.L93'},
  },
  {
    comment: 'Possible future VP9 codec string',
    config: {codec: 'vp09.99.99.08'},
  },
  {
    comment: 'Possible future AV1 codec string',
    config: {codec: 'av01.9.99M.08'},
  },
];  //  validButUnsupportedConfigs

validButUnsupportedConfigs.forEach(entry => {
  promise_test(
      t => {
        return VideoDecoder.isConfigSupported(entry.config).then(support => {
          assert_false(support.supported);
        });
      },
      'Test that VideoDecoder.isConfigSupported() doesn\'t support config: ' +
          entry.comment);
});

validButUnsupportedConfigs.forEach(entry => {
  promise_test(
      t => {
        let isErrorCallbackCalled = false;
        let codec = new VideoDecoder({
          output: t.unreached_func('unexpected output'),
          error: t.step_func(e => {
            isErrorCallbackCalled = true;
            assert_true(e instanceof DOMException);
            assert_equals(e.name, 'NotSupportedError');
            assert_equals(codec.state, 'closed', 'state');
          })
        });
        codec.configure(entry.config);
        return codec.flush()
            .then(t.unreached_func('flush succeeded unexpectedly'))
            .catch(t.step_func(e => {
              assert_true(isErrorCallbackCalled, "isErrorCallbackCalled");
              assert_true(e instanceof DOMException);
              assert_equals(e.name, 'NotSupportedError');
              assert_equals(codec.state, 'closed', 'state');
            }));
      },
      'Test that VideoDecoder.configure() doesn\'t support config: ' +
          entry.comment);
});

promise_test(t => {
  // VideoDecoderInit lacks required fields.
  assert_throws_js(TypeError, () => {
    new VideoDecoder({});
  });

  // VideoDecoderInit has required fields.
  let decoder = new VideoDecoder(getDefaultCodecInit(t));

  assert_equals(decoder.state, 'unconfigured');

  decoder.close();

  return endAfterEventLoopTurn();
}, 'Test VideoDecoder construction');

const validConfigs = [
  {
    comment: 'valid codec with spaces',
    config: {codec: '  vp09.00.10.08  '},
  },
];  // validConfigs

validConfigs.forEach(entry => {
  promise_test(
    async t => {
      try {
        await VideoDecoder.isConfigSupported(entry.config);
      } catch (e) {
        assert_true(false, entry.comment + ' should not throw');
      }
    },
    'Test that VideoDecoder.isConfigSupported() accepts config:' +
        entry.comment);
});