| OLD | NEW |
| 1 <?xml version="1.0" encoding="UTF-8"?> | 1 <?xml version="1.0" encoding="UTF-8"?> |
| 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/
DTD/xhtml11.dtd"> | 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/
DTD/xhtml11.dtd"> |
| 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/js-test.js"></script> |
| 6 </head> | 6 </head> |
| 7 <body> | 7 <body> |
| 8 <script src="script-tests/dataset-xhtml.js"></script> | 8 <script> |
| 9 description("This tests element.dataset for XHTML."); |
| 10 |
| 11 function testGet(attr, expected) |
| 12 { |
| 13 var d = document.createElement("div"); |
| 14 d.setAttribute(attr, "value"); |
| 15 return d.dataset[expected] == "value"; |
| 16 } |
| 17 |
| 18 shouldBeTrue("testGet('data-foo', 'foo')"); |
| 19 shouldBeTrue("testGet('data-foo-bar', 'fooBar')"); |
| 20 shouldBeTrue("testGet('data--', '-')"); |
| 21 shouldBeTrue("testGet('data--foo', 'Foo')"); |
| 22 shouldBeTrue("testGet('data---foo', '-Foo')"); |
| 23 shouldBeTrue("testGet('data-', '')"); |
| 24 shouldBeTrue("testGet('data-\xE0', '\xE0')"); |
| 25 debug(""); |
| 26 |
| 27 function matchesNothingInDataset(attr) |
| 28 { |
| 29 var d = document.createElement("div"); |
| 30 d.setAttribute(attr, "value"); |
| 31 |
| 32 var count = 0; |
| 33 for (var item in d.dataset) |
| 34 count++; |
| 35 return count == 0; |
| 36 } |
| 37 |
| 38 shouldBeTrue("matchesNothingInDataset('dataFoo')"); |
| 39 shouldBeTrue("matchesNothingInDataset('data-Foo')"); |
| 40 debug(""); |
| 41 |
| 42 function testSet(prop, expected) |
| 43 { |
| 44 var d = document.createElement("div"); |
| 45 d.dataset[prop] = "value"; |
| 46 return d.getAttribute(expected) == "value"; |
| 47 } |
| 48 |
| 49 shouldBeTrue("testSet('foo', 'data-foo')"); |
| 50 shouldBeTrue("testSet('fooBar', 'data-foo-bar')"); |
| 51 shouldBeTrue("testSet('-', 'data--')"); |
| 52 shouldBeTrue("testSet('Foo', 'data--foo')"); |
| 53 shouldBeTrue("testSet('-Foo', 'data---foo')"); |
| 54 shouldBeTrue("testSet('', 'data-')"); |
| 55 shouldBeTrue("testSet('\xE0', 'data-\xE0')"); |
| 56 debug(""); |
| 57 |
| 58 shouldThrow("testSet('-foo', 'dummy')", '"SyntaxError: Failed to set the \'-foo\
' property on \'DOMStringMap\': \'-foo\' is not a valid property name."'); |
| 59 shouldThrow("testSet('foo\x20', 'dummy')", '"InvalidCharacterError: Failed to se
t the \'foo\x20\' property on \'DOMStringMap\': \'data-foo\x20\' is not a valid
attribute name."'); |
| 60 shouldThrow("testSet('foo\uF900', 'dummy')", '"InvalidCharacterError: Failed to
set the \'foo\uF900\' property on \'DOMStringMap\': \'data-foo\uF900\' is not a
valid attribute name."'); |
| 61 debug(""); |
| 62 |
| 63 function testDelete(attr, prop) |
| 64 { |
| 65 var d = document.createElement("div"); |
| 66 d.setAttribute(attr, "value"); |
| 67 delete d.dataset[prop]; |
| 68 return d.getAttribute(attr) != "value"; |
| 69 } |
| 70 |
| 71 shouldBeTrue("testDelete('data-foo', 'foo')"); |
| 72 shouldBeTrue("testDelete('data-foo-bar', 'fooBar')"); |
| 73 shouldBeTrue("testDelete('data--', '-')"); |
| 74 shouldBeTrue("testDelete('data--foo', 'Foo')"); |
| 75 shouldBeTrue("testDelete('data---foo', '-Foo')"); |
| 76 shouldBeTrue("testDelete('data-', '')"); |
| 77 shouldBeTrue("testDelete('data-\xE0', '\xE0')"); |
| 78 debug(""); |
| 79 |
| 80 shouldBeFalse("testDelete('dummy', '-foo')"); |
| 81 debug(""); |
| 82 |
| 83 function testForIn(array) |
| 84 { |
| 85 var d = document.createElement("div"); |
| 86 for (var i = 0; i < array.length; ++i) { |
| 87 d.setAttribute(array[i], "value"); |
| 88 } |
| 89 |
| 90 var count = 0; |
| 91 for (var item in d.dataset) |
| 92 count++; |
| 93 |
| 94 return count; |
| 95 } |
| 96 |
| 97 shouldBe("testForIn(['data-foo', 'data-bar', 'data-baz'])", "3"); |
| 98 shouldBe("testForIn(['data-foo', 'data-bar', 'dataFoo'])", "2"); |
| 99 shouldBe("testForIn(['data-foo', 'data-bar', 'style'])", "2"); |
| 100 shouldBe("testForIn(['data-foo', 'data-bar', 'data-'])", "3"); |
| 101 </script> |
| 9 </body> | 102 </body> |
| 10 </html> | 103 </html> |
| OLD | NEW |