From: <rb...@us...> - 2013-08-25 15:42:38
|
Revision: 8450 http://sourceforge.net/p/htmlunit/code/8450 Author: rbri Date: 2013-08-25 15:42:34 +0000 (Sun, 25 Aug 2013) Log Message: ----------- support for the 'media' property of style elements added Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-08-25 13:55:14 UTC (rev 8449) +++ trunk/htmlunit/src/changes/changes.xml 2013-08-25 15:42:34 UTC (rev 8450) @@ -9,7 +9,7 @@ <body> <release version="2.13" date="???" description="Bugfixes"> <action type="add" dev="rbri"> - JavaScript: support for the type property of style elements added. + JavaScript: support for the 'type' and 'media' property of style elements added. </action> <action type="fix" dev="rbri" issue="1534"> WebClient.getTopLevelWindows() returns a snapshot of the list of open top level windows. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElement.java 2013-08-25 13:55:14 UTC (rev 8449) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElement.java 2013-08-25 15:42:34 UTC (rev 8450) @@ -34,6 +34,7 @@ * @version $Revision$ * @author Ahmed Ashour * @author Marc Guillemot + * @author Ronald Brill */ @JsxClass(domClasses = HtmlStyle.class) public class HTMLStyleElement extends HTMLElement { @@ -88,4 +89,14 @@ final HtmlStyle style = (HtmlStyle) getDomNodeOrDie(); return style.getTypeAttribute(); } + + /** + * Returns the media of this style. + * @return the media + */ + @JsxGetter() + public String getMedia() { + final HtmlStyle style = (HtmlStyle) getDomNodeOrDie(); + return style.getAttribute("media"); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 2013-08-25 13:55:14 UTC (rev 8449) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 2013-08-25 15:42:34 UTC (rev 8450) @@ -89,9 +89,9 @@ final String html = "<html><head><title>foo</title>\n" - + "<style id='style_none'>my { }</style>\n" - + "<style type='text/test' id='style_text'>my { }</style>\n" - + "<style type='text/html' id='style_html'>my { }</style>\n" + + "<style id='style_none'>.a > .t { }</style>\n" + + "<style type='text/test' id='style_text'>.b > .t { }</style>\n" + + "<style type='text/html' id='style_html'>.c > .t { }</style>\n" + "<script>\n" + "function doTest() {\n" @@ -118,9 +118,9 @@ final String html = "<html><head><title>foo</title>\n" - + "<style id='style_none'>.a > .t { }</style>\n" - + "<style type='text/test' id='style_text'>.b > .t { }</style>\n" - + "<style type='text/css' id='style_css'>.c > .t { }</style>\n" + + "<style id='style_none'>my { }</style>\n" + + "<style type='text/test' id='style_text'>my { }</style>\n" + + "<style type='text/css' id='style_css'>my { }</style>\n" + "<script>\n" + "function doTest() {\n" @@ -137,4 +137,33 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "", "all", "screen, print,test" }) + public void media() throws Exception { + final String html + = "<html><head><title>foo</title>\n" + + + "<style id='style_none'>my { }</style>\n" + + "<style media='all' id='style_all'>my { }</style>\n" + + "<style media='screen, print,test' id='style_some'>my { }</style>\n" + + + "<script>\n" + + "function doTest() {\n" + + " style = document.getElementById('style_none');\n" + + " alert(style.media);\n" + + " style = document.getElementById('style_all');\n" + + " alert(style.media);\n" + + " style = document.getElementById('style_some');\n" + + " alert(style.media);\n" + + "}\n" + + "</script>\n" + + "</head><body onload='doTest()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |