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

Side by Side Diff: test/common.js

Issue 30013613: Noissue - Add more tests for qualifySelector() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 21, 2019, 8:21 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 | « no previous file | 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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 15 matching lines...) Expand all
26 let sandboxedRequire = createSandbox(); 26 let sandboxedRequire = createSandbox();
27 ( 27 (
28 {qualifySelector} = sandboxedRequire("../lib/common") 28 {qualifySelector} = sandboxedRequire("../lib/common")
29 ); 29 );
30 30
31 callback(); 31 callback();
32 }; 32 };
33 33
34 exports.testQualifySelector = function(test) 34 exports.testQualifySelector = function(test)
35 { 35 {
36 // Simple selectors.
37 test.equal(qualifySelector("#foo", "div"), "div#foo");
38 test.equal(qualifySelector(".foo", "div"), "div.foo");
39 test.equal(qualifySelector("div", "#foo"), "div#foo");
40 test.equal(qualifySelector("div", ".foo"), "div.foo");
41 test.equal(qualifySelector("div#bar", ".foo"), "div.foo#bar");
36 test.equal(qualifySelector("div.bar", "#foo"), "div#foo.bar"); 42 test.equal(qualifySelector("div.bar", "#foo"), "div#foo.bar");
43
44 // Compound selectors.
37 test.equal(qualifySelector("body #foo", "div"), "body div#foo"); 45 test.equal(qualifySelector("body #foo", "div"), "body div#foo");
38 test.equal(qualifySelector(".3bcRuc4 *", "div"), ".3bcRuc4 div"); 46 test.equal(qualifySelector("body .foo", "div"), "body div.foo");
47 test.equal(qualifySelector("body div", "#foo"), "body div#foo");
48 test.equal(qualifySelector("body div", ".foo"), "body div.foo");
49 test.equal(qualifySelector("body div#bar", ".foo"), "body div.foo#bar");
50 test.equal(qualifySelector("body div.bar", "#foo"), "body div#foo.bar");
51
52 // Compound selectors with universal selector.
53 test.equal(qualifySelector("#foo *", "div"), "#foo div");
54 test.equal(qualifySelector(".foo *", "div"), ".foo div");
55 test.equal(qualifySelector("div *", "#foo"), "div #foo");
56 test.equal(qualifySelector("div *", ".foo"), "div .foo");
57 test.equal(qualifySelector("div#bar *", ".foo"), "div#bar .foo");
58 test.equal(qualifySelector("div.bar *", "#foo"), "div.bar #foo");
59
60 // Compound selectors with pseudo-class with parentheses.
61 test.equal(qualifySelector("body #foo:nth-child(1)", "div"),
62 "body div#foo:nth-child(1)");
63 test.equal(qualifySelector("body .foo:nth-child(1)", "div"),
64 "body div.foo:nth-child(1)");
65 test.equal(qualifySelector("body div:nth-child(1)", "#foo"),
66 "body div#foo:nth-child(1)");
67 test.equal(qualifySelector("body div:nth-child(1)", ".foo"),
68 "body div.foo:nth-child(1)");
69 test.equal(qualifySelector("body div#bar:nth-child(1)", ".foo"),
70 "body div.foo#bar:nth-child(1)");
71 test.equal(qualifySelector("body div.bar:nth-child(1)", "#foo"),
72 "body div#foo.bar:nth-child(1)");
73
74 // Compound selectors with pseudo-class with parentheses containing extra
75 // whitespace.
76 test.equal(qualifySelector("body #foo:nth-child( 1 )", "div"),
77 "body div#foo:nth-child( 1 )");
78 test.equal(qualifySelector("body .foo:nth-child( 1 )", "div"),
79 "body div.foo:nth-child( 1 )");
80 test.equal(qualifySelector("body div:nth-child( 1 )", "#foo"),
81 "body div#foo:nth-child( 1 )");
82 test.equal(qualifySelector("body div:nth-child( 1 )", ".foo"),
83 "body div.foo:nth-child( 1 )");
84 test.equal(qualifySelector("body div#bar:nth-child( 1 )", ".foo"),
85 "body div.foo#bar:nth-child( 1 )");
86 test.equal(qualifySelector("body div.bar:nth-child( 1 )", "#foo"),
87 "body div#foo.bar:nth-child( 1 )");
88
89 // Compound selectors with child combinator and pseudo-class with
90 // parentheses.
91 test.equal(qualifySelector("body > #foo:nth-child(1)", "div"),
92 "body > div#foo:nth-child(1)");
93 test.equal(qualifySelector("body > .foo:nth-child(1)", "div"),
94 "body > div.foo:nth-child(1)");
95 test.equal(qualifySelector("body > div:nth-child(1)", "#foo"),
96 "body > div#foo:nth-child(1)");
97 test.equal(qualifySelector("body > div:nth-child(1)", ".foo"),
98 "body > div.foo:nth-child(1)");
99 test.equal(qualifySelector("body > div#bar:nth-child(1)", ".foo"),
100 "body > div.foo#bar:nth-child(1)");
101 test.equal(qualifySelector("body > div.bar:nth-child(1)", "#foo"),
102 "body > div#foo.bar:nth-child(1)");
103
104 // Compound selectors with child combinator surrounded by no whitespace and
105 // pseudo-class with parentheses.
106 test.equal(qualifySelector("body>#foo:nth-child(1)", "div"),
107 "body>div#foo:nth-child(1)");
108 test.equal(qualifySelector("body>.foo:nth-child(1)", "div"),
109 "body>div.foo:nth-child(1)");
110 test.equal(qualifySelector("body>div:nth-child(1)", "#foo"),
111 "body>div#foo:nth-child(1)");
112 test.equal(qualifySelector("body>div:nth-child(1)", ".foo"),
113 "body>div.foo:nth-child(1)");
114 test.equal(qualifySelector("body>div#bar:nth-child(1)", ".foo"),
115 "body>div.foo#bar:nth-child(1)");
116 test.equal(qualifySelector("body>div.bar:nth-child(1)", "#foo"),
117 "body>div#foo.bar:nth-child(1)");
118
119 // Compound selectors with adjacent sibling combinator and pseudo-class with
120 // parentheses.
121 test.equal(qualifySelector("article + #foo:nth-child(1)", "div"),
122 "article + div#foo:nth-child(1)");
123 test.equal(qualifySelector("article + .foo:nth-child(1)", "div"),
124 "article + div.foo:nth-child(1)");
125 test.equal(qualifySelector("article + div:nth-child(1)", "#foo"),
126 "article + div#foo:nth-child(1)");
127 test.equal(qualifySelector("article + div:nth-child(1)", ".foo"),
128 "article + div.foo:nth-child(1)");
129 test.equal(qualifySelector("article + div#bar:nth-child(1)", ".foo"),
130 "article + div.foo#bar:nth-child(1)");
131 test.equal(qualifySelector("article + div.bar:nth-child(1)", "#foo"),
132 "article + div#foo.bar:nth-child(1)");
133
134 // Compound selectors with general sibling combinator and pseudo-class with
135 // parentheses.
136 test.equal(qualifySelector("article ~ #foo:nth-child(1)", "div"),
137 "article ~ div#foo:nth-child(1)");
138 test.equal(qualifySelector("article ~ .foo:nth-child(1)", "div"),
139 "article ~ div.foo:nth-child(1)");
140 test.equal(qualifySelector("article ~ div:nth-child(1)", "#foo"),
141 "article ~ div#foo:nth-child(1)");
142 test.equal(qualifySelector("article ~ div:nth-child(1)", ".foo"),
143 "article ~ div.foo:nth-child(1)");
144 test.equal(qualifySelector("article ~ div#bar:nth-child(1)", ".foo"),
145 "article ~ div.foo#bar:nth-child(1)");
146 test.equal(qualifySelector("article ~ div.bar:nth-child(1)", "#foo"),
147 "article ~ div#foo.bar:nth-child(1)");
148
149 // Compound selectors with child combinator and pseudo-element.
150 test.equal(qualifySelector("body > #foo::first-child", "div"),
151 "body > div#foo::first-child");
152 test.equal(qualifySelector("body > .foo::first-child", "div"),
153 "body > div.foo::first-child");
154 test.equal(qualifySelector("body > div::first-child", "#foo"),
155 "body > div#foo::first-child");
156 test.equal(qualifySelector("body > div::first-child", ".foo"),
157 "body > div.foo::first-child");
158 test.equal(qualifySelector("body > div#bar::first-child", ".foo"),
159 "body > div.foo#bar::first-child");
160 test.equal(qualifySelector("body > div.bar::first-child", "#foo"),
161 "body > div#foo.bar::first-child");
162
163 // Compound selectors with attribute selector.
164 test.equal(qualifySelector("body #foo[style='display: block']", "div"),
165 "body div#foo[style='display: block']");
166 test.equal(qualifySelector("body .foo[style='display: block']", "div"),
167 "body div.foo[style='display: block']");
168 test.equal(qualifySelector("body div[style='display: block']", "#foo"),
169 "body div#foo[style='display: block']");
170 test.equal(qualifySelector("body div[style='display: block']", ".foo"),
171 "body div.foo[style='display: block']");
172 test.equal(qualifySelector("body div#bar[style='display: block']", ".foo"),
173 "body div.foo#bar[style='display: block']");
174 test.equal(qualifySelector("body div.bar[style='display: block']", "#foo"),
175 "body div#foo.bar[style='display: block']");
176
177 // Compound selectors with unqualified attribute selector.
178 test.equal(qualifySelector("body [style='display: block']", "div"),
179 "body div[style='display: block']");
180 test.equal(qualifySelector("body [style='display: block']", "#foo"),
181 "body #foo[style='display: block']");
182 test.equal(qualifySelector("body [style='display: block']", ".foo"),
183 "body .foo[style='display: block']");
184
185 // Multiple selectors.
186 test.equal(qualifySelector("#foo, #bar", "div"), "div#foo, div#bar");
187 test.equal(qualifySelector(".foo, .bar", "div"), "div.foo, div.bar");
188 test.equal(qualifySelector("div, .bar", "#foo"), "div#foo, #foo.bar");
189 test.equal(qualifySelector("div, #bar", ".foo"), "div.foo, .foo#bar");
190
191 // Compound selector with class selector containing Unicode composite
192 // character.
193 test.equal(qualifySelector("body .\ud83d\ude42", "img"),
194 "body img.\ud83d\ude42");
39 195
40 test.done(); 196 test.done();
41 }; 197 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld