| OLD | NEW |
| 1 (function() | 1 (function() |
| 2 { | 2 { |
| 3 var filterClasses = require("filterClasses"); | 3 var filterClasses = require("filterClasses"); |
| 4 var Filter = filterClasses.Filter; | 4 var Filter = filterClasses.Filter; |
| 5 var ElemHideFilter = filterClasses.ElemHideFilter; | 5 var ElemHideFilter = filterClasses.ElemHideFilter; |
| 6 | 6 |
| 7 module( | 7 var filterComposer = require("filterComposer"); |
| 8 "CSS escaping", | 8 var escapeCSS = filterComposer.escapeCSS; |
| 9 { | 9 var quoteCSS = filterComposer.quoteCSS; |
| 10 setup: function() | |
| 11 { | |
| 12 var frame = document.createElement("iframe"); | |
| 13 frame.srcdoc = '<script src="../include.postload.js"></script>'; | |
| 14 | 10 |
| 15 stop(); | 11 module("CSS escaping"); |
| 16 frame.addEventListener("load", function() | |
| 17 { | |
| 18 start(); | |
| 19 | |
| 20 this.escapeCSS = frame.contentWindow.escapeCSS; | |
| 21 this.quote = frame.contentWindow.quote; | |
| 22 | |
| 23 document.body.removeChild(frame); | |
| 24 }.bind(this)); | |
| 25 | |
| 26 document.body.appendChild(frame); | |
| 27 } | |
| 28 } | |
| 29 ); | |
| 30 | 12 |
| 31 test("CSS escaping", function() | 13 test("CSS escaping", function() |
| 32 { | 14 { |
| 33 var escapeCSS = this.escapeCSS; | |
| 34 var quote = this.quote; | |
| 35 | |
| 36 function testSelector(opts) | 15 function testSelector(opts) |
| 37 { | 16 { |
| 38 var mustMatch = opts.mustMatch !== false; | 17 var mustMatch = opts.mustMatch !== false; |
| 39 var doc = document.implementation.createHTMLDocument(); | 18 var doc = document.implementation.createHTMLDocument(); |
| 40 | 19 |
| 41 var style = doc.createElement("style"); | 20 var style = doc.createElement("style"); |
| 42 doc.documentElement.appendChild(style); | 21 doc.documentElement.appendChild(style); |
| 43 style.sheet.insertRule(opts.selector + " {}", 0); | 22 style.sheet.insertRule(opts.selector + " {}", 0); |
| 44 | 23 |
| 45 var element; | 24 var element; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 selector: "." + escapeCSS(s), | 75 selector: "." + escapeCSS(s), |
| 97 attributes: {class: s}, | 76 attributes: {class: s}, |
| 98 | 77 |
| 99 // Whitespace characters split the class name, hence the selector | 78 // Whitespace characters split the class name, hence the selector |
| 100 // won't match. But we still have to make sure that no exception | 79 // won't match. But we still have to make sure that no exception |
| 101 // is thrown when calling .querySelector() and .insertRule() | 80 // is thrown when calling .querySelector() and .insertRule() |
| 102 mustMatch: !/\s/.test(s) | 81 mustMatch: !/\s/.test(s) |
| 103 }); | 82 }); |
| 104 | 83 |
| 105 testSelector({ | 84 testSelector({ |
| 106 selector: "[foo=" + quote(s) + "]", | 85 selector: "[foo=" + quoteCSS(s) + "]", |
| 107 attributes: {foo: s} | 86 attributes: {foo: s} |
| 108 }); | 87 }); |
| 109 } | 88 } |
| 110 | 89 |
| 111 for (var i = 0; i < 0x80; i++) | 90 for (var i = 0; i < 0x80; i++) |
| 112 { | 91 { |
| 113 var chr = String.fromCharCode(i); | 92 var chr = String.fromCharCode(i); |
| 114 | 93 |
| 115 // Make sure that all ASCII characters are correctly escaped. | 94 // Make sure that all ASCII characters are correctly escaped. |
| 116 testEscape(chr); | 95 testEscape(chr); |
| 117 | 96 |
| 118 // Some characters are only escaped when in the first positon, | 97 // Some characters are only escaped when in the first positon, |
| 119 // so we still have to make sure that everything is correctly escaped | 98 // so we still have to make sure that everything is correctly escaped |
| 120 // in subsequent positions. | 99 // in subsequent positions. |
| 121 testEscape("x" + chr); | 100 testEscape("x" + chr); |
| 122 | 101 |
| 123 // Leading dashes must be escaped, when followed by certain characters. | 102 // Leading dashes must be escaped, when followed by certain characters. |
| 124 testEscape("-" + chr); | 103 testEscape("-" + chr); |
| 125 } | 104 } |
| 126 | 105 |
| 127 // Test some non-ASCII characters. However, those shouldn't require escaping
. | 106 // Test some non-ASCII characters. However, those shouldn't require escaping
. |
| 128 testEscape("\uD83D\uDE3B\u2665\u00E4"); | 107 testEscape("\uD83D\uDE3B\u2665\u00E4"); |
| 129 }); | 108 }); |
| 130 })(); | 109 })(); |
| OLD | NEW |