dom/permission/tests/file_shim.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <html>
     2 <head>
     3 <script type="application/javascript;version=1.8">
     4 function TestData(aOpts) {
     5   for (var opt in aOpts) {
     6     if (aOpts.hasOwnProperty(opt)) {
     7       this[opt] = aOpts[opt];
     8     }
     9   }
    10 }
    12 TestData.prototype = {
    13   getObj: function() {
    14     if (!this.obj) {
    15       return null;
    16     }
    18     // only one of the 2 should be set
    19     if ((this.idl && this.webidl) ||
    20         (!this.idl && !this.webidl)) {
    21       return null;
    22     }
    24     var obj = window.navigator[this.obj];
    26     if ((this.webidl && obj instanceof window[this.webidl]) ||
    27         (this.idl && obj instanceof SpecialPowers.Ci[this.idl])) {
    28       return obj;
    29     } else {
    30       return null;
    31     }
    32   },
    34   // default verifier
    35   verifier: function(success, failure) {
    36     try {
    37       if (this.getObj()) {
    38         success(this.perm);
    39       } else {
    40         failure("Did not receive proper object");
    41       }
    42     } catch (e) {
    43       failure("Received exception!: " + e);
    44     }
    45   },
    46 }
    48 function receiveMessage(e) {
    49   var src = e.source;
    50   var step = e.data.step;
    51   var id = e.data.id;
    52   var timer = window.setTimeout(timeout, 10000);
    53   var data = new TestData(e.data.testdata);
    54   var success, failure;
    56   function reply(res, msg) {
    57     window.clearTimeout(timer);
    58     window.removeEventListener("message", receiveMessage, false);
    59     src.postMessage({result: res, msg: msg,
    60                      id: id}, "*");
    61   }
    63   function _success(msg) {
    64     reply(true, msg);
    65   }
    67   function _failure(msg) {
    68     reply(false, msg);
    69   }
    71   function timeout() {
    72     reply(false, "Test timed out", false);
    73   }
    75   // flip success and failure around for precheck
    76   if (step == 0) {
    77     success = _failure;
    78     failure = _success;
    79   } else {
    80     success = _success;
    81     failure = _failure;
    82   }
    84   if (data.verifier instanceof Function) {
    85     data.verifier(success, failure);
    86   } else {
    87     // import toSource() function to global
    88     eval(data.verifier);
    89     verifier.bind(data, success, failure)();
    90   }
    91 }
    93 window.addEventListener("message", receiveMessage, false);
    94 </script>
    95 </head>
    96 <body>
    97 <div id="content" style="display: none"></div>
    98 </body>
    99 </html>

mercurial