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