test_promise_retval_xrays.html (2580B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1436276. 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1436276.</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=1436276.">Mozilla Bug 1436276.</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 <iframe id="t" src="http://example.org/chrome/dom/promise/tests/file_promise_xrays.html"></iframe> 18 </div> 19 20 <pre id="test"> 21 <script src="file_promise_retval_tests.js"></script> 22 <script type="application/javascript"> 23 24 var win = $("t").contentWindow; 25 26 /** Test for Bug 1233324 */ 27 SimpleTest.waitForExplicitFinish(); 28 29 function testLoadComplete() { 30 is(win.location.href, $("t").src, "Should have loaded the right thing"); 31 nextTest(); 32 } 33 34 function testHaveXray() { 35 is(typeof win.Promise.race, "function", "Should see a race() function"); 36 var exception; 37 try { 38 win.Promise.wrappedJSObject.race; 39 } catch (e) { 40 exception = e; 41 } 42 is(exception, "Getting race", "Should have thrown the right exception"); 43 is(win.wrappedJSObject.setupThrew, false, "Setup should not have thrown"); 44 nextTest(); 45 } 46 47 function verifyPromiseGlobal(p, _, msg) { 48 // SpecialPowers.Cu.getGlobalForObject returns a SpecialPowers wrapper for 49 // the actual global. We want to grab the underlying object. 50 var global = SpecialPowers.unwrap(SpecialPowers.Cu.getGlobalForObject(p)); 51 52 // We expect our global to always be "window" here, because we're working over 53 // Xrays. 54 is(global, window, msg + " should come from " + window.label); 55 } 56 57 function expectedExceptionGlobal(_) { 58 // We should end up with an exception from "window" no matter what global 59 // was involved to start with, because we're working over Xrays. 60 return window; 61 } 62 63 function getPromise(global, arg) { 64 return global.TestFunctions.passThroughPromise(arg); 65 } 66 67 function testPromiseRetvals() { 68 runPromiseRetvalTests(nextTest); 69 } 70 71 var tests = [ 72 testLoadComplete, 73 testHaveXray, 74 testPromiseRetvals, 75 ]; 76 77 function nextTest() { 78 if (!tests.length) { 79 SimpleTest.finish(); 80 return; 81 } 82 tests.shift()(); 83 } 84 85 addLoadEvent(function() { 86 frames[0].label = "child"; 87 SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, 88 nextTest); 89 }); 90 91 </script> 92 </pre> 93 </body> 94 </html>