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

Delta Between Two Patch Sets: test/url.js

Issue 30009560: Noissue - Rename lib/domain.js to lib/url.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rename testGetDomain Created Feb. 19, 2019, 1:58 a.m.
Right Patch Set: Add tests for domainSuffixes Created Feb. 19, 2019, 2:36 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/url.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
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 domainSuffixes = null;
27 let isThirdParty = null; 28 let isThirdParty = null;
28 let getBaseDomain = null; 29 let getBaseDomain = null;
29 30
30 exports.setUp = function(callback) 31 exports.setUp = function(callback)
31 { 32 {
32 let sandboxedRequire = createSandbox({ 33 let sandboxedRequire = createSandbox({
33 extraExports: { 34 extraExports: {
34 domain: ["getBaseDomain"] 35 domain: ["getBaseDomain"]
35 } 36 }
36 }); 37 });
37 ( 38 (
38 {normalizeHostname, isThirdParty, 39 {normalizeHostname, domainSuffixes, isThirdParty,
39 getBaseDomain} = sandboxedRequire("../lib/url") 40 getBaseDomain} = sandboxedRequire("../lib/url")
40 ); 41 );
41 42
42 callback(); 43 callback();
43 }; 44 };
44 45
45 function hostnameToURL(hostname) 46 function hostnameToURL(hostname)
46 { 47 {
47 return new URL("http://" + hostname); 48 return new URL("http://" + hostname);
48 } 49 }
(...skipping 27 matching lines...) Expand all
76 77
77 test.equal(normalizeHostname("192.168.1.1"), "192.168.1.1"); 78 test.equal(normalizeHostname("192.168.1.1"), "192.168.1.1");
78 test.equal(normalizeHostname("192.168.1.1."), "192.168.1.1"); 79 test.equal(normalizeHostname("192.168.1.1."), "192.168.1.1");
79 80
80 test.equal(normalizeHostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), 81 test.equal(normalizeHostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
81 "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); 82 "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
82 test.equal(normalizeHostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334."), 83 test.equal(normalizeHostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334."),
83 "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); 84 "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
84 test.equal(normalizeHostname("2001:0DB8:85A3:0000:0000:8A2E:0370:7334"), 85 test.equal(normalizeHostname("2001:0DB8:85A3:0000:0000:8A2E:0370:7334"),
85 "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); 86 "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
87
88 test.done();
89 };
90
91 exports.testDomainSuffixes = function(test)
92 {
93 test.deepEqual([...domainSuffixes("localhost")], ["localhost"]);
94 test.deepEqual([...domainSuffixes("example.com")], ["example.com", "com"]);
95 test.deepEqual([...domainSuffixes("www.example.com")],
96 ["www.example.com", "example.com", "com"]);
97 test.deepEqual([...domainSuffixes("www.example.co.in")],
98 ["www.example.co.in", "example.co.in", "co.in", "in"]);
99
100 // With blank.
101 test.deepEqual([...domainSuffixes("localhost", true)], ["localhost", ""]);
102 test.deepEqual([...domainSuffixes("example.com", true)],
103 ["example.com", "com", ""]);
104 test.deepEqual([...domainSuffixes("www.example.com", true)],
105 ["www.example.com", "example.com", "com", ""]);
106 test.deepEqual([...domainSuffixes("www.example.co.in", true)],
107 ["www.example.co.in", "example.co.in", "co.in", "in", ""]);
108
109 // Quirks and edge cases.
110 test.deepEqual([...domainSuffixes("")], []);
111 test.deepEqual([...domainSuffixes(".")], ["."]);
112 test.deepEqual([...domainSuffixes(".localhost")],
113 [".localhost", "localhost"]);
114 test.deepEqual([...domainSuffixes(".example.com")],
115 [".example.com", "example.com", "com"]);
116 test.deepEqual([...domainSuffixes("localhost.")],
117 ["localhost."]);
118 test.deepEqual([...domainSuffixes("example.com.")],
119 ["example.com.", "com."]);
120 test.deepEqual([...domainSuffixes("..localhost")],
121 ["..localhost", ".localhost", "localhost"]);
122 test.deepEqual([...domainSuffixes("..example..com")],
123 ["..example..com", ".example..com", "example..com", ".com",
124 "com"]);
125 test.deepEqual([...domainSuffixes("localhost..")], ["localhost..", "."]);
126 test.deepEqual([...domainSuffixes("example..com..")],
127 ["example..com..", ".com..", "com..", "."]);
86 128
87 test.done(); 129 test.done();
88 }; 130 };
89 131
90 exports.testIsThirdParty = function(test) 132 exports.testIsThirdParty = function(test)
91 { 133 {
92 testThirdParty(test, "foo", "foo", false, "same domain isn't third-party"); 134 testThirdParty(test, "foo", "foo", false, "same domain isn't third-party");
93 testThirdParty(test, "foo", "bar", true, "different domain is third-party"); 135 testThirdParty(test, "foo", "bar", true, "different domain is third-party");
94 testThirdParty(test, "foo.com", "foo.com", false, 136 testThirdParty(test, "foo.com", "foo.com", false,
95 "same domain with TLD (.com) isn't third-party"); 137 "same domain with TLD (.com) isn't third-party");
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 "us-east-1.amazonaws.com" 287 "us-east-1.amazonaws.com"
246 ); 288 );
247 test.equal(getBaseDomain("example.amazonaws.com"), "amazonaws.com"); 289 test.equal(getBaseDomain("example.amazonaws.com"), "amazonaws.com");
248 test.equal(getBaseDomain("amazonaws.com"), "amazonaws.com"); 290 test.equal(getBaseDomain("amazonaws.com"), "amazonaws.com");
249 291
250 // Edge case. 292 // Edge case.
251 test.equal(getBaseDomain(""), ""); 293 test.equal(getBaseDomain(""), "");
252 294
253 test.done(); 295 test.done();
254 }; 296 };
LEFTRIGHT
« lib/url.js ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld