Truly independent web browser
Tests: Import DOMStringMap WPT tests
Shannon Booth92bd6143ed26
diff --git a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/reactions/DOMStringMap.txt b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/reactions/DOMStringMap.txtnew file mode 100644index 00000000000..0076cc64d21--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/reactions/DOMStringMap.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++4 Pass+4 Fail+Fail setter on DOMStringMap must enqueue an attributeChanged reaction when adding an observed data attribute+Pass setter on DOMStringMap must not enqueue an attributeChanged reaction when adding an unobserved data attribute+Fail setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute+Fail setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute to the same value+Pass setter on DOMStringMap must not enqueue an attributeChanged reaction when mutating the value of an unobserved data attribute+Fail deleter on DOMStringMap must enqueue an attributeChanged reaction when removing an observed data attribute+Pass deleter on DOMStringMap must not enqueue an attributeChanged reaction when removing an unobserved data attribute+Pass deleter on DOMStringMap must not enqueue an attributeChanged reaction when it does not remove a data attribute\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.txtnew file mode 100644index 00000000000..f483f2a460c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.txt@@ -0,0 +1,9 @@+Harness status: OK++Found 4 tests++4 Pass+Pass Getting property descriptor for key 9+Pass Setting property for key 9 with accessor property on prototype+Pass Getting property descriptor for key x+Pass Setting property for key x with accessor property on prototype\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-delete.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-delete.txtnew file mode 100644index 00000000000..565ceac873f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-delete.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 9 tests++9 Pass+Pass Deleting element.dataset['foo'] should also remove an attribute with name 'data-foo' should it exist.+Pass Deleting element.dataset['fooBar'] should also remove an attribute with name 'data-foo-bar' should it exist.+Pass Deleting element.dataset['-'] should also remove an attribute with name 'data--' should it exist.+Pass Deleting element.dataset['Foo'] should also remove an attribute with name 'data--foo' should it exist.+Pass Deleting element.dataset['-foo'] should not remove an attribute with name 'data--foo' should it exist.+Pass Deleting element.dataset['-Foo'] should also remove an attribute with name 'data---foo' should it exist.+Pass Deleting element.dataset[''] should also remove an attribute with name 'data-' should it exist.+Pass Deleting element.dataset['à'] should also remove an attribute with name 'data-à' should it exist.+Pass Deleting element.dataset['foo'] should not throw if even if the element does now have an attribute with the name data-foo.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-enumeration.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-enumeration.txtnew file mode 100644index 00000000000..12a2f1f47fb--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-enumeration.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass A dataset should be enumeratable.+Pass Only attributes who qualify as dataset properties should be enumeratable in the dataset.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-get-invalid-names.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-get-invalid-names.txtnew file mode 100644index 00000000000..a41213f90bf--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-get-invalid-names.txt@@ -0,0 +1,33 @@+Harness status: OK++Found 28 tests++28 Pass+Pass 1 attribute(s): aria-label: dataset["label"] is undefined+Pass 1 attribute(s): aria-label: "label" in dataset is false+Pass 2 attribute(s): aria-label: dataset["label"] is undefined+Pass 2 attribute(s): aria-label: "label" in dataset is false+Pass 1 attribute(s): title: dataset[""] is undefined+Pass 1 attribute(s): title: "" in dataset is false+Pass 2 attribute(s): title: dataset[""] is undefined+Pass 2 attribute(s): title: "" in dataset is false+Pass 1 attribute(s): class: dataset[""] is undefined+Pass 1 attribute(s): class: "" in dataset is false+Pass 2 attribute(s): class: dataset[""] is undefined+Pass 2 attribute(s): class: "" in dataset is false+Pass 1 attribute(s): dataxfoo: dataset["foo"] is undefined+Pass 1 attribute(s): dataxfoo: "foo" in dataset is false+Pass 2 attribute(s): dataxfoo: dataset["foo"] is undefined+Pass 2 attribute(s): dataxfoo: "foo" in dataset is false+Pass 1 attribute(s): data-Foo: dataset["Foo"] is undefined+Pass 1 attribute(s): data-Foo: "Foo" in dataset is false+Pass 2 attribute(s): data-Foo: dataset["Foo"] is undefined+Pass 2 attribute(s): data-Foo: "Foo" in dataset is false+Pass 1 attribute(s): data-foo-bar: dataset["foo-bar"] is undefined+Pass 1 attribute(s): data-foo-bar: "foo-bar" in dataset is false+Pass 2 attribute(s): data-foo-bar: dataset["foo-bar"] is undefined+Pass 2 attribute(s): data-foo-bar: "foo-bar" in dataset is false+Pass 1 attribute(s): data-foo-bar-baz: dataset["foo-barBaz"] is undefined+Pass 1 attribute(s): data-foo-bar-baz: "foo-barBaz" in dataset is false+Pass 2 attribute(s): data-foo-bar-baz: dataset["foo-barBaz"] is undefined+Pass 2 attribute(s): data-foo-bar-baz: "foo-barBaz" in dataset is false\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-get.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-get.txtnew file mode 100644index 00000000000..1529b60390f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-get.txt@@ -0,0 +1,15 @@+Harness status: OK++Found 10 tests++10 Pass+Pass Getting element.dataset['foo'] should return the value of element.getAttribute('data-foo')'+Pass Getting element.dataset['fooBar'] should return the value of element.getAttribute('data-foo-bar')'+Pass Getting element.dataset['-'] should return the value of element.getAttribute('data--')'+Pass Getting element.dataset['Foo'] should return the value of element.getAttribute('data--foo')'+Pass Getting element.dataset['-Foo'] should return the value of element.getAttribute('data---foo')'+Pass Getting element.dataset['foo'] should return the value of element.getAttribute('data-Foo')'+Pass Getting element.dataset[''] should return the value of element.getAttribute('data-')'+Pass Getting element.dataset['à'] should return the value of element.getAttribute('data-à')'+Pass Getting element.dataset['toString'] should return the value of element.getAttribute('data-to-string')'+Pass Tests that an attribute named dataFoo does not make an entry in the dataset DOMStringMap.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-prototype.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-prototype.txtnew file mode 100644index 00000000000..f076600aec1--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-prototype.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass An elements dataset property is an instance of a DOMStringMap+Pass Properties on Object.prototype should shine through.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset.txtnew file mode 100644index 00000000000..97b3f68077f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset.txt@@ -0,0 +1,13 @@+Harness status: OK++Found 8 tests++8 Pass+Pass HTML elements should have a .dataset+Pass Should return 'undefined' before setting an attribute+Pass Should return 'value' if that's the value+Pass Should return the empty string if that's the value+Pass Should return 'undefined' after removing an attribute+Pass Should not have a .dataset on random elements+Pass SVG elements should have a .dataset+Pass MathML elements should have a .dataset\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/custom-elements/reactions/DOMStringMap.html b/Tests/LibWeb/Text/input/wpt-import/custom-elements/reactions/DOMStringMap.htmlnew file mode 100644index 00000000000..7bd1f765526--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/custom-elements/reactions/DOMStringMap.html@@ -0,0 +1,96 @@+<!DOCTYPE html>+<html>+<head>+<title>Custom Elements: CEReactions on DOMStringMap interface</title>+<meta name="author" title="Ryosuke Niwa" href="mailto:[email protected]">+<meta name="assert" content="setter and deleter of DOMStringMap interface must have CEReactions">+<meta name="help" content="https://html.spec.whatwg.org/#domstringmap">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../resources/custom-elements-helpers.js"></script>+<script src="./resources/reactions.js"></script>+</head>+<body>+<div id="log"></div>+<script>++test(function () {+ var element = define_new_custom_element(['data-foo']);+ var instance = document.createElement(element.name);+ assert_array_equals(element.takeLog().types(), ['constructed']);+ instance.dataset.foo = 'bar';+ var logEntries = element.takeLog();+ assert_array_equals(logEntries.types(), ['attributeChanged']);+ assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: null, newValue: 'bar', namespace: null});+}, 'setter on DOMStringMap must enqueue an attributeChanged reaction when adding an observed data attribute');++test(function () {+ var element = define_new_custom_element(['data-bar']);+ var instance = document.createElement(element.name);+ assert_array_equals(element.takeLog().types(), ['constructed']);+ instance.dataset.foo = 'bar';+ assert_array_equals(element.takeLog().types(), []);+}, 'setter on DOMStringMap must not enqueue an attributeChanged reaction when adding an unobserved data attribute');++test(function () {+ var element = define_new_custom_element(['data-foo']);+ var instance = document.createElement(element.name);+ instance.dataset.foo = 'bar';+ assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);+ instance.dataset.foo = 'baz';+ var logEntries = element.takeLog();+ assert_array_equals(logEntries.types(), ['attributeChanged']);+ assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: 'bar', newValue: 'baz', namespace: null});+}, 'setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute');++test(function () {+ var element = define_new_custom_element(['data-foo']);+ var instance = document.createElement(element.name);+ instance.dataset.foo = 'bar';+ assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);+ instance.dataset.foo = 'bar';+ var logEntries = element.takeLog();+ assert_array_equals(logEntries.types(), ['attributeChanged']);+ assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: 'bar', newValue: 'bar', namespace: null});+}, 'setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute to the same value');++test(function () {+ var element = define_new_custom_element(['data-zero']);+ var instance = document.createElement(element.name);+ instance.dataset.foo = 'bar';+ assert_array_equals(element.takeLog().types(), ['constructed']);+ instance.dataset.foo = 'baz';+ assert_array_equals(element.takeLog().types(), []);+}, 'setter on DOMStringMap must not enqueue an attributeChanged reaction when mutating the value of an unobserved data attribute');++test(function () {+ var element = define_new_custom_element(['data-foo']);+ var instance = document.createElement(element.name);+ instance.dataset.foo = 'bar';+ assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);+ delete instance.dataset.foo;+ var logEntries = element.takeLog();+ assert_array_equals(logEntries.types(), ['attributeChanged']);+ assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: 'bar', newValue: null, namespace: null});+}, 'deleter on DOMStringMap must enqueue an attributeChanged reaction when removing an observed data attribute');++test(function () {+ var element = define_new_custom_element(['data-bar']);+ var instance = document.createElement(element.name);+ instance.dataset.foo = 'bar';+ assert_array_equals(element.takeLog().types(), ['constructed']);+ delete instance.dataset.foo;+ assert_array_equals(element.takeLog().types(), []);+}, 'deleter on DOMStringMap must not enqueue an attributeChanged reaction when removing an unobserved data attribute');++test(function () {+ var element = define_new_custom_element(['data-foo']);+ var instance = document.createElement(element.name);+ assert_array_equals(element.takeLog().types(), ['constructed']);+ delete instance.dataset.foo;+ assert_array_equals(element.takeLog().types(), []);+}, 'deleter on DOMStringMap must not enqueue an attributeChanged reaction when it does not remove a data attribute');++</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.htmlnew file mode 100644index 00000000000..183349f5e96--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.html@@ -0,0 +1,8 @@+<!doctype html>+<meta charset=utf-8>++<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../../../../html/dom/elements/global-attributes/dataset-binding.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.js b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.jsnew file mode 100644index 00000000000..e0e85677d1d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-binding.window.js@@ -0,0 +1,45 @@+[9, "x"].forEach(function(key) {+ test(function() {+ var element = document.createElement("div");+ var dataset = element.dataset;++ var value = "value for " + this.name;++ assert_equals(dataset[key], undefined);++ element.setAttribute("data-" + key, value);+ assert_equals(element.getAttribute("data-" + key), value);+ assert_equals(dataset[key], value);++ var propdesc = Object.getOwnPropertyDescriptor(dataset, key);+ assert_not_equals(propdesc, undefined);+ assert_equals(propdesc.value, value);+ assert_true(propdesc.writable);+ assert_true(propdesc.enumerable);+ assert_true(propdesc.configurable);+ }, "Getting property descriptor for key " + key);++ test(function() {+ var element = document.createElement("div");+ var dataset = element.dataset;++ var proto = "proto getter for " + this.name;+ var calledSetter = [];+ Object.defineProperty(DOMStringMap.prototype, key, {+ "get": function() { return proto; },+ "set": this.unreached_func("Should not call [[Set]] on prototype"),+ "configurable": true,+ });+ this.add_cleanup(function() {+ delete DOMStringMap.prototype[key];+ });++ var value = "value for " + this.name;++ assert_equals(dataset[key], proto);+ assert_equals(element.getAttribute("data-" + key), null);+ assert_equals(dataset[key] = value, value);+ assert_equals(dataset[key], value);+ assert_equals(element.getAttribute("data-" + key), value);+ }, "Setting property for key " + key + " with accessor property on prototype");+});diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-delete.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-delete.htmlnew file mode 100644index 00000000000..443ae712a2b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-delete.html@@ -0,0 +1,54 @@+<!DOCTYPE html>+<html>+ <head>+ <title>Dataset - Delete</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <h1>Dataset - Delete</h1>+ <div id="log"></div>+ <script>+ function testDelete(attr, prop)+ {+ var d = document.createElement("div");+ d.setAttribute(attr, "value");+ delete d.dataset[prop];+ return d.hasAttribute(attr) === false && d.getAttribute(attr) != "value";+ }++ function testDeleteNoAdd(prop)+ {+ var d = document.createElement("div");+ delete d.dataset[prop];+ return true;+ }++ test(function() { assert_true(testDelete('data-foo', 'foo')); },+ "Deleting element.dataset['foo'] should also remove an attribute with name 'data-foo' should it exist.");+ test(function() { assert_true(testDelete('data-foo-bar', 'fooBar')); },+ "Deleting element.dataset['fooBar'] should also remove an attribute with name 'data-foo-bar' should it exist.");+ test(function() { assert_true(testDelete('data--', '-')); },+ "Deleting element.dataset['-'] should also remove an attribute with name 'data--' should it exist.");+ test(function() { assert_true(testDelete('data--foo', 'Foo')); },+ "Deleting element.dataset['Foo'] should also remove an attribute with name 'data--foo' should it exist.");+ test(function() {+ var d = document.createElement("div");+ d.setAttribute('data--foo', "value");+ assert_equals(d.dataset['-foo'], undefined);+ assert_false('-foo' in d.dataset);+ delete d.dataset['-foo'];+ assert_true(d.hasAttribute('data--foo'));+ assert_equals(d.getAttribute('data--foo'), "value");+ }, "Deleting element.dataset['-foo'] should not remove an attribute with name 'data--foo' should it exist.");+ test(function() { assert_true(testDelete('data---foo', '-Foo')); },+ "Deleting element.dataset['-Foo'] should also remove an attribute with name 'data---foo' should it exist.");+ test(function() { assert_true(testDelete('data-', '')); },+ "Deleting element.dataset[''] should also remove an attribute with name 'data-' should it exist.");+ test(function() { assert_true(testDelete('data-\xE0', '\xE0')); },+ "Deleting element.dataset['\xE0'] should also remove an attribute with name 'data-\xE0' should it exist.");+ test(function() { assert_true(testDeleteNoAdd('foo')); },+ "Deleting element.dataset['foo'] should not throw if even if the element does now have an attribute with the name data-foo.");+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-enumeration.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-enumeration.htmlnew file mode 100644index 00000000000..75bfd226d33--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-enumeration.html@@ -0,0 +1,31 @@+<!DOCTYPE html>+<html>+ <head>+ <title>Dataset - Enumeration</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <h1>Dataset - Enumeration</h1>+ <div id="log"></div>+ <script>+ function testEnumeration(array)+ {+ var d = document.createElement("div");+ for (var i = 0; i < array.length; ++i)+ d.setAttribute(array[i], "value");++ var count = 0;+ for (var item in d.dataset)+ count++;++ return count;+ }++ test(function() { assert_equals(testEnumeration(['data-foo', 'data-bar', 'data-baz']), 3); },+ "A dataset should be enumeratable.");+ test(function() { assert_equals(testEnumeration(['data-foo', 'data-bar', 'dataFoo']), 2); },+ "Only attributes who qualify as dataset properties should be enumeratable in the dataset.");+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-get-invalid-names.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-get-invalid-names.htmlnew file mode 100644index 00000000000..837971e11a8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-get-invalid-names.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Dataset - Get with names that do not correspond to a data-* attribute</title>+<link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-nameditem">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script>+function makeElement(attributes) {+ const element = document.createElement("div");+ for (const [name, value] of attributes)+ element.setAttributeNS(null, name, value);+ return element;+}++const cases = [+ { attribute: "aria-label", property: "label" },+ { attribute: "title", property: "" },+ { attribute: "class", property: "" },+ { attribute: "dataxfoo", property: "foo" },+ { attribute: "data-Foo", property: "Foo" },+ { attribute: "data-foo-bar", property: "foo-bar" },+ { attribute: "data-foo-bar-baz", property: "foo-barBaz" },+];++for (const { attribute, property } of cases) {+ for (const extra of [[], [["id", "x"]]]) {+ const label = `${extra.length + 1} attribute(s): ${attribute}`;++ test(() => {+ const element = makeElement([[attribute, "value"], ...extra]);+ assert_equals(element.dataset[property], undefined);+ }, `${label}: dataset[${JSON.stringify(property)}] is undefined`);++ test(() => {+ const element = makeElement([[attribute, "value"], ...extra]);+ assert_false(property in element.dataset);+ }, `${label}: ${JSON.stringify(property)} in dataset is false`);+ }+}+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-get.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-get.htmlnew file mode 100644index 00000000000..b4b4a2f2207--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-get.html@@ -0,0 +1,57 @@+<!DOCTYPE html>+<html>+ <head>+ <title>Dataset - Get</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <h1>Dataset - Get</h1>+ <div id="log"></div>+ <script>+ function testGet(attr, expected)+ {+ var d = document.createElement("div");+ d.setAttribute(attr, "value");+ return d.dataset[expected] == "value";+ }++ test(function() { assert_true(testGet('data-foo', 'foo')); },+ "Getting element.dataset['foo'] should return the value of element.getAttribute('data-foo')'");+ test(function() { assert_true(testGet('data-foo-bar', 'fooBar')); },+ "Getting element.dataset['fooBar'] should return the value of element.getAttribute('data-foo-bar')'");+ test(function() { assert_true(testGet('data--', '-')); },+ "Getting element.dataset['-'] should return the value of element.getAttribute('data--')'");+ test(function() { assert_true(testGet('data--foo', 'Foo')); },+ "Getting element.dataset['Foo'] should return the value of element.getAttribute('data--foo')'");+ test(function() { assert_true(testGet('data---foo', '-Foo')); },+ "Getting element.dataset['-Foo'] should return the value of element.getAttribute('data---foo')'");+ test(function() { assert_true(testGet('data-Foo', 'foo')); },+ "Getting element.dataset['foo'] should return the value of element.getAttribute('data-Foo')'");+ test(function() { assert_true(testGet('data-', '')); },+ "Getting element.dataset[''] should return the value of element.getAttribute('data-')'");+ test(function() { assert_true(testGet('data-\xE0', '\xE0')); },+ "Getting element.dataset['\xE0'] should return the value of element.getAttribute('data-\xE0')'");+ test(function() { assert_true(testGet('data-to-string', 'toString')); },+ "Getting element.dataset['toString'] should return the value of element.getAttribute('data-to-string')'");++ function matchesNothingInDataset(attr)+ {+ var d = document.createElement("div");+ d.setAttribute(attr, "value");++ if (!d.dataset)+ return false;++ var count = 0;+ for (var item in d.dataset)+ count++;+ return count == 0;+ }++ test(function() { assert_true(matchesNothingInDataset('dataFoo')); },+ "Tests that an attribute named dataFoo does not make an entry in the dataset DOMStringMap.");++ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-prototype.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-prototype.htmlnew file mode 100644index 00000000000..e4447f49d0c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-prototype.html@@ -0,0 +1,26 @@+<!DOCTYPE html>+<html>+ <head>+ <title>Dataset - element.dataset is an instance of DOMStringMap</title>+ <script src="../../../../resources/testharness.js"></script>+ <script src="../../../../resources/testharnessreport.js"></script>+ </head>+ <body>+ <h1>Dataset - element.dataset is an instance of DOMStringMap</h1>+ <div id="log"></div>+ <script>+ test(function() { assert_true(document.createElement("div").dataset instanceof window.DOMStringMap); },+ "An elements dataset property is an instance of a DOMStringMap");+ test(function() {+ var dataset = document.createElement("div").dataset;+ assert_true("toString" in dataset, '"toString" in dataset');+ assert_equals(dataset.toString, Object.prototype.toString);+ assert_false("expando" in dataset, '"expando" in dataset');+ assert_equals(dataset.expando, undefined);+ Object.prototype.expando = 42;+ assert_true("expando" in dataset, '"expando" in dataset');+ assert_equals(dataset.expando, 42);+ }, "Properties on Object.prototype should shine through.");+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset.htmlnew file mode 100644index 00000000000..e3a7b17e17d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset.html@@ -0,0 +1,42 @@+<!DOCTYPE html>+<title>dataset: should exist and work on HTML and SVG elements, but not random elements</title>+<link rel="author" title="Ms2ger" href="mailto:[email protected]">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<div id="log"></div>+<script>+var div = document.createElement("div");+test(function() {+ assert_true(div.dataset instanceof DOMStringMap);+}, "HTML elements should have a .dataset");+test(function() {+ assert_false("foo" in div.dataset);+ assert_equals(div.dataset.foo, undefined);+}, "Should return 'undefined' before setting an attribute")+test(function() {+ div.setAttribute("data-foo", "value");+ assert_true("foo" in div.dataset);+ assert_equals(div.dataset.foo, "value");+}, "Should return 'value' if that's the value")+test(function() {+ div.setAttribute("data-foo", "");+ assert_true("foo" in div.dataset);+ assert_equals(div.dataset.foo, "");+}, "Should return the empty string if that's the value")+test(function() {+ div.removeAttribute("data-foo");+ assert_false("foo" in div.dataset);+ assert_equals(div.dataset.foo, undefined);+}, "Should return 'undefined' after removing an attribute")+test(function() {+ assert_equals(document.createElementNS("test", "test").dataset, undefined);+}, "Should not have a .dataset on random elements");+test(function() {+ var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg")+ assert_true(svg.dataset instanceof DOMStringMap);+}, "SVG elements should have a .dataset");+test(function() {+ var mathml = document.createElementNS("http://www.w3.org/1998/Math/MathML", "math");+ assert_true(mathml.dataset instanceof DOMStringMap);+}, "MathML elements should have a .dataset");+</script>