Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / before-unload-adopt-within-subframes.html
blobc511e25850b0b97e2a4e09c9cdaacd7b64bb28e7
1 <!DOCTYPE html>
2 <html>
3 <body>
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>
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 if (parent)
16 parent.contentDocument.body.appendChild(iframe);
17 else
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%';
24 return iframe;
27 function log(message) {
28 var log = document.getElementById('log');
29 log.innerHTML += message + '\n';
32 var expectedOrder = ['parent', 'a', 'adoptee', 'b'];
33 var i = 0;
35 function fired(contentWindow, id) {
36 if (expectedOrder[i] == id)
37 log('PASS: fired on ' + id);
38 else
39 log('FAIL: fired on ' + id + ' but expected on ' + expectedOrder[i]);
40 i++;
42 if (contentWindow == adoptee.contentWindow) {
43 log('adopting');
44 b.contentDocument.body.appendChild(b.contentDocument.adoptNode(adoptee));
45 log('adopted');
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)
56 log('DONE');
57 else
58 log('Received ' + i + ' events but expected ' + expectedOrder.length);
59 if (window.testRunner)
60 testRunner.notifyDone();
62 container.src = 'resources/before-unload-in-subframe-destination.html';
64 </script>
65 </body>
66 </html>