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, isThirdParty} = require("../../lib/url"); |
22 isThirdParty} = require("../../lib/url"); | 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 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", () => | 26 test("Extracting hostname from frame", () => |
50 { | 27 { |
51 function testFrameHostname(hierarchy, expectedHostname, message) | 28 function testFrameHostname(hierarchy, expectedHostname, message) |
52 { | 29 { |
53 let frame = null; | 30 let frame = null; |
54 | 31 |
55 for (let url of hierarchy) | 32 for (let url of hierarchy) |
56 frame = {parent: frame, url: new URL(url)}; | 33 frame = {parent: frame, url: new URL(url)}; |
57 | 34 |
58 equal(extractHostFromFrame(frame), expectedHostname, message); | 35 equal(extractHostFromFrame(frame), expectedHostname, message); |
59 } | 36 } |
60 | 37 |
61 testFrameHostname(["http://example.com/"], "example.com", "single frame"); | 38 testFrameHostname(["http://example.com/"], "example.com", "single frame"); |
62 testFrameHostname(["http://example.com/", "http://example.org/"], | 39 testFrameHostname(["http://example.com/", "http://example.org/"], |
63 "example.org", "with parent frame"); | 40 "example.org", "with parent frame"); |
64 testFrameHostname(["http://example.com/", "data:text/plain,foo"], | 41 testFrameHostname(["http://example.com/", "data:text/plain,foo"], |
65 "example.com", "data: URL, hostname in parent"); | 42 "example.com", "data: URL, hostname in parent"); |
66 testFrameHostname(["http://example.com/", "about:blank", "about:blank"], | 43 testFrameHostname(["http://example.com/", "about:blank", "about:blank"], |
67 "example.com", "about:blank, hostname in ancestor"); | 44 "example.com", "about:blank, hostname in ancestor"); |
68 testFrameHostname(["about:blank", "about:blank"], "", | 45 testFrameHostname(["about:blank", "about:blank"], "", |
69 "about:blank, no hostname"); | 46 "about:blank, no hostname"); |
70 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", | 47 |
71 "with punycode"); | 48 // Currently there are two bugs in Microsoft Edge (EdgeHTML 17.17134) |
| 49 // that would make this two assertions fail, |
| 50 // so for now we are not running them on this platform. |
| 51 // See: |
| 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/ |
| 54 if (platform != "edgehtml") |
| 55 { |
| 56 testFrameHostname(["http://xn--f-1gaa.com/"], "xn--f-1gaa.com", |
| 57 "with punycode"); |
| 58 testFrameHostname(["http://user:password@example.com/"], "example.com", |
| 59 "with auth credentials"); |
| 60 } |
72 }); | 61 }); |
73 | 62 |
74 test("Third-party checks", () => | 63 test("Third-party checks", () => |
75 { | 64 { |
76 function hostnameToURL(hostname) | 65 function hostnameToURL(hostname) |
77 { | 66 { |
78 return new URL("http://" + hostname); | 67 return new URL("http://" + hostname); |
79 } | 68 } |
80 | 69 |
81 function testThirdParty(requestHost, documentHost, expected, message) | 70 function testThirdParty(requestHost, documentHost, expected, message) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 testThirdParty( | 133 testThirdParty( |
145 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true, | 134 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true, |
146 "different IPv4-mapped IPv6 address is third-party" | 135 "different IPv4-mapped IPv6 address is third-party" |
147 ); | 136 ); |
148 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false, | 137 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false, |
149 "same IDN isn't third-party"); | 138 "same IDN isn't third-party"); |
150 testThirdParty("example.com..", "example.com....", false, | 139 testThirdParty("example.com..", "example.com....", false, |
151 "traling dots are ignored"); | 140 "traling dots are ignored"); |
152 }); | 141 }); |
153 } | 142 } |
OLD | NEW |