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

Powered by Google App Engine
This is Rietveld