/** appendChild, insertBefore, removeChild, replaceChild. */
  public void testAppendRemoveReplace() {
    Document doc = Document.get();
    BodyElement body = doc.getBody();

    // <div>foo<button/>bar</div>
    DivElement div = doc.createDivElement();
    Text txt0 = doc.createTextNode("foo");
    ButtonElement btn0 = doc.createButtonElement();
    Text txt1 = doc.createTextNode("bar");

    body.appendChild(div);
    div.appendChild(txt0);
    div.appendChild(btn0);
    div.appendChild(txt1);

    // appendChild, insertBefore
    ButtonElement btn1 = doc.createButtonElement();

    // <div>foo<btn0/>bar<btn1/></div>
    div.appendChild(btn1);
    assertEquals(btn1, div.getLastChild());

    // <div>foo<button/>bar<button/></div>
    div.insertBefore(btn1, txt1);
    assertEquals(4, div.getChildNodes().getLength());
    assertEquals(btn1, div.getChildNodes().getItem(2));

    // removeChild
    // <div>foo<btn0/>bar</div> (back to original)
    div.removeChild(btn1);
    assertEquals(3, div.getChildNodes().getLength());

    // replaceChild
    // <div>foo<btn1/>bar</div>
    div.replaceChild(btn1, btn0);
    assertEquals(btn1, txt0.getNextSibling());
    assertEquals(btn1, txt1.getPreviousSibling());

    // insertAfter
    // <div>foo<btn1/><btn0/>bar</div>
    div.insertAfter(btn0, btn1);
    assertEquals(btn0, btn1.getNextSibling());

    // insertFirst
    // <div><btn1/>foo<btn0/>bar</div>
    div.insertFirst(btn1);
    assertEquals(btn1, div.getFirstChild());

    // removeFromParent
    // <div>foo<btn0/>bar</div>
    btn1.removeFromParent();
    assertNull(btn1.getParentElement());
    assertEquals(txt0, div.getFirstChild());
  }
  /** getParentNode, firstChild, lastChild, nextSibling, previousSibling. */
  public void testParentAndSiblings() {
    Document doc = Document.get();
    BodyElement body = doc.getBody();

    // <div>foo<button/>bar</div>
    DivElement div = doc.createDivElement();
    Text txt0 = doc.createTextNode("foo");
    ButtonElement btn0 = doc.createButtonElement();
    Text txt1 = doc.createTextNode("bar");

    body.appendChild(div);
    div.appendChild(txt0);
    div.appendChild(btn0);
    div.appendChild(txt1);

    assertEquals(div, btn0.getParentNode());

    assertEquals(txt0, div.getFirstChild());
    assertEquals(txt1, div.getLastChild());
    assertEquals(btn0, txt0.getNextSibling());
    assertEquals(btn0, txt1.getPreviousSibling());
    assertEquals(null, txt0.getPreviousSibling());
    assertEquals(null, txt1.getNextSibling());
  }