1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/test/test_bug923904.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=923904 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 923904</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + <script type="application/javascript"> 1.15 + 1.16 + /** Test for cloning of |any| and |object| for JS-Implemented WebIDL. **/ 1.17 + SimpleTest.waitForExplicitFinish(); 1.18 + SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go); 1.19 + 1.20 + function go() { 1.21 + var someAny = { a: 11 }; 1.22 + var someObj = { b: 22, c: "str" }; 1.23 + var t = new TestInterfaceJS(someAny, someObj); 1.24 + is(Object.getPrototypeOf(t), TestInterfaceJS.prototype, "Prototype setup works correctly"); 1.25 + is(t.anyArg.toSource(), someAny.toSource(), "anyArg comes back looking like what we sent"); 1.26 + is(t.objectArg.toSource(), someObj.toSource(), "objectArg comes back looking like what we sent"); 1.27 + isnot(t.anyArg, t.anyArg, "get a new anyArg each time"); 1.28 + isnot(t.objectArg, t.objectArg, "get a new objectArg each time"); 1.29 + 1.30 + t.anyAttr = 2; 1.31 + is(t.anyAttr, 2, "ping-pong works"); 1.32 + testObjectCloned(t, 'anyAttr'); 1.33 + testObjectCloned(t, 'objectAttr'); 1.34 + 1.35 + is(someAny.toSource(), t.pingPongAny(someAny).toSource(), "ping-pong works with any"); 1.36 + is(someObj.toSource(), t.pingPongObject(someObj).toSource(), "ping-pong works with obj"); 1.37 + isnot(someAny, t.pingPongAny(someAny), "Clone works for ping-pong any"); 1.38 + isnot(someObj, t.pingPongObject(someObj), "Clone works for ping-pong obj"); 1.39 + 1.40 + SimpleTest.finish(); 1.41 + } 1.42 + 1.43 + function testObjectCloned(iface, propname) { 1.44 + var obj = { prop: 42 }; 1.45 + iface[propname] = obj; 1.46 + is(iface[propname].prop, 42, "objects come back as well"); 1.47 + is(iface[propname].__proto__, Object.prototype, "vanilla object"); 1.48 + isnot(iface[propname], obj, "Should not be the original object"); 1.49 + isnot(iface[propname], iface[propname], "Should get cloned each time"); 1.50 + try { 1.51 + iface[propname] = { stringProp: "hi", reflectorProp: document }; 1.52 + ok(false, "Should throw when trying to clone reflector"); 1.53 + } catch (e) { 1.54 + ok(/cloned/.test(e), "Should throw clone error: " + e); 1.55 + } 1.56 + } 1.57 + 1.58 + </script> 1.59 +</head> 1.60 +<body> 1.61 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=923904">Mozilla Bug 923904</a> 1.62 +<p id="display"></p> 1.63 +<div id="content" style="display: none"> 1.64 + 1.65 +</div> 1.66 +<pre id="test"> 1.67 +</pre> 1.68 +</body> 1.69 +</html>