Left: | ||
Right: |
OLD | NEW |
---|---|
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 let {extractHostFromFrame, | 21 const {extractHostFromFrame, |
geo
2018/09/06 10:24:10
I know that this change is not related to this par
Sebastian Noack
2018/09/06 13:43:21
I agree, but while on it, it also seems unnecessar
geo
2018/09/06 20:10:47
You're right. I was so focused on that let and con
| |
22 isThirdParty} = require("../../lib/url"); | 22 isThirdParty} = require("../../lib/url"); |
23 const {platform} = require("info"); | |
23 | 24 |
24 QUnit.module("URL/host tools"); | 25 QUnit.module("URL/host tools"); |
25 | 26 |
26 test("Extracting hostname from URL", () => | |
27 { | |
28 function testURLHostname(url, expectedHostname, message) | |
29 { | |
30 equal(new URL(url).hostname, expectedHostname, message); | |
31 } | |
32 | |
33 testURLHostname("http://example.com/foo", "example.com", "with path"); | |
34 testURLHostname("http://example.com/?foo=bar", "example.com", "with query"); | |
35 testURLHostname("http://example.com/#top", "example.com", "with hash"); | |
36 testURLHostname("http://example.com:8080/", "example.com", "with port"); | |
37 testURLHostname("http://user:password@example.com/", "example.com", | |
38 "with auth credentials"); | |
39 testURLHostname("http://xn--f-1gaa.com/", "xn--f-1gaa.com", | |
40 "with punycode"); | |
41 testURLHostname("about:blank", "", "about:blank"); | |
42 testURLHostname("data:text/plain,foo", "", "data: URL"); | |
43 testURLHostname("ftp://example.com/", "example.com", "ftp: URL"); | |
44 testURLHostname("http://1.2.3.4:8000/", "1.2.3.4", "IPv4 address"); | |
45 testURLHostname("http://[2001:db8:85a3::8a2e:370:7334]/", | |
46 "[2001:db8:85a3::8a2e:370:7334]", "IPv6 address"); | |
47 }); | |
48 | |
49 test("Extracting hostname from frame", () => | 27 test("Extracting hostname from frame", () => |
50 { | 28 { |
51 function testFrameHostname(hierarchy, expectedHostname, message) | 29 function testFrameHostname(hierarchy, expectedHostname, message) |
52 { | 30 { |
53 let frame = null; | 31 let frame = null; |
54 | 32 |
55 for (let url of hierarchy) | 33 for (let url of hierarchy) |
56 frame = {parent: frame, url: new URL(url)}; | 34 frame = {parent: frame, url: new URL(url)}; |
57 | 35 |
58 equal(extractHostFromFrame(frame), expectedHostname, message); | 36 equal(extractHostFromFrame(frame), expectedHostname, message); |
59 } | 37 } |
60 | 38 |
61 testFrameHostname(["http://example.com/"], "example.com", "single frame"); | 39 testFrameHostname(["http://example.com/"], "example.com", "single frame"); |
62 testFrameHostname(["http://example.com/", "http://example.org/"], | 40 testFrameHostname(["http://example.com/", "http://example.org/"], |
63 "example.org", "with parent frame"); | 41 "example.org", "with parent frame"); |
64 testFrameHostname(["http://example.com/", "data:text/plain,foo"], | 42 testFrameHostname(["http://example.com/", "data:text/plain,foo"], |
65 "example.com", "data: URL, hostname in parent"); | 43 "example.com", "data: URL, hostname in parent"); |
66 testFrameHostname(["http://example.com/", "about:blank", "about:blank"], | 44 testFrameHostname(["http://example.com/", "about:blank", "about:blank"], |
67 "example.com", "about:blank, hostname in ancestor"); | 45 "example.com", "about:blank, hostname in ancestor"); |
68 testFrameHostname(["about:blank", "about:blank"], "", | 46 testFrameHostname(["about:blank", "about:blank"], "", |
69 "about:blank, no hostname"); | 47 "about:blank, no hostname"); |
70 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", | 48 // Currently there are two bugs in Microsoft Edge (EdgeHTML 17.17134) |
Sebastian Noack
2018/09/06 13:43:21
Nit: It might read better with a blank line above.
geo
2018/09/06 20:10:47
Done.
| |
71 "with punycode"); | 49 // that would make this two assertions fail, |
50 // so for now we are not running them on this platform. | |
51 // See: https://issues.adblockplus.org/ticket/6913 | |
Sebastian Noack
2018/09/06 13:43:21
Can we link to the Microsoft Edge bugs directly, r
geo
2018/09/06 20:10:47
Done.
| |
52 if (platform != "edgehtml") | |
53 { | |
54 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", | |
55 "with punycode"); | |
56 testFrameHostname(["http://user:password@example.com/"], "example.com", | |
57 "with auth credentials"); | |
58 } | |
72 }); | 59 }); |
73 | 60 |
74 test("Third-party checks", () => | 61 test("Third-party checks", () => |
75 { | 62 { |
76 function hostnameToURL(hostname) | 63 function hostnameToURL(hostname) |
77 { | 64 { |
78 return new URL("http://" + hostname); | 65 return new URL("http://" + hostname); |
79 } | 66 } |
80 | 67 |
81 function testThirdParty(requestHost, documentHost, expected, message) | 68 function testThirdParty(requestHost, documentHost, expected, message) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 testThirdParty( | 131 testThirdParty( |
145 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true, | 132 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true, |
146 "different IPv4-mapped IPv6 address is third-party" | 133 "different IPv4-mapped IPv6 address is third-party" |
147 ); | 134 ); |
148 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false, | 135 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false, |
149 "same IDN isn't third-party"); | 136 "same IDN isn't third-party"); |
150 testThirdParty("example.com..", "example.com....", false, | 137 testThirdParty("example.com..", "example.com....", false, |
151 "traling dots are ignored"); | 138 "traling dots are ignored"); |
152 }); | 139 }); |
153 } | 140 } |
OLD | NEW |