Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
michael@0 | 4 | type="text/css"?> |
michael@0 | 5 | <window title="MessageManager CPOW tests" |
michael@0 | 6 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 7 | onload="start()"> |
michael@0 | 8 | |
michael@0 | 9 | <!-- test results are displayed in the html:body --> |
michael@0 | 10 | <label value="CPOWs"/> |
michael@0 | 11 | |
michael@0 | 12 | <script type="application/javascript"><![CDATA[ |
michael@0 | 13 | var test_state = "remote"; |
michael@0 | 14 | var test_node = null; |
michael@0 | 15 | var reentered = false; |
michael@0 | 16 | |
michael@0 | 17 | function ok(condition, message) { |
michael@0 | 18 | return opener.wrappedJSObject.ok(condition, message); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | // Make sure that an error in this file actually causes the test to fail. |
michael@0 | 22 | window.onerror = function (msg, url, line) { |
michael@0 | 23 | ok(false, "Error while executing: \n" + msg + "\n" + url + ":" + line); |
michael@0 | 24 | }; |
michael@0 | 25 | |
michael@0 | 26 | function testCpowMessage(message) { |
michael@0 | 27 | ok(message.json.check == "ok", "correct json"); |
michael@0 | 28 | |
michael@0 | 29 | let data = message.objects.data; |
michael@0 | 30 | let document = message.objects.document; |
michael@0 | 31 | ok(data.i === 5, "integer property"); |
michael@0 | 32 | ok(data.b === true, "boolean property"); |
michael@0 | 33 | ok(data.s === "hello", "string property"); |
michael@0 | 34 | ok(data.x.i === 10, "nested property"); |
michael@0 | 35 | ok(data.f() === 99, "function call"); |
michael@0 | 36 | ok(document.title === "Hello, Kitty", "document node"); |
michael@0 | 37 | |
michael@0 | 38 | data.i = 6; |
michael@0 | 39 | data.b = false; |
michael@0 | 40 | data.s = "bye"; |
michael@0 | 41 | data.x = null; |
michael@0 | 42 | ok(data.i === 6, "integer property"); |
michael@0 | 43 | ok(data.b === false, "boolean property"); |
michael@0 | 44 | ok(data.s === "bye", "string property"); |
michael@0 | 45 | ok(data.x === null, "nested property"); |
michael@0 | 46 | |
michael@0 | 47 | let throwing = message.objects.throwing; |
michael@0 | 48 | // Based on the table on: |
michael@0 | 49 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy |
michael@0 | 50 | let tests = [ |
michael@0 | 51 | () => Object.getOwnPropertyDescriptor(throwing, 'test'), |
michael@0 | 52 | () => Object.getOwnPropertyNames(throwing), |
michael@0 | 53 | () => Object.defineProperty(throwing, 'test', {value: 1}), |
michael@0 | 54 | () => delete throwing.test, |
michael@0 | 55 | () => "test" in throwing, |
michael@0 | 56 | () => Object.prototype.hasOwnProperty.call(throwing, 'test'), |
michael@0 | 57 | () => throwing.test, |
michael@0 | 58 | () => { throwing.test = 1 }, |
michael@0 | 59 | // () => { for (let prop in throwing) {} }, Bug 783829 |
michael@0 | 60 | () => { for (let prop of throwing) {} }, |
michael@0 | 61 | () => Object.keys(throwing), |
michael@0 | 62 | () => Function.prototype.call.call(throwing), |
michael@0 | 63 | () => new throwing, |
michael@0 | 64 | () => Object.preventExtensions(throwing), |
michael@0 | 65 | () => Object.freeze(throwing), |
michael@0 | 66 | () => Object.seal(throwing), |
michael@0 | 67 | ] |
michael@0 | 68 | |
michael@0 | 69 | for (let test of tests) { |
michael@0 | 70 | let threw = false; |
michael@0 | 71 | try { |
michael@0 | 72 | test() |
michael@0 | 73 | } catch (e) { |
michael@0 | 74 | threw = true; |
michael@0 | 75 | } |
michael@0 | 76 | ok(threw, "proxy operation threw exception"); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | let array = message.objects.array; |
michael@0 | 80 | let i = 1; |
michael@0 | 81 | for (let elt of array) { |
michael@0 | 82 | ok(elt === i, "correct element found"); |
michael@0 | 83 | i++; |
michael@0 | 84 | } |
michael@0 | 85 | ok(i === 4, "array has correct length"); |
michael@0 | 86 | |
michael@0 | 87 | let j = message.objects.for_json; |
michael@0 | 88 | let str = JSON.stringify(j); |
michael@0 | 89 | let j2 = JSON.parse(str); |
michael@0 | 90 | ok(j2.n === 3, "JSON integer property"); |
michael@0 | 91 | ok(j2.a[0] === 1, "JSON array index"); |
michael@0 | 92 | ok(j2.a[1] === 2, "JSON array index"); |
michael@0 | 93 | ok(j2.a[2] === 3, "JSON array index"); |
michael@0 | 94 | ok(j2.s === "hello", "JSON string property"); |
michael@0 | 95 | ok(j2.o.x === 10, "JSON object property"); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function recvAsyncMessage(message) { |
michael@0 | 99 | testCpowMessage(message); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function recvSyncMessage(message) { |
michael@0 | 103 | testCpowMessage(message); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | function recvRpcMessage(message) { |
michael@0 | 107 | ok(message.json.check == "ok", "correct json"); |
michael@0 | 108 | |
michael@0 | 109 | let data = message.objects.data; |
michael@0 | 110 | |
michael@0 | 111 | // Sanity check. |
michael@0 | 112 | ok(data.i === 5, "integer property"); |
michael@0 | 113 | |
michael@0 | 114 | // Check that we re-enter. |
michael@0 | 115 | reentered = false; |
michael@0 | 116 | let result = data.reenter(); |
michael@0 | 117 | ok(reentered, "re-entered rpc"); |
michael@0 | 118 | ok(result == "ok", "got correct result"); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | function recvReenterMessage(message) { |
michael@0 | 122 | ok(message.objects.data.valid === true, "cpows work"); |
michael@0 | 123 | reentered = true; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | function recvNestedSyncMessage(message) { |
michael@0 | 127 | message.objects.data.reenter(); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function recvReenterSyncMessage(message) { |
michael@0 | 131 | ok(false, "should not have received re-entered sync message"); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | function recvFailMessage(message) { |
michael@0 | 135 | ok(false, message.json.message); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | function recvDoneMessage(message) { |
michael@0 | 139 | if (test_state == "remote") { |
michael@0 | 140 | test_node.parentNode.removeChild(test_node); |
michael@0 | 141 | run_tests("inprocess"); |
michael@0 | 142 | return; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | finish(); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | function run_tests(type) { |
michael@0 | 149 | var node = document.getElementById('cpowbrowser_' + type); |
michael@0 | 150 | |
michael@0 | 151 | test_state = type; |
michael@0 | 152 | test_node = node; |
michael@0 | 153 | |
michael@0 | 154 | var mm = node.messageManager; |
michael@0 | 155 | mm.addMessageListener("cpows:async", recvAsyncMessage); |
michael@0 | 156 | mm.addMessageListener("cpows:sync", recvSyncMessage); |
michael@0 | 157 | mm.addMessageListener("cpows:rpc", recvRpcMessage); |
michael@0 | 158 | mm.addMessageListener("cpows:reenter", recvReenterMessage); |
michael@0 | 159 | mm.addMessageListener("cpows:reenter", recvReenterMessage); |
michael@0 | 160 | mm.addMessageListener("cpows:nested_sync", recvNestedSyncMessage); |
michael@0 | 161 | mm.addMessageListener("cpows:reenter_sync", recvReenterSyncMessage); |
michael@0 | 162 | mm.addMessageListener("cpows:done", recvDoneMessage); |
michael@0 | 163 | mm.addMessageListener("cpows:fail", recvFailMessage); |
michael@0 | 164 | mm.loadFrameScript("chrome://mochitests/content/chrome/content/base/test/chrome/cpows_child.js", true); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | function start() { |
michael@0 | 168 | run_tests('remote'); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | function finish() { |
michael@0 | 172 | opener.setTimeout("done()", 0); |
michael@0 | 173 | window.close(); |
michael@0 | 174 | } |
michael@0 | 175 | ]]></script> |
michael@0 | 176 | |
michael@0 | 177 | <browser type="content" src="about:blank" id="cpowbrowser_remote" remote="true"/> |
michael@0 | 178 | <browser type="content" src="about:blank" id="cpowbrowser_inprocess"/> |
michael@0 | 179 | </window> |