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 12 matching lines...) Expand all Loading... | |
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, doc, data.tag_name); |
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 // They used to behave differently, but the spec changed in https://github.c om/whatwg/dom/pull/291 |
dominicc (has gone to gerrit)
2016/08/18 04:58:38
Delete this line. Maybe just mentioning that PR in
| |
35 test_defined_for_createElement(data.defined, doc_without_browsing_context, d ata.tag_name, 'Without browsing context: '); | |
35 } | 36 } |
36 | 37 |
37 done(); | 38 done(); |
38 }; | 39 }; |
39 | 40 |
40 function test_defined_for_createElement(defined, doc, tag_name, description = '' ) { | 41 function test_defined_for_createElement(defined, doc, tag_name, description = '' ) { |
41 // Test document.createElement(). | 42 // Test document.createElement(). |
42 let element = doc.createElement(tag_name); | 43 let element = doc.createElement(tag_name); |
43 doc.body.appendChild(element); | 44 doc.body.appendChild(element); |
44 test_defined(defined, element, `${description}createElement("${tag_name}")`); | 45 test_defined(defined, element, `${description}createElement("${tag_name}")`); |
45 | 46 |
46 // Test document.createElementNS(). | 47 // Test document.createElementNS(). |
47 let html_element = doc.createElementNS('http://www.w3.org/1999/xhtml', tag_nam e); | 48 let html_element = doc.createElementNS('http://www.w3.org/1999/xhtml', tag_nam e); |
48 doc.body.appendChild(html_element); | 49 doc.body.appendChild(html_element); |
49 test_defined(defined, html_element, `${description}createElementNS("http://www .w3.org/1999/xhtml", "${tag_name}")`); | 50 test_defined(defined, html_element, `${description}createElementNS("http://www .w3.org/1999/xhtml", "${tag_name}")`); |
50 | 51 |
51 // If the element namespace is not HTML, it should be "uncustomized"; i.e., "d efined". | 52 // 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); | 53 let svg_element = doc.createElementNS('http://www.w3.org/2000/svg', tag_name); |
53 doc.body.appendChild(svg_element); | 54 doc.body.appendChild(svg_element); |
54 test_defined(true, svg_element, `${description}createElementNS("http://www.w3. org/2000/svg", "${tag_name}")`); | 55 test_defined(true, svg_element, `${description}createElementNS("http://www.w3. org/2000/svg", "${tag_name}")`); |
55 | 56 |
56 // Test ":defined" changes when the custom element was defined. | 57 // Test ":defined" changes when the custom element was defined. |
57 if (!defined) { | 58 if (!defined && doc.defaultView) { |
dominicc (has gone to gerrit)
2016/08/18 04:58:38
I think these tests would be clearer without this
kojii
2016/08/18 05:26:47
Made whether to test value change or not explicit.
| |
58 let w = doc.defaultView; | 59 let w = doc.defaultView; |
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 |