DOMTokenList-coverage-for-attributes.html (1769B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>DOMTokenList coverage for attributes</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <div id=log></div> 7 <script> 8 "use strict"; 9 10 var pairs = [ 11 // Defined in DOM 12 {attr: "classList", sup: ["anyElement"]}, 13 // Defined in HTML except for a which is also SVG 14 {attr: "relList", sup: ["a", "area", "link"]}, 15 // Defined in HTML 16 {attr: "htmlFor", sup: ["output"]}, 17 {attr: "sandbox", sup: ["iframe"]}, 18 {attr: "sizes", sup: ["link"]} 19 ]; 20 var namespaces = [ 21 "http://www.w3.org/1999/xhtml", 22 "http://www.w3.org/2000/svg", 23 "http://www.w3.org/1998/Math/MathML", 24 "http://example.com/", 25 "" 26 ]; 27 28 var elements = ["a", "area", "link", "iframe", "output", "td", "th"]; 29 function testAttr(pair, new_el){ 30 return (pair.attr === "classList" || 31 (pair.attr === "relList" && new_el.localName === "a" && 32 new_el.namespaceURI === "http://www.w3.org/2000/svg") || 33 (new_el.namespaceURI === "http://www.w3.org/1999/xhtml" && 34 pair.sup.indexOf(new_el.localName) != -1)); 35 } 36 37 pairs.forEach(function(pair) { 38 namespaces.forEach(function(ns) { 39 elements.forEach(function(el) { 40 var new_el = document.createElementNS(ns, el); 41 if (testAttr(pair, new_el)) { 42 test(function() { 43 assert_class_string(new_el[pair.attr], "DOMTokenList"); 44 }, new_el.localName + "." + pair.attr + " in " + new_el.namespaceURI + " namespace should be DOMTokenList."); 45 } 46 else { 47 test(function() { 48 assert_equals(new_el[pair.attr], undefined); 49 }, new_el.localName + "." + pair.attr + " in " + new_el.namespaceURI + " namespace should be undefined."); 50 } 51 }); 52 }); 53 }); 54 55 </script>