<!DOCTYPE html>
<html>
<head>
  <title>Document::nodesFromRect : basic text nodes and links test - bug 47795</title>
  <style type="text/css"> @import "resources/nodesFromRect.css"; </style>
  <script src="../../../resources/js-test-pre.js"></script>
  <script src="resources/nodesFromRect.js"></script>
  <script type="application/javascript">
    function runTest()
    {
      var e = {};

      // Set up shortcut access to elements
      e['html'] = document.getElementsByTagName("html")[0];
      ['p1', 'a1', 'a2', 'a3', 'body'].forEach(function(a) {
        e[a] = document.getElementById(a);
      });

      window.scrollTo(0, 0);

      // Area with links and text nodes:
      var centerA1 = getCenterFor(e.a1);
      var centerA2 = getCenterFor(e.a2);
      var centerA3 = getCenterFor(e.a3);
      var topP1 = getTopFor(e.p1);
      var topA1 = getTopFor(e.a1);
      var centerText = { x : (centerA2.x + centerA1.x) / 2, y : centerA1.y }; //text node between a1 and a2

      check(centerA1.x, centerA1.y, 0, 0, 0, 0, [e.a1.firstChild]);
      check(centerA1.x, centerA1.y, topA1.y - topP1.y, 0, 0, 0, [e.a1.firstChild, e.a1, e.p1]);

      check(centerA1.x, centerA1.y, 0, 0, centerA3.y - centerA1.y, 0, [e.a3.firstChild, e.a3, e.p1, e.a1.firstChild, e.a1]);
      check(centerA1.x, centerA1.y, 0, centerText.x - centerA1.x, 0, 0, [e.p1.childNodes[2], e.a1.firstChild, e.a1, e.p1]);
      check(centerA1.x, centerA1.y, 0, centerA2.x - centerA1.x, 0, 0, [e.a2.firstChild, e.a2, e.p1.childNodes[2], e.a1.firstChild, e.a1, e.p1]);
      check(centerA1.x, centerA1.y, 0, centerA2.x - centerA1.x, centerA3.y - centerA1.y, 0, [e.a3.firstChild, e.a3, e.p1, e.a2.firstChild, e.a2, e.p1.childNodes[2], e.a1.firstChild, e.a1]);

    }
    window.onload = runTest;
  </script>
</head>
<body id="body">
  <p id="p1">
    <a href="#" id="a1">A</a> / <a href="#" id="a2">B</a><br/><a href="#" id="a3">C</a>
  </p>

  <span id="console"></span>
  <script src="../../../resources/js-test-post.js"></script>
</body>
</html>
