content/base/test/chrome/cpows_child.js

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 dump('loaded child cpow test\n');
michael@0 2
michael@0 3 content.document.title = "Hello, Kitty";
michael@0 4
michael@0 5 (function start() {
michael@0 6 sync_test();
michael@0 7 async_test();
michael@0 8 rpc_test();
michael@0 9 nested_sync_test();
michael@0 10 // The sync-ness of this call is important, because otherwise
michael@0 11 // we tear down the child's document while we are
michael@0 12 // still in the async test in the parent.
michael@0 13 sendSyncMessage("cpows:done", {});
michael@0 14 }
michael@0 15 )();
michael@0 16
michael@0 17 function ok(condition, message) {
michael@0 18 dump('condition: ' + condition + ', ' + message + '\n');
michael@0 19 if (!condition) {
michael@0 20 sendAsyncMessage("cpows:fail", { message: message });
michael@0 21 throw 'failed check: ' + message;
michael@0 22 }
michael@0 23 }
michael@0 24
michael@0 25 var sync_obj;
michael@0 26 var async_obj;
michael@0 27
michael@0 28 function make_object()
michael@0 29 {
michael@0 30 let o = { };
michael@0 31 o.i = 5;
michael@0 32 o.b = true;
michael@0 33 o.s = "hello";
michael@0 34 o.x = { i: 10 };
michael@0 35 o.f = function () { return 99; };
michael@0 36
michael@0 37 // Doing anything with this Proxy will throw.
michael@0 38 var throwing = new Proxy({}, new Proxy({}, {
michael@0 39 get: function (trap) { throw trap; }
michael@0 40 }));
michael@0 41
michael@0 42 let array = [1, 2, 3];
michael@0 43
michael@0 44 let for_json = { "n": 3, "a": array, "s": "hello", o: { "x": 10 } };
michael@0 45
michael@0 46 return { "data": o,
michael@0 47 "throwing": throwing,
michael@0 48 "document": content.document,
michael@0 49 "array": array,
michael@0 50 "for_json": for_json
michael@0 51 };
michael@0 52 }
michael@0 53
michael@0 54 function make_json()
michael@0 55 {
michael@0 56 return { check: "ok" };
michael@0 57 }
michael@0 58
michael@0 59 function sync_test()
michael@0 60 {
michael@0 61 dump('beginning cpow sync test\n');
michael@0 62 sync_obj = make_object();
michael@0 63 sendSyncMessage("cpows:sync",
michael@0 64 make_json(),
michael@0 65 make_object());
michael@0 66 }
michael@0 67
michael@0 68 function async_test()
michael@0 69 {
michael@0 70 dump('beginning cpow async test\n');
michael@0 71 async_obj = make_object();
michael@0 72 sendAsyncMessage("cpows:async",
michael@0 73 make_json(),
michael@0 74 async_obj);
michael@0 75 }
michael@0 76
michael@0 77 function rpc_test()
michael@0 78 {
michael@0 79 dump('beginning cpow rpc test\n');
michael@0 80 rpc_obj = make_object();
michael@0 81 rpc_obj.data.reenter = function () {
michael@0 82 sendRpcMessage("cpows:reenter", { }, { data: { valid: true } });
michael@0 83 return "ok";
michael@0 84 }
michael@0 85 sendRpcMessage("cpows:rpc",
michael@0 86 make_json(),
michael@0 87 rpc_obj);
michael@0 88 }
michael@0 89
michael@0 90 function nested_sync_test()
michael@0 91 {
michael@0 92 dump('beginning cpow nested sync test\n');
michael@0 93 sync_obj = make_object();
michael@0 94 sync_obj.data.reenter = function () {
michael@0 95 let caught = false;
michael@0 96 try {
michael@0 97 sendSyncMessage("cpows:reenter_sync", { }, { });
michael@0 98 } catch (e) {
michael@0 99 caught = true;
michael@0 100 }
michael@0 101 if (!ok(caught, "should not allow nested sync"))
michael@0 102 return "fail";
michael@0 103 return "ok";
michael@0 104 }
michael@0 105 sendSyncMessage("cpows:nested_sync",
michael@0 106 make_json(),
michael@0 107 rpc_obj);
michael@0 108 }

mercurial