summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_sandbox.js
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/indexedDB/test/unit/test_sandbox.js
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/indexedDB/test/unit/test_sandbox.js')
-rw-r--r--dom/indexedDB/test/unit/test_sandbox.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_sandbox.js b/dom/indexedDB/test/unit/test_sandbox.js
new file mode 100644
index 000000000..bcd4cad51
--- /dev/null
+++ b/dom/indexedDB/test/unit/test_sandbox.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function exerciseInterface() {
+ function DB(name, store) {
+ this.name = name;
+ this.store = store;
+ this._db = this._create();
+ }
+
+ DB.prototype = {
+ _create: function() {
+ var op = indexedDB.open(this.name);
+ op.onupgradeneeded = e => {
+ var db = e.target.result;
+ db.createObjectStore(this.store);
+ };
+ return new Promise(resolve => {
+ op.onsuccess = e => resolve(e.target.result);
+ });
+ },
+
+ _result: function(tx, op) {
+ return new Promise((resolve, reject) => {
+ op.onsuccess = e => resolve(e.target.result);
+ op.onerror = () => reject(op.error);
+ tx.onabort = () => reject(tx.error);
+ });
+ },
+
+ get: function(k) {
+ return this._db.then(db => {
+ var tx = db.transaction(this.store, 'readonly');
+ var store = tx.objectStore(this.store);
+ return this._result(tx, store.get(k));
+ });
+ },
+
+ add: function(k, v) {
+ return this._db.then(db => {
+ var tx = db.transaction(this.store, 'readwrite');
+ var store = tx.objectStore(this.store);
+ return this._result(tx, store.add(v, k));
+ });
+ }
+ };
+
+ var db = new DB('data', 'base');
+ return db.add('x', [ 10, {} ])
+ .then(_ => db.get('x'))
+ .then(x => {
+ equal(x.length, 2);
+ equal(x[0], 10);
+ equal(typeof x[1], 'object');
+ equal(Object.keys(x[1]).length, 0);
+ });
+}
+
+function run_test() {
+ do_get_profile();
+
+ let Cu = Components.utils;
+ let sb = new Cu.Sandbox('https://www.example.com',
+ { wantGlobalProperties: ['indexedDB'] });
+
+ sb.equal = equal;
+ var innerPromise = new Promise((resolve, reject) => {
+ sb.test_done = resolve;
+ sb.test_error = reject;
+ });
+ Cu.evalInSandbox('(' + exerciseInterface.toSource() + ')()' +
+ '.then(test_done, test_error);', sb);
+
+ Cu.importGlobalProperties(['indexedDB']);
+ do_test_pending();
+ Promise.all([innerPromise, exerciseInterface()])
+ .then(do_test_finished);
+}