Search in sources :

Example 1 with DocumentType

use of org.loboevolution.html.node.DocumentType in project LoboEvolution by LoboEvolution.

the class DOMImplementationTest method testCreateDocument3.

@Test
public void testCreateDocument3() {
    DocumentType doctype = domImpl.createDocumentType("html", null, null);
    assertNull(doctype.getNextSibling());
    assertNull(doctype.getPreviousSibling());
    Document document = domImpl.createDocument(null, "html", doctype);
    assertEquals("CSS1Compat", document.getCompatMode());
    Element docelm = document.getDocumentElement();
    assertNotNull(docelm);
    assertSame(docelm, doctype.getNextSibling());
    assertNull(doctype.getPreviousSibling());
    assertSame(doctype, docelm.getPreviousSibling());
    assertNull(docelm.getNextSibling());
    assertSame(document, docelm.getParentNode());
    assertSame(document, docelm.getOwnerDocument());
    assertSame(document, doctype.getOwnerDocument());
}
Also used : Element(org.loboevolution.html.node.Element) DocumentType(org.loboevolution.html.node.DocumentType) Document(org.loboevolution.html.node.Document) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 2 with DocumentType

use of org.loboevolution.html.node.DocumentType in project LoboEvolution by LoboEvolution.

the class DOMImplementationTest method testCreateDocumentType.

@Test
public void testCreateDocumentType() {
    DocumentType doctype = domImpl.createDocumentType("html", null, null);
    assertEquals("<!DOCTYPE html>", doctype.toString());
    // 
    doctype = domImpl.createDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", null);
    assertEquals("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\">", doctype.toString());
    // 
    doctype = domImpl.createDocumentType("html", null, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
    assertEquals("<!DOCTYPE html SYSTEM \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">", doctype.toString());
    // 
    doctype = domImpl.createDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
    assertEquals("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">", doctype.toString());
    // 
    try {
        domImpl.createDocumentType("html><html><injection/", null, null);
        fail("Must throw exception.");
    } catch (DOMException e) {
        assertEquals(DOMException.INVALID_CHARACTER_ERR, e.getCode());
    }
    // 
    doctype = domImpl.createDocumentType("html", "\"><injection foo=\"", null);
    assertEquals("<!DOCTYPE html PUBLIC \"&quot;&gt;&lt;injection foo=&quot;\">", doctype.toString());
    // 
    doctype = domImpl.createDocumentType("html", null, "\"><injection foo=\"");
    assertEquals("<!DOCTYPE html SYSTEM \"&quot;&gt;&lt;injection foo=&quot;\">", doctype.toString());
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) DocumentType(org.loboevolution.html.node.DocumentType) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 3 with DocumentType

use of org.loboevolution.html.node.DocumentType in project LoboEvolution by LoboEvolution.

the class DOMImplementationTest method testCreateDocument2.

@Test
public void testCreateDocument2() {
    DocumentType doctype = domImpl.createDocumentType("html", null, null);
    assertNull(doctype.getNextSibling());
    assertNull(doctype.getPreviousSibling());
    assertNull(doctype.getParentNode());
    assertNull(doctype.getOwnerDocument());
    Document document = domImpl.createDocument(null, null, doctype);
    assertNull(doctype.getNextSibling());
    assertNull(doctype.getPreviousSibling());
    assertSame(document, doctype.getOwnerDocument());
    try {
        domImpl.createDocument(null, null, doctype);
        fail("Must throw an exception");
    } catch (DOMException e) {
        assertEquals(DOMException.WRONG_DOCUMENT_ERR, e.getCode());
    }
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) DocumentType(org.loboevolution.html.node.DocumentType) Document(org.loboevolution.html.node.Document) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Aggregations

Test (org.junit.Test)3 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)3 DocumentType (org.loboevolution.html.node.DocumentType)3 DOMException (com.gargoylesoftware.css.dom.DOMException)2 Document (org.loboevolution.html.node.Document)2 Element (org.loboevolution.html.node.Element)1