4 <p>This test ensures beforeunload event fires exactly once in a subframe even if the frame was adopted to a frame that appears later in the tree.</p>
8 if (window.layoutTestController) {
9 layoutTestController.dumpAsText();
10 layoutTestController.waitUntilDone();
13 function createFrame(id, parent) {
14 var iframe = document.createElement('iframe');
16 parent.contentDocument.body.appendChild(iframe);
18 document.body.appendChild(iframe);
19 iframe.contentDocument.body.appendChild(iframe.contentDocument.createTextNode(id));
20 iframe.contentDocument.body.appendChild(iframe.contentDocument.createElement('br'));
21 iframe.contentWindow.onbeforeunload = function () { fired(iframe.contentWindow, id); return null; }
22 iframe.style.width = '70%';
23 iframe.style.height = '40%';
27 function log(message) {
28 var log = document.getElementById('log');
29 log.innerHTML += message + '\n';
32 var expectedOrder = ['parent', 'a', 'adoptee', 'b'];
35 function fired(contentWindow, id) {
36 if (expectedOrder[i] == id)
37 log('PASS: fired on ' + id);
39 log('FAIL: fired on ' + id + ' but expected on ' + expectedOrder[i]);
42 if (contentWindow == adoptee.contentWindow) {
44 b.contentDocument.body.appendChild(b.contentDocument.adoptNode(adoptee));
49 var container = createFrame('parent');
50 var a = createFrame('a', container);
51 var adoptee = createFrame('adoptee', a);
52 var b = createFrame('b', container);
54 container.onload = function () {
55 if (i == expectedOrder.length)
58 log('Received ' + i + ' events but expected ' + expectedOrder.length);
59 if (window.layoutTestController)
60 layoutTestController.notifyDone();
62 container.src = 'resources/before-unload-in-subframe-destination.html';