From da4c7e7ed675c3bf405668739c3012d140856109 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:42 +0200 Subject: Adding upstream version 126.0. Signed-off-by: Daniel Baumann --- .../antitracking/test/browser/browser.toml | 12 +- .../test/browser/browser_doublyNestedTracker.js | 2 +- .../test/browser/browser_partitionedABA.js | 86 +++++++++++++ .../test/browser/browser_staticPartition_cache.js | 4 +- .../test/browser/browser_staticPartition_saveAs.js | 4 +- ...torageAccessThirdPartyChecks_alwaysPartition.js | 1 + .../test/browser/file_saveAsPageInfo.html | 2 +- .../antitracking/test/browser/file_video.ogv | Bin 16049 -> 0 bytes .../antitracking/test/browser/file_video.webm | Bin 0 -> 17931 bytes .../test/gtest/TestStoragePrincipalHelper.cpp | 2 +- .../xpcshell/test_validate_strip_on_share_list.js | 141 ++++++++++++--------- 11 files changed, 186 insertions(+), 68 deletions(-) create mode 100644 toolkit/components/antitracking/test/browser/browser_partitionedABA.js delete mode 100644 toolkit/components/antitracking/test/browser/file_video.ogv create mode 100644 toolkit/components/antitracking/test/browser/file_video.webm (limited to 'toolkit/components/antitracking/test') diff --git a/toolkit/components/antitracking/test/browser/browser.toml b/toolkit/components/antitracking/test/browser/browser.toml index 9d0874ed3a..edb429b49e 100644 --- a/toolkit/components/antitracking/test/browser/browser.toml +++ b/toolkit/components/antitracking/test/browser/browser.toml @@ -1,5 +1,9 @@ [DEFAULT] -skip-if = ["os == 'linux' && (asan || tsan)"] # bug 1662229 - task exception +skip-if = [ + "os == 'linux' && os_version == '18.04' && asan", # bug 1662229 - task exception + "os == 'linux' && os_version == '18.04' && tsan", # bug 1662229 - task exception + "debug", # bug 1884982 - takes 20+ minutes to run on debug +] prefs = [ "dom.storage_access.prompt.testing=true", # Disable the Storage Access API prompts for all of the tests in this directory "dom.storage_access.prompt.testing.allow=true", @@ -108,6 +112,8 @@ skip-if = ["os == 'mac' && !debug"] # Bug 1503778, 1577362 ["browser_onModifyRequestNotificationForTrackingResources.js"] +["browser_partitionedABA.js"] + ["browser_partitionedClearSiteDataHeader.js"] support-files = ["clearSiteData.sjs"] @@ -194,7 +200,7 @@ support-files = [ "!/browser/components/originattributes/test/browser/file_thirdPartyChild.request.html", "!/browser/components/originattributes/test/browser/file_thirdPartyChild.script.js", "!/browser/components/originattributes/test/browser/file_thirdPartyChild.sharedworker.js", - "!/browser/components/originattributes/test/browser/file_thirdPartyChild.video.ogv", + "!/browser/components/originattributes/test/browser/file_thirdPartyChild.video.webm", "!/browser/components/originattributes/test/browser/file_thirdPartyChild.worker.fetch.html", "!/browser/components/originattributes/test/browser/file_thirdPartyChild.worker.js", "!/browser/components/originattributes/test/browser/file_thirdPartyChild.worker.request.html", @@ -210,7 +216,7 @@ support-files = [ "file_saveAsImage.sjs", "file_saveAsVideo.sjs", "file_saveAsPageInfo.html", - "file_video.ogv", + "file_video.webm", ] ["browser_staticPartition_tls_session.js"] diff --git a/toolkit/components/antitracking/test/browser/browser_doublyNestedTracker.js b/toolkit/components/antitracking/test/browser/browser_doublyNestedTracker.js index 4f38b29a7d..c3b6342ce1 100644 --- a/toolkit/components/antitracking/test/browser/browser_doublyNestedTracker.js +++ b/toolkit/components/antitracking/test/browser/browser_doublyNestedTracker.js @@ -36,7 +36,7 @@ add_task(async function () { async function runChecks() { is(document.cookie, "", "No cookies for me"); document.cookie = "name=value"; - is(document.cookie, "name=value", "I have the cookies!"); + is(document.cookie, "", "I don't have the cookies!"); } await new Promise(resolve => { diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedABA.js b/toolkit/components/antitracking/test/browser/browser_partitionedABA.js new file mode 100644 index 0000000000..b6acc82d48 --- /dev/null +++ b/toolkit/components/antitracking/test/browser/browser_partitionedABA.js @@ -0,0 +1,86 @@ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * A test to verify that ABA iframes partition at least localStorage and document.cookie + */ + +"use strict"; + +add_setup(async function () { + await setCookieBehaviorPref( + BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN, + false + ); +}); + +add_task(async function runTest() { + info("Creating the tab"); + let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE); + gBrowser.selectedTab = tab; + + let browser = tab.linkedBrowser; + await BrowserTestUtils.browserLoaded(browser); + + info("Creating the third-party iframe"); + let ifrBC = await SpecialPowers.spawn( + browser, + [TEST_TOP_PAGE_7], + async page => { + let ifr = content.document.createElement("iframe"); + + let loading = ContentTaskUtils.waitForEvent(ifr, "load"); + content.document.body.appendChild(ifr); + ifr.src = page; + await loading; + + return ifr.browsingContext; + } + ); + + info("Creating the ABA iframe"); + let ifrABABC = await SpecialPowers.spawn( + ifrBC, + [TEST_TOP_PAGE], + async page => { + let ifr = content.document.createElement("iframe"); + + let loading = ContentTaskUtils.waitForEvent(ifr, "load"); + content.document.body.appendChild(ifr); + ifr.src = page; + await loading; + + return ifr.browsingContext; + } + ); + + info("Write cookie to the ABA third-party iframe"); + await SpecialPowers.spawn(ifrABABC, [], async _ => { + content.document.cookie = "foo; SameSite=None; Secure; Partitioned"; + }); + + let cookie = await SpecialPowers.spawn(browser, [], async () => { + return content.document.cookie; + }); + is(cookie, "", "Cookie is not in the top level"); + + info("Write localstorage to the ABA third-party iframe"); + await SpecialPowers.spawn(ifrABABC, [], async _ => { + content.localStorage.setItem("foo", "bar"); + }); + + let storage = await SpecialPowers.spawn(browser, [], async () => { + return content.localStorage.getItem("foo"); + }); + is(storage, null, "LocalStorage update is not in the top level"); + + info("Clean up"); + BrowserTestUtils.removeTab(tab); + await new Promise(resolve => { + Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () => + resolve() + ); + }); +}); diff --git a/toolkit/components/antitracking/test/browser/browser_staticPartition_cache.js b/toolkit/components/antitracking/test/browser/browser_staticPartition_cache.js index 9afe3180fb..9383e5a6f9 100644 --- a/toolkit/components/antitracking/test/browser/browser_staticPartition_cache.js +++ b/toolkit/components/antitracking/test/browser/browser_staticPartition_cache.js @@ -105,7 +105,7 @@ add_task(async function () { // The CSS cache needs to be cleared in-process. content.windowUtils.clearSharedStyleSheetCache(); - let videoURL = arg.urlPrefix + "file_thirdPartyChild.video.ogv"; + let videoURL = arg.urlPrefix + "file_thirdPartyChild.video.webm"; let audioURL = arg.urlPrefix + "file_thirdPartyChild.audio.ogg"; let URLSuffix = "?r=" + arg.randomSuffix; @@ -176,7 +176,7 @@ add_task(async function () { "xhr.html", "worker.xhr.html", "audio.ogg", - "video.ogv", + "video.webm", "fetch.html", "worker.fetch.html", "request.html", diff --git a/toolkit/components/antitracking/test/browser/browser_staticPartition_saveAs.js b/toolkit/components/antitracking/test/browser/browser_staticPartition_saveAs.js index b9984829eb..9da751cadb 100644 --- a/toolkit/components/antitracking/test/browser/browser_staticPartition_saveAs.js +++ b/toolkit/components/antitracking/test/browser/browser_staticPartition_saveAs.js @@ -401,7 +401,7 @@ add_task(async function testPageInfoMediaSaveAs() { ); info("Open the media panel of the pageinfo."); - let pageInfo = BrowserPageInfo( + let pageInfo = BrowserCommands.pageInfo( gBrowser.selectedBrowser.currentURI.spec, "mediaTab" ); @@ -478,7 +478,7 @@ add_task(async function testPageInfoMediaMultipleSelectedSaveAs() { ); info("Open the media panel of the pageinfo."); - let pageInfo = BrowserPageInfo( + let pageInfo = BrowserCommands.pageInfo( gBrowser.selectedBrowser.currentURI.spec, "mediaTab" ); diff --git a/toolkit/components/antitracking/test/browser/browser_storageAccessThirdPartyChecks_alwaysPartition.js b/toolkit/components/antitracking/test/browser/browser_storageAccessThirdPartyChecks_alwaysPartition.js index f31c7893d0..8ea97dac68 100644 --- a/toolkit/components/antitracking/test/browser/browser_storageAccessThirdPartyChecks_alwaysPartition.js +++ b/toolkit/components/antitracking/test/browser/browser_storageAccessThirdPartyChecks_alwaysPartition.js @@ -53,6 +53,7 @@ AntiTracking._createTask({ "https://tracking.example.org", "https://tracking.example.org", "https://tracking.example.org", + "https://another-tracking.example.net", "https://itisatracker.org", ], }); diff --git a/toolkit/components/antitracking/test/browser/file_saveAsPageInfo.html b/toolkit/components/antitracking/test/browser/file_saveAsPageInfo.html index aa3de2a555..c8c409d130 100644 --- a/toolkit/components/antitracking/test/browser/file_saveAsPageInfo.html +++ b/toolkit/components/antitracking/test/browser/file_saveAsPageInfo.html @@ -1,6 +1,6 @@ - + diff --git a/toolkit/components/antitracking/test/browser/file_video.ogv b/toolkit/components/antitracking/test/browser/file_video.ogv deleted file mode 100644 index 68dee3cf2b..0000000000 Binary files a/toolkit/components/antitracking/test/browser/file_video.ogv and /dev/null differ diff --git a/toolkit/components/antitracking/test/browser/file_video.webm b/toolkit/components/antitracking/test/browser/file_video.webm new file mode 100644 index 0000000000..2cee5a9e51 Binary files /dev/null and b/toolkit/components/antitracking/test/browser/file_video.webm differ diff --git a/toolkit/components/antitracking/test/gtest/TestStoragePrincipalHelper.cpp b/toolkit/components/antitracking/test/gtest/TestStoragePrincipalHelper.cpp index 44959e4dc8..666757c382 100644 --- a/toolkit/components/antitracking/test/gtest/TestStoragePrincipalHelper.cpp +++ b/toolkit/components/antitracking/test/gtest/TestStoragePrincipalHelper.cpp @@ -45,7 +45,7 @@ nsresult CreateMockChannel(nsIPrincipal* aPrincipal, bool isThirdParty, NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr mockLoadInfo = mockChannel->LoadInfo(); - rv = mockLoadInfo->SetIsThirdPartyContextToTopWindow(isThirdParty); + rv = mockLoadInfo->SetIsInThirdPartyContext(isThirdParty); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr cjs; 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"); }); -- cgit v1.2.3