content/base/test/test_bug337631.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug337631.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=337631
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 337631</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=337631">Mozilla Bug 337631</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content">
    1.18 +  
    1.19 +<a href="foo" id="test4">foo</a>
    1.20 +<input id="test1" value="test">
    1.21 +<p id="test2">adsf<a href="#" id="test3">asdf</a><input id="test5"></p>
    1.22 +
    1.23 +</div>
    1.24 +<pre id="test">
    1.25 +<script class="testbody" type="text/javascript">
    1.26 +
    1.27 +/** Test for Bug 337631 **/
    1.28 +
    1.29 +function getActiveElement()
    1.30 +{
    1.31 +  var rv;
    1.32 +
    1.33 +  var el = document.activeElement;
    1.34 +  if (!el) {
    1.35 +    rv = "none";
    1.36 +    return rv;
    1.37 +  }
    1.38 +
    1.39 +  if (el && el != document.documentElement) {
    1.40 +    var nt;
    1.41 +    try {
    1.42 +      nt = el.nodeType;
    1.43 +    } catch (e) {
    1.44 +      rv = "[no permission]";
    1.45 +      return rv;
    1.46 +    }
    1.47 +    if (!nt) {
    1.48 +      rv = "[unknown]";
    1.49 +    } else if (nt == 1) {
    1.50 +      rv = el.tagName;
    1.51 +    } else if (nt == 3) {
    1.52 +      rv = "textnode"
    1.53 +    } else {
    1.54 +      rv = nt;
    1.55 +    }
    1.56 +
    1.57 +    el = el.parentNode;
    1.58 +    while (el && el != document.documentElement) {
    1.59 +      rv += " in ";
    1.60 +      try {
    1.61 +        nt = el.nodeType;
    1.62 +      } catch (e) {
    1.63 +        rv += "[no permission]";
    1.64 +        return rv;
    1.65 +      }
    1.66 +      if (!nt) {
    1.67 +        rv += "[unknown]";
    1.68 +      } else if (nt == 1) {
    1.69 +        rv += el.tagName;
    1.70 +      } else if (nt == 3) {
    1.71 +        rv += "textnode"
    1.72 +      } else {
    1.73 +        rv += nt;
    1.74 +      }
    1.75 +
    1.76 +      el = el.parentNode;
    1.77 +    }
    1.78 +  }
    1.79 +
    1.80 +  return rv;
    1.81 +}
    1.82 +
    1.83 +$('test1').focus();
    1.84 +is(getActiveElement(), "INPUT in DIV in BODY", "getActiveElement tests");
    1.85 +
    1.86 +$('test2').focus();
    1.87 +is(getActiveElement(), "INPUT in DIV in BODY", "getActiveElement tests");
    1.88 +
    1.89 +$('test3').focus();
    1.90 +is(getActiveElement(), "A in P in DIV in BODY", "getActiveElement tests");
    1.91 +
    1.92 +$('test4').focus();
    1.93 +is(getActiveElement(), "A in DIV in BODY", "getActiveElement tests");
    1.94 +
    1.95 +$('test5').focus();
    1.96 +is(getActiveElement(), "INPUT in P in DIV in BODY", "getActiveElement tests");
    1.97 +
    1.98 +</script>
    1.99 +</pre>
   1.100 +</body>
   1.101 +</html>
   1.102 +

mercurial