Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / HTMLDialogElement / inert-focus-in-frames.html
blob92fa36a096fcbb9097c487eeeb025dc1961c794e
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script>
6 description('Tests inert node focusing across frames and iframes.');
7 if (window.testRunner)
8 testRunner.waitUntilDone();
9 </script>
10 </head>
11 <iframe height=400 width=600 id="main-iframe">
12 <frameset rows="*" cols="50,50">
13 <frame src="resources/inert-focus-in-frames-frame1.html">
14 <frame src='data:text/html,<div id="frame2-div" class="target" tabindex="0">Hello</div>'>
15 </frameset>
16 </iframe>
17 <script>
18 framesLoaded = 0;
19 numFrames = 4;
21 function frameLoaded() {
22 framesLoaded++;
23 if (framesLoaded == numFrames)
24 test();
27 function testFocus(element, expectFocus) {
28 focusedElement = null;
29 element.addEventListener('focus', function() { focusedElement = element; }, false);
30 element.focus();
31 expected = expectFocus ? "true" : "false"
32 theElement = element;
33 shouldBe('"' + element.id + '"; focusedElement === theElement', expected);
36 function test() {
37 debug('Opening a modal dialog in frame1. It blocks other nodes in its document.');
38 var frame1 = mainIframe.contentWindow.frames[0].document;
39 frame1.querySelector('dialog').showModal();
41 testFocus(frame1.querySelector('.target'), false);
42 var iframe = frame1.querySelector('iframe').contentDocument;
43 testFocus(iframe.querySelector('.target'), false);
45 debug('Even a modal dialog in the iframe is blocked by the modal dialog in the parent frame1.');
46 iframe.querySelector('dialog').showModal();
47 testFocus(iframe.querySelector('button'), false);
49 debug('A modal dialog does not block nodes in a sibling frame.');
50 var frame2 = mainIframe.contentWindow.frames[1].document;
51 testFocus(frame2.querySelector('.target'), true);
53 debug('Closing the dialog in frame1. The modal dialog in the iframe does not block nodes in its parent.');
54 frame1.querySelector('dialog').close();
55 testFocus(iframe.querySelector('.target'), false);
56 testFocus(frame1.querySelector('.target'), true);
58 if (window.testRunner)
59 testRunner.notifyDone();
62 var mainIframe = document.getElementById('main-iframe');
63 mainIframe.contentDocument.write(mainIframe.textContent);
64 mainIframe.contentDocument.close();
66 mainIframe.contentWindow.frames[1].window.onload = frameLoaded;
68 window.onload = frameLoaded;
69 </script>
70 </body>
71 </html>