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

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: test update 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 let constructor = function () {};
358 constructor.prototype.attributeChangedCallback = function () {
359 invocations.push(arguments[0]);
360 };
361 constructor.observedAttributes = {[Symbol.iterator]:
362 function* () { yield 'a'; }
363 };
364 w.customElements.define('a-a', constructor);
365 w.document.body.appendChild(element);
366 assert_array_equals(invocations, ['a'], 'attributeChangedCllback should be inv oked once for "a"');
367 }, 'ObservedAttributes');
dominicc (has gone to gerrit) 2016/09/12 05:31:44 Could you write prose here? Like observed attribut
368
369 test_with_window((w) => {
370 let constructor = function () {};
371 constructor.prototype.attributeChangedCallback = function () { };
372 constructor.observedAttributes = {[Symbol.iterator]: 1};
373 assert_throws(TypeError.prototype, () => {
374 w.customElements.define('a-a', constructor);
375 }, 'converting value that is not an object should throw TypeError');
376 }, 'Converting observedAttributes to sequence<DOMString>, not an object');
dominicc (has gone to gerrit) 2016/09/12 05:31:44 Maybe write ... non-object observedAttributes ...
377
378 test_with_window((w) => {
353 class X extends w.HTMLElement{ 379 class X extends w.HTMLElement{
354 constructor() { super(); } 380 constructor() { super(); }
355 attributeChangedCallback() {} 381 attributeChangedCallback() {}
356 static get observedAttributes() { return new RegExp(); } 382 static get observedAttributes() { return new RegExp(); }
357 } 383 }
358 assert_throws(TypeError.prototype, () => { 384 assert_throws(TypeError.prototype, () => {
359 w.customElements.define('a-a', X); 385 w.customElements.define('a-a', X);
360 }, 'converting RegExp to sequence<DOMString> should throw TypeError'); 386 }, 'converting RegExp should throw TypeError');
361 }, 'exception thrown while converting observedAttributes to ' + 387 }, 'Converting observedAttributes to sequence<DOMString>, regular expression');
362 'sequence<DOMString> should be rethrown'); 388
389 test_with_window((w) => {
390 let constructor = function () {};
391 constructor.prototype.attributeChangedCallback = function () { };
392 constructor.observedAttributes = {};
393 assert_throws(TypeError.prototype, () => {
394 w.customElements.define('a-a', constructor);
395 }, 'If iterator method is undefined, it should throw TypeError');
396 }, 'Converting observedAttributes to sequence<DOMString>, iterator method not de fined');
363 397
364 // 14.9.2 test Get(constructor, observedAttributes) does not throw if 398 // 14.9.2 test Get(constructor, observedAttributes) does not throw if
365 // attributeChangedCallback is undefined. 399 // attributeChangedCallback is undefined.
366 test_with_window((w) => { 400 test_with_window((w) => {
367 let observedAttributes_invoked = false; 401 let observedAttributes_invoked = false;
368 let X = (function () {}).bind({}); 402 let X = (function () {}).bind({});
369 Object.defineProperty(X, 'observedAttributes', { 403 Object.defineProperty(X, 'observedAttributes', {
370 get() { observedAttributes_invoked = true; } 404 get() { observedAttributes_invoked = true; }
371 }); 405 });
372 assert_false( observedAttributes_invoked, 'Get(constructor, observedAttributes ) should not be invoked'); 406 assert_false( observedAttributes_invoked, 'Get(constructor, observedAttributes ) should not be invoked');
(...skipping 30 matching lines...) Expand all
403 // step 2 437 // step 2
404 test_with_window((w) => { 438 test_with_window((w) => {
405 let invalid_name = 'annotation-xml'; 439 let invalid_name = 'annotation-xml';
406 assert_throws_dom_exception(w, 'SYNTAX_ERR', () => { 440 assert_throws_dom_exception(w, 'SYNTAX_ERR', () => {
407 w.customElements.define(invalid_name, class extends HTMLElement {}); 441 w.customElements.define(invalid_name, class extends HTMLElement {});
408 }, 'defining author-defined custom element constructor should pass this ' + 442 }, 'defining author-defined custom element constructor should pass this ' +
409 'step without throwing TypeError'); 443 'step without throwing TypeError');
410 }, 'Invalid constructor'); 444 }, 'Invalid constructor');
411 </script> 445 </script>
412 </body> 446 </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