2010-12-16 00:20:57 +03:00
|
|
|
<!--
|
|
|
|
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) {
|
2013-09-28 15:25:46 +04:00
|
|
|
ok(false, "indexedDB error, code " + event.target.error.name);
|
2010-12-16 00:20:57 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
window.onerror = function() {
|
|
|
|
return false;
|
2010-12-16 00:20:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
function testSteps() {
|
2014-11-28 11:44:12 +03:00
|
|
|
window.parent.SpecialPowers.addPermission("indexedDB", true, document);
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
// Test 1: Throwing an exception in an upgradeneeded handler should
|
|
|
|
// abort the versionchange transaction and fire an error at the request.
|
2012-06-29 20:48:35 +04:00
|
|
|
let request = indexedDB.open(window.location.pathname, 1);
|
2012-06-29 20:48:34 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2011-10-20 20:10:56 +04:00
|
|
|
request.onupgradeneeded = function () {
|
2012-06-29 20:48:34 +04:00
|
|
|
let transaction = request.transaction;
|
|
|
|
transaction.oncomplete = unexpectedSuccessHandler;
|
|
|
|
transaction.onabort = grabEventAndContinueHandler
|
2011-10-20 20:10:56 +04:00
|
|
|
throw "STOP";
|
|
|
|
};
|
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
let event = yield undefined;
|
2012-06-29 20:48:34 +04:00
|
|
|
is(event.type, "abort",
|
|
|
|
"Throwing during an upgradeneeded event should abort the transaction.");
|
2012-06-29 20:48:34 +04:00
|
|
|
is(event.target.error.name, "AbortError", "Got AbortError object");
|
2012-06-29 20:48:34 +04:00
|
|
|
|
|
|
|
request.onerror = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-10-20 20:10:56 +04:00
|
|
|
|
|
|
|
is(event.type, "error",
|
|
|
|
"Throwing during an upgradeneeded event should fire an error.");
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
// Test 2: Throwing during a request's success handler should abort the
|
|
|
|
// transaction.
|
2014-09-16 03:30:47 +04:00
|
|
|
request = indexedDB.open(window.location.pathname, 1);
|
2012-06-29 20:48:34 +04:00
|
|
|
request.onerror = errorHandler;
|
2011-10-20 20:10:56 +04:00
|
|
|
request.onblocked = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2012-06-29 20:48:34 +04:00
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2011-10-20 20:10:56 +04:00
|
|
|
let openrequest = request;
|
2014-09-16 03:30:47 +04:00
|
|
|
event = yield undefined;
|
2010-12-16 00:20:57 +03:00
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
let db = event.target.result;
|
2010-12-16 00:20:57 +03:00
|
|
|
db.onerror = function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
event.target.transaction.oncomplete = unexpectedSuccessHandler;
|
|
|
|
event.target.transaction.onabort = grabEventAndContinueHandler;
|
2010-12-16 00:20:57 +03:00
|
|
|
|
2011-10-20 20:10:56 +04:00
|
|
|
is(db.version, 1, "Correct version");
|
2010-12-16 00:20:57 +03:00
|
|
|
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
|
|
|
|
2010-12-21 19:02:01 +03:00
|
|
|
let objectStore = db.createObjectStore("foo");
|
2010-12-16 00:20:57 +03:00
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2010-12-16 00:20:57 +03:00
|
|
|
|
|
|
|
is(event.type, "abort", "Got transaction abort event");
|
2012-06-29 20:48:34 +04:00
|
|
|
is(event.target.error.name, "AbortError", "Got AbortError object");
|
2012-06-29 20:48:34 +04:00
|
|
|
openrequest.onerror = grabEventAndContinueHandler;
|
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-29 20:48:34 +04:00
|
|
|
|
|
|
|
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.
|
2014-09-16 03:30:47 +04:00
|
|
|
request = indexedDB.open(window.location.pathname, 1);
|
2012-06-29 20:48:34 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onblocked = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
2014-09-16 03:30:47 +04:00
|
|
|
openrequest = request;
|
|
|
|
event = yield undefined;
|
2012-06-29 20:48:34 +04:00
|
|
|
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
|
2014-09-16 03:30:47 +04:00
|
|
|
db = event.target.result;
|
2012-06-29 20:48:34 +04:00
|
|
|
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");
|
|
|
|
|
2014-09-16 03:30:47 +04:00
|
|
|
objectStore = db.createObjectStore("foo");
|
2012-06-29 20:48:34 +04:00
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-29 20:48:34 +04:00
|
|
|
|
|
|
|
is(event.type, "abort", "Got transaction abort event");
|
2012-06-29 20:48:34 +04:00
|
|
|
is(event.target.error.name, "AbortError", "Got AbortError object");
|
2012-06-29 20:48:34 +04:00
|
|
|
openrequest.onerror = grabEventAndContinueHandler;
|
2010-12-16 00:20:57 +03:00
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2011-10-20 20:10:56 +04:00
|
|
|
|
|
|
|
is(event.type, "error", "Got IDBOpenDBRequest error event");
|
|
|
|
is(event.target, openrequest, "Right event target");
|
2012-06-25 23:15:17 +04:00
|
|
|
is(event.target.error.name, "AbortError", "Right error name");
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2010-12-16 00:20:57 +03:00
|
|
|
finishTest();
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2010-12-16 00:20:57 +03:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="testGenerator.next();"></body>
|
|
|
|
|
|
|
|
</html>
|