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

Side by Side Diff: qunit/tests/url.js

Issue 29991594: Issue 7243 - Update adblockpluscore dependency to hg:e26e122e0702 (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Remove third-party checks from QUnit tests Created Jan. 31, 2019, 12:56 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 | « metadata.chrome ('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 { 20 {
21 const {extractHostFromFrame, isThirdParty} = require("../../lib/url"); 21 const {extractHostFromFrame} = require("../../lib/url");
22 const {platform} = require("info"); 22 const {platform} = require("info");
23 23
24 QUnit.module("URL/host tools"); 24 QUnit.module("URL/host tools");
25 25
26 test("Extracting hostname from frame", () => 26 test("Extracting hostname from frame", () =>
27 { 27 {
28 function testFrameHostname(hierarchy, expectedHostname, message) 28 function testFrameHostname(hierarchy, expectedHostname, message)
29 { 29 {
30 let frame = null; 30 let frame = null;
31 31
(...skipping 20 matching lines...) Expand all
52 // with punycode: https://developer.microsoft.com/en-us/microsoft-edge/platf orm/issues/18861990/ 52 // with punycode: https://developer.microsoft.com/en-us/microsoft-edge/platf orm/issues/18861990/
53 // with auth credentials: https://developer.microsoft.com/en-us/microsoft-ed ge/platform/issues/8004284/ 53 // with auth credentials: https://developer.microsoft.com/en-us/microsoft-ed ge/platform/issues/8004284/
54 if (platform != "edgehtml") 54 if (platform != "edgehtml")
55 { 55 {
56 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", 56 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com",
57 "with punycode"); 57 "with punycode");
58 testFrameHostname(["http://user:password@example.com/"], "example.com", 58 testFrameHostname(["http://user:password@example.com/"], "example.com",
59 "with auth credentials"); 59 "with auth credentials");
60 } 60 }
61 }); 61 });
62
63 test("Third-party checks", () =>
64 {
65 function hostnameToURL(hostname)
66 {
67 return new URL("http://" + hostname);
68 }
69
70 function testThirdParty(requestHost, documentHost, expected, message)
71 {
72 equal(
73 isThirdParty(
74 hostnameToURL(requestHost),
75
76 // Chrome's URL object normalizes IP addresses. So some test
77 // will fail if we don't normalize the document host as well.
78 hostnameToURL(documentHost).hostname
79 ),
80 expected,
81 message
82 );
83 }
84
85 testThirdParty("foo", "foo", false, "same domain isn't third-party");
86 testThirdParty("foo", "bar", true, "different domain is third-party");
87 testThirdParty("foo.com", "foo.com", false,
88 "same domain with TLD (.com) isn't third-party");
89 testThirdParty("foo.com", "bar.com", true,
90 "same TLD (.com) but different domain is third-party");
91 testThirdParty("foo.com", "www.foo.com", false,
92 "same domain but differend subdomain isn't third-party");
93 testThirdParty("foo.example.com", "bar.example.com", false,
94 "same basedomain (example.com) isn't third-party");
95 testThirdParty("foo.uk", "bar.uk", true,
96 "same TLD (.uk) but different domain is third-party");
97 testThirdParty("foo.co.uk", "bar.co.uk", true,
98 "same TLD (.co.uk) but different domain is third-party");
99 testThirdParty("foo.example.co.uk", "bar.example.co.uk", false,
100 "same basedomain (example.co.uk) isn't third-party");
101 testThirdParty("1.2.3.4", "1.2.3.4", false,
102 "same IPv4 address isn't third-party");
103 testThirdParty("1.1.1.1", "2.1.1.1", true,
104 "different IPv4 address is third-party");
105 testThirdParty("0x01ff0101", "0x01ff0101", false,
106 "same IPv4 hexadecimal address isn't third-party");
107 testThirdParty("0x01ff0101", "0x01ff0102", true,
108 "different IPv4 hexadecimal address is third-party");
109 testThirdParty(
110 "1.0xff.3.4", "1.0xff.3.4", false,
111 "same IPv4 address with hexadecimal octet isn't third-party"
112 );
113 testThirdParty(
114 "1.0xff.1.1", "2.0xff.1.1", true,
115 "different IPv4 address with hexadecimal octet is third-party"
116 );
117 testThirdParty(
118 "0xff.example.com", "example.com", false,
119 "domain starts like a hexadecimal IPv4 address but isn't one"
120 );
121 testThirdParty(
122 "[2001:db8:85a3::8a2e:370:7334]", "[2001:db8:85a3::8a2e:370:7334]", false,
123 "same IPv6 address isn't third-party"
124 );
125 testThirdParty(
126 "[2001:db8:85a3::8a2e:370:7334]", "[5001:db8:85a3::8a2e:370:7334]", true,
127 "different IPv6 address is third-party"
128 );
129 testThirdParty(
130 "[::ffff:192.0.2.128]", "[::ffff:192.0.2.128]", false,
131 "same IPv4-mapped IPv6 address isn't third-party"
132 );
133 testThirdParty(
134 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true,
135 "different IPv4-mapped IPv6 address is third-party"
136 );
137 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false,
138 "same IDN isn't third-party");
139 testThirdParty("example.com..", "example.com....", false,
140 "traling dots are ignored");
141 });
142 } 62 }
OLDNEW
« no previous file with comments | « metadata.chrome ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld