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 /testing/web-platform/tests/webstorage/eventTestHarness.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webstorage/eventTestHarness.js')
-rw-r--r-- | testing/web-platform/tests/webstorage/eventTestHarness.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webstorage/eventTestHarness.js b/testing/web-platform/tests/webstorage/eventTestHarness.js new file mode 100644 index 0000000000..0a98546ace --- /dev/null +++ b/testing/web-platform/tests/webstorage/eventTestHarness.js @@ -0,0 +1,54 @@ +storageEventList = []; +iframe = document.createElement("IFRAME"); +document.body.appendChild(iframe); + +function runAfterNStorageEvents(callback, expectedNumEvents) +{ + countStorageEvents(callback, expectedNumEvents, 0) +} + +function countStorageEvents(callback, expectedNumEvents, times) +{ + function onTimeout() + { + var currentCount = storageEventList.length; + if (currentCount == expectedNumEvents) { + callback(); + } else if (currentCount > expectedNumEvents) { + msg = "got at least " + currentCount + ", expected only " + expectedNumEvents + " events"; + callback(msg); + } else if (times > 50) { + msg = "Timeout: only got " + currentCount + ", expected " + expectedNumEvents + " events"; + callback(msg); + } else { + countStorageEvents(callback, expectedNumEvents, times+1); + } + } + setTimeout(onTimeout, 20); +} + +function clearStorage(storageName, callback) +{ + if (window[storageName].length === 0) { + storageEventList = []; + setTimeout(callback, 0); + } else { + window[storageName].clear(); + runAfterNStorageEvents(function() { + storageEventList = []; + callback(); + }, 1); + } +} + +function testStorages(testCallback) +{ + testCallback("sessionStorage"); + var hit = false; + add_result_callback(function() { + if (!hit) { + hit = true; + testCallback("localStorage"); + } + }); +} |