Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: third_party/WebKit/LayoutTests/custom-elements/spec/define-element.html

Issue 2321903003: Custom Elements: layout tests for observedAttributes (Closed)
Patch Set: updates in comment Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698