Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: third_party/WebKit/LayoutTests/custom-elements/spec/selectors/pseudo-class-defined.html

Issue 2039103004: Add tests of state changes for :defined() selector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dominicc review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 { tagName: 'div', defined: true }, 7 { tag_name: 'div', defined: true },
8 { tagName: 'a-a', defined: false }, 8 { tag_name: 'a-a', defined: false },
9 { tagName: 'font-face', defined: true }, 9 { tag_name: 'font-face', defined: true },
10 ]; 10 ];
11 11
12 // Setup iframe to test the parser. 12 // Setup iframe to test the parser.
13 const neither = 'rgb(255, 0, 0)'; 13 const neither = 'rgb(255, 0, 0)';
14 const defined = 'rgb(255, 165, 0)'; 14 const defined = 'rgb(255, 165, 0)';
15 const not_defined = 'rgb(0, 0, 255)'; 15 const not_defined = 'rgb(0, 0, 255)';
16 iframe.srcdoc = `<style> 16 iframe.srcdoc = `<style>
17 * { color:${neither}; } 17 * { color:${neither}; }
18 :defined { color:${defined}; } 18 :defined { color:${defined}; }
19 :not(:defined) { color:${not_defined}; } 19 :not(:defined) { color:${not_defined}; }
20 </style>` 20 </style>`
21 + testList.map(d => `<${d.tagName}></${d.tagName}>`).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.tagName)[0], `<${da ta.tagName}>`); 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.tagName); 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 be "uncustomized"; i.e., "defin ed".
34 test_defined_for_createElement(true, doc_without_browsing_context, data.tagN ame, 'Without browsing context: '); 34 test_defined_for_createElement(true, doc_without_browsing_context, 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, tagName, description = '') { 40 function test_defined_for_createElement(defined, doc, tag_name, description = '' ) {
41 // Test document.createElement(). 41 // Test document.createElement().
42 let element = doc.createElement(tagName); 42 let element = doc.createElement(tag_name);
43 doc.body.appendChild(element); 43 doc.body.appendChild(element);
44 test_defined(defined, element, `${description}createElement("${tagName}")`); 44 test_defined(defined, element, `${description}createElement("${tag_name}")`);
45 45
46 // Test document.createElementNS(). 46 // Test document.createElementNS().
47 element = doc.createElementNS('http://www.w3.org/1999/xhtml', tagName); 47 let html_element = doc.createElementNS('http://www.w3.org/1999/xhtml', tag_nam e);
48 doc.body.appendChild(element); 48 doc.body.appendChild(html_element);
49 test_defined(defined, element, `${description}createElementNS("http://www.w3.o rg/1999/xhtml", "${tagName}")`); 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 element = doc.createElementNS('http://www.w3.org/2000/svg', tagName); 52 let svg_element = doc.createElementNS('http://www.w3.org/2000/svg', tag_name);
53 doc.body.appendChild(element); 53 doc.body.appendChild(svg_element);
54 test_defined(true, element, `${description}createElementNS("http://www.w3.org/ 2000/svg", "${tagName}")`); 54 test_defined(true, svg_element, `${description}createElementNS("http://www.w3. org/2000/svg", "${tag_name}")`);
55
56 // Test ":defined" changes when the custom element was defined.
57 if (!defined) {
58 let w = doc.defaultView;
59 w.customElements.define(tag_name, class extends w.HTMLElement {
60 constructor() { super(); }
61 });
62
63 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 }
55 } 66 }
56 67
57 function test_defined(expected, element, description) { 68 function test_defined(expected, element, description) {
58 test(() => { 69 test(() => {
59 assert_equals(element.matches(':defined'), expected, 'matches(":defined")'); 70 assert_equals(element.matches(':defined'), expected, 'matches(":defined")');
60 assert_equals(element.matches(':not(:defined)'), !expected, 'matches(":not(: defined")'); 71 assert_equals(element.matches(':not(:defined)'), !expected, 'matches(":not(: defined")');
61 const view = element.ownerDocument.defaultView; 72 const view = element.ownerDocument.defaultView;
62 if (!view) 73 if (!view)
63 return; 74 return;
64 const style = view.getComputedStyle(element); 75 const style = view.getComputedStyle(element);
65 assert_equals(style.color, expected ? defined : not_defined, 'getComputedSty le'); 76 assert_equals(style.color, expected ? defined : not_defined, 'getComputedSty le');
66 }, `${description} should ${expected ? 'be' : 'not be'} :defined`); 77 }, `${description} should ${expected ? 'be' : 'not be'} :defined`);
67 } 78 }
68 </script> 79 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698