|
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"> |
|
15 |
|
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> |
|
19 |
|
20 </div> |
|
21 <pre id="test"> |
|
22 <script class="testbody" type="text/javascript"> |
|
23 |
|
24 /** Test for Bug 337631 **/ |
|
25 |
|
26 function getActiveElement() |
|
27 { |
|
28 var rv; |
|
29 |
|
30 var el = document.activeElement; |
|
31 if (!el) { |
|
32 rv = "none"; |
|
33 return rv; |
|
34 } |
|
35 |
|
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 } |
|
53 |
|
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 } |
|
72 |
|
73 el = el.parentNode; |
|
74 } |
|
75 } |
|
76 |
|
77 return rv; |
|
78 } |
|
79 |
|
80 $('test1').focus(); |
|
81 is(getActiveElement(), "INPUT in DIV in BODY", "getActiveElement tests"); |
|
82 |
|
83 $('test2').focus(); |
|
84 is(getActiveElement(), "INPUT in DIV in BODY", "getActiveElement tests"); |
|
85 |
|
86 $('test3').focus(); |
|
87 is(getActiveElement(), "A in P in DIV in BODY", "getActiveElement tests"); |
|
88 |
|
89 $('test4').focus(); |
|
90 is(getActiveElement(), "A in DIV in BODY", "getActiveElement tests"); |
|
91 |
|
92 $('test5').focus(); |
|
93 is(getActiveElement(), "INPUT in P in DIV in BODY", "getActiveElement tests"); |
|
94 |
|
95 </script> |
|
96 </pre> |
|
97 </body> |
|
98 </html> |
|
99 |