test_promise_job_with_bind_from_discarded_iframe.html (2159B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1723124. 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1723124.</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://global/skin"/> 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1723124.">Mozilla Bug 1723124.</a> 15 16 <iframe id="frame" src="http://example.org/chrome/dom/promise/tests/file_promise_job_with_bind_from_discarded_iframe.html"></iframe> 17 18 <pre id="test"> 19 <script type="text/javascript"> 20 /** Test for Bug 1723124. */ 21 SimpleTest.waitForExplicitFinish(); 22 23 var frame = document.getElementById("frame"); 24 25 SimpleTest.waitForCondition(() => { 26 var result = frame.contentDocument.getElementById("result"); 27 if (!result) { 28 return false; 29 } 30 // Wait for the iframe's script to check if it has no access to SpecialPowers. 31 return result.textContent == "ok"; 32 }, () => { 33 var iframe_bind = frame.contentWindow.Function.prototype.bind; 34 // Removing iframe from the tree discards the browsing context, 35 // and promise jobs in the iframe global stops working. 36 frame.remove(); 37 38 Promise.resolve(10) 39 .then(function (v) { 40 // Handler in top-level realm, without bind. 41 // 42 // This job is created with the top-level realm, and should be called. 43 is(v, 10, "normal function should get the value from promise"); 44 return 20; 45 }, function () { 46 ok(false, "unexpectedly rejected"); 47 }) 48 .then(iframe_bind.call(function (bound_arg, v) { 49 // Handler in top-level realm, with bind in discarded iframe. 50 // 51 // This job is also created with the top-level realm, and should be 52 // called. 53 is(v, 20, "bound function should get the value from promise"); 54 is(bound_arg, 30, "bound function should get the arguments from bind"); 55 SimpleTest.finish(); 56 }, this, 30), function () { 57 ok(false, "unexpectedly rejected"); 58 }); 59 }); 60 </script> 61 </pre> 62 </body> 63 </html>