69 lines
2.1 KiB
HTML
69 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
<p>This test ensures beforeunload event does not fire for subframes that has been removed from the DOM within a beforeunload event handler. Also ensures the event doesn't fire for subframes added within a beforeunload event handler. The latter behavior matches MSIE.</p>
|
|
<pre id="log"></pre>
|
|
<script>
|
|
|
|
if (window.testRunner) {
|
|
testRunner.dumpAsText();
|
|
testRunner.waitUntilDone();
|
|
}
|
|
|
|
function createFrame(id, parent) {
|
|
var iframe = document.createElement('iframe');
|
|
iframe.id = id;
|
|
if (parent)
|
|
parent.contentDocument.body.appendChild(iframe);
|
|
else
|
|
document.body.appendChild(iframe);
|
|
if (!iframe.contentDocument.body)
|
|
iframe.contentDocument.appendChild(iframe.contentDocument.createElement('body'));
|
|
iframe.contentDocument.body.appendChild(iframe.contentDocument.createTextNode(id));
|
|
iframe.contentDocument.body.appendChild(iframe.contentDocument.createElement('br'));
|
|
iframe.contentWindow.onbeforeunload = function () { fired(iframe.contentWindow, id); return null; }
|
|
iframe.style.width = '70%';
|
|
iframe.style.height = '40%';
|
|
return iframe;
|
|
}
|
|
|
|
function log(message) {
|
|
var log = document.getElementById('log');
|
|
log.innerHTML += message + '\n';
|
|
}
|
|
|
|
var expectedOrder = ['parent', 'a', 'c'];
|
|
var i = 0;
|
|
|
|
function fired(contentWindow, id) {
|
|
if (expectedOrder[i] == id)
|
|
log('PASS: fired on ' + id);
|
|
else
|
|
log('FAIL: fired on ' + id + ' but expected on ' + expectedOrder[i]);
|
|
i++;
|
|
|
|
if (contentWindow == a.contentWindow) {
|
|
b.parentNode.removeChild(b);
|
|
createFrame('d', container);
|
|
}
|
|
}
|
|
|
|
var container = createFrame('parent');
|
|
var a = createFrame('a', container);
|
|
var b = createFrame('b', container);
|
|
var c = createFrame('c', container);
|
|
|
|
container.onload = function () {
|
|
if (i == expectedOrder.length)
|
|
log('DONE');
|
|
else
|
|
log('Received ' + i + ' events but expected ' + expectedOrder.length);
|
|
if (window.testRunner)
|
|
testRunner.notifyDone();
|
|
}
|
|
container.src = 'resources/before-unload-in-subframe-destination.html';
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|