html5lib-basics.tentative.html (2099B)
1 <!DOCTYPE html> 2 <head> 3 <title>Basic setHTMLUnsafe test cases</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="support/html5lib-testcase-support.js"></script 7 </head> 8 <body> 9 <script type="html5lib-tests"> 10 #data 11 Hello! 12 #document 13 | "Hello!" 14 15 #data 16 <p>bla 17 #document 18 | <p> 19 | "bla" 20 21 #data 22 <p id=abc def='123'>texty<!-- xxx -->textz 23 #document 24 | <p> 25 | def="123" 26 | id="abc" 27 | "texty" 28 | <!-- xxx --> 29 | "textz" 30 31 #data 32 <p>Hello <b>World</b><span>! 33 #document 34 | <p> 35 | "Hello " 36 | <b> 37 | "World" 38 | <span> 39 | "!" 40 41 #data 42 <p>A template example.<template>Hello <b>World</b></template>! 43 #document 44 | <p> 45 | "A template example." 46 | <template> 47 | content 48 | "Hello " 49 | <b> 50 | "World" 51 | "!" 52 53 #data 54 <td>Interesting parse context.</td> 55 #document-fragment 56 table 57 #document 58 | <tbody> 59 | <tr> 60 | <td> 61 | "Interesting parse context." 62 63 #data 64 <p>A rather boring parse context. 65 #document-fragment 66 p 67 #document 68 | <p> 69 | "A rather boring parse context." 70 71 </script> 72 <script> 73 // This runs a number of simple test cases that test setHTMLUnsafe, and 74 // setHTMLUnsafe vs innerHTML. This purposely doesn't include "advanced" test 75 // cases where the behaviours of those two methodsis supposed to differ. 76 // 77 // This sort of also doubles as unit tests for html5lib-testcase-support.js 78 html5lib_testcases_from_script().forEach((testcase, index) => { 79 test(_ => { 80 const context = document.createElement(testcase["document-fragment"] ?? "div"); 81 context.setHTMLUnsafe(testcase.data); 82 assert_testcase(context, testcase); 83 }, `Testcase #${index} with .setHTMLUnsafe("${testcase.data}")`); 84 85 test(_ => { 86 const context_element = testcase["document-fragment"] ?? "div"; 87 const context = document.createElement(context_element); 88 const context2 = document.createElement(context_element); 89 90 context.setHTMLUnsafe(testcase.data); 91 context2.innerHTML = testcase.data; 92 assert_subtree_equals(context, context2); 93 }, `Testcase #${index}, .innerHTML matches .setHTMLUnsafe`); 94 }); 95 </script>