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.

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

mercurial