2010-11-10 15:26:03 -08: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;version=1.7">
|
|
|
|
|
|
|
|
let testGenerator = testSteps();
|
|
|
|
|
|
|
|
function ok(val, message) {
|
|
|
|
val = val ? "true" : "false";
|
|
|
|
window.parent.postMessage("SimpleTest.ok(" + val + ", '" + message +
|
|
|
|
"');", "*");
|
|
|
|
}
|
|
|
|
|
|
|
|
function grabEventAndContinueHandler(event) {
|
|
|
|
testGenerator.send(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function errorHandler(event) {
|
2011-01-06 22:21:36 -08:00
|
|
|
ok(false, "indexedDB error, code " + event.target.errorCode);
|
2010-11-10 15:26:03 -08:00
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest() {
|
2010-11-11 10:57:07 -08:00
|
|
|
// Let window.onerror have a chance to fire
|
|
|
|
setTimeout(function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
testGenerator.close();
|
|
|
|
ok(windowErrorCount == 1, "Good window.onerror count");
|
|
|
|
window.parent.postMessage("SimpleTest.finish();", "*");
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
2010-11-10 15:26:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const eventChain = [
|
|
|
|
"IDBRequest",
|
|
|
|
"IDBTransaction",
|
|
|
|
"IDBDatabase"
|
|
|
|
];
|
|
|
|
|
|
|
|
let captureCount = 0;
|
|
|
|
let bubbleCount = 0;
|
2010-11-11 10:57:07 -08:00
|
|
|
let atTargetCount = 0;
|
2010-11-10 15:26:03 -08:00
|
|
|
let windowErrorCount = 0;
|
|
|
|
|
|
|
|
window.onerror = function(event) {
|
|
|
|
ok(!windowErrorCount++, "Correct number of window.onerror events");
|
2010-11-10 17:49:07 -08:00
|
|
|
setTimeout(function() { testGenerator.next(); }, 0);
|
2010-11-10 15:26:03 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
function errorEventCounter(event) {
|
2011-01-06 22:21:36 -08:00
|
|
|
ok(event.type == "error", "Got an error event");
|
2010-11-10 15:26:03 -08:00
|
|
|
ok(event.target instanceof window[eventChain[0]],
|
|
|
|
"Correct event.target");
|
|
|
|
|
|
|
|
let constructor;
|
|
|
|
if (event.eventPhase == event.AT_TARGET) {
|
2010-11-11 10:57:07 -08:00
|
|
|
atTargetCount++;
|
2010-11-10 15:26:03 -08:00
|
|
|
constructor = eventChain[0];
|
|
|
|
}
|
|
|
|
else if (event.eventPhase == event.CAPTURING_PHASE) {
|
|
|
|
constructor = eventChain[eventChain.length - 1 - captureCount++];
|
|
|
|
}
|
|
|
|
else if (event.eventPhase == event.BUBBLING_PHASE) {
|
|
|
|
constructor = eventChain[++bubbleCount];
|
|
|
|
if (windowErrorCount && bubbleCount == eventChain.length - 1) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(event.currentTarget instanceof window[constructor],
|
|
|
|
"Correct event.currentTarget");
|
|
|
|
|
|
|
|
if (bubbleCount == eventChain.length - 1) {
|
|
|
|
ok(bubbleCount == captureCount,
|
|
|
|
"Got same number of calls for both phases");
|
2010-11-11 10:57:07 -08:00
|
|
|
ok(atTargetCount == 1, "Got one atTarget event");
|
2010-11-10 15:26:03 -08:00
|
|
|
|
2010-11-11 10:57:07 -08:00
|
|
|
captureCount = bubbleCount = atTargetCount = 0;
|
|
|
|
if (windowErrorCount) {
|
|
|
|
finishTest();
|
2010-11-10 15:26:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSteps() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
2011-10-06 07:51:03 -07:00
|
|
|
let uri = window.parent.SpecialPowers.getDocumentURIObject(window.document);
|
2010-11-10 15:26:03 -08:00
|
|
|
Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIPermissionManager)
|
|
|
|
.add(uri, "indexedDB",
|
|
|
|
Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
|
2011-10-20 09:10:56 -07:00
|
|
|
let request = mozIndexedDB.open(window.location.pathname, 1);
|
2010-11-10 15:26:03 -08:00
|
|
|
request.onerror = errorHandler;
|
2011-10-20 09:10:56 -07:00
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2010-11-10 15:26:03 -08:00
|
|
|
let event = yield;
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
let db = event.target.result;
|
2010-11-10 15:26:03 -08:00
|
|
|
db.onerror = errorEventCounter;
|
|
|
|
db.addEventListener("error", errorEventCounter, true);
|
|
|
|
|
2011-10-24 15:49:59 -07:00
|
|
|
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
2010-11-10 15:26:03 -08:00
|
|
|
|
2010-12-21 08:02:01 -08:00
|
|
|
db.createObjectStore("foo", { autoIncrement: true });
|
2010-11-10 15:26:03 -08:00
|
|
|
yield;
|
|
|
|
|
|
|
|
let transaction = db.transaction("foo", IDBTransaction.READ_WRITE);
|
|
|
|
transaction.addEventListener("error", errorEventCounter, false);
|
|
|
|
transaction.addEventListener("error", errorEventCounter, true);
|
|
|
|
|
|
|
|
let objectStore = transaction.objectStore("foo");
|
|
|
|
|
|
|
|
request = objectStore.add({}, 1);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
event = yield;
|
|
|
|
|
|
|
|
request = objectStore.add({}, 1);
|
|
|
|
request.onsuccess = function(event) {
|
|
|
|
ok(false, "Did not expect second add to succeed.");
|
|
|
|
};
|
|
|
|
request.onerror = errorEventCounter;
|
|
|
|
yield;
|
|
|
|
|
|
|
|
transaction = db.transaction("foo", IDBTransaction.READ_WRITE);
|
|
|
|
transaction.addEventListener("error", errorEventCounter, false);
|
|
|
|
transaction.addEventListener("error", errorEventCounter, true);
|
|
|
|
|
|
|
|
objectStore = transaction.objectStore("foo");
|
|
|
|
|
2010-12-15 13:20:57 -08:00
|
|
|
request = objectStore.add({}, 1);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
request = objectStore.add({}, 1);
|
|
|
|
request.onsuccess = function(event) {
|
2010-12-15 13:20:57 -08:00
|
|
|
ok(false, "Did not expect second add to succeed.");
|
2010-11-10 15:26:03 -08:00
|
|
|
};
|
|
|
|
request.onerror = errorEventCounter;
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="testGenerator.next();"></body>
|
|
|
|
|
|
|
|
</html>
|