OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <meta charset="utf-8"> |
| 3 <title></title> |
| 4 <script src="../../../../resources/testharness.js"></script> |
| 5 <script src="../../../../resources/testharnessreport.js"></script> |
| 6 <style> |
| 7 #element { |
| 8 display: none; |
| 9 } |
| 10 </style> |
| 11 |
| 12 <div id="element"></div> |
| 13 <div id="log"></div> |
| 14 |
| 15 <script> |
| 16 var possiblePositions = { |
| 17 'beforebegin': 'previousSibling' |
| 18 , 'afterbegin': 'firstChild' |
| 19 , 'beforeend': 'lastChild' |
| 20 , 'afterend': 'nextSibling' |
| 21 } |
| 22 var texts = { |
| 23 'beforebegin': 'raclette' |
| 24 , 'afterbegin': 'tartiflette' |
| 25 , 'beforeend': 'lasagne' |
| 26 , 'afterend': 'gateau aux pommes' |
| 27 } |
| 28 |
| 29 var el = document.querySelector('#element'); |
| 30 |
| 31 Object.keys(possiblePositions).forEach(function(position) { |
| 32 var div = document.createElement('h3'); |
| 33 test(function() { |
| 34 div.id = texts[position]; |
| 35 el.insertAdjacentElement(position, div); |
| 36 assert_equals(el[possiblePositions[position]].id, texts[position]); |
| 37 }, 'insertAdjacentElement(' + position + ', ' + div + ' )'); |
| 38 |
| 39 test(function() { |
| 40 el.insertAdjacentText(position, texts[position]); |
| 41 assert_equals(el[possiblePositions[position]].textContent, texts[position]); |
| 42 }, 'insertAdjacentText(' + position + ', ' + texts[position] + ' )'); |
| 43 }); |
| 44 |
| 45 test(function() { |
| 46 assert_throws(new TypeError(), function() { |
| 47 el.insertAdjacentElement('afterbegin', |
| 48 document.implementation.createDocumentType("html")) |
| 49 }) |
| 50 }, 'invalid object argument insertAdjacentElement') |
| 51 test(function() { |
| 52 var el = document.implementation.createHTMLDocument().documentElement; |
| 53 assert_throws("HIERARCHY_REQUEST_ERR", function() { |
| 54 el.insertAdjacentElement('beforebegin', document.createElement('banane')) |
| 55 }) |
| 56 }, 'invalid caller object insertAdjacentElement') |
| 57 test(function() { |
| 58 var el = document.implementation.createHTMLDocument().documentElement; |
| 59 assert_throws("HIERARCHY_REQUEST_ERR", function() { |
| 60 el.insertAdjacentText('beforebegin', 'tomate farcie') |
| 61 }) |
| 62 }, 'invalid caller object insertAdjacentText') |
| 63 test(function() { |
| 64 var div = document.createElement('h3'); |
| 65 assert_throws("SYNTAX_ERR", function() { |
| 66 el.insertAdjacentElement('heeeee', div) |
| 67 }) |
| 68 }, "invalid syntax for insertAdjacentElement") |
| 69 test(function() { |
| 70 assert_throws("SYNTAX_ERR", function() { |
| 71 el.insertAdjacentText('hoooo', 'magret de canard') |
| 72 }) |
| 73 }, "invalid syntax for insertAdjacentText") |
| 74 test(function() { |
| 75 var div = document.createElement('div'); |
| 76 assert_equals(div.insertAdjacentElement("beforebegin", el), null); |
| 77 }, 'insertAdjacentText should return null'); |
| 78 |
| 79 </script> |
OLD | NEW |