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

Delta Between Two Patch Sets: test/common.js

Issue 29760699: Issue 6619 - Qualify CSS selectors in document style sheet correctly (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rebase Created May 15, 2018, 12:02 p.m.
Right Patch Set: Reinclude test/common.js Created May 15, 2018, 5:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/content/elemHideEmulation.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 const {createSandbox} = require("./_common");
21
22 let qualifySelector = null;
23
24 exports.setUp = function(callback)
25 {
26 let sandboxedRequire = createSandbox();
27 (
28 {qualifySelector} = sandboxedRequire("../lib/common")
29 );
30 callback();
31 };
32
33 exports.testQualifySelector = function(test)
34 {
35 // Simple selectors.
36 test.equal(qualifySelector("#foo", "div"), "div#foo");
37 test.equal(qualifySelector(".foo", "div"), "div.foo");
38 test.equal(qualifySelector("div", "#foo"), "div#foo");
39 test.equal(qualifySelector("div", ".foo"), "div.foo");
40 test.equal(qualifySelector("div#bar", ".foo"), "div.foo#bar");
41 test.equal(qualifySelector("div.bar", "#foo"), "div#foo.bar");
42
43 // Compound selectors.
44 test.equal(qualifySelector("body #foo", "div"), "body div#foo");
45 test.equal(qualifySelector("body .foo", "div"), "body div.foo");
46 test.equal(qualifySelector("body div", "#foo"), "body div#foo");
47 test.equal(qualifySelector("body div", ".foo"), "body div.foo");
48 test.equal(qualifySelector("body div#bar", ".foo"), "body div.foo#bar");
49 test.equal(qualifySelector("body div.bar", "#foo"), "body div#foo.bar");
50
51 // Compound selectors with pseudo-class with parentheses.
52 test.equal(qualifySelector("body #foo:nth-child(1)", "div"),
53 "body div#foo:nth-child(1)");
54 test.equal(qualifySelector("body .foo:nth-child(1)", "div"),
55 "body div.foo:nth-child(1)");
56 test.equal(qualifySelector("body div:nth-child(1)", "#foo"),
57 "body div#foo:nth-child(1)");
58 test.equal(qualifySelector("body div:nth-child(1)", ".foo"),
59 "body div.foo:nth-child(1)");
60 test.equal(qualifySelector("body div#bar:nth-child(1)", ".foo"),
61 "body div.foo#bar:nth-child(1)");
62 test.equal(qualifySelector("body div.bar:nth-child(1)", "#foo"),
63 "body div#foo.bar:nth-child(1)");
64
65 // Compound selectors with pseudo-class with parentheses containing extra
66 // whitespace.
67 test.equal(qualifySelector("body #foo:nth-child( 1 )", "div"),
68 "body div#foo:nth-child( 1 )");
69 test.equal(qualifySelector("body .foo:nth-child( 1 )", "div"),
70 "body div.foo:nth-child( 1 )");
71 test.equal(qualifySelector("body div:nth-child( 1 )", "#foo"),
72 "body div#foo:nth-child( 1 )");
73 test.equal(qualifySelector("body div:nth-child( 1 )", ".foo"),
74 "body div.foo:nth-child( 1 )");
75 test.equal(qualifySelector("body div#bar:nth-child( 1 )", ".foo"),
76 "body div.foo#bar:nth-child( 1 )");
77 test.equal(qualifySelector("body div.bar:nth-child( 1 )", "#foo"),
78 "body div#foo.bar:nth-child( 1 )");
79
80 // Compound selectors with child combinator and pseudo-class with
81 // parentheses.
82 test.equal(qualifySelector("body > #foo:nth-child(1)", "div"),
83 "body > div#foo:nth-child(1)");
84 test.equal(qualifySelector("body > .foo:nth-child(1)", "div"),
85 "body > div.foo:nth-child(1)");
86 test.equal(qualifySelector("body > div:nth-child(1)", "#foo"),
87 "body > div#foo:nth-child(1)");
88 test.equal(qualifySelector("body > div:nth-child(1)", ".foo"),
89 "body > div.foo:nth-child(1)");
90 test.equal(qualifySelector("body > div#bar:nth-child(1)", ".foo"),
91 "body > div.foo#bar:nth-child(1)");
92 test.equal(qualifySelector("body > div.bar:nth-child(1)", "#foo"),
93 "body > div#foo.bar:nth-child(1)");
94
95 // Compound selectors with child combinator surrounded by no whitespace and
96 // pseudo-class with parentheses.
97 test.equal(qualifySelector("body>#foo:nth-child(1)", "div"),
98 "body>div#foo:nth-child(1)");
99 test.equal(qualifySelector("body>.foo:nth-child(1)", "div"),
100 "body>div.foo:nth-child(1)");
101 test.equal(qualifySelector("body>div:nth-child(1)", "#foo"),
102 "body>div#foo:nth-child(1)");
103 test.equal(qualifySelector("body>div:nth-child(1)", ".foo"),
104 "body>div.foo:nth-child(1)");
105 test.equal(qualifySelector("body>div#bar:nth-child(1)", ".foo"),
106 "body>div.foo#bar:nth-child(1)");
107 test.equal(qualifySelector("body>div.bar:nth-child(1)", "#foo"),
108 "body>div#foo.bar:nth-child(1)");
109
110 // Compound selectors with adjacent sibling combinator and pseudo-class with
111 // parentheses.
112 test.equal(qualifySelector("article + #foo:nth-child(1)", "div"),
113 "article + div#foo:nth-child(1)");
114 test.equal(qualifySelector("article + .foo:nth-child(1)", "div"),
115 "article + div.foo:nth-child(1)");
116 test.equal(qualifySelector("article + div:nth-child(1)", "#foo"),
117 "article + div#foo:nth-child(1)");
118 test.equal(qualifySelector("article + div:nth-child(1)", ".foo"),
119 "article + div.foo:nth-child(1)");
120 test.equal(qualifySelector("article + div#bar:nth-child(1)", ".foo"),
121 "article + div.foo#bar:nth-child(1)");
122 test.equal(qualifySelector("article + div.bar:nth-child(1)", "#foo"),
123 "article + div#foo.bar:nth-child(1)");
124
125 // Compound selectors with general sibling combinator and pseudo-class with
126 // parentheses.
127 test.equal(qualifySelector("article ~ #foo:nth-child(1)", "div"),
128 "article ~ div#foo:nth-child(1)");
129 test.equal(qualifySelector("article ~ .foo:nth-child(1)", "div"),
130 "article ~ div.foo:nth-child(1)");
131 test.equal(qualifySelector("article ~ div:nth-child(1)", "#foo"),
132 "article ~ div#foo:nth-child(1)");
133 test.equal(qualifySelector("article ~ div:nth-child(1)", ".foo"),
134 "article ~ div.foo:nth-child(1)");
135 test.equal(qualifySelector("article ~ div#bar:nth-child(1)", ".foo"),
136 "article ~ div.foo#bar:nth-child(1)");
137 test.equal(qualifySelector("article ~ div.bar:nth-child(1)", "#foo"),
138 "article ~ div#foo.bar:nth-child(1)");
139
140 // Compound selectors with child combinator and pseudo-element.
141 test.equal(qualifySelector("body > #foo::first-child", "div"),
142 "body > div#foo::first-child");
143 test.equal(qualifySelector("body > .foo::first-child", "div"),
144 "body > div.foo::first-child");
145 test.equal(qualifySelector("body > div::first-child", "#foo"),
146 "body > div#foo::first-child");
147 test.equal(qualifySelector("body > div::first-child", ".foo"),
148 "body > div.foo::first-child");
149 test.equal(qualifySelector("body > div#bar::first-child", ".foo"),
150 "body > div.foo#bar::first-child");
151 test.equal(qualifySelector("body > div.bar::first-child", "#foo"),
152 "body > div#foo.bar::first-child");
153
154 // Compound selectors with attribute selector.
155 test.equal(qualifySelector("body #foo[style='display: block']", "div"),
156 "body div#foo[style='display: block']");
157 test.equal(qualifySelector("body .foo[style='display: block']", "div"),
158 "body div.foo[style='display: block']");
159 test.equal(qualifySelector("body div[style='display: block']", "#foo"),
160 "body div#foo[style='display: block']");
161 test.equal(qualifySelector("body div[style='display: block']", ".foo"),
162 "body div.foo[style='display: block']");
163 test.equal(qualifySelector("body div#bar[style='display: block']", ".foo"),
164 "body div.foo#bar[style='display: block']");
165 test.equal(qualifySelector("body div.bar[style='display: block']", "#foo"),
166 "body div#foo.bar[style='display: block']");
167
168 // Compound selectors with unqualified attribute selector.
169 test.equal(qualifySelector("body [style='display: block']", "div"),
170 "body div[style='display: block']");
171 test.equal(qualifySelector("body [style='display: block']", "#foo"),
172 "body #foo[style='display: block']");
173 test.equal(qualifySelector("body [style='display: block']", ".foo"),
174 "body .foo[style='display: block']");
175
176 // Multiple selectors.
177 test.equal(qualifySelector("#foo, #bar", "div"), "div#foo, div#bar");
178 test.equal(qualifySelector(".foo, .bar", "div"), "div.foo, div.bar");
179 test.equal(qualifySelector("div, .bar", "#foo"), "div#foo, #foo.bar");
180 test.equal(qualifySelector("div, #bar", ".foo"), "div.foo, .foo#bar");
181
182 // Compound selector with class selector containing Unicode composite
183 // character.
184 test.equal(qualifySelector("body .\ud83d\ude42", "img"),
185 "body img.\ud83d\ude42");
186
187 test.done();
188 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld