| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: defineElement</title> | 2 <title>Custom Elements: defineElement</title> |
| 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#cus
tomelementsregistry"> | 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#cus
tomelementsregistry"> |
| 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> | 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="resources/custom-elements-helpers.js"></script> | 7 <script src="resources/custom-elements-helpers.js"></script> |
| 8 <body> | 8 <body> |
| 9 <script> | 9 <script> |
| 10 // TODO(dominicc): Merge these tests with | 10 // TODO(dominicc): Merge these tests with |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 assert_throws({ name: 'observedAttributes throws' }, () => { | 344 assert_throws({ name: 'observedAttributes throws' }, () => { |
| 345 w.customElements.define('a-a', X); | 345 w.customElements.define('a-a', X); |
| 346 }, 'Exception from Get(constructor, observedAttributes) should be rethrown'); | 346 }, 'Exception from Get(constructor, observedAttributes) should be rethrown'); |
| 347 }, 'Rethrow any exceptions thrown while getting observedAttributes'); | 347 }, 'Rethrow any exceptions thrown while getting observedAttributes'); |
| 348 | 348 |
| 349 // 14.9.3 If observedAttributesIterable is not undefined, then set observedAttri
butes | 349 // 14.9.3 If observedAttributesIterable is not undefined, then set observedAttri
butes |
| 350 // to the result of converting observedAttributesIterable to a sequence<D
OMString>. | 350 // to the result of converting observedAttributesIterable to a sequence<D
OMString>. |
| 351 // Rethrow any exceptions. | 351 // Rethrow any exceptions. |
| 352 test_with_window((w) => { | 352 test_with_window((w) => { |
| 353 let invocations = []; |
| 354 let element = w.document.createElement('a-a'); |
| 355 element.setAttribute('a', '1'); |
| 356 element.setAttribute('b', '2'); |
| 357 element.setAttribute('c', '3'); |
| 358 let constructor = function () {}; |
| 359 constructor.prototype.attributeChangedCallback = function () { |
| 360 invocations.push(arguments[0]); |
| 361 }; |
| 362 constructor.observedAttributes = {[Symbol.iterator]: |
| 363 function* () { |
| 364 yield 'a'; |
| 365 yield 'c'; |
| 366 } |
| 367 }; |
| 368 w.customElements.define('a-a', constructor); |
| 369 w.document.body.appendChild(element); |
| 370 assert_array_equals(invocations, ['a', 'c'], 'attributeChangedCallback should
be invoked twice for "a" and "c"'); |
| 371 }, 'ObservedAttributes are retrieved from iterators'); |
| 372 |
| 373 test_with_window((w) => { |
| 374 let constructor = function () {}; |
| 375 constructor.prototype.attributeChangedCallback = function () { }; |
| 376 constructor.observedAttributes = {[Symbol.iterator]: 1}; |
| 377 assert_throws(TypeError.prototype, () => { |
| 378 w.customElements.define('a-a', constructor); |
| 379 }, 'converting value that is not an object should throw TypeError'); |
| 380 }, 'Converting non-object observedAttributes to sequence<DOMString>'); |
| 381 |
| 382 test_with_window((w) => { |
| 353 class X extends w.HTMLElement{ | 383 class X extends w.HTMLElement{ |
| 354 constructor() { super(); } | 384 constructor() { super(); } |
| 355 attributeChangedCallback() {} | 385 attributeChangedCallback() {} |
| 356 static get observedAttributes() { return new RegExp(); } | 386 static get observedAttributes() { return new RegExp(); } |
| 357 } | 387 } |
| 358 assert_throws(TypeError.prototype, () => { | 388 assert_throws(TypeError.prototype, () => { |
| 359 w.customElements.define('a-a', X); | 389 w.customElements.define('a-a', X); |
| 360 }, 'converting RegExp to sequence<DOMString> should throw TypeError'); | 390 }, 'converting RegExp should throw TypeError'); |
| 361 }, 'exception thrown while converting observedAttributes to ' + | 391 }, 'Converting regular expression observedAttributes to sequence<DOMString>'); |
| 362 'sequence<DOMString> should be rethrown'); | 392 |
| 393 test_with_window((w) => { |
| 394 let constructor = function () {}; |
| 395 constructor.prototype.attributeChangedCallback = function () { }; |
| 396 constructor.observedAttributes = {}; |
| 397 assert_throws(TypeError.prototype, () => { |
| 398 w.customElements.define('a-a', constructor); |
| 399 }, 'If iterator method is undefined, it should throw TypeError'); |
| 400 }, 'Converting observedAttributes without iterator method to sequence<DOMString>
'); |
| 363 | 401 |
| 364 // 14.9.2 test Get(constructor, observedAttributes) does not throw if | 402 // 14.9.2 test Get(constructor, observedAttributes) does not throw if |
| 365 // attributeChangedCallback is undefined. | 403 // attributeChangedCallback is undefined. |
| 366 test_with_window((w) => { | 404 test_with_window((w) => { |
| 367 let observedAttributes_invoked = false; | 405 let observedAttributes_invoked = false; |
| 368 let X = (function () {}).bind({}); | 406 let X = (function () {}).bind({}); |
| 369 Object.defineProperty(X, 'observedAttributes', { | 407 Object.defineProperty(X, 'observedAttributes', { |
| 370 get() { observedAttributes_invoked = true; } | 408 get() { observedAttributes_invoked = true; } |
| 371 }); | 409 }); |
| 372 assert_false( observedAttributes_invoked, 'Get(constructor, observedAttributes
) should not be invoked'); | 410 assert_false( observedAttributes_invoked, 'Get(constructor, observedAttributes
) should not be invoked'); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 403 // step 2 | 441 // step 2 |
| 404 test_with_window((w) => { | 442 test_with_window((w) => { |
| 405 let invalid_name = 'annotation-xml'; | 443 let invalid_name = 'annotation-xml'; |
| 406 assert_throws_dom_exception(w, 'SYNTAX_ERR', () => { | 444 assert_throws_dom_exception(w, 'SYNTAX_ERR', () => { |
| 407 w.customElements.define(invalid_name, class extends HTMLElement {}); | 445 w.customElements.define(invalid_name, class extends HTMLElement {}); |
| 408 }, 'defining author-defined custom element constructor should pass this ' + | 446 }, 'defining author-defined custom element constructor should pass this ' + |
| 409 'step without throwing TypeError'); | 447 'step without throwing TypeError'); |
| 410 }, 'Invalid constructor'); | 448 }, 'Invalid constructor'); |
| 411 </script> | 449 </script> |
| 412 </body> | 450 </body> |
| OLD | NEW |