OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 TODO(yosin): We should upstream to wpt test. | 3 TODO(yosin): We should upstream to wpt test. |
4 This file is taken from https://github.com/kojiishi/web-platform-tests/blob/5390
8d773012edf931047674f7afe3975bc1820f/custom-elements/custom-elements-registry/ge
t.html | 4 This file is taken from https://github.com/kojiishi/web-platform-tests/blob/5390
8d773012edf931047674f7afe3975bc1820f/custom-elements/custom-elements-registry/ge
t.html |
5 --> | 5 --> |
6 <title>Custom Elements: CustomElementsRegistry.get</title> | 6 <title>Custom Elements: CustomElementRegistry.get</title> |
7 <script src="../../../resources/testharness.js"></script> | 7 <script src="../../../resources/testharness.js"></script> |
8 <script src="../../../resources/testharnessreport.js"></script> | 8 <script src="../../../resources/testharnessreport.js"></script> |
9 <body> | 9 <body> |
10 <div id="log"></div> | 10 <div id="log"></div> |
11 <script> | 11 <script> |
12 'use strict'; | 12 'use strict'; |
13 (() => { | 13 (() => { |
14 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsreg
istry-whendefined | 14 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementregi
stry-whendefined |
15 // Use window from iframe to isolate the test. | 15 // Use window from iframe to isolate the test. |
16 function setup() { | 16 function setup() { |
17 const iframe = document.createElement('iframe'); | 17 const iframe = document.createElement('iframe'); |
18 document.body.appendChild(iframe); | 18 document.body.appendChild(iframe); |
19 const testWindow = iframe.contentWindow; | 19 const testWindow = iframe.contentWindow; |
20 const customElements = testWindow.customElements; | 20 const customElements = testWindow.customElements; |
21 if (!customElements) | 21 if (!customElements) |
22 return Promise.reject('This test requires window.customElements'); | 22 return Promise.reject('This test requires window.customElements'); |
23 if (!('get' in customElements)) | 23 if (!('get' in customElements)) |
24 return Promise.reject('This test requires window.customElements.get'); | 24 return Promise.reject('This test requires window.customElements.get'); |
25 return Promise.resolve(customElements); | 25 return Promise.resolve(customElements); |
26 } | 26 } |
27 | 27 |
28 promise_test(() => setup() | 28 promise_test(() => setup() |
29 .then(customElements => { | 29 .then(customElements => { |
30 // 1. If this CustomElementsRegistry contains an entry with name name, | 30 // 1. If this CustomElementRegistry contains an entry with name name, |
31 // then return that entry's constructor. | 31 // then return that entry's constructor. |
32 const name = 'test-get-existing'; | 32 const name = 'test-get-existing'; |
33 class C extends HTMLElement {}; | 33 class C extends HTMLElement {}; |
34 customElements.define(name, C); | 34 customElements.define(name, C); |
35 assert_equals(customElements.get(name), C, 'get() returns the constructor'
) | 35 assert_equals(customElements.get(name), C, 'get() returns the constructor'
) |
36 return Promise.resolve(customElements); | 36 return Promise.resolve(customElements); |
37 }).then(customElements => { | 37 }).then(customElements => { |
38 // 2. Otherwise, return undefined. | 38 // 2. Otherwise, return undefined. |
39 assert_equals(customElements.get('test-get-not-defined'), undefined, | 39 assert_equals(customElements.get('test-get-not-defined'), undefined, |
40 'get() returns undefined for not-defined name'); | 40 'get() returns undefined for not-defined name'); |
41 }).catch(reason => { throw reason })); | 41 }).catch(reason => { throw reason })); |
42 })(); | 42 })(); |
43 </script> | 43 </script> |
44 </body> | 44 </body> |
OLD | NEW |