summaryrefslogtreecommitdiffstats
path: root/dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html')
-rw-r--r--dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html63
1 files changed, 63 insertions, 0 deletions
diff --git a/dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html b/dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html
new file mode 100644
index 0000000000..1cea250072
--- /dev/null
+++ b/dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1723124.
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1723124.</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1723124.">Mozilla Bug 1723124.</a>
+
+<iframe id="frame" src="http://example.org/chrome/dom/promise/tests/file_promise_job_with_bind_from_discarded_iframe.html"></iframe>
+
+<pre id="test">
+<script type="text/javascript">
+/** Test for Bug 1723124. **/
+SimpleTest.waitForExplicitFinish();
+
+var frame = document.getElementById("frame");
+
+SimpleTest.waitForCondition(() => {
+ var result = frame.contentDocument.getElementById("result");
+ if (!result) {
+ return false;
+ }
+ // Wait for the iframe's script to check if it has no access to SpecialPowers.
+ return result.textContent == "ok";
+}, () => {
+ var iframe_bind = frame.contentWindow.Function.prototype.bind;
+ // Removing iframe from the tree discards the browsing context,
+ // and promise jobs in the iframe global stops working.
+ frame.remove();
+
+ Promise.resolve(10)
+ .then(function (v) {
+ // Handler in top-level realm, without bind.
+ //
+ // This job is created with the top-level realm, and should be called.
+ is(v, 10, "normal function should get the value from promise");
+ return 20;
+ }, function () {
+ ok(false, "unexpectedly rejected");
+ })
+ .then(iframe_bind.call(function (bound_arg, v) {
+ // Handler in top-level realm, with bind in discarded iframe.
+ //
+ // This job is also created with the top-level realm, and should be
+ // called.
+ is(v, 20, "bound function should get the value from promise");
+ is(bound_arg, 30, "bound function should get the arguments from bind");
+ SimpleTest.finish();
+ }, this, 30), function () {
+ ok(false, "unexpectedly rejected");
+ });
+});
+</script>
+</pre>
+</body>
+</html>