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

Side by Side Diff: test/url.js

Issue 30009560: Noissue - Rename lib/domain.js to lib/url.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase Created Feb. 19, 2019, 1:57 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 | « lib/url.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 /* 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 // Only starting NodeJS 10 that URL is in the global space. 20 // Only starting NodeJS 10 that URL is in the global space.
21 const {URL} = require("url"); 21 const {URL} = require("url");
22 const {createSandbox} = require("./_common"); 22 const {createSandbox} = require("./_common");
23 23
24 const publicSuffixes = require("../data/publicSuffixList.json"); 24 const publicSuffixes = require("../data/publicSuffixList.json");
25 25
26 let normalizeHostname = null; 26 let normalizeHostname = null;
27 let isThirdParty = null; 27 let isThirdParty = null;
28 let getDomain = null; 28 let getBaseDomain = null;
29 29
30 exports.setUp = function(callback) 30 exports.setUp = function(callback)
31 { 31 {
32 let sandboxedRequire = createSandbox({ 32 let sandboxedRequire = createSandbox({
33 extraExports: { 33 extraExports: {
34 domain: ["getDomain"] 34 domain: ["getBaseDomain"]
35 } 35 }
36 }); 36 });
37 ( 37 (
38 {normalizeHostname, isThirdParty, 38 {normalizeHostname, isThirdParty,
39 getDomain} = sandboxedRequire("../lib/domain") 39 getBaseDomain} = sandboxedRequire("../lib/url")
40 ); 40 );
41 41
42 callback(); 42 callback();
43 }; 43 };
44 44
45 function hostnameToURL(hostname) 45 function hostnameToURL(hostname)
46 { 46 {
47 return new URL("http://" + hostname); 47 return new URL("http://" + hostname);
48 } 48 }
49 49
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 "Not enough domain parts for testing"); 170 "Not enough domain parts for testing");
171 171
172 for (let i = 0; i < offset + levels; i++) 172 for (let i = 0; i < offset + levels; i++)
173 { 173 {
174 let hostname = parts.slice(0, i).join("."); 174 let hostname = parts.slice(0, i).join(".");
175 hostname += (hostname ? "." : "") + suffix; 175 hostname += (hostname ? "." : "") + suffix;
176 176
177 let expected = parts.slice(Math.max(0, i - offset), i).join("."); 177 let expected = parts.slice(Math.max(0, i - offset), i).join(".");
178 expected += (expected ? "." : "") + suffix; 178 expected += (expected ? "." : "") + suffix;
179 179
180 test.equal(getDomain(hostname), expected, 180 test.equal(getBaseDomain(hostname), expected,
181 `getDomain("${hostname}") == "${expected}"` + 181 `getBaseDomain("${hostname}") == "${expected}"` +
182 ` with {suffix: "${suffix}", offset: ${offset}}`); 182 ` with {suffix: "${suffix}", offset: ${offset}}`);
183 } 183 }
184 } 184 }
185 185
186 // Unknown suffixes. 186 // Unknown suffixes.
187 test.equal(typeof publicSuffixes["localhost"], "undefined"); 187 test.equal(typeof publicSuffixes["localhost"], "undefined");
188 test.equal(typeof publicSuffixes["localhost.localdomain"], "undefined"); 188 test.equal(typeof publicSuffixes["localhost.localdomain"], "undefined");
189 189
190 test.equal(getDomain("localhost"), "localhost"); 190 test.equal(getBaseDomain("localhost"), "localhost");
191 test.equal(getDomain("localhost.localdomain"), "localhost.localdomain"); 191 test.equal(getBaseDomain("localhost.localdomain"), "localhost.localdomain");
192 test.equal(getDomain("mail.localhost.localdomain"), "localhost.localdomain"); 192 test.equal(
193 test.equal(getDomain("www.example.localhost.localdomain"), 193 getBaseDomain("mail.localhost.localdomain"),
194 "localhost.localdomain"
195 );
196 test.equal(getBaseDomain("www.example.localhost.localdomain"),
194 "localhost.localdomain"); 197 "localhost.localdomain");
195 198
196 // Unknown suffixes that overlap partly with known suffixes. 199 // Unknown suffixes that overlap partly with known suffixes.
197 test.equal(typeof publicSuffixes["example.com"], "undefined"); 200 test.equal(typeof publicSuffixes["example.com"], "undefined");
198 test.equal(typeof publicSuffixes["africa.com"], "number"); 201 test.equal(typeof publicSuffixes["africa.com"], "number");
199 test.equal(typeof publicSuffixes["compute.amazonaws.com"], "number"); 202 test.equal(typeof publicSuffixes["compute.amazonaws.com"], "number");
200 203
201 test.equal(getDomain("example.com"), "example.com"); 204 test.equal(getBaseDomain("example.com"), "example.com");
202 test.equal(getDomain("mail.example.com"), "example.com"); 205 test.equal(getBaseDomain("mail.example.com"), "example.com");
203 test.equal(getDomain("secure.mail.example.com"), "example.com"); 206 test.equal(getBaseDomain("secure.mail.example.com"), "example.com");
204 207
205 // Cascading offsets. 208 // Cascading offsets.
206 209
207 // If these sanity checks fail, look for other examles of cascading offsets 210 // If these sanity checks fail, look for other examles of cascading offsets
208 // from the public suffix list. 211 // from the public suffix list.
209 test.equal( 212 test.equal(
210 typeof publicSuffixes[ 213 typeof publicSuffixes[
211 "images.example.s3.dualstack.us-east-1.amazonaws.com" 214 "images.example.s3.dualstack.us-east-1.amazonaws.com"
212 ], 215 ],
213 "undefined" 216 "undefined"
214 ); 217 );
215 test.equal( 218 test.equal(
216 typeof publicSuffixes["example.s3.dualstack.us-east-1.amazonaws.com"], 219 typeof publicSuffixes["example.s3.dualstack.us-east-1.amazonaws.com"],
217 "undefined" 220 "undefined"
218 ); 221 );
219 test.equal(publicSuffixes["s3.dualstack.us-east-1.amazonaws.com"], 1); 222 test.equal(publicSuffixes["s3.dualstack.us-east-1.amazonaws.com"], 1);
220 test.equal(typeof publicSuffixes["dualstack.us-east-1.amazonaws.com"], 223 test.equal(typeof publicSuffixes["dualstack.us-east-1.amazonaws.com"],
221 "undefined"); 224 "undefined");
222 test.equal(typeof publicSuffixes["example.us-east-1.amazonaws.com"], 225 test.equal(typeof publicSuffixes["example.us-east-1.amazonaws.com"],
223 "undefined"); 226 "undefined");
224 test.equal(publicSuffixes["us-east-1.amazonaws.com"], 1); 227 test.equal(publicSuffixes["us-east-1.amazonaws.com"], 1);
225 test.equal(typeof publicSuffixes["example.amazonaws.com"], "undefined"); 228 test.equal(typeof publicSuffixes["example.amazonaws.com"], "undefined");
226 test.equal(typeof publicSuffixes["amazonaws.com"], "undefined"); 229 test.equal(typeof publicSuffixes["amazonaws.com"], "undefined");
227 230
228 test.equal(getDomain("images.example.s3.dualstack.us-east-1.amazonaws.com"), 231 test.equal(
232 getBaseDomain("images.example.s3.dualstack.us-east-1.amazonaws.com"),
233 "example.s3.dualstack.us-east-1.amazonaws.com"
234 );
235 test.equal(getBaseDomain("example.s3.dualstack.us-east-1.amazonaws.com"),
229 "example.s3.dualstack.us-east-1.amazonaws.com"); 236 "example.s3.dualstack.us-east-1.amazonaws.com");
230 test.equal(getDomain("example.s3.dualstack.us-east-1.amazonaws.com"), 237 test.equal(getBaseDomain("s3.dualstack.us-east-1.amazonaws.com"),
231 "example.s3.dualstack.us-east-1.amazonaws.com");
232 test.equal(getDomain("s3.dualstack.us-east-1.amazonaws.com"),
233 "s3.dualstack.us-east-1.amazonaws.com"); 238 "s3.dualstack.us-east-1.amazonaws.com");
234 test.equal(getDomain("dualstack.us-east-1.amazonaws.com"), 239 test.equal(getBaseDomain("dualstack.us-east-1.amazonaws.com"),
235 "dualstack.us-east-1.amazonaws.com"); 240 "dualstack.us-east-1.amazonaws.com");
236 test.equal(getDomain("example.us-east-1.amazonaws.com"), 241 test.equal(getBaseDomain("example.us-east-1.amazonaws.com"),
237 "example.us-east-1.amazonaws.com"); 242 "example.us-east-1.amazonaws.com");
238 test.equal(getDomain("us-east-1.amazonaws.com"), "us-east-1.amazonaws.com"); 243 test.equal(
239 test.equal(getDomain("example.amazonaws.com"), "amazonaws.com"); 244 getBaseDomain("us-east-1.amazonaws.com"),
240 test.equal(getDomain("amazonaws.com"), "amazonaws.com"); 245 "us-east-1.amazonaws.com"
246 );
247 test.equal(getBaseDomain("example.amazonaws.com"), "amazonaws.com");
248 test.equal(getBaseDomain("amazonaws.com"), "amazonaws.com");
241 249
242 // Edge case. 250 // Edge case.
243 test.equal(getDomain(""), ""); 251 test.equal(getBaseDomain(""), "");
244 252
245 test.done(); 253 test.done();
246 }; 254 };
OLDNEW
« no previous file with comments | « lib/url.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld