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/browser/beforeunload_test_page.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.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/browser/beforeunload_test_page.html')
-rw-r--r-- | dom/tests/browser/beforeunload_test_page.html | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/dom/tests/browser/beforeunload_test_page.html b/dom/tests/browser/beforeunload_test_page.html new file mode 100644 index 0000000000..12dc636e23 --- /dev/null +++ b/dom/tests/browser/beforeunload_test_page.html @@ -0,0 +1,92 @@ +<!doctype html> +<html> +<body> + +<p> + There are currently <span id="totalInnerHandlers">0</span> beforeunload handlers registered in this frame. +</p> +<p> + There are currently <span id="totalOuterHandlers">0</span> beforeunload handlers registered on my subframe. +</p> + +<iframe src="about:blank" id="subframe"></iframe> + +<script> + this.BeforeUnloader = { + _innerEventHandlers: [], + _outerEventHandlers: [], + + get $totalInner() { + delete this.$totalInner; + return this.$totalInner = document.getElementById("totalInnerHandlers"); + }, + + get $totalOuter() { + delete this.$totalOuter; + return this.$totalOuter = document.getElementById("totalOuterHandlers"); + }, + + get $subframe() { + delete this.$subframe; + return this.$subframe = document.getElementById("subframe"); + }, + + pushInner(howMany) { + for (let i = 0; i < howMany; ++i) { + let func = () => {}; + this._innerEventHandlers.push(func); + addEventListener("beforeunload", func); + } + + this.$totalInner.textContent = this._innerEventHandlers.length; + }, + + popInner(howMany) { + for (let i = 0; i < howMany; ++i) { + let func = this._innerEventHandlers.pop(); + if (func) { + removeEventListener("beforeunload", func); + } + } + + this.$totalInner.textContent = this._innerEventHandlers.length; + }, + + pushOuter(howMany) { + if (!this.$subframe.parentNode) { + throw new Error("Subframe I'm holding a reference to detached!"); + } + + for (let i = 0; i < howMany; ++i) { + let func = () => {}; + this._outerEventHandlers.push(func); + this.$subframe.contentWindow.addEventListener("beforeunload", func); + } + + this.$totalOuter.textContent = this._outerEventHandlers.length; + }, + + popOuter(howMany) { + if (!this.$subframe.parentNode) { + throw new Error("Subframe I'm holding a reference to detached!"); + } + + for (let i = 0; i < howMany; ++i) { + let func = this._outerEventHandlers.pop(); + if (func) { + this.$subframe.contentWindow.removeEventListener("beforeunload", func); + } + } + + this.$totalOuter.textContent = this._outerEventHandlers.length; + }, + + reset() { + this.popInner(this._innerEventHandlers.length); + this.popOuter(this._outerEventHandlers.length); + }, + }; +</script> + +</body> +</html> |