OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Custom Elements: CustomElementsRegistry.whenDefined</title> | 2 <title>Custom Elements: CustomElementsRegistry.whenDefined</title> |
3 <script src="../../../resources/testharness.js"></script> | 3 <script src="../../../resources/testharness.js"></script> |
4 <script src="../../../resources/testharnessreport.js"></script> | 4 <script src="../../../resources/testharnessreport.js"></script> |
5 <script src="../resources/custom-elements-helpers.js"></script> | |
5 <body> | 6 <body> |
6 <div id="log"></div> | 7 <div id="log"></div> |
7 <script> | 8 <script> |
8 'use strict'; | 9 'use strict'; |
9 (() => { | 10 (() => { |
10 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsreg istry-whendefined | 11 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsreg istry-whendefined |
11 // Use window from iframe to isolate the test. | 12 // Use window from iframe to isolate the test. |
12 function setup() { | 13 function setup() { |
13 const iframe = document.createElement('iframe'); | 14 const iframe = document.createElement('iframe'); |
14 document.body.appendChild(iframe); | 15 document.body.appendChild(iframe); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 'When name is defined, we should have a new promise.'); | 52 'When name is defined, we should have a new promise.'); |
52 assert_not_equals(promiseAfterDefined, | 53 assert_not_equals(promiseAfterDefined, |
53 customElements.whenDefined(kNameToBeDefined), | 54 customElements.whenDefined(kNameToBeDefined), |
54 'Once name is defined, whenDefined() always returns a new promise.'); | 55 'Once name is defined, whenDefined() always returns a new promise.'); |
55 return customElements; | 56 return customElements; |
56 }).then(customElements => { | 57 }).then(customElements => { |
57 assert_true(beforeDefined, 'promise before defined should be resolved.'); | 58 assert_true(beforeDefined, 'promise before defined should be resolved.'); |
58 assert_true(afterDefined, 'promise after defined should be resolved.'); | 59 assert_true(afterDefined, 'promise after defined should be resolved.'); |
59 assert_true(notDefined, 'promise for not defined name should not be resolv ed.'); | 60 assert_true(notDefined, 'promise for not defined name should not be resolv ed.'); |
60 }).catch(reason => { throw reason })); | 61 }).catch(reason => { throw reason })); |
62 | |
63 // Calling whenDefined() with invalid names should throw "SyntaxError"DOMExcep tion | |
64 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element- name | |
65 let invalid_names = [ | |
yosin_UTC9
2016/09/21 09:42:31
nit: s/let/const/
| |
66 'annotation-xml', | |
67 'color-profile', | |
68 'font-face', | |
69 'font-face-src', | |
70 'font-face-uri', | |
71 'font-face-format', | |
72 'font-face-name', | |
73 'missing-glyph', | |
74 'div', 'p', | |
75 'nothtmlbutnohyphen', | |
76 '-not-initial-a-z', '0not-initial-a-z', 'Not-initial-a-z', | |
77 'intermediate-UPPERCASE-letters', | |
78 'bad-\u00b6', 'bad-\u00b8', 'bad-\u00bf', 'bad-\u00d7', 'bad-\u00f7', | |
79 'bad-\u037e', 'bad-\u037e', 'bad-\u2000', 'bad-\u200e', 'bad-\u203e', | |
80 'bad-\u2041', 'bad-\u206f', 'bad-\u2190', 'bad-\u2bff', 'bad-\u2ff0', | |
81 'bad-\u3000', 'bad-\ud800', 'bad-\uf8ff', 'bad-\ufdd0', 'bad-\ufdef', | |
82 'bad-\ufffe', 'bad-\uffff', 'bad-' + String.fromCodePoint(0xf0000) | |
yosin_UTC9
2016/09/21 09:42:31
You can write as 'bad-\u{F0000}'.
| |
83 ]; | |
84 | |
85 invalid_names.forEach((name) => { | |
86 promise_test((t) => { | |
87 return create_window_in_test(t) | |
88 .then((w) => { | |
89 return promise_rejects_with_dom_exception_syntax_error(w, t, w.customEle ments.whenDefined(name)); | |
yosin_UTC9
2016/09/21 09:42:31
You can write as below:
.then(w => promise_rejects
| |
90 }); | |
91 }, 'whenDefined() called with invalid name ' + name + ' should throw "Syntax Error"DOMException'); | |
yosin_UTC9
2016/09/21 09:42:31
You can write as below:
`whenDefined() called with
| |
92 }); | |
93 | |
94 function promise_rejects_with_dom_exception_syntax_error(global_context, test, promise, description) { | |
95 return promise.then(test.unreached_func("Should have rejected: " + descripti on)).catch(function(e) { | |
96 assert_throws_dom_exception(global_context, 'SYNTAX_ERR', function () { throw e; }) | |
97 }); | |
98 } | |
61 })(); | 99 })(); |
62 </script> | 100 </script> |
63 </body> | 101 </body> |
OLD | NEW |