summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_traffic_jam.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/indexedDB/test/unit/test_traffic_jam.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/indexedDB/test/unit/test_traffic_jam.js')
-rw-r--r--dom/indexedDB/test/unit/test_traffic_jam.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_traffic_jam.js b/dom/indexedDB/test/unit/test_traffic_jam.js
new file mode 100644
index 0000000000..6505b66964
--- /dev/null
+++ b/dom/indexedDB/test/unit/test_traffic_jam.js
@@ -0,0 +1,99 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* exported testGenerator */
+var testGenerator = testSteps();
+
+function* testSteps() {
+ const name = this.window ? window.location.pathname : "Splendid Test";
+
+ let requests = [];
+ function doOpen(
+ version,
+ errorCallback,
+ upgradeNeededCallback,
+ successCallback
+ ) {
+ let request = indexedDB.open(name, version);
+ request.onerror = errorCallback;
+ request.onupgradeneeded = upgradeNeededCallback;
+ request.onsuccess = successCallback;
+ requests.push(request);
+ }
+
+ doOpen(
+ 1,
+ errorHandler,
+ grabEventAndContinueHandler,
+ grabEventAndContinueHandler
+ );
+ doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
+
+ let event = yield undefined;
+ is(event.type, "upgradeneeded", "expect an upgradeneeded event");
+ is(event.target, requests[0], "fired at the right request");
+
+ let db = event.target.result;
+ db.createObjectStore("foo");
+
+ doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
+ doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
+ doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
+
+ event.target.transaction.oncomplete = grabEventAndContinueHandler;
+
+ event = yield undefined;
+ is(event.type, "complete", "expect a complete event");
+ is(
+ event.target,
+ requests[0].transaction,
+ "expect it to be fired at the transaction"
+ );
+
+ event = yield undefined;
+ is(event.type, "success", "expect a success event");
+ is(event.target, requests[0], "fired at the right request");
+ event.target.result.close();
+
+ requests[1].onupgradeneeded = grabEventAndContinueHandler;
+
+ event = yield undefined;
+ is(event.type, "upgradeneeded", "expect an upgradeneeded event");
+ is(event.target, requests[1], "fired at the right request");
+
+ requests[1].onsuccess = grabEventAndContinueHandler;
+
+ event = yield undefined;
+ is(event.type, "success", "expect a success event");
+ is(event.target, requests[1], "fired at the right request");
+ event.target.result.close();
+
+ requests[2].onupgradeneeded = grabEventAndContinueHandler;
+
+ event = yield undefined;
+ is(event.type, "upgradeneeded", "expect an upgradeneeded event");
+ is(event.target, requests[2], "fired at the right request");
+
+ requests[2].onsuccess = grabEventAndContinueHandler;
+
+ event = yield undefined;
+ is(event.type, "success", "expect a success event");
+ is(event.target, requests[2], "fired at the right request");
+ event.target.result.close();
+
+ requests[3].onerror = null;
+ requests[3].addEventListener("error", new ExpectError("VersionError", true));
+
+ event = yield undefined;
+
+ requests[4].onsuccess = grabEventAndContinueHandler;
+
+ event = yield undefined;
+ is(event.type, "success", "expect a success event");
+ is(event.target, requests[4], "fired at the right request");
+ event.target.result.close();
+
+ finishTest();
+}