@Test
public void testGetAllChildren() throws Exception {
String gre_home = "./tools/xulrunner-1.9.0.13-sdk/bin";
Crawler.setupXULRunner(gre_home);
Crawler crawler = null;
try {
crawler = new Crawler() { /* nothing */ };
URL url = SelectorTest.class.getResource("/select.all.children.html");
crawler.navigateTo(url);
nsIDOMNode document = crawler.getDocument();
Selector selector = new Selector(document);
List<nsIDOMNode> children = selector.getAllChildren(document);
// for (nsIDOMNode child : children) {
// XPCOMInspector.inspect(child, false);
// }
assertEquals(14, children.size());
// the document node, has one child <html>
assertEquals(9, children.get(0).getNodeType());
assertEquals(1, children.get(0).getChildNodes().getLength());
// the html node, has two children <head>, <body>
assertEquals("HTML", children.get(1).getNodeName());
assertEquals(2, children.get(1).getChildNodes().getLength());
// the head node, has one empty child #text
assertEquals("HEAD", children.get(2).getNodeName());
assertEquals(1, children.get(2).getChildNodes().getLength());
assertEquals(3, children.get(3).getNodeType());
// the body node, has three children, #text, <p>, #text
assertEquals("BODY", children.get(4).getNodeName());
assertEquals(3, children.get(4).getChildNodes().getLength());
// body -> #text
assertEquals(3, children.get(5).getNodeType());
// body -> p, has four children, #text, <em>, #text, <strong>
assertEquals("P", children.get(6).getNodeName());
assertEquals(4, children.get(6).getChildNodes().getLength());
// body -> p -> #text
assertEquals(3, children.get(7).getNodeType());
// body -> p -> em, has one child, #text
assertEquals("EM", children.get(8).getNodeName());
assertEquals(1, children.get(8).getChildNodes().getLength());
// body -> p -> em -> #text
assertEquals(3, children.get(9).getNodeType());
// body -> p -> #text
assertEquals(3, children.get(10).getNodeType());
// body -> p -> strong, has one child, #text
assertEquals("STRONG", children.get(11).getNodeName());
assertEquals(1, children.get(11).getChildNodes().getLength());
// body -> p -> strong -> #text
assertEquals(3, children.get(12).getNodeType());
}
finally {
if (null != crawler) {
crawler.teardown();
}
}
}