Skip to content

Commit

Permalink
Bug 1840902 - Adjusted browser chrome tests under the Anti-tracking t…
Browse files Browse the repository at this point in the history
…est suite to support only secure context storage access. r=bvandersloot

Depends on D182366

Differential Revision: https://phabricator.services.mozilla.com/D184979
  • Loading branch information
HarshitSohaney committed Aug 15, 2023
1 parent 5bc8930 commit 8349767
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 45 deletions.
2 changes: 1 addition & 1 deletion browser/base/content/test/protectionsUI/trackingAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ onmessage = event => {
case "image":
createImage(
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://trackertest.org/browser/browser/base/content/test/protectionsUI/cookieServer.sjs?type=image-no-cookie"
"https://trackertest.org/browser/browser/base/content/test/protectionsUI/cookieServer.sjs?type=image-no-cookie"
);
break;
case "window-open":
Expand Down
2 changes: 2 additions & 0 deletions toolkit/components/antitracking/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ prefs =
network.cookie.sameSite.laxByDefault=false
# Disable https-first because of explicit http/https testing
dom.security.https_first=false
# Enable constraining storage access api to secure contexts
dom.storage_access.dont_grant_insecure_contexts=true

support-files =
container.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ var testCases = [
"privacy.partition.always_partition_third_party_non_cookie_storage",
false,
],
// Testing Storage Access API grants constrained to secure contexts
["dom.storage_access.dont_grant_insecure_contexts", true],
],
expectedBlockingNotifications: 0,
runInPrivateWindow: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ PartitionedStorageHelper.runTest(

is(locks.length, 2, "We should have granted 2 lock requests at this point");
},
/* cleanupFunction */ undefined,
async _ => {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
resolve()
);
});
},
/* extraPrefs */ undefined,
{ runInSecureContext: true }
);
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ PartitionedStorageHelper.runTest(
);
is(
res.value,
"http://not-tracking.example.com/browser/toolkit/components/antitracking/test/browser/empty.js",
"https://not-tracking.example.com/browser/toolkit/components/antitracking/test/browser/empty.js",
"The first-party service worker received fetch event."
);
res = await sendAndWaitWorkerMessage(
Expand Down Expand Up @@ -463,7 +463,7 @@ PartitionedStorageHelper.runTest(
);
is(
res.value,
"http://not-tracking.example.com/browser/toolkit/components/antitracking/test/browser/empty.js",
"https://not-tracking.example.com/browser/toolkit/components/antitracking/test/browser/empty.js",
"The third-party service worker received fetch event."
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ PartitionedStorageHelper.runTestInNormalAndPrivateMode(
resolve()
);
});
}
},
[],
false
);

PartitionedStorageHelper.runPartitioningTestInNormalAndPrivateMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ add_task(async function test_privilege_api_with_dFPI() {
);
let browser = tab.linkedBrowser;

await insertSubFrame(browser, TEST_4TH_PARTY_PAGE, "test");
await insertSubFrame(browser, TEST_4TH_PARTY_PAGE_HTTPS, "test");

// Verify that the third-party context doesn't have storage access at
// beginning.
Expand All @@ -282,7 +282,7 @@ add_task(async function test_privilege_api_with_dFPI() {
});

let storagePermissionPromise = waitStoragePermission(
"http://not-tracking.example.com"
"https://not-tracking.example.com"
);

// Verify if the prompt has been shown.
Expand All @@ -299,7 +299,7 @@ add_task(async function test_privilege_api_with_dFPI() {

try {
await content.document.requestStorageAccessForOrigin(
"http://not-tracking.example.com/"
"https://not-tracking.example.com/"
);
} catch (e) {
ok(false, "The API shouldn't throw.");
Expand Down Expand Up @@ -328,7 +328,7 @@ add_task(async function test_privilege_api_with_dFPI() {
});

// Insert another third-party content iframe and check if it has storage access.
await insertSubFrame(browser, TEST_4TH_PARTY_PAGE, "test2");
await insertSubFrame(browser, TEST_4TH_PARTY_PAGE_HTTPS, "test2");
await runScriptInSubFrame(browser, "test2", async _ => {
await hasStorageAccessInitially();

Expand All @@ -350,7 +350,7 @@ add_task(async function test_privilege_api_with_dFPI() {
is(document.cookie, "name=value", "Setting cookie to partitioned context.");
});

await clearStoragePermission("http://not-tracking.example.com");
await clearStoragePermission("https://not-tracking.example.com");
Services.cookies.removeAll();
BrowserTestUtils.removeTab(tab);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ Services.scriptloader.loadSubScript(
);

add_task(async function testInsecureContext() {
await SpecialPowers.pushPrefEnv({
set: [["dom.storage_access.dont_grant_insecure_contexts", true]],
});

await setPreferences();

await openPageAndRunCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AntiTracking._createTask({
await callRequestStorageAccess();

const TRACKING_PAGE =
"http://another-tracking.example.net/browser/browser/base/content/test/protectionsUI/trackingPage.html";
"https://another-tracking.example.net/browser/browser/base/content/test/protectionsUI/trackingPage.html";
async function runChecks(name) {
let iframe = document.createElement("iframe");
iframe.src = TRACKING_PAGE;
Expand Down Expand Up @@ -44,11 +44,11 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: [
"http://tracking.example.org",
"http://tracking.example.org",
"http://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
],
});

Expand Down Expand Up @@ -79,10 +79,10 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: [
"http://tracking.example.org",
"http://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
],
});

Expand Down Expand Up @@ -110,10 +110,10 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: [
"http://tracking.example.org",
"http://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
],
});

Expand Down Expand Up @@ -141,10 +141,10 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: [
"http://tracking.example.org",
"http://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AntiTracking._createTask({
await callRequestStorageAccess();

const TRACKING_PAGE =
"http://another-tracking.example.net/browser/browser/base/content/test/protectionsUI/trackingPage.html";
"https://another-tracking.example.net/browser/browser/base/content/test/protectionsUI/trackingPage.html";
async function runChecks(name) {
let iframe = document.createElement("iframe");
iframe.src = TRACKING_PAGE;
Expand Down Expand Up @@ -47,13 +47,13 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: [
"http://tracking.example.org",
"http://tracking.example.org",
"http://tracking.example.org",
"http://tracking.example.org",
"http://trackertest.org",
"https://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
"https://tracking.example.org",
// "http://trackertest.org" does not show an error message since it is an insecure context
],
});

Expand Down Expand Up @@ -84,8 +84,8 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
errorMessageDomains: ["http://tracking.example.org"],
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: ["https://tracking.example.org"],
});

add_task(async _ => {
Expand All @@ -112,8 +112,8 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
errorMessageDomains: ["http://example.net", "http://tracking.example.org"],
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: ["http://example.net", "https://tracking.example.org"],
});

add_task(async _ => {
Expand All @@ -140,8 +140,8 @@ AntiTracking._createTask({
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
thirdPartyPage: TEST_3RD_PARTY_PAGE_HTTP,
errorMessageDomains: ["http://tracking.example.org"],
thirdPartyPage: TEST_3RD_PARTY_PAGE,
errorMessageDomains: ["https://tracking.example.org"],
});

add_task(async _ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ Services.scriptloader.loadSubScript(
);

this.PartitionedStorageHelper = {
runTestInNormalAndPrivateMode(name, callback, cleanupFunction, extraPrefs) {
runTestInNormalAndPrivateMode(
name,
callback,
cleanupFunction,
extraPrefs,
runInSecure = true
) {
// Normal mode
this.runTest(name, callback, cleanupFunction, extraPrefs, {
runInSecureContext: runInSecure,
runInPrivateWindow: false,
});

// Private mode
this.runTest(name, callback, cleanupFunction, extraPrefs, {
runInSecureContext: runInSecure,
runInPrivateWindow: true,
});
},
Expand All @@ -30,7 +38,7 @@ this.PartitionedStorageHelper = {
callback,
cleanupFunction,
extraPrefs,
{ runInPrivateWindow = false, runInSecureContext = false } = {}
{ runInPrivateWindow = false, runInSecureContext = true } = {}
) {
DynamicFPIHelper.runTest(
name,
Expand Down

0 comments on commit 8349767

Please sign in to comment.