Search in sources :

Example 1 with HTMLLinkElement

use of org.loboevolution.html.dom.HTMLLinkElement in project LoboEvolution by LoboEvolution.

the class HTMLDocumentTest method testCreateElement.

@Test
public void testCreateElement() {
    Element elm = document.createElement("link");
    assertTrue(elm instanceof HTMLLinkElement);
    elm = document.createElement("LINK");
    assertTrue(elm instanceof HTMLLinkElement);
    assertEquals("LINK", elm.getLocalName());
    assertEquals("LINK", elm.getTagName());
    elm = document.createElement("style");
    assertTrue(elm instanceof HTMLLinkElement);
    elm = document.createElement("STYLE");
    assertTrue(elm instanceof HTMLLinkElement);
    assertEquals("style", elm.getLocalName());
    HTMLElement html = (HTMLElement) document.createElement("html");
    try {
        elm.appendChild(html);
        fail("Must throw exception");
    } catch (DOMException e) {
        assertEquals(DOMException.HIERARCHY_REQUEST_ERR, e.getCode());
    }
    try {
        document.createElement(null);
        fail("Must throw exception");
    } catch (DOMException e) {
        assertEquals(DOMException.INVALID_CHARACTER_ERR, e.getCode());
    }
    try {
        document.createElement("");
        fail("Must throw exception");
    } catch (DOMException e) {
        assertEquals(DOMException.INVALID_CHARACTER_ERR, e.getCode());
    }
    try {
        document.createElement("\u0000");
        fail("Must throw exception");
    } catch (DOMException e) {
        assertEquals(DOMException.INVALID_CHARACTER_ERR, e.getCode());
    }
    try {
        document.createElement("<");
        fail("Must throw exception");
    } catch (DOMException e) {
        assertEquals(DOMException.INVALID_CHARACTER_ERR, e.getCode());
    }
    try {
        document.createElement(">");
        fail("Must throw exception");
    } catch (DOMException e) {
        assertEquals(DOMException.INVALID_CHARACTER_ERR, e.getCode());
    }
}
Also used : HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) DOMException(com.gargoylesoftware.css.dom.DOMException) HTMLElement(org.loboevolution.html.dom.HTMLElement) HTMLElement(org.loboevolution.html.dom.HTMLElement) HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 2 with HTMLLinkElement

use of org.loboevolution.html.dom.HTMLLinkElement in project LoboEvolution by LoboEvolution.

the class HTMLDocumentTest method testLinkElement.

@Test
public void testLinkElement() {
    Element link = (Element) document.getElementsByTagName("link").item(0);
    CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) link).getSheet();
    assertNotNull(sheet);
    assertEquals(0, sheet.getMedia().getLength());
    assertTrue(sheet.getCssRules().getLength() > 0);
    assertSame(sheet.getOwnerNode(), link);
    link.setAttribute("media", "screen");
    CSSStyleSheetImpl sheet2 = (CSSStyleSheetImpl) ((HTMLLinkElement) link).getSheet();
    assertNotNull(sheet2);
    assertSame(sheet2, sheet);
    assertEquals(1, sheet2.getMedia().getLength());
    assertEquals("screen", sheet2.getMedia().item(0));
    link.setAttribute("href", "css/alter1.css");
    sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) link).getSheet();
    assertSame(sheet2, sheet);
    assertSame(sheet.getOwnerNode(), link);
    Attr href = link.getAttributeNode("href");
    assertNotNull(href);
    href.setValue("http://www.example.com/css/example.css");
    assertNotNull(((HTMLLinkElement) link).getSheet());
    assertEquals(0, sheet.getCssRules().getLength());
    link.setAttribute("media", "screen only and");
    assertNull(((HTMLLinkElement) link).getSheet());
}
Also used : HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) CSSStyleSheetImpl(org.loboevolution.html.js.css.CSSStyleSheetImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 3 with HTMLLinkElement

use of org.loboevolution.html.dom.HTMLLinkElement in project LoboEvolution by LoboEvolution.

the class HTMLDocumentTest method testLinkElementBadMIMEType.

@Test
public void testLinkElementBadMIMEType() {
    Element link = document.createElement("link");
    link.setAttribute("href", "http://www.example.com/css/background.png");
    assertNull(((HTMLLinkElement) link).getSheet());
    link.setAttribute("rel", "stylesheet");
    CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) link).getSheet();
    assertNull(sheet);
}
Also used : CSSStyleSheetImpl(org.loboevolution.html.js.css.CSSStyleSheetImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 4 with HTMLLinkElement

use of org.loboevolution.html.dom.HTMLLinkElement in project LoboEvolution by LoboEvolution.

the class HTMLDocumentTest method testLinkElement2.

@Test
public void testLinkElement2() {
    Element link = document.createElement("link");
    link.setAttribute("href", "http://www.example.com/foo");
    assertNull(((HTMLLinkElement) link).getSheet());
    link.setAttribute("rel", "stylesheet");
    CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) link).getSheet();
    assertNotNull(sheet);
    assertEquals(0, sheet.getMedia().getLength());
    assertEquals(0, sheet.getCssRules().getLength());
    assertSame(sheet.getOwnerNode(), link);
}
Also used : CSSStyleSheetImpl(org.loboevolution.html.js.css.CSSStyleSheetImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 5 with HTMLLinkElement

use of org.loboevolution.html.dom.HTMLLinkElement in project LoboEvolution by LoboEvolution.

the class HTMLDocumentTest method testLinkElementEvil.

@Test(timeout = 8000)
public void testLinkElementEvil() {
    Element link = document.createElement("link");
    link.setAttribute("rel", "stylesheet");
    link.setAttribute("href", "file:/dev/zero");
    CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) link).getSheet();
    assertNotNull(sheet);
    assertEquals(0, sheet.getMedia().getLength());
    assertEquals(0, sheet.getCssRules().getLength());
    assertSame(sheet.getOwnerNode(), link);
}
Also used : CSSStyleSheetImpl(org.loboevolution.html.js.css.CSSStyleSheetImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) HTMLLinkElement(org.loboevolution.html.dom.HTMLLinkElement) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Aggregations

Test (org.junit.Test)13 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)13 HTMLElement (org.loboevolution.html.dom.HTMLElement)13 HTMLLinkElement (org.loboevolution.html.dom.HTMLLinkElement)13 CSSStyleSheetImpl (org.loboevolution.html.js.css.CSSStyleSheetImpl)11 DOMException (com.gargoylesoftware.css.dom.DOMException)3 CSSRuleList (org.loboevolution.html.node.css.CSSRuleList)1