Bug 1425079 - Add WPT test for the attributeChangedCallback which is triggered from parser; r=smaug

MozReview-Commit-ID: G0Cnxmv3sP8

--HG--
extra : rebase_source : 13e63c709566463c723d56917da69fdc975ff2a0
This commit is contained in:
Edgar Chen 2018-01-15 17:23:27 +08:00
Родитель 086e0422c4
Коммит 6ed22c88c6
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -529272,7 +529272,7 @@
"testharness"
],
"custom-elements/parser/parser-sets-attributes-and-children.html": [
"422bd43f10b48f0450b20fd4b0de046d465bec38",
"9157427f1c1e3d30d8a470ce7bd756dbf3a0cdfe",
"testharness"
],
"custom-elements/parser/parser-uses-constructed-element.html": [

Просмотреть файл

@ -8,6 +8,7 @@
<link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/custom-elements-helpers.js"></script>
</head>
<body>
<div id="log"></div>
@ -15,6 +16,7 @@
var numberOfAttributesInConstructor;
var numberOfChildNodesInConstructor;
var attributesChangedCalls = [];
class MyCustomElement extends HTMLElement {
constructor(...args) {
@ -22,6 +24,14 @@ class MyCustomElement extends HTMLElement {
numberOfAttributesInConstructor = this.attributes.length;
numberOfChildNodesInConstructor = this.childNodes.length;
}
attributeChangedCallback(...args) {
attributesChangedCalls.push(create_attribute_changed_callback_log(this, ...args));
}
static get observedAttributes() {
return ['id', 'class'];
}
};
customElements.define('my-custom-element', MyCustomElement);
@ -54,6 +64,12 @@ test(function () {
assert_equals(numberOfChildNodesInConstructor, 0, 'HTML parser must not append child nodes to a custom element before invoking the constructor');
}, 'HTML parser must set the attributes or append children before calling constructor');
test(function () {
assert_equals(attributesChangedCalls.length, 2);
assert_attribute_log_entry(attributesChangedCalls[0], {name: 'id', oldValue: null, newValue: 'custom-element-id', namespace: null});
assert_attribute_log_entry(attributesChangedCalls[1], {name: 'class', oldValue: null, newValue: 'class1 class2', namespace: null});
}, 'HTML parser must enqueue attributeChanged reactions');
</script>
</body>
</html>