Bug 1430034 - Fix attributeChangedCallback isn't fired with correct newValue when the attribute value is an empty string; r=smaug

MozReview-Commit-ID: L3RvNPNDfUC

--HG--
extra : rebase_source : dbe1d825beaec044ebb91d00a45b6feececfc46b
This commit is contained in:
Edgar Chen 2018-01-15 15:24:41 +08:00
Родитель a32790ea40
Коммит 4281f3eea3
3 изменённых файлов: 33 добавлений и 2 удалений

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

@ -934,7 +934,7 @@ CustomElementRegistry::Upgrade(Element* aElement,
LifecycleCallbackArgs args = {
nsDependentAtomString(attrName),
VoidString(),
(attrValue.IsEmpty() ? VoidString() : attrValue),
attrValue,
(namespaceURI.IsEmpty() ? VoidString() : namespaceURI)
};
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged,

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

@ -529241,7 +529241,7 @@
"testharness"
],
"custom-elements/attribute-changed-callback.html": [
"1ad26231aa638a0e0f9b76d77bdd93a3712dda98",
"320fb2bb26e7495d0829c39c113df3ea7ec1f4ef",
"testharness"
],
"custom-elements/connected-callbacks.html": [

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

@ -11,6 +11,7 @@
</head>
<body>
<div id="log"></div>
<parser-created-element title></parser-created-element>
<script>
var customElement = define_new_custom_element(['title', 'id', 'r']);
@ -218,6 +219,36 @@ test(function () {
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: 'hello', namespace: null});
}, 'attributedChangedCallback must not be enqueued when mutating inline style declaration if the style attribute is not observed');
test(function () {
var calls = [];
class CustomElement extends HTMLElement { }
CustomElement.prototype.attributeChangedCallback = function (...args) {
calls.push(create_attribute_changed_callback_log(this, ...args));
}
CustomElement.observedAttributes = ['title'];
customElements.define('parser-created-element', CustomElement);
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: '', namespace: null});
}, 'Upgrading a parser created element must enqueue and invoke attributeChangedCallback for an HTML attribute');
test(function () {
var calls = [];
class CustomElement extends HTMLElement { }
CustomElement.prototype.attributeChangedCallback = function (...args) {
calls.push(create_attribute_changed_callback_log(this, ...args));
}
CustomElement.observedAttributes = ['title'];
customElements.define('cloned-element-with-attribute', CustomElement);
var instance = document.createElement('cloned-element-with-attribute');
assert_equals(calls.length, 0);
instance.title = '';
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: '', namespace: null});
calls = [];
var clone = instance.cloneNode(false);
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: '', namespace: null});
}, 'Upgrading a cloned element must enqueue and invoke attributeChangedCallback for an HTML attribute');
</script>
</body>
</html>