test_returnUnion.html (2095B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1048659 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1048659</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 /* global TestInterfaceJS */ 13 /** Test for returning unions from JS-implemented WebIDL. */ 14 SimpleTest.waitForExplicitFinish(); 15 SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go); 16 17 function go() { 18 var t = new TestInterfaceJS(); 19 var t2 = new TestInterfaceJS(); 20 21 is(t.pingPongUnion(t2), t2, "ping pong union for left case should be identity"); 22 is(t.pingPongUnion(12), 12, "ping pong union for right case should be identity"); 23 24 is(t.pingPongUnionContainingNull("this is not a string"), "this is not a string", 25 "ping pong union containing union for left case should be identity"); 26 is(t.pingPongUnionContainingNull(null), null, 27 "ping pong union containing null for right case null should be identity"); 28 is(t.pingPongUnionContainingNull(t2), t2, 29 "ping pong union containing null for right case should be identity"); 30 31 is(t.pingPongNullableUnion(t2), t2, "ping pong nullable union for left case should be identity"); 32 is(t.pingPongNullableUnion(12), 12, "ping pong nullable union for right case should be identity"); 33 is(t.pingPongNullableUnion(null), null, "ping pong nullable union for null case should be identity"); 34 35 var rejectedBadUnion = false; 36 var result = null; 37 try { 38 result = t.returnBadUnion(); 39 } catch (e) { 40 rejectedBadUnion = true; 41 } 42 is(result, null, "bad union should not set a value for result"); 43 ok(rejectedBadUnion, "bad union should throw an exception"); 44 45 SimpleTest.finish(); 46 } 47 48 </script> 49 </head> 50 <body> 51 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1048659">Mozilla Bug 1048659</a> 52 <p id="display"></p> 53 <div id="content" style="display: none"> 54 55 </div> 56 <pre id="test"> 57 </pre> 58 </body> 59 </html>