4 <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>
8 if (window.layoutTestController) {
9 layoutTestController.dumpAsText();
10 layoutTestController.waitUntilDone();
13 function createFrame(id, parent) {
14 var iframe = document.createElement('iframe');
17 parent.contentDocument.body.appendChild(iframe);
19 document.body.appendChild(iframe);
20 if (!iframe.contentDocument.body)
21 iframe.contentDocument.appendChild(iframe.contentDocument.createElement('body'));
22 iframe.contentDocument.body.appendChild(iframe.contentDocument.createTextNode(id));
23 iframe.contentDocument.body.appendChild(iframe.contentDocument.createElement('br'));
24 iframe.contentWindow.onbeforeunload = function () { fired(iframe.contentWindow, id); return null; }
25 iframe.style.width = '70%';
26 iframe.style.height = '40%';
30 function log(message) {
31 var log = document.getElementById('log');
32 log.innerHTML += message + '\n';
35 var expectedOrder = ['parent', 'a', 'c'];
38 function fired(contentWindow, id) {
39 if (expectedOrder[i] == id)
40 log('PASS: fired on ' + id);
42 log('FAIL: fired on ' + id + ' but expected on ' + expectedOrder[i]);
45 if (contentWindow == a.contentWindow) {
46 b.parentNode.removeChild(b);
47 createFrame('d', container);
51 var container = createFrame('parent');
52 var a = createFrame('a', container);
53 var b = createFrame('b', container);
54 var c = createFrame('c', container);
56 container.onload = function () {
57 if (i == expectedOrder.length)
60 log('Received ' + i + ' events but expected ' + expectedOrder.length);
61 if (window.layoutTestController)
62 layoutTestController.notifyDone();
64 container.src = 'resources/before-unload-in-subframe-destination.html';