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());
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations