summaryrefslogtreecommitdiffstats
path: root/dom/permission/tests/file_shim.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/permission/tests/file_shim.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/permission/tests/file_shim.html')
-rw-r--r--dom/permission/tests/file_shim.html99
1 files changed, 99 insertions, 0 deletions
diff --git a/dom/permission/tests/file_shim.html b/dom/permission/tests/file_shim.html
new file mode 100644
index 000000000..7791eba65
--- /dev/null
+++ b/dom/permission/tests/file_shim.html
@@ -0,0 +1,99 @@
+<html>
+<head>
+<script type="application/javascript;version=1.8">
+function TestData(aOpts) {
+ for (var opt in aOpts) {
+ if (aOpts.hasOwnProperty(opt)) {
+ this[opt] = aOpts[opt];
+ }
+ }
+}
+
+TestData.prototype = {
+ getObj: function() {
+ if (!this.obj) {
+ return null;
+ }
+
+ // only one of the 2 should be set
+ if ((this.idl && this.webidl) ||
+ (!this.idl && !this.webidl)) {
+ return null;
+ }
+
+ // split on . to allow nested props
+ var props = this.obj.split(".");
+ var obj = window.navigator;
+
+ for (var i = 0; i < props.length && obj !== undefined; i++) {
+ obj = obj[props[i]];
+ }
+
+ if ((this.webidl && obj instanceof window[this.webidl]) ||
+ (this.idl && obj instanceof SpecialPowers.Ci[this.idl])) {
+ return obj;
+ } else {
+ return null;
+ }
+ },
+
+ // default verifier
+ verifier: function(success, failure) {
+ try {
+ if (this.getObj()) {
+ success(this.perm);
+ } else {
+ failure("Did not receive proper object");
+ }
+ } catch (e) {
+ failure("Received exception!: " + e);
+ }
+ },
+}
+
+function receiveMessage(e) {
+ var src = e.source;
+ var step = e.data.step;
+ var id = e.data.id;
+ var data = new TestData(e.data.testdata);
+ var success, failure;
+
+ function reply(res, msg) {
+ window.removeEventListener("message", receiveMessage, false);
+ src.postMessage({result: res, msg: msg,
+ id: id}, "*");
+ }
+
+ function _success(msg) {
+ reply(true, msg);
+ }
+
+ function _failure(msg) {
+ reply(false, msg);
+ }
+
+ // flip success and failure around for precheck
+ if (step == 0) {
+ success = _failure;
+ failure = _success;
+ } else {
+ success = _success;
+ failure = _failure;
+ }
+
+ if (data.verifier instanceof Function) {
+ data.verifier(success, failure);
+ } else {
+ // import toSource() function to global
+ eval(data.verifier);
+ verifier.bind(data, success, failure)();
+ }
+}
+
+window.addEventListener("message", receiveMessage, false);
+</script>
+</head>
+<body>
+<div id="content" style="display: none"></div>
+</body>
+</html>