summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/test/xpcshell
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /toolkit/components/antitracking/test/xpcshell
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/antitracking/test/xpcshell')
-rw-r--r--toolkit/components/antitracking/test/xpcshell/test_validate_strip_on_share_list.js141
1 files changed, 83 insertions, 58 deletions
diff --git a/toolkit/components/antitracking/test/xpcshell/test_validate_strip_on_share_list.js b/toolkit/components/antitracking/test/xpcshell/test_validate_strip_on_share_list.js
index 48a0bd4682..f8be5fccad 100644
--- a/toolkit/components/antitracking/test/xpcshell/test_validate_strip_on_share_list.js
+++ b/toolkit/components/antitracking/test/xpcshell/test_validate_strip_on_share_list.js
@@ -7,67 +7,19 @@ const { JsonSchema } = ChromeUtils.importESModule(
"resource://gre/modules/JsonSchema.sys.mjs"
);
-let stripOnShareList;
+let stripOnShareMergedList, stripOnShareLGPLParams, stripOnShareList;
-// Fetching strip on share list
-add_setup(async function () {
- /* globals fetch */
- let response = await fetch(
- "chrome://global/content/antitracking/StripOnShare.json"
- );
+async function fetchAndParseList(fileName) {
+ let response = await fetch("chrome://global/content/" + fileName);
if (!response.ok) {
throw new Error(
"Error fetching strip-on-share strip list" + response.status
);
}
- stripOnShareList = await response.json();
-});
-
-// Check if the Strip on Share list contains any duplicate params
-add_task(async function test_check_duplicates() {
- let stripOnShareParams = stripOnShareList;
-
- const allQueryParams = [];
-
- for (const domain in stripOnShareParams) {
- for (let param in stripOnShareParams[domain].queryParams) {
- allQueryParams.push(stripOnShareParams[domain].queryParams[param]);
- }
- }
-
- let setOfParams = new Set(allQueryParams);
-
- if (setOfParams.size != allQueryParams.length) {
- let setToCheckDupes = new Set();
- let dupeList = new Set();
- for (const domain in stripOnShareParams) {
- for (let param in stripOnShareParams[domain].queryParams) {
- let tempParam = stripOnShareParams[domain].queryParams[param];
-
- if (setToCheckDupes.has(tempParam)) {
- dupeList.add(tempParam);
- } else {
- setToCheckDupes.add(tempParam);
- }
- }
- }
-
- Assert.equal(
- setOfParams.size,
- allQueryParams.length,
- "There are duplicates rules. The duplicate rules are " + [...dupeList]
- );
- }
+ return await response.json();
+}
- Assert.equal(
- setOfParams.size,
- allQueryParams.length,
- "There are no duplicates rules."
- );
-});
-
-// Validate the format of Strip on Share list with Schema
-add_task(async function test_check_schema() {
+async function validateSchema(paramList, nameOfList) {
let schema = {
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
@@ -88,13 +40,86 @@ add_task(async function test_check_schema() {
required: ["global"],
};
- let stripOnShareParams = stripOnShareList;
let validator = new JsonSchema.Validator(schema);
- let { valid, errors } = validator.validate(stripOnShareParams);
+ let { valid, errors } = validator.validate(paramList);
if (!valid) {
- info("validation errors: " + JSON.stringify(errors, null, 2));
+ info(
+ nameOfList +
+ " JSON contains these validation errors: " +
+ JSON.stringify(errors, null, 2)
+ );
+ }
+
+ Assert.ok(valid, nameOfList + " JSON is valid");
+}
+
+// Fetching strip on share list
+add_setup(async function () {
+ /* globals fetch */
+
+ [stripOnShareList, stripOnShareLGPLParams] = await Promise.all([
+ fetchAndParseList("antitracking/StripOnShare.json"),
+ fetchAndParseList("antitracking/StripOnShareLGPL.json"),
+ ]);
+
+ stripOnShareMergedList = stripOnShareList;
+
+ // Combines the mozilla licensed strip on share param
+ // list and the LGPL licensed strip on share param list
+ for (const key in stripOnShareLGPLParams) {
+ if (Object.hasOwn(stripOnShareMergedList, key)) {
+ stripOnShareMergedList[key].queryParams.push(
+ ...stripOnShareLGPLParams[key].queryParams
+ );
+ } else {
+ stripOnShareMergedList[key] = stripOnShareLGPLParams[key];
+ }
+ }
+});
+
+// Check if the Strip on Share list contains any duplicate params
+add_task(async function test_check_duplicates() {
+ for (const domain in stripOnShareMergedList) {
+ // Creates a set of query parameters for a given domain to check
+ // for duplicates
+ let setOfParams = new Set(stripOnShareMergedList[domain].queryParams);
+
+ // If there are duplicates which is known because the sizes of the set
+ // and array don't match, then we check which parameters are duplciates
+ if (setOfParams.size != stripOnShareMergedList[domain].queryParams.length) {
+ let setToCheckDupes = new Set();
+ let dupeList = new Set();
+ for (let param in stripOnShareMergedList[domain].queryParams) {
+ let tempParam = stripOnShareMergedList[domain].queryParams[param];
+
+ if (setToCheckDupes.has(tempParam)) {
+ dupeList.add(tempParam);
+ } else {
+ setToCheckDupes.add(tempParam);
+ }
+ }
+
+ Assert.equal(
+ setOfParams.size,
+ stripOnShareMergedList[domain].queryParams.length,
+ "There are duplicates rules in " +
+ domain +
+ ". The duplicate rules are " +
+ [...dupeList]
+ );
+ }
+
+ Assert.equal(
+ setOfParams.size,
+ stripOnShareMergedList[domain].queryParams.length,
+ "There are no duplicates rules."
+ );
}
+});
- Assert.ok(valid, "Strip on share JSON is valid");
+// Validate the format of Strip on Share list with Schema
+add_task(async function test_check_schema() {
+ validateSchema(stripOnShareLGPLParams, "Strip On Share LGPL");
+ validateSchema(stripOnShareList, "Strip On Share");
});