Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / before-unload-remove-and-add-subframe.html
blobc9812955ac151e86fe9282be9aca04320ee64b21
1 <!DOCTYPE html>
2 <html>
3 <body>
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>
5 <pre id="log"></pre>
6 <script>
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
13 function createFrame(id, parent) {
14 var iframe = document.createElement('iframe');
15 iframe.id = id;
16 if (parent)
17 parent.contentDocument.body.appendChild(iframe);
18 else
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%';
27 return iframe;
30 function log(message) {
31 var log = document.getElementById('log');
32 log.innerHTML += message + '\n';
35 var expectedOrder = ['parent', 'a', 'c'];
36 var i = 0;
38 function fired(contentWindow, id) {
39 if (expectedOrder[i] == id)
40 log('PASS: fired on ' + id);
41 else
42 log('FAIL: fired on ' + id + ' but expected on ' + expectedOrder[i]);
43 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)
58 log('DONE');
59 else
60 log('Received ' + i + ' events but expected ' + expectedOrder.length);
61 if (window.testRunner)
62 testRunner.notifyDone();
64 container.src = 'resources/before-unload-in-subframe-destination.html';
66 </script>
67 </body>
68 </html>