| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> | 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> | 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <iframe id="iframe"></iframe> | 4 <iframe id="iframe"></iframe> |
| 5 <script> | 5 <script> |
| 6 const testList = [ | 6 const testList = [ |
| 7 { tag_name: 'div', defined: true }, | 7 { tag_name: 'div', defined: true }, |
| 8 { tag_name: 'a-a', defined: false }, | 8 { tag_name: 'a-a', defined: false }, |
| 9 { tag_name: 'font-face', defined: true }, | 9 { tag_name: 'font-face', defined: true }, |
| 10 ]; | 10 ]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 + testList.map(d => `<${d.tag_name}></${d.tag_name}>`).join(''); | 21 + testList.map(d => `<${d.tag_name}></${d.tag_name}>`).join(''); |
| 22 setup({ explicit_done: true }); | 22 setup({ explicit_done: true }); |
| 23 iframe.onload = () => { | 23 iframe.onload = () => { |
| 24 const doc = iframe.contentDocument; | 24 const doc = iframe.contentDocument; |
| 25 const doc_without_browsing_context = doc.implementation.createHTMLDocument(); | 25 const doc_without_browsing_context = doc.implementation.createHTMLDocument(); |
| 26 for (const data of testList) { | 26 for (const data of testList) { |
| 27 // Test elements inserted by parser. | 27 // Test elements inserted by parser. |
| 28 test_defined(data.defined, doc.getElementsByTagName(data.tag_name)[0], `<${d
ata.tag_name}>`); | 28 test_defined(data.defined, doc.getElementsByTagName(data.tag_name)[0], `<${d
ata.tag_name}>`); |
| 29 | 29 |
| 30 // Test DOM createElement() methods. | 30 // Test DOM createElement() methods. |
| 31 test_defined_for_createElement(data.defined, doc, data.tag_name); | 31 test_defined_for_createElement(data.defined, !data.defined, doc, data.tag_na
me); |
| 32 | 32 |
| 33 // Documents without browsing context should be "uncustomized"; i.e., "defin
ed". | 33 // Documents without browsing context should behave the same. |
| 34 test_defined_for_createElement(true, doc_without_browsing_context, data.tag_
name, 'Without browsing context: '); | 34 test_defined_for_createElement(data.defined, false, doc_without_browsing_con
text, data.tag_name, 'Without browsing context: '); |
| 35 } | 35 } |
| 36 | 36 |
| 37 done(); | 37 done(); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 function test_defined_for_createElement(defined, doc, tag_name, description = ''
) { | 40 function test_defined_for_createElement(defined, should_test_change, doc, tag_na
me, description = '') { |
| 41 // Test document.createElement(). | 41 // Test document.createElement(). |
| 42 let element = doc.createElement(tag_name); | 42 let element = doc.createElement(tag_name); |
| 43 doc.body.appendChild(element); | 43 doc.body.appendChild(element); |
| 44 test_defined(defined, element, `${description}createElement("${tag_name}")`); | 44 test_defined(defined, element, `${description}createElement("${tag_name}")`); |
| 45 | 45 |
| 46 // Test document.createElementNS(). | 46 // Test document.createElementNS(). |
| 47 let html_element = doc.createElementNS('http://www.w3.org/1999/xhtml', tag_nam
e); | 47 let html_element = doc.createElementNS('http://www.w3.org/1999/xhtml', tag_nam
e); |
| 48 doc.body.appendChild(html_element); | 48 doc.body.appendChild(html_element); |
| 49 test_defined(defined, html_element, `${description}createElementNS("http://www
.w3.org/1999/xhtml", "${tag_name}")`); | 49 test_defined(defined, html_element, `${description}createElementNS("http://www
.w3.org/1999/xhtml", "${tag_name}")`); |
| 50 | 50 |
| 51 // If the element namespace is not HTML, it should be "uncustomized"; i.e., "d
efined". | 51 // If the element namespace is not HTML, it should be "uncustomized"; i.e., "d
efined". |
| 52 let svg_element = doc.createElementNS('http://www.w3.org/2000/svg', tag_name); | 52 let svg_element = doc.createElementNS('http://www.w3.org/2000/svg', tag_name); |
| 53 doc.body.appendChild(svg_element); | 53 doc.body.appendChild(svg_element); |
| 54 test_defined(true, svg_element, `${description}createElementNS("http://www.w3.
org/2000/svg", "${tag_name}")`); | 54 test_defined(true, svg_element, `${description}createElementNS("http://www.w3.
org/2000/svg", "${tag_name}")`); |
| 55 | 55 |
| 56 // Test ":defined" changes when the custom element was defined. | 56 // Test ":defined" changes when the custom element was defined. |
| 57 if (!defined) { | 57 if (should_test_change) { |
| 58 let w = doc.defaultView; | 58 let w = doc.defaultView; |
| 59 assert_false(!w, 'defaultView required to test change'); |
| 59 w.customElements.define(tag_name, class extends w.HTMLElement { | 60 w.customElements.define(tag_name, class extends w.HTMLElement { |
| 60 constructor() { super(); } | 61 constructor() { super(); } |
| 61 }); | 62 }); |
| 62 | 63 |
| 63 test_defined(true, element, `Upgraded ${description}createElement("${tag_nam
e}")`); | 64 test_defined(true, element, `Upgraded ${description}createElement("${tag_nam
e}")`); |
| 64 test_defined(true, html_element, `Upgraded ${description}createElementNS("ht
tp://www.w3.org/1999/xhtml", "${tag_name}")`); | 65 test_defined(true, html_element, `Upgraded ${description}createElementNS("ht
tp://www.w3.org/1999/xhtml", "${tag_name}")`); |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 | 68 |
| 68 function test_defined(expected, element, description) { | 69 function test_defined(expected, element, description) { |
| 69 test(() => { | 70 test(() => { |
| 70 assert_equals(element.matches(':defined'), expected, 'matches(":defined")'); | 71 assert_equals(element.matches(':defined'), expected, 'matches(":defined")'); |
| 71 assert_equals(element.matches(':not(:defined)'), !expected, 'matches(":not(:
defined")'); | 72 assert_equals(element.matches(':not(:defined)'), !expected, 'matches(":not(:
defined")'); |
| 72 const view = element.ownerDocument.defaultView; | 73 const view = element.ownerDocument.defaultView; |
| 73 if (!view) | 74 if (!view) |
| 74 return; | 75 return; |
| 75 const style = view.getComputedStyle(element); | 76 const style = view.getComputedStyle(element); |
| 76 assert_equals(style.color, expected ? defined : not_defined, 'getComputedSty
le'); | 77 assert_equals(style.color, expected ? defined : not_defined, 'getComputedSty
le'); |
| 77 }, `${description} should ${expected ? 'be' : 'not be'} :defined`); | 78 }, `${description} should ${expected ? 'be' : 'not be'} :defined`); |
| 78 } | 79 } |
| 79 </script> | 80 </script> |
| OLD | NEW |