use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class HTMLStyleElement method getSheet.
/**
* Gets the associated sheet.
* @see <a href="http://www.xulplanet.com/references/objref/HTMLStyleElement.html">Mozilla doc</a>
* @return the sheet
*/
@JsxGetter
public CSSStyleSheet getSheet() {
if (sheet_ != null) {
return sheet_;
}
final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
final String css = style.getTextContent();
final Window window = getWindow();
final Cache cache = window.getWebWindow().getWebClient().getCache();
final CSSStyleSheetImpl cached = cache.getCachedStyleSheet(css);
final String uri = getDomNodeOrDie().getPage().getWebResponse().getWebRequest().getUrl().toExternalForm();
if (cached != null) {
sheet_ = new CSSStyleSheet(this, window, cached, uri);
} else {
sheet_ = new CSSStyleSheet(this, css, uri);
cache.cache(css, sheet_.getWrappedSheet());
}
return sheet_;
}
use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class CSSStyleSheet2Test method testSelects.
private void testSelects(final String css, final boolean selectBody, final boolean selectDivD, final boolean selectSpanS) throws Exception {
final String html = "<html>\n" + " <body id='b'>\n" + " <style></style>\n" + " <div id='d' class='foo bar' lang='en-GB'>\n" + " <span>x</span>\n" + " <span id='s'>a</span>b\n" + " </div>\n" + " </body>\n" + "</html>";
final HtmlPage page = loadPage(html);
final BrowserVersion browserVersion = getBrowserVersion();
final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0);
final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject();
final CSSStyleSheet sheet = host.getSheet();
final Selector selector = sheet.parseSelectors(css).get(0);
assertEquals(selectBody, CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("b"), null, false));
assertEquals(selectDivD, CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("d"), null, false));
assertEquals(selectSpanS, CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("s"), null, false));
}
use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class CSSStyleSheet2Test method selectsIdConditionWithSpecialChars.
/**
* @throws Exception if an error occurs
*/
@Test
public void selectsIdConditionWithSpecialChars() throws Exception {
final String html = "<html><body><style></style>\n" + "<div id='d:e'></div>\n" + "<div id='d-e'></div>\n" + "</body></html>";
final HtmlPage page = loadPage(html);
final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0);
final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject();
final BrowserVersion browserVersion = getBrowserVersion();
final CSSStyleSheet sheet = host.getSheet();
Selector selector = sheet.parseSelectors("#d\\:e").get(0);
assertTrue(CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("d:e"), null, false));
selector = sheet.parseSelectors("#d-e").get(0);
assertTrue(CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("d-e"), null, false));
}
Aggregations