OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Custom Elements: CustomElementsRegistry.whenDefined</title> | 2 <title>Custom Elements: CustomElementRegistry.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 <script src="../resources/custom-elements-helpers.js"></script> |
6 <body> | 6 <body> |
7 <div id="log"></div> | 7 <div id="log"></div> |
8 <script> | 8 <script> |
9 'use strict'; | 9 'use strict'; |
10 (() => { | 10 (() => { |
11 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementsreg
istry-whendefined | 11 // https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementregi
stry-whendefined |
12 // Use window from iframe to isolate the test. | 12 // Use window from iframe to isolate the test. |
13 function setup() { | 13 function setup() { |
14 const iframe = document.createElement('iframe'); | 14 const iframe = document.createElement('iframe'); |
15 document.body.appendChild(iframe); | 15 document.body.appendChild(iframe); |
16 const testWindow = iframe.contentWindow; | 16 const testWindow = iframe.contentWindow; |
17 const customElements = testWindow.customElements; | 17 const customElements = testWindow.customElements; |
18 if (!customElements) | 18 if (!customElements) |
19 return Promise.reject('This test requires window.customElements'); | 19 return Promise.reject('This test requires window.customElements'); |
20 if (!('whenDefined' in customElements)) | 20 if (!('whenDefined' in customElements)) |
21 return Promise.reject('This test requires window.customElements.whenDefine
d'); | 21 return Promise.reject('This test requires window.customElements.whenDefine
d'); |
(...skipping 14 matching lines...) Expand all Loading... |
36 // 5. Let promise be the value of the entry in map with key name. | 36 // 5. Let promise be the value of the entry in map with key name. |
37 // 6. Return promise | 37 // 6. Return promise |
38 assert_equals(promiseBeforeDefined, | 38 assert_equals(promiseBeforeDefined, |
39 customElements.whenDefined(kNameToBeDefined), | 39 customElements.whenDefined(kNameToBeDefined), |
40 'There is only one promise defined before.'); | 40 'There is only one promise defined before.'); |
41 const promiseNotDefined = customElements.whenDefined(kNameNotDefined); | 41 const promiseNotDefined = customElements.whenDefined(kNameNotDefined); |
42 promiseNotDefined.then(() => notDefined = false); | 42 promiseNotDefined.then(() => notDefined = false); |
43 assert_not_equals(promiseBeforeDefined, promiseNotDefined, | 43 assert_not_equals(promiseBeforeDefined, promiseNotDefined, |
44 'whenDefined() returns different promises for different names.'); | 44 'whenDefined() returns different promises for different names.'); |
45 customElements.define(kNameToBeDefined, class {}); | 45 customElements.define(kNameToBeDefined, class {}); |
46 // 3. If this CustomElementsRegistry contains an entry with name name, | 46 // 3. If this CustomElementRegistry contains an entry with name name, |
47 // then return a new promise resolved with undefined and abort these | 47 // then return a new promise resolved with undefined and abort these |
48 // steps. | 48 // steps. |
49 const promiseAfterDefined = customElements.whenDefined(kNameToBeDefined); | 49 const promiseAfterDefined = customElements.whenDefined(kNameToBeDefined); |
50 promiseAfterDefined.then(() => afterDefined = true); | 50 promiseAfterDefined.then(() => afterDefined = true); |
51 assert_not_equals(promiseBeforeDefined, promiseAfterDefined, | 51 assert_not_equals(promiseBeforeDefined, promiseAfterDefined, |
52 'When name is defined, we should have a new promise.'); | 52 'When name is defined, we should have a new promise.'); |
53 assert_not_equals(promiseAfterDefined, | 53 assert_not_equals(promiseAfterDefined, |
54 customElements.whenDefined(kNameToBeDefined), | 54 customElements.whenDefined(kNameToBeDefined), |
55 'Once name is defined, whenDefined() always returns a new promise.'); | 55 'Once name is defined, whenDefined() always returns a new promise.'); |
56 return customElements; | 56 return customElements; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 }); | 92 }); |
93 | 93 |
94 function promise_rejects_with_dom_exception_syntax_error(global_context, test,
promise, description) { | 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) { | 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; }) | 96 assert_throws_dom_exception(global_context, 'SYNTAX_ERR', function () {
throw e; }) |
97 }); | 97 }); |
98 } | 98 } |
99 })(); | 99 })(); |
100 </script> | 100 </script> |
101 </body> | 101 </body> |
OLD | NEW |