gecko/dom/indexedDB/test/exceptions_in_success_events_iframe.html
Kyle Huey 72ac2e4c02 Bug 687361: Implement the new IndexedDB setVersion API. r=bent
--HG--
rename : dom/indexedDB/nsIIDBVersionChangeRequest.idl => dom/indexedDB/nsIIDBOpenDBRequest.idl
2011-10-20 12:10:56 -04:00

123 lines
3.5 KiB
HTML

<!--
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.errorCode);
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(event) {
event.preventDefault();
};
function testSteps() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
let uri = SpecialPowers.getDocumentURIObject(window.document);
Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager)
.add(uri, "indexedDB",
Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
let request = mozIndexedDB.open(window.location.pathname, 1);
request.onerror = grabEventAndContinueHandler;
request.onsuccess = errorHandler;
request.onupgradeneeded = function () {
throw "STOP";
};
let event = yield;
is(event.type, "error",
"Throwing during an upgradeneeded event should fire an error.");
ok(event.target.result instanceof IDBDatabase, "Should have a DB");
event.target.result.close();
let request = mozIndexedDB.open(window.location.pathname, 1);
request.onerror = grabEventAndContinueHandler;
request.onblocked = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
let openrequest = request;
let event = yield;
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;
is(event.type, "abort", "Got transaction abort event");
event = yield;
is(event.type, "error", "Got IDBOpenDBRequest error event");
is(event.target, openrequest, "Right event target");
finishTest();
yield;
}
</script>
</head>
<body onload="testGenerator.next();"></body>
</html>