| Index: test/domain.js |
| =================================================================== |
| --- a/test/domain.js |
| +++ b/test/domain.js |
| @@ -18,28 +18,30 @@ |
| "use strict"; |
| // Only starting NodeJS 10 that URL is in the global space. |
| const {URL} = require("url"); |
| const {createSandbox} = require("./_common"); |
| const publicSuffixes = require("../data/publicSuffixList.json"); |
| +let normalizeHostname = null; |
| let isThirdParty = null; |
| let getDomain = null; |
| exports.setUp = function(callback) |
| { |
| let sandboxedRequire = createSandbox({ |
| extraExports: { |
| domain: ["getDomain"] |
| } |
| }); |
| ( |
| - {isThirdParty, getDomain} = sandboxedRequire("../lib/domain") |
| + {normalizeHostname, isThirdParty, |
| + getDomain} = sandboxedRequire("../lib/domain") |
| ); |
| callback(); |
| }; |
| function hostnameToURL(hostname) |
| { |
| return new URL("http://" + hostname); |
| @@ -56,16 +58,40 @@ |
| // will fail if we don't normalize the document host as well. |
| hostnameToURL(documentHostname).hostname |
| ), |
| expected, |
| message |
| ); |
| } |
| +exports.testNormalizeHostname = function(test) |
| +{ |
| + test.equal(normalizeHostname("example.com"), "example.com"); |
| + test.equal(normalizeHostname("example.com."), "example.com"); |
| + test.equal(normalizeHostname("example.com.."), "example.com"); |
| + test.equal(normalizeHostname("example.com..."), "example.com"); |
| + |
| + test.equal(normalizeHostname("Example.com"), "example.com"); |
| + test.equal(normalizeHostname("ExaMple.Com"), "example.com"); |
| + test.equal(normalizeHostname("ExaMple.Com.."), "example.com"); |
| + |
| + test.equal(normalizeHostname("192.168.1.1"), "192.168.1.1"); |
| + test.equal(normalizeHostname("192.168.1.1."), "192.168.1.1"); |
| + |
| + test.equal(normalizeHostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), |
| + "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); |
| + test.equal(normalizeHostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334."), |
| + "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); |
| + test.equal(normalizeHostname("2001:0DB8:85A3:0000:0000:8A2E:0370:7334"), |
| + "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); |
| + |
| + test.done(); |
| +}; |
| + |
| exports.testIsThirdParty = function(test) |
| { |
| testThirdParty(test, "foo", "foo", false, "same domain isn't third-party"); |
| testThirdParty(test, "foo", "bar", true, "different domain is third-party"); |
| testThirdParty(test, "foo.com", "foo.com", false, |
| "same domain with TLD (.com) isn't third-party"); |
| testThirdParty(test, "foo.com", "bar.com", true, |
| "same TLD (.com) but different domain is third-party"); |