Bug 1663192 - Part 1: Add a test to ensure the top-level window in a file url is considered as top-level. r=dimi

Differential Revision: https://phabricator.services.mozilla.com/D91001
This commit is contained in:
Tim Huang 2020-09-24 09:12:48 +00:00
Родитель 5a699ddc37
Коммит 85ee48719b
3 изменённых файлов: 61 добавлений и 0 удалений

Просмотреть файл

@ -36,6 +36,7 @@ support-files =
empty-altsvc.js
empty-altsvc.js^headers^
empty.html
file_localStorage.html
popup.html
redirect.sjs
server.sjs
@ -73,6 +74,7 @@ skip-if = os == "linux" && debug #bug 1627094
[browser_blockingNoOpener.js]
[browser_doublyNestedTracker.js]
[browser_existingCookiesForSubresources.js]
[browser_fileUrl.js]
[browser_firstPartyCookieRejectionHonoursAllowList.js]
[browser_hasStorageAccess.js]
[browser_imageCache4.js]

Просмотреть файл

@ -0,0 +1,38 @@
/**
* Bug 1663192 - Testing for ensuring the top-level window in a fire url is
* treated as first-party.
*/
"use strict";
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [["network.cookie.cookieBehavior", 1]],
});
});
add_task(async function() {
let dir = getChromeDir(getResolvedURI(gTestPath));
dir.append("file_localStorage.html");
const uriString = Services.io.newFileURI(dir).spec;
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, uriString);
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
let result = content.document.getElementById("result");
is(
result.textContent,
"PASS",
"The localStorage is accessible in top-level window"
);
let loadInfo = content.docShell.currentDocumentChannel.loadInfo;
ok(
!loadInfo.isThirdPartyContextToTopWindow,
"The top-level window shouldn't be third-party"
);
});
BrowserTestUtils.removeTab(tab);
});

Просмотреть файл

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Bug 1663192 - Accessing localStorage in a file urls</title>
</head>
<script>
window.addEventListener("DOMContentLoaded", () => {
let result = document.getElementById("result");
try {
window.localStorage.setItem("foo", "bar");
result.textContent = "PASS";
} catch (e) {
result.textContent = "FAIL";
}
}, { once: true });
</script>
<body>
<a id="result"></a>
</body>
</html>