1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
5 * Tests origin attributes partitionKey pattern matching.
10 function testMatch(oa, pattern, shouldMatch = true) {
11 let msg = `Origin attributes should ${
12 shouldMatch ? "match" : "not match"
14 msg += ` oa: ${JSON.stringify(oa)} - pattern: ${JSON.stringify(pattern)}`;
16 ChromeUtils.originAttributesMatchPattern(oa, pattern),
22 function getPartitionKey(scheme, baseDomain, port) {
23 if (!scheme || !baseDomain) {
26 return `(${scheme},${baseDomain}${port ? `,${port}` : ``})`;
29 function getOAWithPartitionKey(scheme, baseDomain, port, oa = {}) {
30 oa.partitionKey = getPartitionKey(scheme, baseDomain, port);
35 * Tests that an OriginAttributesPattern which is empty or only has an empty
36 * partitionKeyPattern matches any partitionKey.
38 add_task(async function test_empty_pattern_matches_any() {
40 getOAWithPartitionKey("https", "example.com"),
41 getOAWithPartitionKey("http", "example.net", 8080),
42 getOAWithPartitionKey(),
45 for (let oa of list) {
47 testMatch(oa, { partitionKeyPattern: {} });
52 * Tests that if a partitionKeyPattern is passed, but the partitionKey is
53 * invalid, the pattern match will always fail.
55 add_task(async function test_invalid_pk() {
62 "(http,example.com,invalid)",
63 "(http,example.com,8000,1000)",
64 ].map(partitionKey => ({ partitionKey }));
66 for (let oa of list) {
68 testMatch(oa, { partitionKeyPattern: {} });
71 { partitionKeyPattern: { baseDomain: "example.com" } },
74 testMatch(oa, { partitionKeyPattern: { scheme: "https" } }, false);
79 * Tests that if a pattern sets "partitionKey" it takes precedence over "partitionKeyPattern".
81 add_task(async function test_string_overwrites_pattern() {
82 let oa = getOAWithPartitionKey("https", "example.com", 8080, {
86 testMatch(oa, { partitionKey: oa.partitionKey });
88 partitionKey: oa.partitionKey,
89 partitionKeyPattern: { baseDomain: "example.com" },
92 partitionKey: oa.partitionKey,
93 partitionKeyPattern: { baseDomain: "example.net" },
98 partitionKey: getPartitionKey("https", "example.net"),
99 partitionKeyPattern: { scheme: "https", baseDomain: "example.com" },
106 * Tests that we can match parts of a partitionKey by setting
107 * partitionKeyPattern.
109 add_task(async function test_pattern() {
110 let a = getOAWithPartitionKey("https", "example.com", 8080, {
113 let b = getOAWithPartitionKey("https", "example.com", undefined, {
114 privateBrowsingId: 1,
117 for (let oa of [a, b]) {
119 testMatch(oa, { partitionKeyPattern: { scheme: "https" } });
121 partitionKeyPattern: { scheme: "https", baseDomain: "example.com" },
126 partitionKeyPattern: {
128 baseDomain: "example.com",
135 partitionKeyPattern: { baseDomain: "example.com" },
140 partitionKeyPattern: { port: 8080 },
146 testMatch(oa, { partitionKeyPattern: { scheme: "http" } }, false);
149 { partitionKeyPattern: { baseDomain: "example.net" } },
152 testMatch(oa, { partitionKeyPattern: { port: 8443 } }, false);
155 { partitionKeyPattern: { scheme: "https", baseDomain: "example.net" } },