OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>dataset: should return 'undefined' for non-existent properties</title> | 2 <title>dataset: should exist and work on HTML and SVG elements, but not random e
lements</title> |
3 <link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com"> | 3 <link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com"> |
4 <script src="/resources/testharness.js"></script> | 4 <script src="/resources/testharness.js"></script> |
5 <script src="/resources/testharnessreport.js"></script> | 5 <script src="/resources/testharnessreport.js"></script> |
6 <div id="log"></div> | 6 <div id="log"></div> |
7 <script> | 7 <script> |
8 var div = document.createElement("div"); | 8 var div = document.createElement("div"); |
9 test(function() { | 9 test(function() { |
| 10 assert_true(div.dataset instanceof DOMStringMap); |
| 11 }, "HTML elements should have a .dataset"); |
| 12 test(function() { |
10 assert_false("foo" in div.dataset); | 13 assert_false("foo" in div.dataset); |
11 assert_equals(div.dataset.foo, undefined); | 14 assert_equals(div.dataset.foo, undefined); |
12 }, "Should return 'undefined' before setting an attribute") | 15 }, "Should return 'undefined' before setting an attribute") |
13 test(function() { | 16 test(function() { |
14 div.setAttribute("data-foo", "value"); | 17 div.setAttribute("data-foo", "value"); |
15 assert_true("foo" in div.dataset); | 18 assert_true("foo" in div.dataset); |
16 assert_equals(div.dataset.foo, "value"); | 19 assert_equals(div.dataset.foo, "value"); |
17 }, "Should return 'value' if that's the value") | 20 }, "Should return 'value' if that's the value") |
18 test(function() { | 21 test(function() { |
19 div.setAttribute("data-foo", ""); | 22 div.setAttribute("data-foo", ""); |
20 assert_true("foo" in div.dataset); | 23 assert_true("foo" in div.dataset); |
21 assert_equals(div.dataset.foo, ""); | 24 assert_equals(div.dataset.foo, ""); |
22 }, "Should return the empty string if that's the value") | 25 }, "Should return the empty string if that's the value") |
23 test(function() { | 26 test(function() { |
24 div.removeAttribute("data-foo"); | 27 div.removeAttribute("data-foo"); |
25 assert_false("foo" in div.dataset); | 28 assert_false("foo" in div.dataset); |
26 assert_equals(div.dataset.foo, undefined); | 29 assert_equals(div.dataset.foo, undefined); |
27 }, "Should return 'undefined' after removing an attribute") | 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"); |
28 </script> | 38 </script> |
OLD | NEW |