summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/exceptions_in_events_iframe.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/indexedDB/test/exceptions_in_events_iframe.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/indexedDB/test/exceptions_in_events_iframe.html')
-rw-r--r--dom/indexedDB/test/exceptions_in_events_iframe.html182
1 files changed, 182 insertions, 0 deletions
diff --git a/dom/indexedDB/test/exceptions_in_events_iframe.html b/dom/indexedDB/test/exceptions_in_events_iframe.html
new file mode 100644
index 000000000..e8002d56c
--- /dev/null
+++ b/dom/indexedDB/test/exceptions_in_events_iframe.html
@@ -0,0 +1,182 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+ <title>Indexed Database Property Test</title>
+
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+
+ <script type="text/javascript;version=1.7">
+ let testGenerator = testSteps();
+
+ function ok(val, message) {
+ val = val ? "true" : "false";
+ window.parent.postMessage("SimpleTest.ok(" + val + ", '" + message +
+ "');", "*");
+ }
+
+ function is(a, b, message) {
+ ok(a == b, message);
+ }
+
+ function grabEventAndContinueHandler(event) {
+ testGenerator.send(event);
+ }
+
+ function errorHandler(event) {
+ ok(false, "indexedDB error, code " + event.target.error.name);
+ finishTest();
+ }
+
+ function unexpectedSuccessHandler(event) {
+ ok(false, "got success when it was not expected!");
+ finishTest();
+ }
+
+ function finishTest() {
+ // Let window.onerror have a chance to fire
+ setTimeout(function() {
+ setTimeout(function() {
+ testGenerator.close();
+ window.parent.postMessage("SimpleTest.finish();", "*");
+ }, 0);
+ }, 0);
+ }
+
+ window.onerror = function() {
+ return false;
+ };
+
+ function testSteps() {
+ window.parent.SpecialPowers.addPermission("indexedDB", true, document);
+
+ // Test 1: Throwing an exception in an upgradeneeded handler should
+ // abort the versionchange transaction and fire an error at the request.
+ let request = indexedDB.open(window.location.pathname, 1);
+ request.onerror = errorHandler;
+ request.onsuccess = unexpectedSuccessHandler;
+ request.onupgradeneeded = function () {
+ let transaction = request.transaction;
+ transaction.oncomplete = unexpectedSuccessHandler;
+ transaction.onabort = grabEventAndContinueHandler
+ throw "STOP";
+ };
+
+ let event = yield undefined;
+ is(event.type, "abort",
+ "Throwing during an upgradeneeded event should abort the transaction.");
+ is(event.target.error.name, "AbortError", "Got AbortError object");
+
+ request.onerror = grabEventAndContinueHandler;
+ event = yield undefined;
+
+ is(event.type, "error",
+ "Throwing during an upgradeneeded event should fire an error.");
+
+ // Test 2: Throwing during a request's success handler should abort the
+ // transaction.
+ request = indexedDB.open(window.location.pathname, 1);
+ request.onerror = errorHandler;
+ request.onblocked = errorHandler;
+ request.onupgradeneeded = grabEventAndContinueHandler;
+ request.onsuccess = unexpectedSuccessHandler;
+ let openrequest = request;
+ event = yield undefined;
+
+ request.onupgradeneeded = unexpectedSuccessHandler;
+
+ let db = event.target.result;
+ db.onerror = function(event) {
+ event.preventDefault();
+ };
+
+ event.target.transaction.oncomplete = unexpectedSuccessHandler;
+ event.target.transaction.onabort = grabEventAndContinueHandler;
+
+ is(db.version, 1, "Correct version");
+ is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
+
+ let objectStore = db.createObjectStore("foo");
+
+ is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
+ ok(db.objectStoreNames.contains("foo"), "Has correct objectStore");
+
+ request = objectStore.add({}, 1);
+ request.onsuccess = function(event) {
+ throw "foo";
+ };
+
+ event = yield undefined;
+
+ is(event.type, "abort", "Got transaction abort event");
+ is(event.target.error.name, "AbortError", "Got AbortError object");
+ openrequest.onerror = grabEventAndContinueHandler;
+
+ event = yield undefined;
+
+ is(event.type, "error", "Got IDBOpenDBRequest error event");
+ is(event.target, openrequest, "Right event target");
+ is(event.target.error.name, "AbortError", "Right error name");
+
+ // Test 3: Throwing during a request's error handler should abort the
+ // transaction, even if preventDefault is called on the error event.
+ request = indexedDB.open(window.location.pathname, 1);
+ request.onerror = errorHandler;
+ request.onblocked = errorHandler;
+ request.onupgradeneeded = grabEventAndContinueHandler;
+ request.onsuccess = unexpectedSuccessHandler;
+ openrequest = request;
+ event = yield undefined;
+
+ request.onupgradeneeded = unexpectedSuccessHandler;
+
+ db = event.target.result;
+ db.onerror = function(event) {
+ event.preventDefault();
+ };
+
+ event.target.transaction.oncomplete = unexpectedSuccessHandler;
+ event.target.transaction.onabort = grabEventAndContinueHandler;
+
+ is(db.version, 1, "Correct version");
+ is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
+
+ objectStore = db.createObjectStore("foo");
+
+ is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
+ ok(db.objectStoreNames.contains("foo"), "Has correct objectStore");
+
+ request = objectStore.add({}, 1);
+ request.onerror = errorHandler;
+ request = objectStore.add({}, 1);
+ request.onsuccess = unexpectedSuccessHandler;
+ request.onerror = function (event) {
+ event.preventDefault();
+ throw "STOP";
+ };
+
+ event = yield undefined;
+
+ is(event.type, "abort", "Got transaction abort event");
+ is(event.target.error.name, "AbortError", "Got AbortError object");
+ openrequest.onerror = grabEventAndContinueHandler;
+
+ event = yield undefined;
+
+ is(event.type, "error", "Got IDBOpenDBRequest error event");
+ is(event.target, openrequest, "Right event target");
+ is(event.target.error.name, "AbortError", "Right error name");
+
+ finishTest();
+ yield undefined;
+ }
+ </script>
+
+</head>
+
+<body onload="testGenerator.next();"></body>
+
+</html>