forked from FULU-Foundation/CRW-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsiteScope.test.ts
More file actions
74 lines (67 loc) · 1.98 KB
/
Copy pathsiteScope.test.ts
File metadata and controls
74 lines (67 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import assert from "node:assert/strict";
import test from "node:test";
import {
canonicalizeSiteScopeList,
getSiteScopeHostname,
hostnameMatchesSiteScope,
isHostnameInSiteScopeList,
normalizeSiteScopeList,
removeMatchingSiteScopes,
} from "../src/shared/siteScope.ts";
test("getSiteScopeHostname collapses subdomains to the registrable domain", () => {
assert.equal(getSiteScopeHostname("support.google.com"), "google.com");
assert.equal(getSiteScopeHostname("www.bbc.co.uk"), "bbc.co.uk");
assert.equal(getSiteScopeHostname("localhost"), "localhost");
});
test("hostnameMatchesSiteScope includes subdomains but not sibling lookalikes", () => {
assert.equal(hostnameMatchesSiteScope("example.com", "example.com"), true);
assert.equal(
hostnameMatchesSiteScope("support.example.com", "example.com"),
true,
);
assert.equal(
hostnameMatchesSiteScope("badexample.com", "example.com"),
false,
);
});
test("isHostnameInSiteScopeList recognizes matching parent domains", () => {
assert.equal(
isHostnameInSiteScopeList("shop.example.com", ["example.com"]),
true,
);
assert.equal(
isHostnameInSiteScopeList("shop.example.com", ["example.org"]),
false,
);
});
test("normalizeSiteScopeList strips www, blanks, and duplicates", () => {
assert.deepEqual(
normalizeSiteScopeList([
"www.example.com",
"example.com",
"",
" Example.com ",
]),
["example.com"],
);
});
test("canonicalizeSiteScopeList upgrades hostnames to site scopes", () => {
assert.deepEqual(
canonicalizeSiteScopeList([
"support.example.com",
"www.example.com",
"news.bbc.co.uk",
"localhost",
]),
["example.com", "bbc.co.uk", "localhost"],
);
});
test("removeMatchingSiteScopes removes the stored scope that suppresses the current host", () => {
assert.deepEqual(
removeMatchingSiteScopes(
["example.com", "support.example.com", "example.org"],
"shop.example.com",
),
["example.org"],
);
});