Commit 75613110 authored by davaajav's avatar davaajav Committed by Commit bot

Custom Elements: layout tests for observedAttributes

1. attributeChangedCallback should be fired only from
the elements in observedAttributes
2. Checks for cases when converting observedAttributes
to sequence<DOMString> should throw TypeError
https://heycam.github.io/webidl/#create-sequence-from-iterable

BUG=643049

Review-Url: https://codereview.chromium.org/2321903003
Cr-Commit-Position: refs/heads/master@{#418761}
parent c39517b0
......@@ -349,6 +349,36 @@ test_with_window((w) => {
// 14.9.3 If observedAttributesIterable is not undefined, then set observedAttributes
// to the result of converting observedAttributesIterable to a sequence<DOMString>.
// Rethrow any exceptions.
test_with_window((w) => {
let invocations = [];
let element = w.document.createElement('a-a');
element.setAttribute('a', '1');
element.setAttribute('b', '2');
element.setAttribute('c', '3');
let constructor = function () {};
constructor.prototype.attributeChangedCallback = function () {
invocations.push(arguments[0]);
};
constructor.observedAttributes = {[Symbol.iterator]:
function* () {
yield 'a';
yield 'c';
}
};
w.customElements.define('a-a', constructor);
w.document.body.appendChild(element);
assert_array_equals(invocations, ['a', 'c'], 'attributeChangedCallback should be invoked twice for "a" and "c"');
}, 'ObservedAttributes are retrieved from iterators');
test_with_window((w) => {
let constructor = function () {};
constructor.prototype.attributeChangedCallback = function () { };
constructor.observedAttributes = {[Symbol.iterator]: 1};
assert_throws(TypeError.prototype, () => {
w.customElements.define('a-a', constructor);
}, 'converting value that is not an object should throw TypeError');
}, 'Converting non-object observedAttributes to sequence<DOMString>');
test_with_window((w) => {
class X extends w.HTMLElement{
constructor() { super(); }
......@@ -357,9 +387,17 @@ test_with_window((w) => {
}
assert_throws(TypeError.prototype, () => {
w.customElements.define('a-a', X);
}, 'converting RegExp to sequence<DOMString> should throw TypeError');
}, 'exception thrown while converting observedAttributes to ' +
'sequence<DOMString> should be rethrown');
}, 'converting RegExp should throw TypeError');
}, 'Converting regular expression observedAttributes to sequence<DOMString>');
test_with_window((w) => {
let constructor = function () {};
constructor.prototype.attributeChangedCallback = function () { };
constructor.observedAttributes = {};
assert_throws(TypeError.prototype, () => {
w.customElements.define('a-a', constructor);
}, 'If iterator method is undefined, it should throw TypeError');
}, 'Converting observedAttributes without iterator method to sequence<DOMString>');
// 14.9.2 test Get(constructor, observedAttributes) does not throw if
// attributeChangedCallback is undefined.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment