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