blob: 8c054250963f2e217efef87d6f11f23eb2c80189 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src=../media-file.js></script>
<script src=../video-test.js></script>
<script>
function loaded()
{
expectedData = new Uint8Array([4, 5, 2, 1, 9]);
cue = new DataCue(3, 10, expectedData.buffer);
consoleWrite("<br>*** Test DataCue's TextTrackCue interface.");
testExpected("cue", TextTrackCue, "instanceof");
testExpected("cue.track", null);
testExpected("cue.id", "");
testExpected("cue.startTime", 3);
testExpected("cue.endTime", 10);
testExpected("cue.pauseOnExit", false);
consoleWrite("<br>*** Test DataCue interface.");
testExpected("cue", DataCue, "instanceof");
testArraysEqual("new Uint8Array(cue.data)", expectedData);
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=24687
consoleWrite("<br>*** Changing the original buffer data should not effect DataCue.data.");
// Passing data to constructor then changing the original buffer
run("expectedData[0] = 7");
testExpected("new Uint8Array(cue.data)[0]", 4);
// Setting .data then changing the original buffer
run("cue.data = expectedData.buffer");
testExpected("new Uint8Array(cue.data)[0]", 7);
run("expectedData[0] = 11");
testExpected("new Uint8Array(cue.data)[0]", 7);
// Getting .data then changing the original buffer
run("new Uint8Array(cue.data)[0] = 8");
testExpected("(new Uint8Array(cue.data))[0]", 7);
consoleWrite("<br>*** Throw exception if data is not an ArrayBuffer.");
var error = "'TypeError: The DataCue.data attribute must be an instance of ArrayBuffer'";
testException("cue.data = null", error);
testException("cue.data = 'test'", error);
testException("cue.data = [5]", error);
consoleWrite("<br>*** Constructor with value argument.");
testExpected("new DataCue(1, 2, null).value", null, "===");
testExpected("new DataCue(1, 2, 'test').value", 'test', "===");
testArraysEqual("new DataCue(1, 2, [5]).value", [5]);
consoleWrite("<br>*** Test adding DataCue to track with kind = 'metadata'.");
var video = document.createElement("video");
metadataTrack = video.addTextTrack("metadata");
metadataTrack.addCue(cue);
testExpected("cue.track", metadataTrack);
testExpected("metadataTrack.cues[0]", cue);
consoleWrite("<br>*** Test adding DataCue to track with kind != 'metadata'.");
["subtitles", "captions", "descriptions", "chapters"].forEach(function(kind) {
track = video.addTextTrack(kind);
testDOMException("track.addCue(cue)", "DOMException.INVALID_NODE_TYPE_ERR");
testExpected("track.cues.length", 0);
});
endTest();
}
</script>
</head>
<body onload="loaded()">
<p>Tests DataCue interface</p>
</body>
</html>