diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/webvtt/api | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webvtt/api')
28 files changed, 1035 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/align.html b/testing/web-platform/tests/webvtt/api/VTTCue/align.html new file mode 100644 index 0000000000..e3a920ae94 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/align.html @@ -0,0 +1,67 @@ +<!doctype html> +<title>VTTCue.align</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-align"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=common.js></script> +<div id=log></div> +<script> +test(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + + var cue = new VTTCue(0, 1, 'text'); + assert_true('align' in cue, 'align is not supported'); + assert_equals(cue.align, 'center'); + + var track = document.createElement('track'); + var t = track.track; + t.addCue(cue); + + assert_equals(cue.align, 'center'); + + video.appendChild(track); + assert_equals(cue.align, 'center'); + + t.mode = 'showing'; + assert_equals(cue.align, 'center'); + + cue.align = 'start'; + assert_equals(cue.align, 'start'); + + cue.align = 'end'; + assert_equals(cue.align, 'end'); + + ['start\u0000', 'centre', 'middle'].forEach(function(invalid) { + cue.align = invalid; + assert_equals(cue.align, 'end'); + }); +}, document.title+', script-created cue'); + +var t_parsed = async_test(document.title+', parsed cue'); +t_parsed.step(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + var t = document.createElement('track'); + t.onload = this.step_func(function(){ + var c1 = t.track.cues[0]; + var c2 = t.track.cues[1]; + var c3 = t.track.cues[2]; + var c4 = t.track.cues[3]; + assert_equals(c1.align, 'center'); + assert_equals(c2.align, 'start'); + assert_equals(c3.align, 'center'); + assert_equals(c4.align, 'end'); + this.done(); + }); + t.onerror = this.step_func(function() { + assert_unreached('got error event'); + }); + t.src = make_vtt_track('WEBVTT\n\n00:00:00.000 --> 00:00:00.001\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 align:start\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 align:center\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 align:end\ntest', this); + t.track.mode = 'showing'; + video.appendChild(t); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/categories.json b/testing/web-platform/tests/webvtt/api/VTTCue/categories.json new file mode 100644 index 0000000000..eaa5ef17fc --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/categories.json @@ -0,0 +1,3 @@ +{ + "region.html": "regions" +} diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/common.js b/testing/web-platform/tests/webvtt/api/VTTCue/common.js new file mode 100644 index 0000000000..2c39352a84 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/common.js @@ -0,0 +1,8 @@ +function make_vtt_track(contents, test) { + var track_blob = new Blob([contents], { type: 'text/vtt' }); + var track_url = URL.createObjectURL(track_blob); + test.add_cleanup(function() { + URL.revokeObjectURL(track_url); + }); + return track_url; +} diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/constructor-exceptions.html b/testing/web-platform/tests/webvtt/api/VTTCue/constructor-exceptions.html new file mode 100644 index 0000000000..06ad7f041c --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/constructor-exceptions.html @@ -0,0 +1,25 @@ +<!doctype html> +<title>VTTCue constructor exceptions</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +test(function() { + assert_throws_js(TypeError, function() { new VTTCue(NaN, 0, 'foo'); }); + assert_throws_js(TypeError, function() { new VTTCue(Infinity, 0, 'foo'); }); + assert_throws_js(TypeError, function() { new VTTCue('tomorrow', 0, 'foo'); }); +}, document.title+', invalid start time'); +test(function() { + assert_throws_js(TypeError, function() { new VTTCue(0, NaN, 'foo'); }); + assert_throws_js(TypeError, function() { new VTTCue(0, -Infinity, 'foo'); }); + assert_throws_js(TypeError, function() { new VTTCue(0, 'tomorrow', 'foo'); }); +}, document.title+', invalid end time'); +test(function() { + var start = { valueOf: function() { return 42; } }; + var end = { valueOf: function() { return 84; } }; + var cue = new VTTCue(start, end, 'bar'); + assert_equals(cue.startTime, 42); + assert_equals(cue.endTime, 84); + assert_equals(cue.text, 'bar'); +}, document.title+', valueOf'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/constructor.html b/testing/web-platform/tests/webvtt/api/VTTCue/constructor.html new file mode 100644 index 0000000000..2937f0cecb --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/constructor.html @@ -0,0 +1,56 @@ +<!doctype html> +<title>VTTCue()</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-vttcue"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var cue = new VTTCue(3, 12, 'foo bar'); + + assert_equals(cue.startTime, 3); + assert_equals(cue.endTime, 12); + assert_equals(cue.text, 'foo bar'); + assert_equals(cue.id, ''); + assert_equals(cue.region, null); + assert_equals(cue.pauseOnExit, false); + assert_equals(cue.snapToLines, true); + assert_equals(cue.line, 'auto'); + assert_equals(cue.lineAlign, 'start'); + assert_equals(cue.position, 'auto'); + assert_equals(cue.positionAlign, 'auto'); + assert_equals(cue.size, 100); + assert_equals(cue.align, 'center'); +}, document.title + ', initial values'); + +test(function() { + var cue = new VTTCue(-1, 12, 'foo bar'); + + assert_equals(cue.startTime, -1); + assert_equals(cue.endTime, 12); +}, document.title + ', bad start time'); + + +test(function() { + var cue = new VTTCue(2, -1, 'foo bar'); + + assert_equals(cue.startTime, 2); + assert_equals(cue.endTime, -1); +}, document.title + ', bad end time'); + +test(function() { + var cue = new VTTCue(2, +Infinity, 'foo bar'); + + assert_equals(cue.startTime, 2); + assert_equals(cue.endTime, +Infinity); +}, document.title + ', unbounded end time'); + +test(function() { + var cue = new VTTCue(3, 12, '<i>foo bar</i>'); + + var frag = cue.getCueAsHTML(); + assert_equals(frag.childNodes.length, 1); + assert_equals(frag.childNodes[0].localName, 'i'); + assert_equals(frag.childNodes[0].textContent, 'foo bar'); +}, document.title + ', text formatting'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/getCueAsHTML.html b/testing/web-platform/tests/webvtt/api/VTTCue/getCueAsHTML.html new file mode 100644 index 0000000000..2f07d3aa0a --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/getCueAsHTML.html @@ -0,0 +1,93 @@ +<!doctype html> +<title>VTTCue.getCueAsHTML()</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-getcueashtml"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var video = document.createElement('video'); + var t1 = video.addTextTrack('subtitles'); + document.body.appendChild(video); + var c1 = new VTTCue(0, 1, '<c></c><c.a.b></c><i></i><b></b><u></u><ruby><rt></rt></ruby><v></v><v a b></v><1:00:00.500>x\0'); + t1.addCue(c1); + window.frag = c1.getCueAsHTML(); + assert_equals(frag.childNodes.length, 10, 'childNodes.length'); + assert_true(frag instanceof DocumentFragment, 'getCueAsHTML() should return DocumentFragment'); +}, document.title+', creating the cue'); +test(function(){ + assert_equals(frag.childNodes[0].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[0].localName, 'span', 'localName'); + assert_equals(frag.childNodes[0].attributes.length, 0, 'attributes'); + assert_false(frag.childNodes[0].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[0] instanceof HTMLElement, 'instanceof'); +}, document.title+', <c>'); +test(function(){ + assert_equals(frag.childNodes[1].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[1].localName, 'span', 'localName'); + assert_equals(frag.childNodes[1].attributes.length, 1, 'attributes'); + assert_equals(frag.childNodes[1].getAttributeNS('', 'class'), 'a b', 'class attribute'); + assert_false(frag.childNodes[1].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[1] instanceof HTMLElement, 'instanceof'); +}, document.title+', <c.a.b>'); +test(function(){ + assert_equals(frag.childNodes[2].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[2].localName, 'i', 'localName'); + assert_equals(frag.childNodes[2].attributes.length, 0, 'attributes'); + assert_false(frag.childNodes[2].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[2] instanceof HTMLElement, 'instanceof'); +}, document.title+', <i>'); +test(function(){ + assert_equals(frag.childNodes[3].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[3].localName, 'b', 'localName'); + assert_equals(frag.childNodes[3].attributes.length, 0, 'attributes'); + assert_false(frag.childNodes[3].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[3] instanceof HTMLElement, 'instanceof'); +}, document.title+', <b>'); +test(function(){ + assert_equals(frag.childNodes[4].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[4].localName, 'u', 'localName'); + assert_equals(frag.childNodes[4].attributes.length, 0, 'attributes'); + assert_false(frag.childNodes[4].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[4] instanceof HTMLElement, 'instanceof'); +}, document.title+', <u>'); +test(function(){ + assert_equals(frag.childNodes[5].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[5].localName, 'ruby', 'localName'); + assert_equals(frag.childNodes[5].attributes.length, 0, 'attributes'); + assert_true(frag.childNodes[5].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[5] instanceof HTMLElement, 'instanceof'); +}, document.title+', <ruby>'); +test(function(){ + assert_equals(frag.childNodes[5].firstChild.namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[5].firstChild.localName, 'rt', 'localName'); + assert_equals(frag.childNodes[5].firstChild.attributes.length, 0, 'attributes'); + assert_false(frag.childNodes[5].firstChild.hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[5].firstChild instanceof HTMLElement, 'instanceof'); +}, document.title+', <rt>'); +test(function(){ + assert_equals(frag.childNodes[6].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[6].localName, 'span', 'localName'); + assert_equals(frag.childNodes[6].attributes.length, 1, 'attributes'); + assert_equals(frag.childNodes[6].getAttributeNS('', 'title'), '', 'title attribute'); + assert_false(frag.childNodes[6].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[6] instanceof HTMLElement, 'instanceof'); +}, document.title+', <v>'); +test(function(){ + assert_equals(frag.childNodes[7].namespaceURI, 'http://www.w3.org/1999/xhtml', 'namespaceURI'); + assert_equals(frag.childNodes[7].localName, 'span', 'localName'); + assert_equals(frag.childNodes[7].attributes.length, 1, 'attributes'); + assert_equals(frag.childNodes[7].getAttributeNS('', 'title'), 'a b', 'title attribute'); + assert_false(frag.childNodes[7].hasChildNodes(), 'hasChildNodes()'); + assert_true(frag.childNodes[7] instanceof HTMLElement, 'instanceof'); +}, document.title+', <v a b>'); +test(function(){ + assert_equals(frag.childNodes[8].target, 'timestamp', 'target'); + assert_equals(frag.childNodes[8].data, '01:00:00.500', 'data'); + assert_true(frag.childNodes[8] instanceof ProcessingInstruction, 'instanceof'); +}, document.title+', <1:00:00.500>'); +test(function(){ + assert_equals(frag.childNodes[9].data, 'x\0', 'data'); + assert_true(frag.childNodes[9] instanceof Text, 'instanceof'); +}, document.title+', x\\0'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/line.html b/testing/web-platform/tests/webvtt/api/VTTCue/line.html new file mode 100644 index 0000000000..dcf46db052 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/line.html @@ -0,0 +1,65 @@ +<!doctype html> +<title>VTTCue.line</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-line"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=common.js></script> +<div id=log></div> +<script> +test(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + var c1 = new VTTCue(0, 1, 'text1'); + assert_true('line' in c1, 'line is not supported'); + assert_equals(c1.line, "auto"); + var track = document.createElement('track'); + var t = track.track; + t.addCue(c1); + assert_equals(c1.line, "auto"); + video.appendChild(track); + assert_equals(c1.line, "auto"); + t.mode = 'showing'; + assert_equals(c1.line, "auto"); + var c2 = new VTTCue(0, 1, 'text2'); + var track2 = document.createElement('track'); + var t2 = track2.track; + t2.addCue(c2); + assert_equals(c2.line, "auto"); + video.appendChild(track2); + t2.mode = 'showing'; + assert_equals(c2.line, "auto"); + assert_equals(c1.line, "auto"); + c1.line = -5; + assert_equals(c1.line, -5); + assert_equals(c2.line, "auto"); + c1.line = 0; + c1.snapToLines = false; + assert_equals(c1.line, 0); + assert_equals(c2.line, "auto"); +}, document.title+', script-created cue'); + +var t_parsed = async_test(document.title+', parsed cue'); +t_parsed.step(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + var t = document.createElement('track'); + t.onload = this.step_func(function(){ + var c1 = t.track.cues[0]; + var c2 = t.track.cues[1]; + var c3 = t.track.cues[2]; + assert_equals(c1.line, "auto"); + assert_equals(c2.line, 0); + assert_equals(c3.line, 0); + + this.done(); + }); + t.onerror = this.step_func(function() { + assert_unreached('got error event'); + }); + t.src = make_vtt_track('WEBVTT\n\n00:00:00.000 --> 00:00:00.001\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 line:0\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 line:0%\ntest', this); + t.track.mode = 'showing'; + video.appendChild(t); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/lineAlign.html b/testing/web-platform/tests/webvtt/api/VTTCue/lineAlign.html new file mode 100644 index 0000000000..7be0d540e1 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/lineAlign.html @@ -0,0 +1,39 @@ +<!doctype html> +<title>VTTCue.lineAlign</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-linealign"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + + var cue = new VTTCue(0, 1, 'text'); + assert_true('lineAlign' in cue, 'lineAlign is not supported'); + assert_equals(cue.lineAlign, 'start'); + + var track = document.createElement('track'); + var t = track.track; + t.addCue(cue); + + assert_equals(cue.lineAlign, 'start'); + + video.appendChild(track); + assert_equals(cue.lineAlign, 'start'); + + t.mode = 'showing'; + assert_equals(cue.lineAlign, 'start'); + + cue.lineAlign = 'center'; + assert_equals(cue.lineAlign, 'center'); + + cue.lineAlign = 'end'; + assert_equals(cue.lineAlign, 'end'); + + ['start\u0000', 'centre', 'middle'].forEach(function(invalid) { + cue.lineAlign = invalid; + assert_equals(cue.lineAlign, 'end'); + }); +}, document.title+', script-created cue'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/position.html b/testing/web-platform/tests/webvtt/api/VTTCue/position.html new file mode 100644 index 0000000000..c0485e7a79 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/position.html @@ -0,0 +1,32 @@ +<!doctype html> +<title>VTTCue.position</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-position"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var cue = new VTTCue(0, 1, 'text'); + assert_true('position' in cue, 'position is not supported'); + + cue.position = 'auto'; + assert_equals(cue.position, 'auto'); + + for (i = 0; i <= 100; i++) { + cue.position = i; + assert_equals(cue.position, i); + } + + [-1, -100, -101, 101, 200, 201].forEach(function(invalid) { + assert_throws_dom('IndexSizeError', function() { + cue.position = invalid; + }); + }); + + cue.position = 1.5; + assert_equals(cue.position, 1.5); + + cue.position = 'auto'; + assert_equals(cue.position, 'auto'); +}, document.title+', script-created cue'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/positionAlign.html b/testing/web-platform/tests/webvtt/api/VTTCue/positionAlign.html new file mode 100644 index 0000000000..bde1c6eee7 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/positionAlign.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>VTTCue.positionAlign</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-positionalign"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var cue = new VTTCue(0, 1, 'text'); + assert_true('positionAlign' in cue, 'positionAlign is not supported'); + + ['line-left', 'center', 'line-right', 'auto'].forEach(function(valid) { + cue.positionAlign = valid; + assert_equals(cue.positionAlign, valid); + }); + + cue.positionAlign = 'center'; + ['auto\u0000', 'centre', 'middle'].forEach(function(invalid) { + cue.positionAlign = invalid; + assert_equals(cue.positionAlign, 'center'); + }); +}, document.title+', script-created cue'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/region.html b/testing/web-platform/tests/webvtt/api/VTTCue/region.html new file mode 100644 index 0000000000..ae51c5f603 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/region.html @@ -0,0 +1,38 @@ +<!doctype html> +<title>VTTCue.region</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-region"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + + var cue = new VTTCue(0, 1, 'text'); + assert_true('region' in cue, 'region is not supported'); + assert_equals(cue.region, null); + + var track = document.createElement('track'); + var t = track.track; + t.addCue(cue); + + assert_equals(cue.region, null); + + video.appendChild(track); + assert_equals(cue.region, null); + + t.mode = 'showing'; + assert_equals(cue.region, null); + + var region = new VTTRegion(); + cue.region = region; + assert_equals(cue.region, region); + + cue.region = 'foo'; + assert_equals(cue.region, region); + + cue.region = null; + assert_equals(cue.region, null); +}, document.title+', script-created cue'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/size.html b/testing/web-platform/tests/webvtt/api/VTTCue/size.html new file mode 100644 index 0000000000..fdb8059c72 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/size.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>VTTCue.size</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-size"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var cue = new VTTCue(0, 1, 'text'); + assert_true('size' in cue, 'size is not supported'); + + for (i = 0; i <= 100; i++) { + cue.size = i; + assert_equals(cue.size, i); + } + + [-1, -100, -101, 101, 200, 201].forEach(function(invalid) { + assert_throws_dom('IndexSizeError', function() { + cue.size = invalid; + }); + }); + + cue.size = 1.5; + assert_equals(cue.size, 1.5); +}, document.title+', script-created cue'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/snapToLines.html b/testing/web-platform/tests/webvtt/api/VTTCue/snapToLines.html new file mode 100644 index 0000000000..b3f9f34f10 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/snapToLines.html @@ -0,0 +1,100 @@ +<!doctype html> +<title>VTTCue.snapToLines</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-snaptolines"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=common.js></script> +<div id=log></div> +<script> +setup(function(){ + window.video = document.createElement('video'); + window.t1 = video.addTextTrack('subtitles'); + document.body.appendChild(video); +}); +test(function(){ + var c1 = new VTTCue(0, 1, 'text1'); + assert_true('snapToLines' in c1, 'snapToLines is not supported'); + assert_true(c1.snapToLines); + c1.line = 101; + c1.snapToLines = false; + assert_false(c1.snapToLines); + c1.snapToLines = true; + assert_true(c1.snapToLines); + c1.line = -1; + c1.snapToLines = false; + assert_false(c1.snapToLines); + c1.snapToLines = true; + assert_true(c1.snapToLines); + c1.line = 0; + c1.snapToLines = false; + assert_false(c1.snapToLines); +}, document.title+', script-created cue'); + +var t_parsed = async_test(document.title+', parsed cue'); +t_parsed.step(function(){ + var t = document.createElement('track'); + t.onload = this.step_func(function(){ + var c1 = t.track.cues[0]; + assert_true(c1.snapToLines); + c1.line = 101; + c1.snapToLines = false; + assert_false(c1.snapToLines); + c1.snapToLines = true; + assert_true(c1.snapToLines); + c1.line = -1; + c1.snapToLines = false; + assert_false(c1.snapToLines); + c1.snapToLines = true; + assert_true(c1.snapToLines); + c1.line = 0; + c1.snapToLines = false; + assert_false(c1.snapToLines); + + var c2 = t.track.cues[1]; + assert_true(c2.snapToLines); + c2.line = 101; + c2.snapToLines = false; + assert_false(c2.snapToLines); + c2.snapToLines = true; + assert_true(c2.snapToLines); + c2.line = -1; + c2.snapToLines = false; + assert_false(c2.snapToLines); + c2.snapToLines = true; + assert_true(c2.snapToLines); + c2.line = 0; + c2.snapToLines = false; + assert_false(c2.snapToLines); + + var c3 = t.track.cues[2]; + assert_false(c3.snapToLines); + c3.snapToLines = false; + assert_false(c3.snapToLines); + c3.snapToLines = true; + assert_true(c3.snapToLines); + c3.line = 101; + c3.snapToLines = false; + assert_false(c3.snapToLines); + c3.snapToLines = true; + assert_true(c3.snapToLines); + c3.line = -1; + c3.snapToLines = false; + assert_false(c3.snapToLines); + c3.snapToLines = true; + assert_true(c3.snapToLines); + c3.line = 0; + c3.snapToLines = false; + assert_false(c3.snapToLines); + + this.done(); + }); + t.onerror = this.step_func(function() { + assert_unreached('got error event'); + }); + t.src = make_vtt_track('WEBVTT\n\n00:00:00.000 --> 00:00:00.001\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 line:0\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 line:0%\ntest', this); + t.track.mode = 'showing'; + video.appendChild(t); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/text.html b/testing/web-platform/tests/webvtt/api/VTTCue/text.html new file mode 100644 index 0000000000..a61c600db9 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/text.html @@ -0,0 +1,41 @@ +<!doctype html> +<title>VTTCue.text</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-text"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=common.js></script> +<div id=log></div> +<script> +setup(function(){ + window.video = document.createElement('video'); + window.t1 = video.addTextTrack('subtitles'); + document.body.appendChild(video); +}); +test(function(){ + var c1 = new VTTCue(0, 1, 'text1\r\n\n\u0000'); + assert_true('text' in c1, 'text is not supported'); + assert_equals(c1.text, 'text1\r\n\n\u0000'); + c1.text = c1.text; + assert_equals(c1.text, 'text1\r\n\n\u0000'); + c1.text = null; + assert_equals(c1.text, 'null'); +}, document.title+', script-created cue'); + +var t_parsed = async_test(document.title+', parsed cue'); +t_parsed.step(function(){ + var t = document.createElement('track'); + t.onload = this.step_func(function(){ + var c = t.track.cues; + assert_equals(c[0].text, ''); + assert_equals(c[1].text, 'test'); + this.done(); + }); + t.onerror = this.step_func(function() { + assert_unreached('got error event'); + }); + t.src = make_vtt_track('WEBVTT\n\n00:00:00.000 --> 00:00:00.001\n'+ + '\n\nfoobar\n00:00:00.000 --> 00:00:00.001\ntest', this); + t.track.mode = 'showing'; + video.appendChild(t); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTCue/vertical.html b/testing/web-platform/tests/webvtt/api/VTTCue/vertical.html new file mode 100644 index 0000000000..8b93f6b003 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTCue/vertical.html @@ -0,0 +1,57 @@ +<!doctype html> +<title>VTTCue.vertical</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttcue-vertical"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=common.js></script> +<div id=log></div> +<script> +setup(function(){ + window.video = document.createElement('video'); + window.t1 = video.addTextTrack('subtitles'); + document.body.appendChild(video); +}); +test(function(){ + var video = document.createElement('video'); + document.body.appendChild(video); + var c1 = new VTTCue(0, 1, 'text1'); + assert_true('vertical' in c1, 'vertical is not supported'); + assert_equals(c1.vertical, ''); + var track = document.createElement('track'); + var t = track.track; + t.addCue(c1); + assert_equals(c1.vertical, ''); + video.appendChild(track); + assert_equals(c1.vertical, ''); + t.mode = 'showing'; + assert_equals(c1.vertical, ''); + c1.vertical = 'rl'; + assert_equals(c1.vertical, 'rl'); + c1.vertical = 'lr'; + assert_equals(c1.vertical, 'lr'); + c1.vertical = 'rl\u0000'; + assert_equals(c1.vertical, 'lr'); +}, document.title+', script-created cue'); + +var t_parsed = async_test(document.title+', parsed cue'); +t_parsed.step(function(){ + var t = document.createElement('track'); + t.onload = this.step_func(function(){ + var c1 = t.track.cues[0]; + var c2 = t.track.cues[1]; + var c3 = t.track.cues[2]; + assert_equals(c1.vertical, ''); + assert_equals(c2.vertical, 'rl'); + assert_equals(c3.vertical, 'lr'); + this.done(); + }); + t.onerror = this.step_func(function() { + assert_unreached('got error event'); + }); + t.src = make_vtt_track('WEBVTT\n\n00:00:00.000 --> 00:00:00.001\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 vertical:rl\ntest\n\n'+ + '00:00:00.000 --> 00:00:00.001 vertical:lr\ntest', this); + t.track.mode = 'showing'; + video.appendChild(t); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/constructor.html b/testing/web-platform/tests/webvtt/api/VTTRegion/constructor.html new file mode 100644 index 0000000000..a427f4f7d6 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/constructor.html @@ -0,0 +1,67 @@ +<!doctype html> +<title>VTTRegion()</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-vttregion"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true(region instanceof VTTRegion, "instanceof"); + + assert_equals(region.scroll, ""); + assert_equals(region.viewportAnchorX, 0); + assert_equals(region.viewportAnchorY, 100); + assert_equals(region.regionAnchorX, 0); + assert_equals(region.regionAnchorY, 100); + assert_equals(region.lines, 3); + assert_equals(region.width, 100); +}, document.title + " initial values"); + +test(function() { + var region = new VTTRegion(); + region.scroll = "invalid-scroll-value"; + assert_equals(region.scroll, ""); + + checkValues([-1, 101], "IndexSizeError"); + checkValues([-Infinity, Infinity, NaN], TypeError); + + function assert_throws_something(error, func) { + if (typeof error == "string") { + assert_throws_dom(error, func); + } else { + assert_throws_js(error, func); + } + } + + function checkValues(invalidValues, exception) { + for (var value of invalidValues) { + assert_throws_something(exception, function() { region.viewportAnchorX = value; }); + assert_equals(region.viewportAnchorX, 0); + assert_throws_something(exception, function() { region.viewportAnchorY = value; }); + assert_equals(region.viewportAnchorY, 100); + assert_throws_something(exception, function() { region.regionAnchorX = value; }); + assert_equals(region.regionAnchorX, 0); + assert_throws_something(exception, function() { region.regionAnchorY = value; }); + assert_equals(region.regionAnchorY, 100); + assert_throws_something(exception, function() { region.width = value; }); + assert_equals(region.width, 100); + } + } + + assert_equals(region.lines, 3); + + region.lines = 130; + assert_equals(region.lines, 130); + region.viewportAnchorX = 64; + assert_equals(region.viewportAnchorX, 64); + region.viewportAnchorY = 32; + assert_equals(region.viewportAnchorY, 32); + region.regionAnchorX = 16; + assert_equals(region.regionAnchorX, 16); + region.regionAnchorY = 8; + assert_equals(region.regionAnchorY, 8); + region.width = 42; + assert_equals(region.width, 42); +}, document.title + " mutations"); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/id.html b/testing/web-platform/tests/webvtt/api/VTTRegion/id.html new file mode 100644 index 0000000000..1eabac2d16 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/id.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>VTTRegion.id</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-id"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('id' in region, 'id is not supported'); + + assert_equals(region.id, '', 'initial value'); + + region.id = '1'; + assert_equals(region.id, '1', 'value after setting to "1"'); + + region.id = ''; + assert_equals(region.id, '', 'value after setting to the empty string'); + +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/lines.html b/testing/web-platform/tests/webvtt/api/VTTRegion/lines.html new file mode 100644 index 0000000000..9bde9a1947 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/lines.html @@ -0,0 +1,36 @@ +<!doctype html> +<title>VTTRegion.lines</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-lines"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('lines' in region, 'lines is not supported'); + + for (var i = 1; i <= 100; i++) { + region.lines = i; + assert_equals(region.lines, i); + } + + // https://webidl.spec.whatwg.org/#abstract-opdef-converttoint + [[0, 0], + [-0, 0], + [-1, 4294967295], + [-100, 4294967196], + [101, 101], + [-2147483648, 2147483648], + [2147483647, 2147483647], + [2147483648, 2147483648], + [NaN, 0], + [Infinity, 0], + [-Infinity, 0]].forEach(function (pair) { + var input = pair[0]; + var expected = pair[1]; + region.lines = input; + assert_equals(region.lines, expected); + }); + +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/non-visible-cue-with-region.html b/testing/web-platform/tests/webvtt/api/VTTRegion/non-visible-cue-with-region.html new file mode 100644 index 0000000000..5a48e46520 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/non-visible-cue-with-region.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<title>Box-less VTTCue attached to VTTRegion</title> +<script src="/common/media.js"></script> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<video></video> +<script> +setup(function() { + window.video = document.querySelector('video'); + video.src = getVideoURI('/media/test'); +}); +async_test(function(t) { + let track = video.addTextTrack('subtitles'); + let cue = new VTTCue(0, 1, ''); + cue.region = new VTTRegion(); + cue.onexit = t.step_func_done(function() { + video.pause(); + }); + track.addCue(cue); + video.onloadedmetadata = t.step_func(function() { + video.currentTime = 0.8; + video.play(); + }); + video.onended = t.unreached_func('test ends before video'); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/regionAnchorX.html b/testing/web-platform/tests/webvtt/api/VTTRegion/regionAnchorX.html new file mode 100644 index 0000000000..f7663366cb --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/regionAnchorX.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>VTTRegion.regionAnchorX</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-regionanchorx"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('regionAnchorX' in region, 'regionAnchorX is not supported'); + + for (var i = 0; i <= 100; i++) { + region.regionAnchorX = i; + assert_equals(region.regionAnchorX, i); + } + + region.regionAnchorX = 1.5; + assert_equals(region.regionAnchorX, 1.5); + + [-1, -100, -150, 101, 200, 250].forEach(function (invalid) { + assert_throws_dom('IndexSizeError', function() { + region.regionAnchorX = invalid; + }); + }); +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/regionAnchorY.html b/testing/web-platform/tests/webvtt/api/VTTRegion/regionAnchorY.html new file mode 100644 index 0000000000..174ff67890 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/regionAnchorY.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>VTTRegion.regionAnchorY</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-regionanchory"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('regionAnchorY' in region, 'regionAnchorY is not supported'); + + for (var i = 0; i <= 100; i++) { + region.regionAnchorY = i; + assert_equals(region.regionAnchorY, i); + } + + region.regionAnchorX = 1.5; + assert_equals(region.regionAnchorX, 1.5); + + [-1, -100, -150, 101, 200, 250].forEach(function (invalid) { + assert_throws_dom('IndexSizeError', function() { + region.regionAnchorY = invalid; + }); + }); +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/scroll.html b/testing/web-platform/tests/webvtt/api/VTTRegion/scroll.html new file mode 100644 index 0000000000..63dc50ab45 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/scroll.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>VTTRegion.scroll</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-scroll"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('scroll' in region, 'scroll is not supported'); + + region.scroll = ''; + assert_equals(region.scroll, ''); + + region.scroll = 'up'; + assert_equals(region.scroll, 'up'); + + region.scroll = 'down'; + assert_equals(region.scroll, 'up'); + + region.scroll = ''; + for (var invalid in ['left', 'right', 'center', 'top', 'bottom', 'down']) { + region.scroll = invalid; + assert_equals(region.scroll, ''); + } +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/viewportAnchorX.html b/testing/web-platform/tests/webvtt/api/VTTRegion/viewportAnchorX.html new file mode 100644 index 0000000000..0786585d46 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/viewportAnchorX.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>VTTRegion.viewportAnchorX</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-viewportanchorx"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('viewportAnchorX' in region, 'viewportAnchorX is not supported'); + + for (var i = 0; i <= 100; i++) { + region.viewportAnchorX = i; + assert_equals(region.viewportAnchorX, i); + } + + region.viewportAnchorX = 1.5; + assert_equals(region.viewportAnchorX, 1.5); + + [-1, -100, -150, 101, 200, 250].forEach(function (invalid) { + assert_throws_dom('IndexSizeError', function() { + region.viewportAnchorX = invalid; + }); + }); +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/viewportAnchorY.html b/testing/web-platform/tests/webvtt/api/VTTRegion/viewportAnchorY.html new file mode 100644 index 0000000000..de43567b62 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/viewportAnchorY.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>VTTRegion.viewportAnchorY</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-viewportanchory"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var region = new VTTRegion(); + assert_true('viewportAnchorY' in region, 'viewportAnchorY is not supported'); + + for (var i = 0; i <= 100; i++) { + region.viewportAnchorY = i; + assert_equals(region.viewportAnchorY, i); + } + + region.viewportAnchorY = 1.5; + assert_equals(region.viewportAnchorY, 1.5); + + [-1, -100, -150, 101, 200, 250].forEach(function (invalid) { + assert_throws_dom('IndexSizeError', function() { + region.viewportAnchorY = invalid; + }); + }); +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/VTTRegion/width.html b/testing/web-platform/tests/webvtt/api/VTTRegion/width.html new file mode 100644 index 0000000000..97c1c73956 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/VTTRegion/width.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>VTTRegion.width</title> +<link rel="help" href="https://w3c.github.io/webvtt/#dom-vttregion-width"> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function(){ + var region = new VTTRegion(); + assert_true('width' in region, 'width is not supported'); + + for (var i = 0; i <= 100; i++) { + region.width = i; + assert_equals(region.width, i); + } + + region.width = 1.5; + assert_equals(region.width, 1.5); + + [-1, -100, -150, 101, 200, 250].forEach(function (invalid) { + assert_throws_dom('IndexSizeError', function() { + region.width = invalid; + }); + }); +}, document.title + ' script-created region'); +</script> diff --git a/testing/web-platform/tests/webvtt/api/categories.json b/testing/web-platform/tests/webvtt/api/categories.json new file mode 100644 index 0000000000..7ce5b13f72 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/categories.json @@ -0,0 +1,5 @@ +{ + ":subcategories": ["VTTCue/categories.json"], + "VTTCue/*": "cues", + "VTTRegion/*": "regions" +} diff --git a/testing/web-platform/tests/webvtt/api/historical.html b/testing/web-platform/tests/webvtt/api/historical.html new file mode 100644 index 0000000000..8f6c09bf52 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/historical.html @@ -0,0 +1,35 @@ +<!doctype html> +<title>Historical WebVTT APIs must not be supported</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +// Also see /html/semantics/embedded-content/media-elements/historical.html + +[ + // https://github.com/w3c/webvtt/pull/31 + ['VTTCue', 'regionId'], + ['TextTrack', 'regions'], + ['TextTrack', 'addRegion'], + ['TextTrack', 'removeRegion'], + ['VTTRegion', 'track'], + // id re-introduced in https://github.com/w3c/webvtt/pull/349/files + +].forEach(function(feature) { + var interf = feature[0]; + var member = feature[1]; + test(function() { + assert_true(interf in window, interf + ' is not supported'); + assert_false(member in window[interf].prototype); + }, interf + ' ' + member + ' member must be nuked'); +}); + +[ + // https://github.com/w3c/webvtt/pull/31 + 'VTTRegionList', + +].forEach(function(interf) { + test(function() { + assert_false(interf in window); + }, interf + ' interface must be nuked'); +}); +</script> diff --git a/testing/web-platform/tests/webvtt/api/idlharness.window.js b/testing/web-platform/tests/webvtt/api/idlharness.window.js new file mode 100644 index 0000000000..53c1ded674 --- /dev/null +++ b/testing/web-platform/tests/webvtt/api/idlharness.window.js @@ -0,0 +1,15 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js + +'use strict'; + +idl_test( + ['webvtt'], + ['html', 'dom'], + idl_array => { + idl_array.add_objects({ + VTTCue: ['new VTTCue(0, 0, "")'], + VTTRegion: ['new VTTRegion()'], + }); + } +); |