summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser/browser_localStorage_privatestorageevent.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/tests/browser/browser_localStorage_privatestorageevent.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/browser/browser_localStorage_privatestorageevent.js')
-rw-r--r--dom/tests/browser/browser_localStorage_privatestorageevent.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/dom/tests/browser/browser_localStorage_privatestorageevent.js b/dom/tests/browser/browser_localStorage_privatestorageevent.js
new file mode 100644
index 0000000000..ad797319b8
--- /dev/null
+++ b/dom/tests/browser/browser_localStorage_privatestorageevent.js
@@ -0,0 +1,87 @@
+add_task(async function() {
+ var privWin = OpenBrowserWindow({ private: true });
+ await new privWin.Promise(resolve => {
+ privWin.addEventListener(
+ "load",
+ function() {
+ resolve();
+ },
+ { once: true }
+ );
+ });
+
+ var pubWin = OpenBrowserWindow({ private: false });
+ await new pubWin.Promise(resolve => {
+ pubWin.addEventListener(
+ "load",
+ function() {
+ resolve();
+ },
+ { once: true }
+ );
+ });
+
+ var URL =
+ "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";
+
+ var privTab = BrowserTestUtils.addTab(privWin.gBrowser, URL);
+ await BrowserTestUtils.browserLoaded(
+ privWin.gBrowser.getBrowserForTab(privTab)
+ );
+ var privBrowser = gBrowser.getBrowserForTab(privTab);
+
+ var pubTab = BrowserTestUtils.addTab(pubWin.gBrowser, URL);
+ await BrowserTestUtils.browserLoaded(
+ pubWin.gBrowser.getBrowserForTab(pubTab)
+ );
+ var pubBrowser = gBrowser.getBrowserForTab(pubTab);
+
+ // Check if pubWin can see privWin's storage events
+ await SpecialPowers.spawn(pubBrowser, [], function(opts) {
+ content.window.gotStorageEvent = false;
+ content.window.addEventListener("storage", ev => {
+ content.window.gotStorageEvent = true;
+ });
+ });
+
+ await SpecialPowers.spawn(privBrowser, [], function(opts) {
+ content.window.localStorage.key = "ablooabloo";
+ });
+
+ let pubSaw = await SpecialPowers.spawn(pubBrowser, [], function(opts) {
+ return content.window.gotStorageEvent;
+ });
+
+ ok(!pubSaw, "pubWin shouldn't be able to see privWin's storage events");
+
+ await SpecialPowers.spawn(privBrowser, [], function(opts) {
+ content.window.gotStorageEvent = false;
+ content.window.addEventListener("storage", ev => {
+ content.window.gotStorageEvent = true;
+ });
+ });
+
+ // Check if privWin can see pubWin's storage events
+ await SpecialPowers.spawn(privBrowser, [], function(opts) {
+ content.window.gotStorageEvent = false;
+ content.window.addEventListener("storage", ev => {
+ content.window.gotStorageEvent = true;
+ });
+ });
+
+ await SpecialPowers.spawn(pubBrowser, [], function(opts) {
+ content.window.localStorage.key = "ablooabloo";
+ });
+
+ let privSaw = await SpecialPowers.spawn(privBrowser, [], function(opts) {
+ return content.window.gotStorageEvent;
+ });
+
+ ok(!privSaw, "privWin shouldn't be able to see pubWin's storage events");
+
+ BrowserTestUtils.removeTab(privTab);
+ await BrowserTestUtils.closeWindow(privWin);
+
+ BrowserTestUtils.removeTab(pubTab);
+ await BrowserTestUtils.closeWindow(pubWin);
+});