gecko/dom/indexedDB/test/event_propagation_iframe.html

160 lines
4.8 KiB
HTML
Raw Normal View History

<!--
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) {
ok(false, "indexedDB error (" + event.code + "): " + event.message);
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);
}
const eventChain = [
"IDBRequest",
"IDBTransaction",
"IDBDatabase"
];
let captureCount = 0;
let bubbleCount = 0;
2010-11-11 10:57:07 -08:00
let atTargetCount = 0;
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);
};
function errorEventCounter(event) {
ok(event instanceof IDBErrorEvent, "Got an error event");
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++;
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-11 10:57:07 -08:00
captureCount = bubbleCount = atTargetCount = 0;
if (windowErrorCount) {
finishTest();
}
}
}
function testSteps() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
let uri = window.document.documentURIObject;
Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager)
.add(uri, "indexedDB",
Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
let request = moz_indexedDB.open(window.location.pathname);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let db = event.result;
db.onerror = errorEventCounter;
db.addEventListener("error", errorEventCounter, true);
request = db.setVersion("1");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
event.transaction.oncomplete = grabEventAndContinueHandler;
db.createObjectStore("foo", "", true);
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");
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;
}
</script>
</head>
<body onload="testGenerator.next();"></body>
</html>