Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: qunit/tests/cssEscaping.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Created Jan. 13, 2017, 12:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 (function()
2 { 1 {
3 var filterClasses = require("filterClasses"); 2 let filterClasses = require("filterClasses");
4 var Filter = filterClasses.Filter; 3 let Filter = filterClasses.Filter;
5 var ElemHideFilter = filterClasses.ElemHideFilter; 4 let ElemHideFilter = filterClasses.ElemHideFilter;
6 5
7 var filterComposer = require("filterComposer"); 6 let filterComposer = require("filterComposer");
8 var escapeCSS = filterComposer.escapeCSS; 7 let escapeCSS = filterComposer.escapeCSS;
9 var quoteCSS = filterComposer.quoteCSS; 8 let quoteCSS = filterComposer.quoteCSS;
10 9
11 module("CSS escaping"); 10 module("CSS escaping");
12 11
13 test("CSS escaping", function() 12 test("CSS escaping", () =>
14 { 13 {
15 function testSelector(opts) 14 function testSelector(opts)
16 { 15 {
17 var mustMatch = opts.mustMatch !== false; 16 let mustMatch = opts.mustMatch !== false;
18 var doc = document.implementation.createHTMLDocument(); 17 let doc = document.implementation.createHTMLDocument();
19 18
20 var style = doc.createElement("style"); 19 let style = doc.createElement("style");
21 doc.documentElement.appendChild(style); 20 doc.documentElement.appendChild(style);
22 style.sheet.insertRule(opts.selector + " {}", 0); 21 style.sheet.insertRule(opts.selector + " {}", 0);
23 22
24 var element; 23 let element;
25 try 24 try
26 { 25 {
27 element = doc.createElement(opts.tagName || "div"); 26 element = doc.createElement(opts.tagName || "div");
28 } 27 }
29 catch (e) 28 catch (e)
30 { 29 {
31 // Some characters we are going to test can not occur in tag names, 30 // Some characters we are going to test can not occur in tag names,
32 // but we still have to make sure that no exception is thrown when 31 // but we still have to make sure that no exception is thrown when
33 // calling .querySelector() and .insertRule() 32 // calling .querySelector() and .insertRule()
34 element = null; 33 element = null;
35 mustMatch = false; 34 mustMatch = false;
36 } 35 }
37 36
38 if (element) 37 if (element)
39 { 38 {
40 for (var attr in opts.attributes) 39 for (let attr in opts.attributes)
41 element.setAttribute(attr, opts.attributes[attr]); 40 element.setAttribute(attr, opts.attributes[attr]);
42 41
43 doc.documentElement.appendChild(element); 42 doc.documentElement.appendChild(element);
44 } 43 }
45 44
46 var foundElement = doc.querySelector(opts.selector); 45 let foundElement = doc.querySelector(opts.selector);
47 var filter = Filter.fromText("##" + opts.selector); 46 let filter = Filter.fromText("##" + opts.selector);
48 47
49 if (!(filter instanceof ElemHideFilter)) 48 if (!(filter instanceof ElemHideFilter))
50 { 49 {
51 ok(false, opts.selector + " (not allowed in elemhide filters)"); 50 ok(false, opts.selector + " (not allowed in elemhide filters)");
52 } 51 }
53 else 52 else
54 { 53 {
55 if (mustMatch) 54 if (mustMatch)
56 equal(foundElement, element, opts.selector); 55 equal(foundElement, element, opts.selector);
57 else 56 else
(...skipping 22 matching lines...) Expand all
80 // is thrown when calling .querySelector() and .insertRule() 79 // is thrown when calling .querySelector() and .insertRule()
81 mustMatch: !/\s/.test(s) 80 mustMatch: !/\s/.test(s)
82 }); 81 });
83 82
84 testSelector({ 83 testSelector({
85 selector: "[foo=" + quoteCSS(s) + "]", 84 selector: "[foo=" + quoteCSS(s) + "]",
86 attributes: {foo: s} 85 attributes: {foo: s}
87 }); 86 });
88 } 87 }
89 88
90 for (var i = 1; i < 0x80; i++) 89 for (let i = 1; i < 0x80; i++)
91 { 90 {
92 var chr = String.fromCharCode(i); 91 let chr = String.fromCharCode(i);
93 92
94 // Make sure that all ASCII characters are correctly escaped. 93 // Make sure that all ASCII characters are correctly escaped.
95 testEscape(chr); 94 testEscape(chr);
96 95
97 // Some characters are only escaped when in the first positon, 96 // Some characters are only escaped when in the first positon,
98 // so we still have to make sure that everything is correctly escaped 97 // so we still have to make sure that everything is correctly escaped
99 // in subsequent positions. 98 // in subsequent positions.
100 testEscape("x" + chr); 99 testEscape("x" + chr);
101 100
102 // Leading dashes must be escaped, when followed by certain characters. 101 // Leading dashes must be escaped, when followed by certain characters.
103 testEscape("-" + chr); 102 testEscape("-" + chr);
104 } 103 }
105 104
106 // Test some non-ASCII characters. However, those shouldn't require escaping . 105 // Test some non-ASCII characters. However, those shouldn't require escaping .
107 testEscape("\uD83D\uDE3B\u2665\u00E4"); 106 testEscape("\uD83D\uDE3B\u2665\u00E4");
108 }); 107 });
109 })(); 108 }
OLDNEW
« chrome/ext/common.js ('K') | « qunit/common.js ('k') | qunit/tests/filterValidation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld