<!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];
      ['a1', 'iframe1', 'body'].forEach(function(a) {
        e[a] = document.getElementById(a);
      });

      window.scrollTo(0, 0);

      var a1Center = getCenterFor(e.a1);
      var iframe1Center = getCenterFor(e.iframe1);

      // Elements inside iframe shouldn't be returned:
      check(iframe1Center.x, iframe1Center.y, 0, 0, 0, 0, [e.iframe1]);
      check(iframe1Center.x, iframe1Center.y, 10, 10, 10, 10, [e.iframe1]);

      // NOTE: e.body.childNodes[2] is a TextNode whose content is ' '.
      check(a1Center.x, a1Center.y, 0, e.iframe1.getBoundingClientRect().left - a1Center.x, 0, 0, [e.iframe1, e.body.childNodes[2],  e.a1.firstChild, e.a1, e.body]);

      // Testing nodesFromRect in an inner node.
      var innerDocument = window.frames[0].document;
      var div = innerDocument.getElementsByTagName('div')[0];
      var p = innerDocument.getElementsByTagName('p')[0];
      var body = innerDocument.getElementsByTagName('body')[0];
      var divCenter = getCenterFor(div);
      var divBottom = getBottomFor(div);
      var pCenter = getCenterFor(p);
      check(divCenter.x, divCenter.y, 0, 0, 0, 0, [div], innerDocument);
      check(divCenter.x, divCenter.y, 0, 0, divBottom.y - divCenter.y, 0, [div, body], innerDocument);
      check(divCenter.x, divCenter.y, 0, 0, pCenter.y - divCenter.y, 0, [p, div, body], innerDocument);
    }
    window.onload = runTest;
  </script>
</head>
<body id="body">
  <a id="a1" href="#">A</a>
  <iframe id="iframe1" src="data:text/html,<div>div</div><p>p</p>"></iframe>
  
  <div id="console"></div>
  <script src="../../../resources/js-test-post.js"></script>
</body>
</html>
