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

Unified Diff: test/domain.js

Issue 30002580: Noissue - Abstract hostname normalization (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created Feb. 8, 2019, 7:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/matcher.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
« no previous file with comments | « lib/matcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld