1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/chrome/cpows_parent.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,179 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<window title="MessageManager CPOW tests" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + onload="start()"> 1.11 + 1.12 + <!-- test results are displayed in the html:body --> 1.13 + <label value="CPOWs"/> 1.14 + 1.15 + <script type="application/javascript"><![CDATA[ 1.16 + var test_state = "remote"; 1.17 + var test_node = null; 1.18 + var reentered = false; 1.19 + 1.20 + function ok(condition, message) { 1.21 + return opener.wrappedJSObject.ok(condition, message); 1.22 + } 1.23 + 1.24 + // Make sure that an error in this file actually causes the test to fail. 1.25 + window.onerror = function (msg, url, line) { 1.26 + ok(false, "Error while executing: \n" + msg + "\n" + url + ":" + line); 1.27 + }; 1.28 + 1.29 + function testCpowMessage(message) { 1.30 + ok(message.json.check == "ok", "correct json"); 1.31 + 1.32 + let data = message.objects.data; 1.33 + let document = message.objects.document; 1.34 + ok(data.i === 5, "integer property"); 1.35 + ok(data.b === true, "boolean property"); 1.36 + ok(data.s === "hello", "string property"); 1.37 + ok(data.x.i === 10, "nested property"); 1.38 + ok(data.f() === 99, "function call"); 1.39 + ok(document.title === "Hello, Kitty", "document node"); 1.40 + 1.41 + data.i = 6; 1.42 + data.b = false; 1.43 + data.s = "bye"; 1.44 + data.x = null; 1.45 + ok(data.i === 6, "integer property"); 1.46 + ok(data.b === false, "boolean property"); 1.47 + ok(data.s === "bye", "string property"); 1.48 + ok(data.x === null, "nested property"); 1.49 + 1.50 + let throwing = message.objects.throwing; 1.51 + // Based on the table on: 1.52 + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy 1.53 + let tests = [ 1.54 + () => Object.getOwnPropertyDescriptor(throwing, 'test'), 1.55 + () => Object.getOwnPropertyNames(throwing), 1.56 + () => Object.defineProperty(throwing, 'test', {value: 1}), 1.57 + () => delete throwing.test, 1.58 + () => "test" in throwing, 1.59 + () => Object.prototype.hasOwnProperty.call(throwing, 'test'), 1.60 + () => throwing.test, 1.61 + () => { throwing.test = 1 }, 1.62 + // () => { for (let prop in throwing) {} }, Bug 783829 1.63 + () => { for (let prop of throwing) {} }, 1.64 + () => Object.keys(throwing), 1.65 + () => Function.prototype.call.call(throwing), 1.66 + () => new throwing, 1.67 + () => Object.preventExtensions(throwing), 1.68 + () => Object.freeze(throwing), 1.69 + () => Object.seal(throwing), 1.70 + ] 1.71 + 1.72 + for (let test of tests) { 1.73 + let threw = false; 1.74 + try { 1.75 + test() 1.76 + } catch (e) { 1.77 + threw = true; 1.78 + } 1.79 + ok(threw, "proxy operation threw exception"); 1.80 + } 1.81 + 1.82 + let array = message.objects.array; 1.83 + let i = 1; 1.84 + for (let elt of array) { 1.85 + ok(elt === i, "correct element found"); 1.86 + i++; 1.87 + } 1.88 + ok(i === 4, "array has correct length"); 1.89 + 1.90 + let j = message.objects.for_json; 1.91 + let str = JSON.stringify(j); 1.92 + let j2 = JSON.parse(str); 1.93 + ok(j2.n === 3, "JSON integer property"); 1.94 + ok(j2.a[0] === 1, "JSON array index"); 1.95 + ok(j2.a[1] === 2, "JSON array index"); 1.96 + ok(j2.a[2] === 3, "JSON array index"); 1.97 + ok(j2.s === "hello", "JSON string property"); 1.98 + ok(j2.o.x === 10, "JSON object property"); 1.99 + } 1.100 + 1.101 + function recvAsyncMessage(message) { 1.102 + testCpowMessage(message); 1.103 + } 1.104 + 1.105 + function recvSyncMessage(message) { 1.106 + testCpowMessage(message); 1.107 + } 1.108 + 1.109 + function recvRpcMessage(message) { 1.110 + ok(message.json.check == "ok", "correct json"); 1.111 + 1.112 + let data = message.objects.data; 1.113 + 1.114 + // Sanity check. 1.115 + ok(data.i === 5, "integer property"); 1.116 + 1.117 + // Check that we re-enter. 1.118 + reentered = false; 1.119 + let result = data.reenter(); 1.120 + ok(reentered, "re-entered rpc"); 1.121 + ok(result == "ok", "got correct result"); 1.122 + } 1.123 + 1.124 + function recvReenterMessage(message) { 1.125 + ok(message.objects.data.valid === true, "cpows work"); 1.126 + reentered = true; 1.127 + } 1.128 + 1.129 + function recvNestedSyncMessage(message) { 1.130 + message.objects.data.reenter(); 1.131 + } 1.132 + 1.133 + function recvReenterSyncMessage(message) { 1.134 + ok(false, "should not have received re-entered sync message"); 1.135 + } 1.136 + 1.137 + function recvFailMessage(message) { 1.138 + ok(false, message.json.message); 1.139 + } 1.140 + 1.141 + function recvDoneMessage(message) { 1.142 + if (test_state == "remote") { 1.143 + test_node.parentNode.removeChild(test_node); 1.144 + run_tests("inprocess"); 1.145 + return; 1.146 + } 1.147 + 1.148 + finish(); 1.149 + } 1.150 + 1.151 + function run_tests(type) { 1.152 + var node = document.getElementById('cpowbrowser_' + type); 1.153 + 1.154 + test_state = type; 1.155 + test_node = node; 1.156 + 1.157 + var mm = node.messageManager; 1.158 + mm.addMessageListener("cpows:async", recvAsyncMessage); 1.159 + mm.addMessageListener("cpows:sync", recvSyncMessage); 1.160 + mm.addMessageListener("cpows:rpc", recvRpcMessage); 1.161 + mm.addMessageListener("cpows:reenter", recvReenterMessage); 1.162 + mm.addMessageListener("cpows:reenter", recvReenterMessage); 1.163 + mm.addMessageListener("cpows:nested_sync", recvNestedSyncMessage); 1.164 + mm.addMessageListener("cpows:reenter_sync", recvReenterSyncMessage); 1.165 + mm.addMessageListener("cpows:done", recvDoneMessage); 1.166 + mm.addMessageListener("cpows:fail", recvFailMessage); 1.167 + mm.loadFrameScript("chrome://mochitests/content/chrome/content/base/test/chrome/cpows_child.js", true); 1.168 + } 1.169 + 1.170 + function start() { 1.171 + run_tests('remote'); 1.172 + } 1.173 + 1.174 + function finish() { 1.175 + opener.setTimeout("done()", 0); 1.176 + window.close(); 1.177 + } 1.178 + ]]></script> 1.179 + 1.180 + <browser type="content" src="about:blank" id="cpowbrowser_remote" remote="true"/> 1.181 + <browser type="content" src="about:blank" id="cpowbrowser_inprocess"/> 1.182 +</window>