dom/permission/tests/file_shim.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/permission/tests/file_shim.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +<script type="application/javascript;version=1.8">
     1.7 +function TestData(aOpts) {
     1.8 +  for (var opt in aOpts) {
     1.9 +    if (aOpts.hasOwnProperty(opt)) {
    1.10 +      this[opt] = aOpts[opt];
    1.11 +    }
    1.12 +  }
    1.13 +}
    1.14 +
    1.15 +TestData.prototype = {
    1.16 +  getObj: function() {
    1.17 +    if (!this.obj) {
    1.18 +      return null;
    1.19 +    }
    1.20 +
    1.21 +    // only one of the 2 should be set
    1.22 +    if ((this.idl && this.webidl) ||
    1.23 +        (!this.idl && !this.webidl)) {
    1.24 +      return null;
    1.25 +    }
    1.26 +
    1.27 +    var obj = window.navigator[this.obj];
    1.28 +
    1.29 +    if ((this.webidl && obj instanceof window[this.webidl]) ||
    1.30 +        (this.idl && obj instanceof SpecialPowers.Ci[this.idl])) {
    1.31 +      return obj;
    1.32 +    } else {
    1.33 +      return null;
    1.34 +    }
    1.35 +  },
    1.36 +
    1.37 +  // default verifier
    1.38 +  verifier: function(success, failure) {
    1.39 +    try {
    1.40 +      if (this.getObj()) {
    1.41 +        success(this.perm);
    1.42 +      } else {
    1.43 +        failure("Did not receive proper object");
    1.44 +      }
    1.45 +    } catch (e) {
    1.46 +      failure("Received exception!: " + e);
    1.47 +    }
    1.48 +  },
    1.49 +}
    1.50 +
    1.51 +function receiveMessage(e) {
    1.52 +  var src = e.source;
    1.53 +  var step = e.data.step;
    1.54 +  var id = e.data.id;
    1.55 +  var timer = window.setTimeout(timeout, 10000);
    1.56 +  var data = new TestData(e.data.testdata);
    1.57 +  var success, failure;
    1.58 +
    1.59 +  function reply(res, msg) {
    1.60 +    window.clearTimeout(timer);
    1.61 +    window.removeEventListener("message", receiveMessage, false);
    1.62 +    src.postMessage({result: res, msg: msg,
    1.63 +                     id: id}, "*");
    1.64 +  }
    1.65 +
    1.66 +  function _success(msg) {
    1.67 +    reply(true, msg);
    1.68 +  }
    1.69 +
    1.70 +  function _failure(msg) {
    1.71 +    reply(false, msg);
    1.72 +  }
    1.73 +
    1.74 +  function timeout() {
    1.75 +    reply(false, "Test timed out", false);
    1.76 +  }
    1.77 +
    1.78 +  // flip success and failure around for precheck
    1.79 +  if (step == 0) {
    1.80 +    success = _failure;
    1.81 +    failure = _success;
    1.82 +  } else {
    1.83 +    success = _success;
    1.84 +    failure = _failure;
    1.85 +  }
    1.86 +
    1.87 +  if (data.verifier instanceof Function) {
    1.88 +    data.verifier(success, failure);
    1.89 +  } else {
    1.90 +    // import toSource() function to global
    1.91 +    eval(data.verifier);
    1.92 +    verifier.bind(data, success, failure)();
    1.93 +  }
    1.94 +}
    1.95 +
    1.96 +window.addEventListener("message", receiveMessage, false);
    1.97 +</script>
    1.98 +</head>
    1.99 +<body>
   1.100 +<div id="content" style="display: none"></div>
   1.101 +</body>
   1.102 +</html>

mercurial