From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- devtools/server/tests/browser/storage-helpers.js | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 devtools/server/tests/browser/storage-helpers.js (limited to 'devtools/server/tests/browser/storage-helpers.js') diff --git a/devtools/server/tests/browser/storage-helpers.js b/devtools/server/tests/browser/storage-helpers.js new file mode 100644 index 0000000000..8c3840a1d2 --- /dev/null +++ b/devtools/server/tests/browser/storage-helpers.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// This file assumes head.js is loaded in the global scope. +/* import-globals-from head.js */ + +/* exported openTabAndSetupStorage, clearStorage */ + +"use strict"; + +const LEGACY_ACTORS_PREF = "devtools.storage.test.forceLegacyActors"; + +/** + * This generator function opens the given url in a new tab, then sets up the + * page by waiting for all cookies, indexedDB items etc. to be created. + * + * @param url {String} The url to be opened in the new tab + * + * @return {Promise} A promise that resolves after storage inspector is ready + */ +async function openTabAndSetupStorage(url) { + // Enable testing prefs + SpecialPowers.pushPrefEnv({ + set: [[LEGACY_ACTORS_PREF, true]], + }); + + await addTab(url); + + // Setup the async storages in main window and for all its iframes + const browsingContexts = + gBrowser.selectedBrowser.browsingContext.getAllBrowsingContextsInSubtree(); + for (const browsingContext of browsingContexts) { + await SpecialPowers.spawn(browsingContext, [], async function () { + if (content.wrappedJSObject.setup) { + await content.wrappedJSObject.setup(); + } + }); + } + + // selected tab is set in addTab + const commands = await CommandsFactory.forTab(gBrowser.selectedTab); + await commands.targetCommand.startListening(); + const target = commands.targetCommand.targetFront; + return { commands, target }; +} + +async function clearStorage() { + const browsingContexts = + gBrowser.selectedBrowser.browsingContext.getAllBrowsingContextsInSubtree(); + for (const browsingContext of browsingContexts) { + await SpecialPowers.spawn(browsingContext, [], async function () { + if (content.wrappedJSObject.clear) { + await content.wrappedJSObject.clear(); + } + }); + } +} -- cgit v1.2.3