<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p>This tests XPath expressions on detached document fragments and nodes.
<br/>See https://bugs.webkit.org/show_bug.cgi?id=36427
<div id="console"></div>

<script>
  frag = document.createDocumentFragment();
  child = document.createElement('div');
  frag.appendChild(child);
  child.appendChild(document.createElement('h2'));
  shouldBe("document.evaluate('count(/div)', child, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");
  shouldBe("document.evaluate('count(/html)', child, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "0");
  shouldBe("document.evaluate('count(/)', child, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");
  shouldBe("document.evaluate('count(//html)', child, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "0");
  shouldBe("document.evaluate('count(//div)', child, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");
  shouldBe("document.evaluate('count(//h2)', child, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");

  ele = document.createElement('p');
  ele.appendChild(document.createElement('h1'));
  shouldBe("document.evaluate('count(/h1)', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");
  shouldBe("document.evaluate('count(/html)', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "0");
  shouldBe("document.evaluate('count(/)', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");
  shouldBe("document.evaluate('count(//html)', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "0");
  shouldBe("document.evaluate('count(//p)', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "0");
  shouldBe("document.evaluate('count(//h1)', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "1");
  shouldBe("document.evaluate('/* | *', ele, null, XPathResult.NUMBER_TYPE, null).numberValue",
           "NaN");
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
