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

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

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Use var for ext declarations again Created Feb. 8, 2017, 9:02 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
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
(...skipping 18 matching lines...) Expand all
29 { 29 {
30 function testURLHostname(url, expectedHostname, message) 30 function testURLHostname(url, expectedHostname, message)
31 { 31 {
32 equal(getDecodedHostname(new URL(url)), expectedHostname, message); 32 equal(getDecodedHostname(new URL(url)), expectedHostname, message);
33 } 33 }
34 34
35 testURLHostname("http://example.com/foo", "example.com", "with path"); 35 testURLHostname("http://example.com/foo", "example.com", "with path");
36 testURLHostname("http://example.com/?foo=bar", "example.com", "with query"); 36 testURLHostname("http://example.com/?foo=bar", "example.com", "with query");
37 testURLHostname("http://example.com/#top", "example.com", "with hash"); 37 testURLHostname("http://example.com/#top", "example.com", "with hash");
38 testURLHostname("http://example.com:8080/", "example.com", "with port"); 38 testURLHostname("http://example.com:8080/", "example.com", "with port");
39 testURLHostname("http://user:password@example.com/", "example.com", "with au th credentials"); 39 testURLHostname("http://user:password@example.com/", "example.com",
40 testURLHostname("http://xn--f-1gaa.com/", "f\u00f6\u00f6.com", "with punycod e"); 40 "with auth credentials");
41 testURLHostname("http://xn--f-1gaa.com/", "f\u00f6\u00f6.com",
42 "with punycode");
41 testURLHostname("about:blank", "", "about:blank"); 43 testURLHostname("about:blank", "", "about:blank");
42 testURLHostname("data:text/plain,foo", "", "data: URL"); 44 testURLHostname("data:text/plain,foo", "", "data: URL");
43 testURLHostname("ftp://example.com/", "example.com", "ftp: URL"); 45 testURLHostname("ftp://example.com/", "example.com", "ftp: URL");
44 testURLHostname("http://1.2.3.4:8000/", "1.2.3.4", "IPv4 address"); 46 testURLHostname("http://1.2.3.4:8000/", "1.2.3.4", "IPv4 address");
45 testURLHostname("http://[2001:db8:85a3::8a2e:370:7334]/", "[2001:db8:85a3::8 a2e:370:7334]", "IPv6 address"); 47 testURLHostname("http://[2001:db8:85a3::8a2e:370:7334]/",
48 "[2001:db8:85a3::8a2e:370:7334]", "IPv6 address");
46 }); 49 });
47 50
48 test("Extracting hostname from frame", () => 51 test("Extracting hostname from frame", () =>
49 { 52 {
50 function testFrameHostname(hierarchy, expectedHostname, message) 53 function testFrameHostname(hierarchy, expectedHostname, message)
51 { 54 {
52 let frame = null; 55 let frame = null;
53 56
54 for (let url of hierarchy) 57 for (let url of hierarchy)
55 frame = {parent: frame, url: new URL(url)}; 58 frame = {parent: frame, url: new URL(url)};
56 59
57 equal(extractHostFromFrame(frame), expectedHostname, message); 60 equal(extractHostFromFrame(frame), expectedHostname, message);
58 } 61 }
59 62
60 testFrameHostname(["http://example.com/"], "example.com", "single frame"); 63 testFrameHostname(["http://example.com/"], "example.com", "single frame");
61 testFrameHostname(["http://example.com/", "http://example.org/"], "example.o rg", "with parent frame"); 64 testFrameHostname(["http://example.com/", "http://example.org/"],
62 testFrameHostname(["http://example.com/", "data:text/plain,foo"], "example.c om", "data: URL, hostname in parent"); 65 "example.org", "with parent frame");
63 testFrameHostname(["http://example.com/", "about:blank", "about:blank"], "ex ample.com", "about:blank, hostname in ancestor"); 66 testFrameHostname(["http://example.com/", "data:text/plain,foo"],
64 testFrameHostname(["about:blank", "about:blank"], "", "about:blank, no hostn ame"); 67 "example.com", "data: URL, hostname in parent");
65 testFrameHostname(["http://xn--f-1gaa.com/"], "f\u00f6\u00f6.com", "with pun ycode"); 68 testFrameHostname(["http://example.com/", "about:blank", "about:blank"],
69 "example.com", "about:blank, hostname in ancestor");
70 testFrameHostname(["about:blank", "about:blank"], "",
71 "about:blank, no hostname");
72 testFrameHostname(["http://xn--f-1gaa.com/"], "f\u00f6\u00f6.com",
73 "with punycode");
66 }); 74 });
67 75
68 test("Stringifying URLs", () => 76 test("Stringifying URLs", () =>
69 { 77 {
70 function testNormalizedURL(url, expectedURL, message) 78 function testNormalizedURL(url, expectedURL, message)
71 { 79 {
72 equal(stringifyURL(new URL(url)), expectedURL, message); 80 equal(stringifyURL(new URL(url)), expectedURL, message);
73 } 81 }
74 82
75 function testPreservedURL(url, message) 83 function testPreservedURL(url, message)
76 { 84 {
77 testNormalizedURL(url, url, message); 85 testNormalizedURL(url, url, message);
78 } 86 }
79 87
80 testPreservedURL("http://example.com/foo", "includes path"); 88 testPreservedURL("http://example.com/foo", "includes path");
81 testPreservedURL("http://example.com/?foo=bar", "includes query"); 89 testPreservedURL("http://example.com/?foo=bar", "includes query");
82 testPreservedURL("http://example.com:8080/", "includes port"); 90 testPreservedURL("http://example.com:8080/", "includes port");
83 testPreservedURL("http://example.com/?", "with empty query string"); 91 testPreservedURL("http://example.com/?", "with empty query string");
84 testNormalizedURL("http://example.com/#top","http://example.com/", "stripped hash"); 92 testNormalizedURL("http://example.com/#top", "http://example.com/",
85 testNormalizedURL("http://example.com/#top?", "http://example.com/", "stripp ed hash with trailing question mark"); 93 "stripped hash");
86 testNormalizedURL("http://xn--f-1gaa.com/","http://f\u00f6\u00f6.com/", "dec oded punycode"); 94 testNormalizedURL("http://example.com/#top?", "http://example.com/",
95 "stripped hash with trailing question mark");
96 testNormalizedURL("http://xn--f-1gaa.com/", "http://f\u00f6\u00f6.com/",
97 "decoded punycode");
87 testPreservedURL("about:blank", "about:blank"); 98 testPreservedURL("about:blank", "about:blank");
88 testPreservedURL("data:text/plain,foo", "data: URL"); 99 testPreservedURL("data:text/plain,foo", "data: URL");
89 }); 100 });
90 101
91 test("Third-party checks", () => 102 test("Third-party checks", () =>
92 { 103 {
93 function hostnameToURL(hostname) 104 function hostnameToURL(hostname)
94 { 105 {
95 return new URL("http://" + hostname); 106 return new URL("http://" + hostname);
96 } 107 }
97 108
98 function testThirdParty(requestHost, documentHost, expected, message) 109 function testThirdParty(requestHost, documentHost, expected, message)
99 { 110 {
100 equal( 111 equal(
101 isThirdParty( 112 isThirdParty(
102 hostnameToURL(requestHost), 113 hostnameToURL(requestHost),
103 114
104 // Chrome's URL object normalizes IP addresses. So some test 115 // Chrome's URL object normalizes IP addresses. So some test
105 // will fail if we don't normalize the document host as well. 116 // will fail if we don't normalize the document host as well.
106 getDecodedHostname(hostnameToURL(documentHost)) 117 getDecodedHostname(hostnameToURL(documentHost))
107 ), 118 ),
108 expected, 119 expected,
109 message 120 message
110 ); 121 );
111 } 122 }
112 123
113 testThirdParty("foo", "foo", false, "same domain isn't third-party"); 124 testThirdParty("foo", "foo", false, "same domain isn't third-party");
114 testThirdParty("foo", "bar", true, "different domain is third-party"); 125 testThirdParty("foo", "bar", true, "different domain is third-party");
115 testThirdParty("foo.com", "foo.com", false, "same domain with TLD (.com) isn 't third-party"); 126 testThirdParty("foo.com", "foo.com", false,
116 testThirdParty("foo.com", "bar.com", true, "same TLD (.com) but different do main is third-party"); 127 "same domain with TLD (.com) isn't third-party");
117 testThirdParty("foo.com", "www.foo.com", false, "same domain but differend s ubdomain isn't third-party"); 128 testThirdParty("foo.com", "bar.com", true,
118 testThirdParty("foo.example.com", "bar.example.com", false, "same basedomain (example.com) isn't third-party"); 129 "same TLD (.com) but different domain is third-party");
119 testThirdParty("foo.uk", "bar.uk", true, "same TLD (.uk) but different domai n is third-party"); 130 testThirdParty("foo.com", "www.foo.com", false,
120 testThirdParty("foo.co.uk", "bar.co.uk", true, "same TLD (.co.uk) but differ ent domain is third-party"); 131 "same domain but differend subdomain isn't third-party");
121 testThirdParty("foo.example.co.uk", "bar.example.co.uk", false, "same basedo main (example.co.uk) isn't third-party"); 132 testThirdParty("foo.example.com", "bar.example.com", false,
122 testThirdParty("1.2.3.4", "1.2.3.4", false, "same IPv4 address isn't third-p arty"); 133 "same basedomain (example.com) isn't third-party");
123 testThirdParty("1.1.1.1", "2.1.1.1", true, "different IPv4 address is third- party"); 134 testThirdParty("foo.uk", "bar.uk", true,
124 testThirdParty("0x01ff0101", "0x01ff0101", false, "same IPv4 hexadecimal add ress isn't third-party"); 135 "same TLD (.uk) but different domain is third-party");
125 testThirdParty("0x01ff0101", "0x01ff0102", true, "different IPv4 hexadecimal address is third-party"); 136 testThirdParty("foo.co.uk", "bar.co.uk", true,
126 testThirdParty("1.0xff.3.4", "1.0xff.3.4", false, "same IPv4 address with he xadecimal octet isn't third-party"); 137 "same TLD (.co.uk) but different domain is third-party");
127 testThirdParty("1.0xff.1.1", "2.0xff.1.1", true, "different IPv4 address wit h hexadecimal octet is third-party"); 138 testThirdParty("foo.example.co.uk", "bar.example.co.uk", false,
128 testThirdParty("0xff.example.com", "example.com", false, "domain starts like a hexadecimal IPv4 address but isn't one"); 139 "same basedomain (example.co.uk) isn't third-party");
129 testThirdParty("[2001:db8:85a3::8a2e:370:7334]", "[2001:db8:85a3::8a2e:370:7 334]", false, "same IPv6 address isn't third-party"); 140 testThirdParty("1.2.3.4", "1.2.3.4", false,
130 testThirdParty("[2001:db8:85a3::8a2e:370:7334]", "[5001:db8:85a3::8a2e:370:7 334]", true, "different IPv6 address is third-party"); 141 "same IPv4 address isn't third-party");
131 testThirdParty("[::ffff:192.0.2.128]", "[::ffff:192.0.2.128]", false, "same IPv4-mapped IPv6 address isn't third-party"); 142 testThirdParty("1.1.1.1", "2.1.1.1", true,
132 testThirdParty("[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true, "differ ent IPv4-mapped IPv6 address is third-party"); 143 "different IPv4 address is third-party");
133 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false, "same IDN isn't third-party"); 144 testThirdParty("0x01ff0101", "0x01ff0101", false,
134 testThirdParty("example.com..", "example.com....", false, "traling dots are ignored"); 145 "same IPv4 hexadecimal address isn't third-party");
146 testThirdParty("0x01ff0101", "0x01ff0102", true,
147 "different IPv4 hexadecimal address is third-party");
148 testThirdParty(
149 "1.0xff.3.4", "1.0xff.3.4", false,
150 "same IPv4 address with hexadecimal octet isn't third-party"
151 );
152 testThirdParty(
153 "1.0xff.1.1", "2.0xff.1.1", true,
154 "different IPv4 address with hexadecimal octet is third-party"
155 );
156 testThirdParty(
157 "0xff.example.com", "example.com", false,
158 "domain starts like a hexadecimal IPv4 address but isn't one"
159 );
160 testThirdParty(
161 "[2001:db8:85a3::8a2e:370:7334]", "[2001:db8:85a3::8a2e:370:7334]", false,
162 "same IPv6 address isn't third-party"
163 );
164 testThirdParty(
165 "[2001:db8:85a3::8a2e:370:7334]", "[5001:db8:85a3::8a2e:370:7334]", true,
166 "different IPv6 address is third-party"
167 );
168 testThirdParty(
169 "[::ffff:192.0.2.128]", "[::ffff:192.0.2.128]", false,
170 "same IPv4-mapped IPv6 address isn't third-party"
171 );
172 testThirdParty(
173 "[::ffff:192.0.2.128]", "[::ffff:192.1.2.128]", true,
174 "different IPv4-mapped IPv6 address is third-party"
175 );
176 testThirdParty("xn--f-1gaa.com", "f\u00f6\u00f6.com", false,
177 "same IDN isn't third-party");
178 testThirdParty("example.com..", "example.com....", false,
179 "traling dots are ignored");
135 }); 180 });
136 } 181 }
OLDNEW
« options.js ('K') | « qunit/tests/prefs.js ('k') | qunit/tests/versionComparator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld