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

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

Issue 5989801094283264: Issue 1587 - Escape curly brackets for elemhide filters (Closed)
Patch Set: Created Nov. 20, 2014, 2:03 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
« no previous file with comments | « include.postload.js ('k') | 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 module( 1 module(
2 "CSS escaping", 2 "CSS escaping",
3 { 3 {
4 setup: function() 4 setup: function()
5 { 5 {
6 var frame = document.createElement("iframe"); 6 var frame = document.createElement("iframe");
7 frame.srcdoc = '<script src="../include.postload.js"></script>'; 7 frame.srcdoc = '<script src="../include.postload.js"></script>';
8 8
9 stop(); 9 stop();
10 frame.addEventListener("load", function() 10 frame.addEventListener("load", function()
11 { 11 {
12 start(); 12 start();
13 13
14 this.escapeCSS = frame.contentWindow.escapeCSS; 14 this.escapeCSS = frame.contentWindow.escapeCSS;
15 this.quote = frame.contentWindow.quote; 15 this.quote = frame.contentWindow.quote;
16 16
17 document.body.removeChild(frame); 17 document.body.removeChild(frame);
18 }.bind(this)); 18 }.bind(this));
19 19
20 document.body.appendChild(frame); 20 document.body.appendChild(frame);
21
22 this.filterClasses = require("filterClasses");
Wladimir Palant 2014/11/20 14:33:05 As with the other review, no point having this in
Sebastian Noack 2014/11/20 15:47:27 Done, using an IFEE.
21 } 23 }
22 } 24 }
23 ); 25 );
24 26
25 test("CSS escaping", function() 27 test("CSS escaping", function()
26 { 28 {
27 var escapeCSS = this.escapeCSS; 29 var escapeCSS = this.escapeCSS;
28 var quote = this.quote; 30 var quote = this.quote;
29 31
32 var Filter = this.filterClasses.Filter;
33 var ElemHideFilter = this.filterClasses.ElemHideFilter;
34
30 function testSelector(opts) 35 function testSelector(opts)
31 { 36 {
32 var mustMatch = opts.mustMatch !== false; 37 var mustMatch = opts.mustMatch !== false;
33 var doc = document.implementation.createHTMLDocument(); 38 var doc = document.implementation.createHTMLDocument();
34 39
35 var style = doc.createElement("style"); 40 var style = doc.createElement("style");
36 doc.documentElement.appendChild(style); 41 doc.documentElement.appendChild(style);
37 style.sheet.insertRule(opts.selector + " {}", 0); 42 style.sheet.insertRule(opts.selector + " {}", 0);
38 43
39 var element; 44 var element;
(...skipping 12 matching lines...) Expand all
52 57
53 if (element) 58 if (element)
54 { 59 {
55 for (var attr in opts.attributes) 60 for (var attr in opts.attributes)
56 element.setAttribute(attr, opts.attributes[attr]); 61 element.setAttribute(attr, opts.attributes[attr]);
57 62
58 doc.documentElement.appendChild(element); 63 doc.documentElement.appendChild(element);
59 } 64 }
60 65
61 var foundElement = doc.querySelector(opts.selector); 66 var foundElement = doc.querySelector(opts.selector);
62 if (mustMatch) 67 var filter = Filter.fromText("##" + opts.selector);
63 equal(foundElement, element, opts.selector); 68
69 if (!(filter instanceof ElemHideFilter))
70 {
71 ok(false, opts.selector + " (not allowed in elemhide filters)");
Wladimir Palant 2014/11/20 14:33:05 There are very few cases where code like this is j
Sebastian Noack 2014/11/20 15:47:27 So far testSelector() only generates one assert pe
Wladimir Palant 2014/11/20 17:01:20 Not sure I agree but not really that important...
72 }
64 else 73 else
65 ok(true, opts.selector); 74 {
75 if (mustMatch)
76 equal(foundElement, element, opts.selector);
77 else
78 ok(true, opts.selector);
79 }
66 } 80 }
67 81
68 function testEscape(s) 82 function testEscape(s)
69 { 83 {
70 testSelector({ 84 testSelector({
71 selector: escapeCSS(s), 85 selector: escapeCSS(s),
72 tagName: s 86 tagName: s
73 }); 87 });
74 88
75 testSelector({ 89 testSelector({
(...skipping 29 matching lines...) Expand all
105 // in subsequent positions. 119 // in subsequent positions.
106 testEscape("x" + chr); 120 testEscape("x" + chr);
107 121
108 // Leading dashes must be escaped, when followed by certain characters. 122 // Leading dashes must be escaped, when followed by certain characters.
109 testEscape("-" + chr); 123 testEscape("-" + chr);
110 } 124 }
111 125
112 // Test some non-ASCII characters. However, those shouldn't require escaping. 126 // Test some non-ASCII characters. However, those shouldn't require escaping.
113 testEscape("\uD83D\uDE3B\u2665\u00E4"); 127 testEscape("\uD83D\uDE3B\u2665\u00E4");
114 }); 128 });
OLDNEW
« no previous file with comments | « include.postload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld