| <!doctype html> |
| <title>TextTrackCue constructor</title> |
| <script src="../../../resources/testharness.js"></script> |
| <script src="../../../resources/testharnessreport.js"></script> |
| <script> |
| if (window.internals) |
| internals.settings.setGenericCueAPIEnabled(true); |
| |
| test( test => { |
| assert_throws(new TypeError, _ => { new TextTrackCue(0, 10, "") }); |
| assert_throws(new TypeError, _ => { new TextTrackCue(0, 10, { }) }); |
| assert_throws(new TypeError, _ => { new TextTrackCue(0, 10, document.createElement('div')) }); |
| }, 'TextTrackCue should throw "TypeError" if the cue node is not a documentFragment'); |
| |
| test( test => { |
| assert_throws("InvalidNodeTypeError", _ => { new TextTrackCue(0, 10, document.createDocumentFragment()) }); |
| }, 'TextTrackCue should throw "InvalidNodeTypeError" if passed an invalid documentFragment'); |
| |
| function createValidCueFragment() |
| { |
| let cueNode = document.createElement('span'); |
| cueNode.setAttribute('cue', ''); |
| |
| let backgroundNode = document.createElement('div'); |
| backgroundNode.setAttribute('cuebackground', ''); |
| backgroundNode.appendChild(cueNode); |
| |
| fragment = document.createDocumentFragment(); |
| fragment.appendChild(backgroundNode); |
| |
| return fragment; |
| } |
| |
| test( test => { |
| let fragment = createValidCueFragment(); |
| let validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.appendChild(document.createElement('table')); |
| assert_throws("InvalidNodeTypeError", _ => { new TextTrackCue(0, 10, fragment) }); |
| |
| }, `TextTrackCue should throw "InvalidNodeTypeError" if documentFragment has an invalid node`); |
| |
| test( test => { |
| let fragment = createValidCueFragment(); |
| let validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.removeAttribute('cuebackground') |
| assert_throws("InvalidStateError", _ => { new TextTrackCue(0, 10, fragment) }); |
| |
| fragment = createValidCueFragment(); |
| fragment.firstChild.firstChild.removeAttribute('cue') |
| assert_throws("InvalidStateError", _ => { new TextTrackCue(0, 10, fragment) }); |
| }, `TextTrackCue should throw "InvalidStateError" if documentFragment doesn't have 'cuebackground' and 'cue' nodes`); |
| |
| test( test => { |
| let fragment = createValidCueFragment(); |
| let validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('br')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('div')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('img')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('p')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('rb')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('rt')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('rtc')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('ruby')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createElement('span')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| fragment.firstChild.appendChild(document.createTextNode('Hello!')); |
| validCue = new TextTrackCue(0, 10, fragment); |
| |
| }, `TextTrackCue should allow all valid node types`); |
| |
| |
| test( test => { |
| let sourceFragment = createValidCueFragment(); |
| let validCue = new TextTrackCue(0, 10, fragment); |
| |
| let cueFragment = validCue.getCueAsHTML(); |
| assert_true(cueFragment instanceof DocumentFragment); |
| |
| assert_true(cueFragment.isEqualNode(sourceFragment)); |
| |
| assert_not_equals(validCue.getCueAsHTML(), cueFragment, "getCueAsHTML() should return a different fragment each time"); |
| |
| }, `Test TextTrackCue.getCueAsHTML()`); |
| |
| </script> |