Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=337631
5 -->
6 <head>
7 <title>Test for Bug 337631</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=337631">Mozilla Bug 337631</a>
13 <p id="display"></p>
14 <div id="content">
16 <a href="foo" id="test4">foo</a>
17 <input id="test1" value="test">
18 <p id="test2">adsf<a href="#" id="test3">asdf</a><input id="test5"></p>
20 </div>
21 <pre id="test">
22 <script class="testbody" type="text/javascript">
24 /** Test for Bug 337631 **/
26 function getActiveElement()
27 {
28 var rv;
30 var el = document.activeElement;
31 if (!el) {
32 rv = "none";
33 return rv;
34 }
36 if (el && el != document.documentElement) {
37 var nt;
38 try {
39 nt = el.nodeType;
40 } catch (e) {
41 rv = "[no permission]";
42 return rv;
43 }
44 if (!nt) {
45 rv = "[unknown]";
46 } else if (nt == 1) {
47 rv = el.tagName;
48 } else if (nt == 3) {
49 rv = "textnode"
50 } else {
51 rv = nt;
52 }
54 el = el.parentNode;
55 while (el && el != document.documentElement) {
56 rv += " in ";
57 try {
58 nt = el.nodeType;
59 } catch (e) {
60 rv += "[no permission]";
61 return rv;
62 }
63 if (!nt) {
64 rv += "[unknown]";
65 } else if (nt == 1) {
66 rv += el.tagName;
67 } else if (nt == 3) {
68 rv += "textnode"
69 } else {
70 rv += nt;
71 }
73 el = el.parentNode;
74 }
75 }
77 return rv;
78 }
80 $('test1').focus();
81 is(getActiveElement(), "INPUT in DIV in BODY", "getActiveElement tests");
83 $('test2').focus();
84 is(getActiveElement(), "INPUT in DIV in BODY", "getActiveElement tests");
86 $('test3').focus();
87 is(getActiveElement(), "A in P in DIV in BODY", "getActiveElement tests");
89 $('test4').focus();
90 is(getActiveElement(), "A in DIV in BODY", "getActiveElement tests");
92 $('test5').focus();
93 is(getActiveElement(), "INPUT in P in DIV in BODY", "getActiveElement tests");
95 </script>
96 </pre>
97 </body>
98 </html>