content/base/test/test_ipc_messagemanager_blob.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for OOP Blobs in MessageManager</title>
michael@0 5 <script type="application/javascript"
michael@0 6 src="/tests/SimpleTest/SimpleTest.js">
michael@0 7 </script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 9 </head>
michael@0 10 <body>
michael@0 11
michael@0 12 <script type="application/javascript;version=1.7">
michael@0 13 "use strict";
michael@0 14
michael@0 15 SimpleTest.waitForExplicitFinish();
michael@0 16
michael@0 17 const childFrameURL =
michael@0 18 "data:text/html,<!DOCTYPE HTML><html><body></body></html>";
michael@0 19
michael@0 20 function childFrameScript() {
michael@0 21 "use strict";
michael@0 22
michael@0 23 addMessageListener("test:ipcClonedMessage", function(message) {
michael@0 24 if (!(message.json instanceof Components.interfaces.nsIDOMBlob)) {
michael@0 25 sendAsyncMessage(message.name, message.json);
michael@0 26 return;
michael@0 27 }
michael@0 28
michael@0 29 let reader =
michael@0 30 Components.classes["@mozilla.org/files/filereader;1"]
michael@0 31 .createInstance(Components.interfaces.nsIDOMFileReader);
michael@0 32 reader.addEventListener("load", function() {
michael@0 33 let response = reader.result == "this is a great success!" ?
michael@0 34 message.json :
michael@0 35 "error";
michael@0 36 sendAsyncMessage(message.name, response);
michael@0 37 });
michael@0 38 reader.readAsText(message.json);
michael@0 39 });
michael@0 40 }
michael@0 41
michael@0 42 function runTests() {
michael@0 43 ok("Browser prefs set.");
michael@0 44
michael@0 45 let iframe = document.createElement("iframe");
michael@0 46 SpecialPowers.wrap(iframe).mozbrowser = true;
michael@0 47 iframe.id = "iframe";
michael@0 48 iframe.src = childFrameURL;
michael@0 49
michael@0 50 iframe.addEventListener("mozbrowserloadend", function() {
michael@0 51 ok(true, "Got iframe load event.");
michael@0 52
michael@0 53 const messages = [
michael@0 54 "hi!",
michael@0 55 "",
michael@0 56 2,
michael@0 57 -.04,
michael@0 58 3432987324987239872948732982,
michael@0 59 true,
michael@0 60 false,
michael@0 61 null,
michael@0 62 0,
michael@0 63 new Blob(["this ", "is ", "a ", "great ", "success!"],
michael@0 64 {"type" : "text\/plain"}),
michael@0 65 ];
michael@0 66 let receivedMessageIndex = 0;
michael@0 67
michael@0 68 let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
michael@0 69 mm.addMessageListener("test:ipcClonedMessage", function(message) {
michael@0 70 // We need to wrap to access message.json, and unwrap to do the
michael@0 71 // identity check.
michael@0 72 is(SpecialPowers.unwrap(SpecialPowers.wrap(message).json),
michael@0 73 messages[receivedMessageIndex++],
michael@0 74 "Got correct round-tripped response");
michael@0 75 if (receivedMessageIndex == messages.length) {
michael@0 76 SpecialPowers.removePermission("browser", document);
michael@0 77 SimpleTest.finish();
michael@0 78 }
michael@0 79 });
michael@0 80 mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
michael@0 81 false);
michael@0 82
michael@0 83 for each (let message in messages) {
michael@0 84 mm.sendAsyncMessage("test:ipcClonedMessage", message);
michael@0 85 }
michael@0 86 });
michael@0 87
michael@0 88 document.body.appendChild(iframe);
michael@0 89 }
michael@0 90
michael@0 91 addEventListener("load", function() {
michael@0 92 info("Got load event.");
michael@0 93
michael@0 94 SpecialPowers.addPermission("browser", true, document);
michael@0 95 SpecialPowers.pushPrefEnv({
michael@0 96 "set": [
michael@0 97 ["dom.ipc.browser_frames.oop_by_default", true],
michael@0 98 ["dom.mozBrowserFramesEnabled", true],
michael@0 99 ["browser.pagethumbnails.capturing_disabled", true]
michael@0 100 ]
michael@0 101 }, runTests);
michael@0 102 });
michael@0 103 </script>
michael@0 104 </body>
michael@0 105 </html>

mercurial