devtools/server/tests/mochitest/test_inspector_getOffsetParent.html
author Stanford Lockhart <lockhart@cs.dal.ca>
Tue, 21 Mar 2017 21:59:22 -0300
changeset 349387 4e4817e5b6d488f9e43946577f7fdad861927973
parent 349185 c67e5d94d6c3f8eeb431ff964c73471cb86016cf
child 349188 7145d2ae3fab42d776cad260afdb5ec6e3e23f9b
permissions -rw-r--r--
Bug 1345119 - Part 4: Test test_inspector_getOffsetParent for new actor methods. r=pbro MozReview-Commit-ID: AqSOEdEZKIy

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1345119
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1345119</title>

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  <script type="application/javascript" src="inspector-helpers.js"></script>
  <script type="application/javascript">
const inspector = require("devtools/shared/fronts/inspector");

window.onload = function() {
  SimpleTest.waitForExplicitFinish();
  runNextTest();
}

var gWalker;
var gBodyNode;

addTest(function setup() {
  let url = document.getElementById("inspectorContent").href;
  attachURL(url, function(err, client, tab, doc) {
    let {InspectorFront} = require("devtools/shared/fronts/inspector");
    let inspector = InspectorFront(client, tab);

    promiseDone(inspector.getWalker().then(walker => {
      gWalker = walker;
      return gWalker.querySelector(gWalker.rootNode, "body");
    }).then(node => {
      gBodyNode = node;
    }).then(runNextTest));
  });
});

addTest(function() {
  info("Try to get the offset parent for a node that is absolutely positioned inside a relative node");
  gWalker.querySelector(gWalker.rootNode, "#absolute_child").then(node => {
    return gWalker.getOffsetParent(node);
  }).then(offsetParent => {
    ok(offsetParent, "The node has an offset parent");
    gWalker.querySelector(gWalker.rootNode, "#relative_parent").then(parent => {
      ok(offsetParent === parent, "The offset parent is the correct node");
      runNextTest();
    });
  });
});

addTest(function() {
  info("Try to get the offset parent for a node that is absolutely positioned outside a relative node");
  gWalker.querySelector(gWalker.rootNode, "#no_parent").then(node => {
    return gWalker.getOffsetParent(node);
  }).then(offsetParent => {
    ok(offsetParent === gBodyNode, "The node's offset parent is the body");
    runNextTest();
  });
});

addTest(function() {
  info("Try to get the offset parent for a relatively positioned node");
  gWalker.querySelector(gWalker.rootNode, "#relative_parent").then(node => {
    return gWalker.getOffsetParent(node);
  }).then(offsetParent => {
    ok(offsetParent === gBodyNode, "The node's offset parent is the body");
    runNextTest();
  });
});

addTest(function() {
  info("Try to get the offset parent for a statically positioned node");
  gWalker.querySelector(gWalker.rootNode, "#static").then(node => {
    return gWalker.getOffsetParent(node);
  }).then(offsetParent => {
    ok(offsetParent === gBodyNode, "The node's offset parent is the body");
    runNextTest();
  });
});

addTest(function() {
  info("Try to get the offset parent for a fixed positioned node");
  gWalker.querySelector(gWalker.rootNode, "#fixed").then(node => {
    return gWalker.getOffsetParent(node);
  }).then(offsetParent => {
    ok(offsetParent === gBodyNode, "The node's offset parent is the body");
    runNextTest();
  });
});

addTest(function() {
  info("Try to get the offset parent for the body");
  gWalker.querySelector(gWalker.rootNode, "body").then(node => {
    return gWalker.getOffsetParent(node);
  }).then(offsetParent => {
    ok(!offsetParent, "The body has no offset parent");
    runNextTest();
  });
});

addTest(function() {
  gWalker = null;
  gBodyNode = null;
  runNextTest();
});
  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1345119">Mozilla Bug 1345119</a>
<a id="inspectorContent" target="_blank" href="inspector_getOffsetParent.html">Test Document</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
</body>
</html>