blob: 92fa36a096fcbb9097c487eeeb025dc1961c794e [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script>
description('Tests inert node focusing across frames and iframes.');
if (window.testRunner)
testRunner.waitUntilDone();
</script>
</head>
<iframe height=400 width=600 id="main-iframe">
<frameset rows="*" cols="50,50">
<frame src="resources/inert-focus-in-frames-frame1.html">
<frame src='data:text/html,<div id="frame2-div" class="target" tabindex="0">Hello</div>'>
</frameset>
</iframe>
<script>
framesLoaded = 0;
numFrames = 4;
function frameLoaded() {
framesLoaded++;
if (framesLoaded == numFrames)
test();
}
function testFocus(element, expectFocus) {
focusedElement = null;
element.addEventListener('focus', function() { focusedElement = element; }, false);
element.focus();
expected = expectFocus ? "true" : "false"
theElement = element;
shouldBe('"' + element.id + '"; focusedElement === theElement', expected);
}
function test() {
debug('Opening a modal dialog in frame1. It blocks other nodes in its document.');
var frame1 = mainIframe.contentWindow.frames[0].document;
frame1.querySelector('dialog').showModal();
testFocus(frame1.querySelector('.target'), false);
var iframe = frame1.querySelector('iframe').contentDocument;
testFocus(iframe.querySelector('.target'), false);
debug('Even a modal dialog in the iframe is blocked by the modal dialog in the parent frame1.');
iframe.querySelector('dialog').showModal();
testFocus(iframe.querySelector('button'), false);
debug('A modal dialog does not block nodes in a sibling frame.');
var frame2 = mainIframe.contentWindow.frames[1].document;
testFocus(frame2.querySelector('.target'), true);
debug('Closing the dialog in frame1. The modal dialog in the iframe does not block nodes in its parent.');
frame1.querySelector('dialog').close();
testFocus(iframe.querySelector('.target'), false);
testFocus(frame1.querySelector('.target'), true);
if (window.testRunner)
testRunner.notifyDone();
}
var mainIframe = document.getElementById('main-iframe');
mainIframe.contentDocument.write(mainIframe.textContent);
mainIframe.contentDocument.close();
mainIframe.contentWindow.frames[1].window.onload = frameLoaded;
window.onload = frameLoaded;
</script>
</body>
</html>