summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_transaction_lifetimes.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_transaction_lifetimes.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_transaction_lifetimes.js')
-rw-r--r--dom/indexedDB/test/unit/test_transaction_lifetimes.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_transaction_lifetimes.js b/dom/indexedDB/test/unit/test_transaction_lifetimes.js
new file mode 100644
index 000000000..e42f7a218
--- /dev/null
+++ b/dom/indexedDB/test/unit/test_transaction_lifetimes.js
@@ -0,0 +1,91 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var testGenerator = testSteps();
+
+function testSteps()
+{
+ let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
+ request.onerror = errorHandler;
+ request.onupgradeneeded = grabEventAndContinueHandler;
+ request.onsuccess = unexpectedSuccessHandler;
+ let event = yield undefined;
+
+ let db = event.target.result;
+ db.onerror = errorHandler;
+
+ event.target.transaction.onerror = errorHandler;
+ event.target.transaction.oncomplete = grabEventAndContinueHandler;
+
+ let os = db.createObjectStore("foo", { autoIncrement: true });
+ let index = os.createIndex("bar", "foo.bar");
+ event = yield undefined;
+
+ is(request.transaction, event.target,
+ "request.transaction should still be set");
+
+ request.onsuccess = grabEventAndContinueHandler;
+ event = yield undefined;
+
+ is(request.transaction, null, "request.transaction should be cleared");
+
+ let transaction = db.transaction("foo", "readwrite");
+
+ os = transaction.objectStore("foo");
+ // Place a request to keep the transaction alive long enough for our
+ // executeSoon.
+ let requestComplete = false;
+
+ let wasAbleToGrabObjectStoreOutsideOfCallback = false;
+ let wasAbleToGrabIndexOutsideOfCallback = false;
+ executeSoon(function() {
+ ok(!requestComplete, "Ordering is correct.");
+ wasAbleToGrabObjectStoreOutsideOfCallback = !!transaction.objectStore("foo");
+ wasAbleToGrabIndexOutsideOfCallback =
+ !!transaction.objectStore("foo").index("bar");
+ });
+
+ request = os.add({});
+ request.onerror = errorHandler;
+ request.onsuccess = grabEventAndContinueHandler;
+
+ event = yield undefined;
+
+ requestComplete = true;
+
+ ok(wasAbleToGrabObjectStoreOutsideOfCallback,
+ "Should be able to get objectStore");
+ ok(wasAbleToGrabIndexOutsideOfCallback,
+ "Should be able to get index");
+
+ transaction.oncomplete = grabEventAndContinueHandler;
+ yield undefined;
+
+ try {
+ transaction.objectStore("foo");
+ ok(false, "Should have thrown!");
+ }
+ catch (e) {
+ ok(e instanceof DOMException, "Got database exception.");
+ is(e.name, "InvalidStateError", "Good error.");
+ is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
+ }
+
+ continueToNextStep();
+ yield undefined;
+
+ try {
+ transaction.objectStore("foo");
+ ok(false, "Should have thrown!");
+ }
+ catch (e) {
+ ok(e instanceof DOMException, "Got database exception.");
+ is(e.name, "InvalidStateError", "Good error.");
+ is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
+ }
+
+ finishTest();
+ yield undefined;
+}