diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/mochitest/localstorage/localStorageCommon.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/localstorage/localStorageCommon.js')
-rw-r--r-- | dom/tests/mochitest/localstorage/localStorageCommon.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/dom/tests/mochitest/localstorage/localStorageCommon.js b/dom/tests/mochitest/localstorage/localStorageCommon.js new file mode 100644 index 0000000000..364e708870 --- /dev/null +++ b/dom/tests/mochitest/localstorage/localStorageCommon.js @@ -0,0 +1,131 @@ +function localStorageFlush(cb) { + if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) { + SimpleTest.executeSoon(function () { + cb(); + }); + return; + } + + var ob = { + observe(sub, top, dat) { + os().removeObserver(ob, "domstorage-test-flushed"); + cb(); + }, + }; + os().addObserver(ob, "domstorage-test-flushed"); + notify("domstorage-test-flush-force"); +} + +function localStorageReload(callback) { + if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) { + localStorage.close(); + let qms = SpecialPowers.Services.qms; + let principal = SpecialPowers.wrap(document).nodePrincipal; + let request = qms.resetStoragesForPrincipal(principal, "default", "ls"); + request.callback = SpecialPowers.wrapCallback(function () { + localStorage.open(); + callback(); + }); + return; + } + + notify("domstorage-test-reload"); + SimpleTest.executeSoon(function () { + callback(); + }); +} + +function localStorageFlushAndReload(callback) { + if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) { + localStorage.close(); + let qms = SpecialPowers.Services.qms; + let principal = SpecialPowers.wrap(document).nodePrincipal; + let request = qms.resetStoragesForPrincipal(principal, "default", "ls"); + request.callback = SpecialPowers.wrapCallback(function () { + localStorage.open(); + callback(); + }); + return; + } + + localStorageFlush(function () { + localStorageReload(callback); + }); +} + +function localStorageClearAll(callback) { + if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) { + let qms = SpecialPowers.Services.qms; + let ssm = SpecialPowers.Services.scriptSecurityManager; + + qms.getUsage( + SpecialPowers.wrapCallback(function (request) { + if (request.resultCode != SpecialPowers.Cr.NS_OK) { + callback(); + return; + } + + let clearRequestCount = 0; + for (let item of request.result) { + let principal = ssm.createContentPrincipalFromOrigin(item.origin); + let clearRequest = qms.clearStoragesForPrincipal( + principal, + "default", + "ls" + ); + clearRequestCount++; + clearRequest.callback = SpecialPowers.wrapCallback(function () { + if (--clearRequestCount == 0) { + callback(); + } + }); + } + }) + ); + return; + } + + os().notifyObservers(null, "cookie-changed", "cleared"); + SimpleTest.executeSoon(function () { + callback(); + }); +} + +function localStorageClearDomain(domain, callback) { + if (SpecialPowers.Services.domStorageManager.nextGenLocalStorageEnabled) { + let qms = SpecialPowers.Services.qms; + let principal = SpecialPowers.wrap(document).effectiveStoragePrincipal; + let request = qms.clearStoragesForPrincipal(principal, "default", "ls"); + let cb = SpecialPowers.wrapCallback(callback); + request.callback = cb; + return; + } + + os().notifyObservers(null, "extension:purge-localStorage", domain); + SimpleTest.executeSoon(function () { + callback(); + }); +} + +function os() { + return SpecialPowers.Services.obs; +} + +function notify(top) { + os().notifyObservers(null, top); +} + +/** + * Enable testing observer notifications in DOMStorageObserver.cpp. + */ +function localStorageEnableTestingMode(cb) { + SpecialPowers.pushPrefEnv( + { + set: [ + ["dom.storage.testing", true], + ["dom.quotaManager.testing", true], + ], + }, + cb + ); +} |