document-level-apis.html (1540B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>HTML Test: focus - document-level APIs</title> 4 <link rel="author" title="Intel" href="http://www.intel.com/"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#document-level-focus-apis"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <input id="test"> 10 <script> 11 12 test(function () { 13 assert_equals(document.activeElement, document.body, "The active element should be the body element."); 14 }, "The body element must be the active element if no element is focused"); 15 16 test(function () { 17 document.getElementById("test").focus(); 18 assert_equals(document.activeElement, document.getElementById("test"), "The active element should be the input element."); 19 }, "The element must be the active element if it is focused"); 20 21 function frame_load () { 22 test(function () { 23 document.getElementById("fr").contentDocument.getElementById("ipt").focus(); 24 assert_equals(document.activeElement, document.getElementById("fr"), "The active element should be the iframe element."); 25 }, "When a child browsing context is focused, its browsing context container is also focused"); 26 } 27 28 test(function () { 29 var doc = document.implementation.createHTMLDocument("test"); 30 assert_false(doc.hasFocus(), "The hasFocus() method should return false."); 31 }, "The hasFocus() method must return false if the Document has no browsing context"); 32 33 </script> 34 <iframe id="fr" src="support/test.html" onload="frame_load()"></iframe>