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

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: 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 { tagName: 'div', defined: true },
8 { tagName: 'a-a', defined: false }, 8 { tagName: 'a-a', defined: false },
9 { tagName: 'font-face', defined: true }, 9 { tagName: 'font-face', defined: true },
10 ]; 10 ];
(...skipping 19 matching lines...) Expand all
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.tagName);
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.tagN ame, '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, tagName, description = '') {
dominicc (has gone to gerrit) 2016/06/07 12:01:06 Nit: Consider tagName -> tag_name if you're going
kojii 2016/06/07 18:59:31 Done. testharness.js forcing us to mix styles alwa
41 // Test document.createElement(). 41 // Test document.createElement().
42 let element = doc.createElement(tagName); 42 const element = doc.createElement(tagName);
dominicc (has gone to gerrit) 2016/06/07 12:01:05 Why const and not let?
kojii 2016/06/07 18:59:31 Changed back to let. Read somewhere that I should
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("${tagName}")`);
45 45
46 // Test document.createElementNS(). 46 // Test document.createElementNS().
47 element = doc.createElementNS('http://www.w3.org/1999/xhtml', tagName); 47 const html_element = doc.createElementNS('http://www.w3.org/1999/xhtml', tagNa me);
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", "${tagName}")`);
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 const svg_element = doc.createElementNS('http://www.w3.org/2000/svg', tagName) ;
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", "${tagName}")`);
55
56 // Test ":defined" changes when the custom element was defined.
57 if (!defined) {
58 const w = doc.defaultView;
59 w.customElements.define(tagName, class extends w.HTMLElement {
60 constructor() { super(); }
61 });
rune 2016/06/07 09:39:08 Would it make sense to test the two other cases in
kojii 2016/06/07 10:48:54 is="" is not supported yet, it requires quite amou
rune 2016/06/07 10:56:00 Acknowledged.
62
63 test_defined(true, element, `Upgraded ${description}createElement("${tagName }")`);
64 test_defined(true, html_element, `Upgraded ${description}createElementNS("ht tp://www.w3.org/1999/xhtml", "${tagName}")`);
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