dataset.html (1545B)
1 <!DOCTYPE html> 2 <title>dataset: should exist and work on HTML and SVG elements, but not random elements</title> 3 <link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <div id="log"></div> 7 <script> 8 var div = document.createElement("div"); 9 test(function() { 10 assert_true(div.dataset instanceof DOMStringMap); 11 }, "HTML elements should have a .dataset"); 12 test(function() { 13 assert_false("foo" in div.dataset); 14 assert_equals(div.dataset.foo, undefined); 15 }, "Should return 'undefined' before setting an attribute") 16 test(function() { 17 div.setAttribute("data-foo", "value"); 18 assert_true("foo" in div.dataset); 19 assert_equals(div.dataset.foo, "value"); 20 }, "Should return 'value' if that's the value") 21 test(function() { 22 div.setAttribute("data-foo", ""); 23 assert_true("foo" in div.dataset); 24 assert_equals(div.dataset.foo, ""); 25 }, "Should return the empty string if that's the value") 26 test(function() { 27 div.removeAttribute("data-foo"); 28 assert_false("foo" in div.dataset); 29 assert_equals(div.dataset.foo, undefined); 30 }, "Should return 'undefined' after removing an attribute") 31 test(function() { 32 assert_equals(document.createElementNS("test", "test").dataset, undefined); 33 }, "Should not have a .dataset on random elements"); 34 test(function() { 35 var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg") 36 assert_true(svg.dataset instanceof DOMStringMap); 37 }, "SVG elements should have a .dataset"); 38 </script>