Ejemplo n.º 1
0
  public void testGetPossibleOpenTagsInContext() throws ParseException {
    HtmlParseResult result =
        parse(
            "<!DOCTYPE html><html><head><title>hello</title></head><body><div>ahoj</div></body></html>");

    assertNotNull(result.root());

    Node body = ElementUtils.query(result.root(), "html/body");
    Collection<HtmlTag> possible = result.getPossibleOpenTags(body);

    assertTrue(!possible.isEmpty());

    HtmlTag divTag = new HtmlTagImpl("div");
    HtmlTag headTag = new HtmlTagImpl("head");

    assertTrue(possible.contains(divTag));
    assertFalse(possible.contains(headTag));

    Node head = ElementUtils.query(result.root(), "html/head");
    possible = result.getPossibleOpenTags(head);

    assertTrue(!possible.isEmpty());

    HtmlTag titleTag = new HtmlTagImpl("title");
    assertTrue(possible.contains(titleTag));
    assertFalse(possible.contains(headTag));

    Node html = ElementUtils.query(result.root(), "html");
    possible = result.getPossibleOpenTags(html);
    assertTrue(!possible.isEmpty());
    assertTrue(possible.contains(divTag));
  }
Ejemplo n.º 2
0
  public void testAllowDialogInDiv() throws ParseException {
    HtmlParseResult result =
        parse(
            "<!doctype html>"
                + "<html>\n"
                + "<title>title</title>\n"
                + "<body>\n"
                + "<div>\n"
                + "</div>\n"
                + "</body>\n"
                + "</html>\n");

    assertNotNull(result.root());

    Node div = ElementUtils.query(result.root(), "html/body/div");
    Collection<HtmlTag> possible = result.getPossibleOpenTags(div);

    assertTrue(!possible.isEmpty());

    HtmlTag divTag = new HtmlTagImpl("div");
    HtmlTag dialogTag = new HtmlTagImpl("dialog");

    assertTrue(possible.contains(divTag));

    // fails - bug
    //        assertFalse(possible.contains(dialogTag));

  }