From: <rb...@us...> - 2013-06-19 18:58:16
|
Revision: 8348 http://sourceforge.net/p/htmlunit/code/8348 Author: rbri Date: 2013-06-19 18:58:08 +0000 (Wed, 19 Jun 2013) Log Message: ----------- make the handling of empty responses more error proof Issue 1510 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DownloadedContent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponseData.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DownloadedContent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DownloadedContent.java 2013-06-16 08:00:03 UTC (rev 8347) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DownloadedContent.java 2013-06-19 18:58:08 UTC (rev 8348) @@ -30,6 +30,7 @@ * * @version $Revision$ * @author Marc Guillemot + * @author Ronald Brill */ public interface DownloadedContent extends Serializable { /** @@ -37,6 +38,7 @@ */ static class InMemory implements DownloadedContent { private final byte[] bytes_; + public InMemory(final byte[] byteArray) { if (byteArray == null) { bytes_ = ArrayUtils.EMPTY_BYTE_ARRAY; @@ -51,7 +53,12 @@ } public void cleanUp() { + // nothing to do } + + public boolean isEmpty() { + return bytes_.length == 0; + } } /** @@ -79,6 +86,10 @@ FileUtils.deleteQuietly(file_); } } + + public boolean isEmpty() { + return false; + } } /** @@ -93,4 +104,9 @@ */ void cleanUp(); + /** + * Returns true if the content is empty. + * @return true or false + */ + boolean isEmpty(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponseData.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponseData.java 2013-06-16 08:00:03 UTC (rev 8347) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponseData.java 2013-06-19 18:58:08 UTC (rev 8348) @@ -86,10 +86,18 @@ downloadedContent_ = responseBody; } - private InputStream getStream(InputStream stream, final List<NameValuePair> headers) throws IOException { + private InputStream getStream(final DownloadedContent downloadedContent, + final List<NameValuePair> headers) throws IOException { + + InputStream stream = downloadedContent_.getInputStream(); if (stream == null) { return null; } + + if (downloadedContent.isEmpty()) { + return stream; + } + final String encoding = getHeader(headers, "content-encoding"); if (encoding != null) { // check content length @@ -153,7 +161,7 @@ * @throws IOException in case of IO problems */ public InputStream getInputStream() throws IOException { - return getStream(downloadedContent_.getInputStream(), getResponseHeaders()); + return getStream(downloadedContent_, getResponseHeaders()); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2013-06-16 08:00:03 UTC (rev 8347) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2013-06-19 18:58:08 UTC (rev 8348) @@ -43,6 +43,7 @@ * @version $Revision$ * @author Daniel Gredler * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class WebResponseDataTest extends WebServerTestCase { @@ -72,11 +73,41 @@ */ @Test public void testEmptyGZippedContent() throws Exception { + testEmptyGZippedContent(HttpStatus.SC_OK, 0, null); + } + + /** + * Tests that empty gzipped content is handled correctly (bug #1510). + * @throws Exception if the test fails + */ + @Test + public void contentLengthIsZero() throws Exception { + testEmptyGZippedContent(HttpStatus.SC_OK, 0, "text/html"); + } + + /** + * Tests that empty gzipped content is handled correctly (bug #1510). + * @throws Exception if the test fails + */ + @Test + public void contentLengthIsMissing() throws Exception { + testEmptyGZippedContent(HttpStatus.SC_NO_CONTENT, -1, null); + } + + private void testEmptyGZippedContent(final int statusCode, final int contentLength, + final String contentType) throws Exception { final List<NameValuePair> headers = new ArrayList<NameValuePair>(); - headers.add(new NameValuePair("Content-Length", "0")); headers.add(new NameValuePair("Content-Encoding", "gzip")); - final WebResponseData data = new WebResponseData("".getBytes(), HttpStatus.SC_OK, "OK", headers); + if (contentLength != -1) { + headers.add(new NameValuePair("Content-Length", String.valueOf(contentLength))); + } + + if (contentType != null) { + headers.add(new NameValuePair("Content-Type", contentType)); + } + + final WebResponseData data = new WebResponseData("".getBytes(), statusCode, "OK", headers); data.getBody(); } |
From: <rb...@us...> - 2013-06-20 20:17:27
|
Revision: 8351 http://sourceforge.net/p/htmlunit/code/8351 Author: rbri Date: 2013-06-20 20:17:23 +0000 (Thu, 20 Jun 2013) Log Message: ----------- rename the enum members to match the w3c spec naming; remove some error log for cases that are valid from the spec Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/gae/GAELoadPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-06-20 15:52:53 UTC (rev 8350) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-06-20 20:17:23 UTC (rev 8351) @@ -86,6 +86,7 @@ * @author Stuart Begg * @author Ronald Brill * + * @see <a href="http://www.w3.org/TR/XMLHttpRequest/">W3C XMLHttpRequest</a> * @see <a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">Safari documentation</a> */ @JsxClass(browsers = { @WebBrowser(value = IE, minVersion = 7), @WebBrowser(FF), @WebBrowser(CHROME) }) @@ -94,15 +95,15 @@ private static final Log LOG = LogFactory.getLog(XMLHttpRequest.class); /** The object has been created, but not initialized (the open() method has not been called). */ - public static final int STATE_UNINITIALIZED = 0; + public static final int STATE_UNSENT = 0; /** The object has been created, but the send() method has not been called. */ - public static final int STATE_LOADING = 1; + public static final int STATE_OPENED = 1; /** The send() method has been called, but the status and headers are not yet available. */ - public static final int STATE_LOADED = 2; + public static final int STATE_HEADERS_RECEIVED = 2; /** Some data has been received. */ - public static final int STATE_INTERACTIVE = 3; + public static final int STATE_LOADING = 3; /** All the data has been received; the complete data is available in responseBody and responseText. */ - public static final int STATE_COMPLETED = 4; + public static final int STATE_DONE = 4; private static final String[] ALL_PROPERTIES_ = {"onreadystatechange", "readyState", "responseText", "responseXML", "status", "statusText", "abort", "getAllResponseHeaders", "getResponseHeader", "open", "send", @@ -138,7 +139,7 @@ */ public XMLHttpRequest(final boolean caseSensitiveProperties) { caseSensitiveProperties_ = caseSensitiveProperties; - state_ = STATE_UNINITIALIZED; + state_ = STATE_UNSENT; } /** @@ -165,7 +166,7 @@ @JsxSetter public void setOnreadystatechange(final Function stateChangeHandler) { stateChangeHandler_ = stateChangeHandler; - if (state_ == STATE_LOADING) { + if (state_ == STATE_OPENED) { setState(state_, null); } } @@ -183,14 +184,14 @@ // Firefox doesn't trigger onreadystatechange handler for sync requests except for completed for FF10 final boolean noTriggerForSync = browser.hasFeature( XHR_ONREADYSTATECANGE_SYNC_REQUESTS_NOT_TRIGGERED); - final boolean triggerForSyncCompleted = (state == STATE_COMPLETED) + final boolean triggerForSyncCompleted = (state == STATE_DONE) && browser.hasFeature(XHR_ONREADYSTATECANGE_SYNC_REQUESTS_COMPLETED); if (stateChangeHandler_ != null && (async_ || !noTriggerForSync || triggerForSyncCompleted)) { final Scriptable scope = stateChangeHandler_.getParentScope(); final JavaScriptEngine jsEngine = containingPage_.getWebClient().getJavaScriptEngine(); final int nbExecutions; - if (async_ && STATE_LOADING == state) { + if (async_ && STATE_OPENED == state) { // quite strange but IE and FF seem both to fire state loading twice // in async mode (at least with HTML of the unit tests) nbExecutions = 2; @@ -230,7 +231,7 @@ // Firefox has a separate onload handler, too. final boolean triggerOnload = browser.hasFeature(XHR_TRIGGER_ONLOAD_ON_COMPLETED); - if (triggerOnload && loadHandler_ != null && state == STATE_COMPLETED) { + if (triggerOnload && loadHandler_ != null && state == STATE_DONE) { final Scriptable scope = loadHandler_.getParentScope(); final JavaScriptEngine jsEngine = containingPage_.getWebClient().getJavaScriptEngine(); jsEngine.callFunction(containingPage_, loadHandler_, scope, this, ArrayUtils.EMPTY_OBJECT_ARRAY); @@ -376,10 +377,14 @@ */ @JsxGetter public int getStatus() { + if (state_ == STATE_UNSENT || state_ == STATE_OPENED) { + return 0; + } if (webResponse_ != null) { return webResponse_.getStatusCode(); } - LOG.error("XMLHttpRequest.status was retrieved before the response was available."); + + LOG.error("XMLHttpRequest.status was retrieved without a response available."); return 0; } @@ -389,10 +394,14 @@ */ @JsxGetter public String getStatusText() { + if (state_ == STATE_UNSENT || state_ == STATE_OPENED) { + return ""; + } if (webResponse_ != null) { return webResponse_.getStatusMessage(); } - LOG.error("XMLHttpRequest.statusText was retrieved before the response was available."); + + LOG.error("XMLHttpRequest.statusText was retrieved without a response available."); return null; } @@ -410,6 +419,9 @@ */ @JsxFunction public String getAllResponseHeaders() { + if (state_ == STATE_UNSENT || state_ == STATE_OPENED) { + return null; + } if (webResponse_ != null) { final StringBuilder buffer = new StringBuilder(); for (final NameValuePair header : webResponse_.getResponseHeaders()) { @@ -417,7 +429,8 @@ } return buffer.toString(); } - LOG.error("XMLHttpRequest.getAllResponseHeaders() was called before the response was available."); + + LOG.error("XMLHttpRequest.getAllResponseHeaders() was called without a response available."); return null; } @@ -428,10 +441,14 @@ */ @JsxFunction public String getResponseHeader(final String headerName) { + if (state_ == STATE_UNSENT || state_ == STATE_OPENED) { + return null; + } if (webResponse_ != null) { return webResponse_.getResponseHeaderValue(headerName); } + LOG.error("XMLHttpRequest.getAllResponseHeaders(..) was called without a response available."); return null; } @@ -500,7 +517,7 @@ // Async stays a boolean. async_ = async; // Change the state! - setState(STATE_LOADING, null); + setState(STATE_OPENED, null); } /** @@ -611,7 +628,7 @@ private void doSend(final Context context) { final WebClient wc = getWindow().getWebWindow().getWebClient(); try { - setState(STATE_LOADED, context); + setState(STATE_HEADERS_RECEIVED, context); final boolean crossOriginResourceSharing = webRequest_.getAdditionalHeaders().get("Origin") != null; if (crossOriginResourceSharing && isPreflight()) { final WebRequest preflightRequest = new WebRequest(webRequest_.getUrl(), HttpMethod.OPTIONS); @@ -632,8 +649,8 @@ preflightRequest.setAdditionalHeader("Access-Control-Request-Headers", builder.toString()); final WebResponse preflightResponse = wc.loadWebResponse(preflightRequest); if (!isPreflightAuthorized(preflightResponse)) { - setState(STATE_INTERACTIVE, context); - setState(STATE_COMPLETED, context); + setState(STATE_LOADING, context); + setState(STATE_DONE, context); if (LOG.isDebugEnabled()) { LOG.debug("No permitted request for URL " + webRequest_.getUrl()); } @@ -665,8 +682,8 @@ }; } } - setState(STATE_INTERACTIVE, context); - setState(STATE_COMPLETED, context); + setState(STATE_LOADING, context); + setState(STATE_DONE, context); if (!allowOriginResponse) { if (LOG.isDebugEnabled()) { LOG.debug("No permitted \"Access-Control-Allow-Origin\" header for URL " + webRequest_.getUrl()); @@ -679,7 +696,7 @@ LOG.debug("IOException: returning a network error response.", e); } webResponse_ = new NetworkErrorWebResponse(webRequest_); - setState(STATE_COMPLETED, context); + setState(STATE_DONE, context); if (async_) { processError(context); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/gae/GAELoadPageTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/gae/GAELoadPageTest.java 2013-06-20 15:52:53 UTC (rev 8350) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/gae/GAELoadPageTest.java 2013-06-20 20:17:23 UTC (rev 8351) @@ -113,12 +113,12 @@ client.getPage(FIRST_URL); final int executedJobs = client.getJavaScriptEngine().pumpEventLoop(1000); - final String[] alerts = {String.valueOf(XMLHttpRequest.STATE_UNINITIALIZED), + final String[] alerts = {String.valueOf(XMLHttpRequest.STATE_UNSENT), + String.valueOf(XMLHttpRequest.STATE_OPENED), + String.valueOf(XMLHttpRequest.STATE_OPENED), + String.valueOf(XMLHttpRequest.STATE_HEADERS_RECEIVED), String.valueOf(XMLHttpRequest.STATE_LOADING), - String.valueOf(XMLHttpRequest.STATE_LOADING), - String.valueOf(XMLHttpRequest.STATE_LOADED), - String.valueOf(XMLHttpRequest.STATE_INTERACTIVE), - String.valueOf(XMLHttpRequest.STATE_COMPLETED), xml}; + String.valueOf(XMLHttpRequest.STATE_DONE), xml}; assertEquals(Arrays.asList(alerts).toString(), collectedAlerts.toString()); assertEquals(1, executedJobs); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest3Test.java 2013-06-20 15:52:53 UTC (rev 8350) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest3Test.java 2013-06-20 20:17:23 UTC (rev 8351) @@ -64,11 +64,11 @@ private static final String MSG_NO_CONTENT = "no Content"; private static final String MSG_PROCESSING_ERROR = "error processing"; - private static final String UNINITIALIZED = String.valueOf(XMLHttpRequest.STATE_UNINITIALIZED); - private static final String LOADING = String.valueOf(XMLHttpRequest.STATE_LOADING); - private static final String LOADED = String.valueOf(XMLHttpRequest.STATE_LOADED); - private static final String INTERACTIVE = String.valueOf(XMLHttpRequest.STATE_INTERACTIVE); - private static final String COMPLETED = String.valueOf(XMLHttpRequest.STATE_COMPLETED); + private static final String UNINITIALIZED = String.valueOf(XMLHttpRequest.STATE_UNSENT); + private static final String LOADING = String.valueOf(XMLHttpRequest.STATE_OPENED); + private static final String LOADED = String.valueOf(XMLHttpRequest.STATE_HEADERS_RECEIVED); + private static final String INTERACTIVE = String.valueOf(XMLHttpRequest.STATE_LOADING); + private static final String COMPLETED = String.valueOf(XMLHttpRequest.STATE_DONE); /** * Tests asynchronous use of XMLHttpRequest, using Mozilla style object creation. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2013-06-20 15:52:53 UTC (rev 8350) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2013-06-20 20:17:23 UTC (rev 8351) @@ -52,9 +52,9 @@ @RunWith(BrowserRunner.class) public class XMLHttpRequestTest extends WebDriverTestCase { - private static final String UNINITIALIZED = String.valueOf(XMLHttpRequest.STATE_UNINITIALIZED); - private static final String LOADING = String.valueOf(XMLHttpRequest.STATE_LOADING); - private static final String COMPLETED = String.valueOf(XMLHttpRequest.STATE_COMPLETED); + private static final String UNINITIALIZED = String.valueOf(XMLHttpRequest.STATE_UNSENT); + private static final String LOADING = String.valueOf(XMLHttpRequest.STATE_OPENED); + private static final String COMPLETED = String.valueOf(XMLHttpRequest.STATE_DONE); /** * Tests synchronous use of XMLHttpRequest. @@ -126,6 +126,60 @@ } /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0-", "0-" }) + public void statusBeforeSend() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <title>XMLHttpRequest Test</title>\n" + + " <script>\n" + + " var request;\n" + + " if (window.XMLHttpRequest)\n" + + " request = new XMLHttpRequest();\n" + + " else if (window.ActiveXObject)\n" + + " request = new ActiveXObject('Microsoft.XMLHTTP');\n" + + + " alert(request.status + '-' + request.statusText);\n" + + " request.open('GET', '/foo.xml', false);\n" + + " alert(request.status + '-' + request.statusText);\n" + + " </script>\n" + + " </head>\n" + + " <body></body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"null", "null" }) + public void responseHeaderBeforeSend() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <title>XMLHttpRequest Test</title>\n" + + " <script>\n" + + " var request;\n" + + " if (window.XMLHttpRequest)\n" + + " request = new XMLHttpRequest();\n" + + " else if (window.ActiveXObject)\n" + + " request = new ActiveXObject('Microsoft.XMLHTTP');\n" + + + " alert(request.getResponseHeader('content-length'));\n" + + " request.open('GET', '/foo.xml', false);\n" + + " alert(request.getResponseHeader('content-length'));\n" + + " </script>\n" + + " </head>\n" + + " <body></body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } + + /** * Regression test for http://sourceforge.net/tracker/index.php?func=detail&aid=1209692&group_id=47038&atid=448266. * @throws Exception if the test fails */ |
From: <rb...@us...> - 2013-06-30 12:18:59
|
Revision: 8360 http://sourceforge.net/p/htmlunit/code/8360 Author: rbri Date: 2013-06-30 12:18:56 +0000 (Sun, 30 Jun 2013) Log Message: ----------- some defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-26 06:16:14 UTC (rev 8359) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 12:18:56 UTC (rev 8360) @@ -120,12 +120,30 @@ static { HashMap<String, String> map = new HashMap<String, String>(); map.put("A", "inline"); + map.put("ABBR", "inline"); + map.put("ACRONYM", "inline"); + map.put("AREA", "none"); + map.put("AUDIO", "none"); + map.put("B", "inline"); + map.put("BDO", "inline"); + map.put("BIG", "inline"); + map.put("BR", "inline"); + map.put("BUTTON", "inline-block"); + map.put("CANVAS", "inline"); + map.put("CAPTION", "table-caption"); + map.put("CITE", "inline"); map.put("CODE", "inline"); + map.put("COL", "table-column"); + map.put("COLGROUP", "table-column-group"); + map.put("DEL", "inline"); + map.put("DFN", "inline"); + map.put("EM", "inline"); + map.put("EMBED", "inline"); + map.put("FONT", "inline"); map.put("SPAN", "inline"); DEFAULT_DISPLAYS = Collections.unmodifiableMap(map); - map = new HashMap<String, String>(); - map.put("A", "inline"); + map = new HashMap<String, String>(map); map.put("CODE", "inline"); map.put("SPAN", "inline"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-26 06:16:14 UTC (rev 8359) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 12:18:56 UTC (rev 8360) @@ -246,16 +246,300 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = "block block block block block block block block block", - FF = "table table-header-group table-row-group table-cell table-row table-cell block list-item block") - public void defaultDisplayValues() throws Exception { + @Alerts(FF = { "inline", "inline", "inline", "block", /* "inline-block", */ "none", "block", "block", "none" }, + IE = { "inline", "inline", "inline", "block", /* "none", */ "inline", "block", "block", "none" }) + public void defaultDisplayValues_A() throws Exception { final String html = "<html><body>\n" + + " <p id='p'>\n" + + " <a id='a'></a>\n" + + " <abbr id='abbr'></abbr>\n" + + " <acronym id='acronym'></acronym>\n" + + " <address id='address'></address>\n" + + " <article id='article'></article>\n" + + " <aside id='aside'></aside>\n" + + " <audio id='audio'></audio>\n" + + " </p>\n" + + // + " <applet id='applet'></applet>\n" + + + " <img usemap='#imgmap'>\n" + + " <map name='imgmap'>\n" + + " <area id='area'>\n" + + " </map>\n" + + " </img>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('a'));\n" + + " alert(x('abbr'));\n" + + " alert(x('acronym'));\n" + + " alert(x('address'));\n" + // + " alert(x('applet'));\n" + + " alert(x('area'));\n" + + " alert(x('article'));\n" + + " alert(x('aside'));\n" + + " alert(x('audio'));\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "inline", "inline", "inline", "block", "inline", "inline-block" }) + public void defaultDisplayValues_B() throws Exception { + final String html = "<html><body>\n" + + " <p id='p'>\n" + + " <b id='b'></b>\n" + // + " <bdi id='bdi'></bdi>\n" + + " <bdo id='bdo'></bdo>\n" + + " <big id='big'></big>\n" + + " <blockquote id='blockquote'></blockquote>\n" + + " <br id='br'>\n" + + " <button id='button' type='button'></button>\n" + + " </p>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('b'));\n" + // + " alert(x('bdi'));\n" + + + " alert(x('bdo'));\n" + + " alert(x('big'));\n" + + " alert(x('blockquote'));\n" + + " alert(x('br'));\n" + + " alert(x('button'));\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "inline", "table-caption", "block", "inline", "inline", "table-column", "table-column-group" }) + public void defaultDisplayValues_C() throws Exception { + final String html = "<html><body>\n" + + " <canvas id='canvas'></canvas>\n" + + " <center id='center'></center>\n" + + " <code id='code'></code>\n" + + + " <table>\n" + + " <caption id='caption'></caption>\n" + + " <colgroup id='colgroup'>\n" + + " <col id='col'>\n" + + " </colgroup>\n" + + " </table>\n" + + + " <p id='p'>\n" + + " <cite id='cite'></cite>\n" + + " </p>\n" + + + " <menu>\n" + // + " <command id='command'></command>\n" + + " </menu>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('canvas'));\n" + + " alert(x('caption'));\n" + + " alert(x('center'));\n" + + " alert(x('cite'));\n" + + " alert(x('code'));\n" + + " alert(x('col'));\n" + + " alert(x('colgroup'));\n" + // + " alert(x('command'));\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "block", "inline", "inline", "block", "block", "block", "block" }) + public void defaultDisplayValues_D() throws Exception { + final String html = "<html><body>\n" + + " <datalist id='datalist'></datalist>\n" + + + " <dl id='dl'>\n" + + " <dt id='dt'></dt>\n" + + " <dd id='dd'><dd>\n" + + " </dl>\n" + + + " <p id='p'>\n" + + " <del id='del'></del>\n" + + " </p>\n" + + // + " <details id='details'></details>\n" + + " <dfn id='dfn'></dfn>\n" + // + " <dialog id='dialog'></dialog>\n" + + " <dir id='dir'></dir>\n" + + " <dir id='div'></div>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + // + " alert(x('datalist'));\n" + + " alert(x('dd'));\n" + + " alert(x('del'));\n" + // + " alert(x('details'));\n" + + " alert(x('dfn'));\n" + // + " alert(x('dialog'));\n" + + " alert(x('dir'));\n" + + " alert(x('div'));\n" + + " alert(x('dl'));\n" + + " alert(x('dt'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "inline", "inline" }) + public void defaultDisplayValues_E() throws Exception { + final String html = "<html><body>\n" + + " <p id='p'>\n" + + " <em id='em'></em>\n" + + " </p>\n" + + + " <embed id='embed'>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('em'));\n" + + " alert(x('embed'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "block", "block", "block", "inline", "block", "block" }) + public void defaultDisplayValues_F() throws Exception { + final String html = "<html><body>\n" + + " <form id='form'>\n" + + " <fieldset id='fieldset'></fieldset>\n" + + " </form>\n" + + + " <figure id='figure'>\n" + + " <figcaption id='figcaption'></figcaption>\n" + + " </figure>\n" + + + " <p id='p'>\n" + + " <font id='font'></font>\n" + + " </p>\n" + + + " <footer id='footer'></footer>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('fieldset'));\n" + + " alert(x('figcaption'));\n" + + " alert(x('figure'));\n" + + " alert(x('font'));\n" + + " alert(x('footer'));\n" + + " alert(x('form'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "block", "block", "block", "block", "block", "block", "block", "block" }) + public void defaultDisplayValues_H() throws Exception { + final String html = "<html><body>\n" + + " <h1 id='h1'></h1>\n" + + " <h2 id='h2'></h2>\n" + + " <h3 id='h3'></h3>\n" + + " <h4 id='h4'></h4>\n" + + " <h5 id='h5'></h5>\n" + + " <h6 id='h6'></h6>\n" + + + " <header id='header'></header>\n" + + " <hr id='hr'>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('h1'));\n" + + " alert(x('h2'));\n" + + " alert(x('h3'));\n" + + " alert(x('h4'));\n" + + " alert(x('h5'));\n" + + " alert(x('h6'));\n" + + " alert(x('header'));\n" + + " alert(x('hr'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(IE = "block block block block block block block block", + FF = "table table-header-group table-row-group table-cell table-row table-cell block list-item") + public void defaultDisplayValuesTable() throws Exception { + final String html = "<html><body>\n" + " <table id='table'>\n" + " <thead id='thead'><tr id='tr'><th id='th'>header</th></tr></thead>\n" + " <tbody id='tbody'><tr><td id='td'>body</td></tr></tbody>\n" + " </table>\n" + + " <ul id='ul'><li id='li'>blah</li></ul>\n" - + " <div id='div'></div>\n" + + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" @@ -264,7 +548,8 @@ + " </script>\n" + " <script>\n" + " alert(x('table') + ' ' + x('thead') + ' ' + x('tbody') + ' ' + x('th') + ' ' + x('tr') +\n" - + " ' ' + x('td') + ' ' + x('ul') + ' ' + x('li') + ' ' + x('div'));</script>\n" + + " ' ' + x('td') + ' ' + x('ul') + ' ' + x('li'));\n" + + " </script>\n" + "</body></html>"; loadPageWithAlerts2(html); } |
From: <rb...@us...> - 2013-06-30 12:44:20
|
Revision: 8361 http://sourceforge.net/p/htmlunit/code/8361 Author: rbri Date: 2013-06-30 12:44:17 +0000 (Sun, 30 Jun 2013) Log Message: ----------- adjust expectations for IE8 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 12:18:56 UTC (rev 8360) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 12:44:17 UTC (rev 8361) @@ -122,8 +122,10 @@ map.put("A", "inline"); map.put("ABBR", "inline"); map.put("ACRONYM", "inline"); - map.put("AREA", "none"); - map.put("AUDIO", "none"); + map.put("AREA", "inline"); + map.put("ARTICLE", "inline"); + map.put("ASIDE", "inline"); + map.put("AUDIO", "inline"); map.put("B", "inline"); map.put("BDO", "inline"); map.put("BIG", "inline"); @@ -139,12 +141,24 @@ map.put("DFN", "inline"); map.put("EM", "inline"); map.put("EMBED", "inline"); + map.put("FIGCAPTION", "inline"); + map.put("FIGURE", "inline"); map.put("FONT", "inline"); + map.put("FOOTER", "inline"); + map.put("HEADER", "inline"); map.put("SPAN", "inline"); DEFAULT_DISPLAYS = Collections.unmodifiableMap(map); map = new HashMap<String, String>(map); + map.put("AREA", "none"); + map.put("ARTICLE", "block"); + map.put("ASIDE", "block"); + map.put("AUDIO", "none"); map.put("CODE", "inline"); + map.put("FIGCAPTION", "block"); + map.put("FIGURE", "block"); + map.put("FOOTER", "block"); + map.put("HEADER", "block"); map.put("SPAN", "inline"); map.put("LI", "list-item"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 12:18:56 UTC (rev 8360) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 12:44:17 UTC (rev 8361) @@ -246,10 +246,10 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF = { "inline", "inline", "inline", "block", /* "inline-block", */ "none", "block", "block", "none" }, - IE = { "inline", "inline", "inline", "block", /* "none", */ "inline", "block", "block", "none" }) + @Alerts(DEFAULT = { "inline", "inline", "inline", "block", /* "inline-block", */ "none", "block", "block", "none" }, + IE = { "inline", "inline", "inline", "block", /* "none", */ "inline", "inline", "inline", "inline" }) public void defaultDisplayValues_A() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <p id='p'>\n" + " <a id='a'></a>\n" + " <abbr id='abbr'></abbr>\n" @@ -295,7 +295,7 @@ @Test @Alerts({ "inline", "inline", "inline", "block", "inline", "inline-block" }) public void defaultDisplayValues_B() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <p id='p'>\n" + " <b id='b'></b>\n" // + " <bdi id='bdi'></bdi>\n" @@ -332,7 +332,7 @@ @Test @Alerts({ "inline", "table-caption", "block", "inline", "inline", "table-column", "table-column-group" }) public void defaultDisplayValues_C() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <canvas id='canvas'></canvas>\n" + " <center id='center'></center>\n" + " <code id='code'></code>\n" @@ -378,7 +378,7 @@ @Test @Alerts({ "block", "inline", "inline", "block", "block", "block", "block" }) public void defaultDisplayValues_D() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <datalist id='datalist'></datalist>\n" + " <dl id='dl'>\n" @@ -425,7 +425,7 @@ @Test @Alerts({ "inline", "inline" }) public void defaultDisplayValues_E() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <p id='p'>\n" + " <em id='em'></em>\n" + " </p>\n" @@ -451,9 +451,10 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "block", "block", "block", "inline", "block", "block" }) + @Alerts(DEFAULT = { "block", "block", "block", "inline", "block", "block" }, + IE = { "block", "inline", "inline", "inline", "inline", "block" }) public void defaultDisplayValues_F() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <form id='form'>\n" + " <fieldset id='fieldset'></fieldset>\n" + " </form>\n" @@ -491,9 +492,10 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "block", "block", "block", "block", "block", "block", "block", "block" }) + @Alerts(DEFAULT = { "block", "block", "block", "block", "block", "block", "block", "block" }, + IE = { "block", "block", "block", "block", "block", "block", "inline", "block" }) public void defaultDisplayValues_H() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <h1 id='h1'></h1>\n" + " <h2 id='h2'></h2>\n" + " <h3 id='h3'></h3>\n" |
From: <rb...@us...> - 2013-06-30 15:43:24
|
Revision: 8362 http://sourceforge.net/p/htmlunit/code/8362 Author: rbri Date: 2013-06-30 15:43:20 +0000 (Sun, 30 Jun 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 12:44:17 UTC (rev 8361) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 15:43:20 UTC (rev 8362) @@ -146,7 +146,24 @@ map.put("FONT", "inline"); map.put("FOOTER", "inline"); map.put("HEADER", "inline"); + map.put("I", "inline"); + map.put("IFRAME", "inline"); + map.put("IMG", "inline"); + map.put("INPUT", "inline-block"); + map.put("INS", "inline"); + map.put("KBD", "inline"); + map.put("KEYGEN", "inline"); + map.put("LABEL", "inline"); + map.put("LEGEND", "inline"); + map.put("LI", "list-item"); map.put("SPAN", "inline"); + + map.put("TABLE", "table"); + map.put("TBODY", "table-row-group"); + map.put("TD", "table-cell"); + map.put("TH", "table-cell"); + map.put("THEAD", "table-header-group"); + map.put("TR", "table-row"); DEFAULT_DISPLAYS = Collections.unmodifiableMap(map); map = new HashMap<String, String>(map); @@ -159,15 +176,9 @@ map.put("FIGURE", "block"); map.put("FOOTER", "block"); map.put("HEADER", "block"); - map.put("SPAN", "inline"); + map.put("INPUT", "inline"); + map.put("LEGEND", "block"); - map.put("LI", "list-item"); - map.put("TABLE", "table"); - map.put("TBODY", "table-row-group"); - map.put("TD", "table-cell"); - map.put("TH", "table-cell"); - map.put("THEAD", "table-header-group"); - map.put("TR", "table-row"); DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 12:44:17 UTC (rev 8361) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 15:43:20 UTC (rev 8362) @@ -531,10 +531,105 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = "block block block block block block block block", - FF = "table table-header-group table-row-group table-cell table-row table-cell block list-item") + @Alerts(DEFAULT = { "inline", "inline", "inline", "inline", "inline", "inline", + "inline", "inline", "inline", "inline" }, + IE = { "inline", "inline", "inline", "inline-block", "inline-block", + "inline-block", "inline-block", "inline-block", "inline-block", "inline" }) + public void defaultDisplayValues_I() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <p id='p'>\n" + + " <i id='i'></i>\n" + + " <ins id='ins'></ins>\n" + + " </p>\n" + + + " <iframe id='iframe'></iframe>\n" + + " <img id='img'></img>\n" + + + " <form id='form'>\n" + + " <input id='submit' type='submit'>\n" + + " <input id='reset' type='reset'>\n" + + " <input id='text' type='text'>\n" + + " <input id='password' type='password'>\n" + + " <input id='checkbox' type='checkbox'>\n" + + " <input id='radio' type='radio'>\n" + + " </form>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('i'));\n" + + " alert(x('iframe'));\n" + + " alert(x('img'));\n" + + + " alert(x('submit'));\n" + + " alert(x('reset'));\n" + + " alert(x('text'));\n" + + " alert(x('password'));\n" + + " alert(x('checkbox'));\n" + + " alert(x('radio'));\n" + + + " alert(x('ins'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "inline", "inline", "inline", "block", "list-item" }, + IE = { "inline", "inline", "inline", "inline", "list-item" }) + public void defaultDisplayValues_KL() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <p id='p'>\n" + + " <kbd id='kbd'></kbd>\n" + + " <ins id='ins'></ins>\n" + + " </p>\n" + + + " <ol>\n" + + " <li id='li'></li>\n" + + " </ol>\n" + + + " <form id='form'>\n" + + " <keygen id='keygen'>\n" + + " <label id='label'>\n" + + " <fieldset id='fieldset'>\n" + + " <legend id='legend'></legend>\n" + + " </fieldset>\n" + + " </form>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('kbd'));\n" + + " alert(x('keygen'));\n" + + + " alert(x('label'));\n" + + " alert(x('legend'));\n" + + " alert(x('li'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts("table table-header-group table-row-group table-cell table-row table-cell block list-item") public void defaultDisplayValuesTable() throws Exception { - final String html = "<html><body>\n" + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <table id='table'>\n" + " <thead id='thead'><tr id='tr'><th id='th'>header</th></tr></thead>\n" + " <tbody id='tbody'><tr><td id='td'>body</td></tr></tbody>\n" |
From: <rb...@us...> - 2013-06-30 15:53:49
|
Revision: 8363 http://sourceforge.net/p/htmlunit/code/8363 Author: rbri Date: 2013-06-30 15:53:44 +0000 (Sun, 30 Jun 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 15:43:20 UTC (rev 8362) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 15:53:44 UTC (rev 8363) @@ -156,6 +156,10 @@ map.put("LABEL", "inline"); map.put("LEGEND", "inline"); map.put("LI", "list-item"); + map.put("MAP", "inline"); + map.put("MARK", "inline"); + map.put("METER", "inline"); + map.put("SPAN", "inline"); map.put("TABLE", "table"); @@ -178,6 +182,7 @@ map.put("HEADER", "block"); map.put("INPUT", "inline"); map.put("LEGEND", "block"); + map.put("METER", "inline-block"); DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 15:43:20 UTC (rev 8362) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 15:53:44 UTC (rev 8363) @@ -627,6 +627,47 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { "inline", "inline", "block", "inline-block" }, + IE = { "inline", "inline", "block", "inline" }) + public void defaultDisplayValues_M() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <img usemap='#imgmap'>\n" + + " <map id='map' name='imgmap'>\n" + + " <area id='area'>\n" + + " </map>\n" + + " </img>\n" + + + " <p id='p'>\n" + + " <mark id='mark'></mark>\n" + + " </p>\n" + + + " <menu id='menu'>\n" + + " <li id='li'></li>\n" + + " </menu>\n" + + + " <meter id='meter'></meter>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " alert(x('map'));\n" + + " alert(x('mark'));\n" + + " alert(x('menu'));\n" + + " alert(x('meter'));\n" + + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts("table table-header-group table-row-group table-cell table-row table-cell block list-item") public void defaultDisplayValuesTable() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" |
From: <rb...@us...> - 2013-06-30 20:32:22
|
Revision: 8364 http://sourceforge.net/p/htmlunit/code/8364 Author: rbri Date: 2013-06-30 20:32:19 +0000 (Sun, 30 Jun 2013) Log Message: ----------- try to fix the build, the real fix seems to need more time Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 15:53:44 UTC (rev 8363) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-30 20:32:19 UTC (rev 8364) @@ -147,7 +147,7 @@ map.put("FOOTER", "inline"); map.put("HEADER", "inline"); map.put("I", "inline"); - map.put("IFRAME", "inline"); + // map.put("IFRAME", "inline"); map.put("IMG", "inline"); map.put("INPUT", "inline-block"); map.put("INS", "inline"); @@ -629,7 +629,8 @@ map = DEFAULT_DISPLAYS_CSS; } - final String defaultValue = map.get(getElement().getTagName()); + final String tagName = getElement().getTagName(); + final String defaultValue = map.get(tagName); if (defaultValue == null) { return "block"; } @@ -1200,7 +1201,16 @@ */ public int getContentWidth() { int width = 0; - for (final DomNode child : getDomNodeOrDie().getChildren()) { + final DomNode domNode = getDomNodeOrDie(); + final Iterable<DomNode> childs = domNode.getChildren(); +// if (domNode instanceof BaseFrameElement) { +// final Page enclosedPage = ((BaseFrameElement) domNode).getEnclosedPage(); +// if (enclosedPage instanceof HtmlPage) { +// final HtmlPage htmlPage = (HtmlPage) enclosedPage; +// childs = htmlPage.getChildren(); +// } +// } + for (final DomNode child : childs) { if (child.getScriptObject() instanceof HTMLElement) { final HTMLElement e = (HTMLElement) child.getScriptObject(); final int w = e.getCurrentStyle().getCalculatedWidth(true, true); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 15:53:44 UTC (rev 8363) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-06-30 20:32:19 UTC (rev 8364) @@ -535,6 +535,7 @@ "inline", "inline", "inline", "inline" }, IE = { "inline", "inline", "inline", "inline-block", "inline-block", "inline-block", "inline-block", "inline-block", "inline-block", "inline" }) + @NotYetImplemented public void defaultDisplayValues_I() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <p id='p'>\n" |
From: <rb...@us...> - 2013-07-05 19:55:51
|
Revision: 8368 http://sourceforge.net/p/htmlunit/code/8368 Author: rbri Date: 2013-07-05 19:55:49 +0000 (Fri, 05 Jul 2013) Log Message: ----------- some more hacking on element visibility Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-05 18:54:28 UTC (rev 8367) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-05 19:55:49 UTC (rev 8368) @@ -45,9 +45,22 @@ import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.html.BaseFrameElement; import com.gargoylesoftware.htmlunit.html.DomNode; +import com.gargoylesoftware.htmlunit.html.HtmlButton; +import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput; +import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame; +import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; +import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlResetInput; +import com.gargoylesoftware.htmlunit.html.HtmlSelect; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTableRow; +import com.gargoylesoftware.htmlunit.html.HtmlTextArea; +import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.host.Element; import com.gargoylesoftware.htmlunit.javascript.host.Text; @@ -55,8 +68,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLIFrameElement; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTextAreaElement; /** * A JavaScript object for a ComputedCSSStyleDeclaration. @@ -152,7 +163,7 @@ map.put("I", "inline"); map.put("IFRAME", "inline"); map.put("IMG", "inline"); - // map.put("INPUT", "inline-block"); + map.put("INPUT", "inline-block"); map.put("INS", "inline"); map.put("KBD", "inline"); map.put("KEYGEN", "inline"); @@ -183,7 +194,7 @@ map.put("FIGURE", "block"); map.put("FOOTER", "block"); map.put("HEADER", "block"); - // map.put("INPUT", "inline"); + map.put("INPUT", "inline"); map.put("LEGEND", "block"); map.put("METER", "inline-block"); @@ -1161,7 +1172,7 @@ final String cssFloat = getCssFloat(); if ("right".equals(cssFloat) || "left".equals(cssFloat)) { // We're floating; simplistic approximation: text content * pixels per character. - width = getDomNodeOrDie().getTextContent().length() * PIXELS_PER_CHAR; + width = node.getTextContent().length() * PIXELS_PER_CHAR; } else if ("block".equals(display)) { // Block elements take up 100% of the parent's width. @@ -1180,6 +1191,23 @@ } width -= (getBorderHorizontal() + getPaddingHorizontal()); } + else if (node instanceof HtmlSubmitInput || node instanceof HtmlResetInput + || node instanceof HtmlButtonInput || node instanceof HtmlButton) { + final String text = node.asText(); + width = 10 + (text.length() * PIXELS_PER_CHAR); + } + else if (node instanceof HtmlTextInput || node instanceof HtmlPasswordInput) { + width = 50; // wild guess + } + else if (node instanceof HtmlRadioButtonInput || node instanceof HtmlCheckBoxInput) { + width = 20; // wild guess + } + else if (node instanceof HtmlTextInput || node instanceof HtmlPasswordInput) { + width = 50; // wild guess + } + else if (node instanceof HtmlTextArea) { + width = 100; // wild guess + } else { // Inline elements take up however much space is required by their children. width = getContentWidth(); @@ -1310,12 +1338,19 @@ final int defaultHeight; if (getElement().getFirstChild() == null) { - if (getElement() instanceof HTMLIFrameElement) { - defaultHeight = 154; + if (node instanceof HtmlButton + || (node instanceof HtmlInput && !(node instanceof HtmlHiddenInput))) { + defaultHeight = 20; } - else if (getElement() instanceof HTMLTextAreaElement) { + else if (node instanceof HtmlSelect) { + defaultHeight = 20; + } + else if (node instanceof HtmlTextArea) { defaultHeight = 49; } + else if (node instanceof HtmlInlineFrame) { + defaultHeight = 154; + } else { defaultHeight = 0; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-05 18:54:28 UTC (rev 8367) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-05 19:55:49 UTC (rev 8368) @@ -535,7 +535,6 @@ "inline", "inline", "inline", "inline" }, IE = { "inline", "inline", "inline", "inline-block", "inline-block", "inline-block", "inline-block", "inline-block", "inline-block", "inline" }) - @NotYetImplemented public void defaultDisplayValues_I() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <p id='p'>\n" @@ -902,6 +901,51 @@ } /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "true", "true", "true", "true", "true", "true", "true", "true", + "true", "true", "true", "true", "false", "false", + "true", "true", "true", "true" }) + public void widthAndHeightInputElements() throws Exception { + final String html = "<html>\n" + + "<body>\n" + + " <form id='form'>\n" + + " <input id='submit' type='submit'>\n" + + " <input id='reset' type='reset'>\n" + + " <input id='text' type='text'>\n" + + " <input id='password' type='password'>\n" + + " <input id='checkbox' type='checkbox'>\n" + + " <input id='radio' type='radio'>\n" + + " <input id='hidden' type='hidden'>\n" + + " <button id='button' type='button'></button>\n" + + " <textarea id='myTextarea'></textarea>\n" + + " </form>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " alert(e.offsetWidth > 0);\n" + + " alert(e.offsetHeight > 0);\n" + + " }\n" + + " </script>\n" + + + " <script>\n" + + " x('submit');\n" + + " x('reset');\n" + + " x('text');\n" + + " x('password');\n" + + " x('checkbox');\n" + + " x('radio');\n" + + " x('hidden');\n" + + " x('button');\n" + + " x('myTextarea');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** * @throws Exception if the test fails */ @Test |
From: <rb...@us...> - 2013-07-07 13:57:53
|
Revision: 8379 http://sourceforge.net/p/htmlunit/code/8379 Author: rbri Date: 2013-07-07 13:57:50 +0000 (Sun, 07 Jul 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-06 16:29:28 UTC (rev 8378) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-07 13:57:50 UTC (rev 8379) @@ -173,6 +173,12 @@ map.put("MAP", "inline"); map.put("MARK", "inline"); map.put("METER", "inline"); + map.put("NAV", "inline"); + // map.put("NOSCRIPT", "inline"); + map.put("OBJECT", "inline"); + map.put("OPTGROUP", "inline"); + map.put("OPTION", "inline"); + map.put("OUTPUT", "inline"); map.put("SPAN", "inline"); @@ -197,6 +203,10 @@ map.put("INPUT", "inline"); map.put("LEGEND", "block"); map.put("METER", "inline-block"); + map.put("NAV", "block"); + // map.put("NOSCRIPT", "none"); + map.put("OPTGROUP", "block"); + map.put("OPTION", "block"); DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-06 16:29:28 UTC (rev 8378) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-07 13:57:50 UTC (rev 8379) @@ -271,19 +271,20 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('a'));\n" - + " alert(x('abbr'));\n" - + " alert(x('acronym'));\n" - + " alert(x('address'));\n" - // + " alert(x('applet'));\n" - + " alert(x('area'));\n" - + " alert(x('article'));\n" - + " alert(x('aside'));\n" - + " alert(x('audio'));\n" + + " x('a');\n" + + " x('abbr');\n" + + " x('acronym');\n" + + " x('address');\n" + // + " x('applet');\n" + + " x('area');\n" + + " x('article');\n" + + " x('aside');\n" + + " x('audio');\n" + " </script>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -309,18 +310,19 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('b'));\n" - // + " alert(x('bdi'));\n" + + " x('b');\n" + // + " x('bdi');\n" - + " alert(x('bdo'));\n" - + " alert(x('big'));\n" - + " alert(x('blockquote'));\n" - + " alert(x('br'));\n" - + " alert(x('button'));\n" + + " x('bdo');\n" + + " x('big');\n" + + " x('blockquote');\n" + + " x('br');\n" + + " x('button');\n" + " </script>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -355,18 +357,19 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('canvas'));\n" - + " alert(x('caption'));\n" - + " alert(x('center'));\n" - + " alert(x('cite'));\n" - + " alert(x('code'));\n" - + " alert(x('col'));\n" - + " alert(x('colgroup'));\n" - // + " alert(x('command'));\n" + + " x('canvas');\n" + + " x('caption');\n" + + " x('center');\n" + + " x('cite');\n" + + " x('code');\n" + + " x('col');\n" + + " x('colgroup');\n" + // + " x('command');\n" + " </script>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -399,20 +402,21 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - // + " alert(x('datalist'));\n" - + " alert(x('dd'));\n" - + " alert(x('del'));\n" - // + " alert(x('details'));\n" - + " alert(x('dfn'));\n" - // + " alert(x('dialog'));\n" - + " alert(x('dir'));\n" - + " alert(x('div'));\n" - + " alert(x('dl'));\n" - + " alert(x('dt'));\n" + // + " x('datalist');\n" + + " x('dd');\n" + + " x('del');\n" + // + " x('details');\n" + + " x('dfn');\n" + // + " x('dialog');\n" + + " x('dir');\n" + + " x('div');\n" + + " x('dl');\n" + + " x('dt');\n" + " </script>\n" + "</body></html>"; @@ -435,12 +439,13 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('em'));\n" - + " alert(x('embed'));\n" + + " x('em');\n" + + " x('embed');\n" + " </script>\n" + "</body></html>"; @@ -472,16 +477,17 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('fieldset'));\n" - + " alert(x('figcaption'));\n" - + " alert(x('figure'));\n" - + " alert(x('font'));\n" - + " alert(x('footer'));\n" - + " alert(x('form'));\n" + + " x('fieldset');\n" + + " x('figcaption');\n" + + " x('figure');\n" + + " x('font');\n" + + " x('footer');\n" + + " x('form');\n" + " </script>\n" + "</body></html>"; @@ -509,18 +515,19 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('h1'));\n" - + " alert(x('h2'));\n" - + " alert(x('h3'));\n" - + " alert(x('h4'));\n" - + " alert(x('h5'));\n" - + " alert(x('h6'));\n" - + " alert(x('header'));\n" - + " alert(x('hr'));\n" + + " x('h1');\n" + + " x('h2');\n" + + " x('h3');\n" + + " x('h4');\n" + + " x('h5');\n" + + " x('h6');\n" + + " x('header');\n" + + " x('hr');\n" + " </script>\n" + "</body></html>"; @@ -557,22 +564,23 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('i'));\n" - + " alert(x('iframe'));\n" - + " alert(x('img'));\n" + + " x('i');\n" + + " x('iframe');\n" + + " x('img');\n" - + " alert(x('submit'));\n" - + " alert(x('reset'));\n" - + " alert(x('text'));\n" - + " alert(x('password'));\n" - + " alert(x('checkbox'));\n" - + " alert(x('radio'));\n" + + " x('submit');\n" + + " x('reset');\n" + + " x('text');\n" + + " x('password');\n" + + " x('checkbox');\n" + + " x('radio');\n" - + " alert(x('ins'));\n" + + " x('ins');\n" + " </script>\n" + "</body></html>"; @@ -607,16 +615,17 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('kbd'));\n" - + " alert(x('keygen'));\n" + + " x('kbd');\n" + + " x('keygen');\n" - + " alert(x('label'));\n" - + " alert(x('legend'));\n" - + " alert(x('li'));\n" + + " x('label');\n" + + " x('legend');\n" + + " x('li');\n" + " </script>\n" + "</body></html>"; @@ -650,14 +659,15 @@ + " <script>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('map'));\n" - + " alert(x('mark'));\n" - + " alert(x('menu'));\n" - + " alert(x('meter'));\n" + + " x('map');\n" + + " x('mark');\n" + + " x('menu');\n" + + " x('meter');\n" + " </script>\n" + "</body></html>"; @@ -668,6 +678,57 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { "block", "none", "inline", "block", "block", "block", "inline" }, + IE = { "inline", "inline", "inline", "block", "inline", "inline", "inline" }) + @NotYetImplemented + public void defaultDisplayValues_NO() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <nav id='nav'>\n" + + " <a id='a'></a>\n" + + " </nav>\n" + + + " <noscript id='noscript'></noscript> \n" + + + " <object id='object'></object> " + + " <ol id='ol'>\n" + + " <li></li>\n" + + " </ol>\n" + + + " <form>\n" + + " <select>\n" + + " <optgroup id='optgroup'>\n" + + " <option></option>\n" + + " </optgroup>\n" + + " <option id='option'></option>\n" + + " </select>\n" + + " <output id='output'></output>\n" + + " </form>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " x('nav');\n" + + " x('noscript');\n" + + + " x('object');\n" + + " x('ol');\n" + + " x('optgroup');\n" + + " x('option');\n" + + " x('output');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts("table table-header-group table-row-group table-cell table-row table-cell block list-item") public void defaultDisplayValuesTable() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" |
From: <rb...@us...> - 2013-07-07 21:27:52
|
Revision: 8380 http://sourceforge.net/p/htmlunit/code/8380 Author: rbri Date: 2013-07-07 21:27:49 +0000 (Sun, 07 Jul 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-07 13:57:50 UTC (rev 8379) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-07 21:27:49 UTC (rev 8380) @@ -179,6 +179,9 @@ map.put("OPTGROUP", "inline"); map.put("OPTION", "inline"); map.put("OUTPUT", "inline"); + map.put("PARAM", "inline"); + map.put("PROGRESS", "inline"); + map.put("Q", "inline"); map.put("SPAN", "inline"); @@ -207,6 +210,8 @@ // map.put("NOSCRIPT", "none"); map.put("OPTGROUP", "block"); map.put("OPTION", "block"); + map.put("PARAM", "none"); + map.put("PROGRESS", "inline-block"); DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-07 13:57:50 UTC (rev 8379) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-07 21:27:49 UTC (rev 8380) @@ -729,6 +729,43 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { "block", "none", "block", "inline-block", "inline" }, + IE = { "block", "inline", "block", "inline", "inline" }) + public void defaultDisplayValues_PQ() throws Exception { + // this fails in real IE8 but works in IE9 + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <p id='p'><q id='q'></q></p>\n" + + + " <object>\n" + + " <param id='param' name='movie' value=''></param>\n" + + " </object> " + + + " <pre id='pre'></pre>\n" + + " <progress id='progress'></progress>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " x('p');\n" + + " x('param');\n" + + " x('pre');\n" + + " x('progress');\n" + + + " x('q');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts("table table-header-group table-row-group table-cell table-row table-cell block list-item") public void defaultDisplayValuesTable() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" |
From: <mgu...@us...> - 2013-07-09 09:04:50
|
Revision: 8381 http://sourceforge.net/p/htmlunit/code/8381 Author: mguillem Date: 2013-07-09 09:04:47 +0000 (Tue, 09 Jul 2013) Log Message: ----------- JavaScript: add basic support for window.navigator.security (FF only) Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Netscape.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NetscapeTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-07 21:27:49 UTC (rev 8380) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-09 09:04:47 UTC (rev 8381) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="mguillem"> + JavaScript: add basic support for window.navigator.security (FF only). + </action> <action type="fix" dev="rbri" issue="1510"> Make the handling of empty responses more error proof. </action> Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Netscape.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Netscape.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Netscape.java 2013-07-09 09:04:47 UTC (rev 8381) @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import net.sourceforge.htmlunit.corejs.javascript.Context; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; + +/** + * A JavaScript object for window.netscape (FF simulation only). + * + * @version $Revision$ + * @author Marc Guillemot + */ +@JsxClass(browsers = @WebBrowser(FF)) +public class Netscape extends SimpleScriptable { + + Netscape(final Window window) { + setParentScope(window); + + // simply put "new Object()" for property "security" + put("security", this, Context.getCurrentContext().newObject(window)); + } + + @Override + public String getClassName() { + return "Object"; + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Netscape.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2013-07-07 21:27:49 UTC (rev 8380) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2013-07-09 09:04:47 UTC (rev 8381) @@ -1939,6 +1939,15 @@ } /** + * Returns the value of "netscape" property. + * @return the value of "netscape" property + */ + @JsxGetter(@WebBrowser(FF)) + public Netscape getNetscape() { + return new Netscape(this); + } + + /** * Executes the event on this object only (needed for instance for onload on (i)frame tags). * @param event the event * @return the result Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NetscapeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NetscapeTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NetscapeTest.java 2013-07-09 09:04:47 UTC (rev 8381) @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; + +/** + * Tests for {@link Netscape}. + * + * @version $Revision$ + * @author Marc Guillemot + */ +@RunWith(BrowserRunner.class) +public class NetscapeTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "undefined", "exception" }, + FF3_6 = { "[object Object]", "undefined", "[object Object]", "[object Object]" }, + FF = { "[object Object]", "undefined", "[object Object]", "undefined" }) + @NotYetImplemented(Browser.FF3_6) + public void netscape() throws Exception { + final String html = "<html><body><script>\n" + + "try {\n" + + " alert(window.netscape);\n" + + " alert(window.Netscape);\n" + + " alert(window.netscape.security);\n" + + " alert(window.netscape.security.PrivilegeManager);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script></body></html>"; + + loadPageWithAlerts2(html); + } + +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NetscapeTest.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |
From: <rb...@us...> - 2013-07-09 16:05:44
|
Revision: 8383 http://sourceforge.net/p/htmlunit/code/8383 Author: rbri Date: 2013-07-09 16:05:40 +0000 (Tue, 09 Jul 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-09 11:44:19 UTC (rev 8382) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-09 16:05:40 UTC (rev 8383) @@ -182,8 +182,23 @@ map.put("PARAM", "inline"); map.put("PROGRESS", "inline"); map.put("Q", "inline"); - + map.put("RUBY", "ruby"); + map.put("RT", "ruby-text"); + map.put("RP", "inline"); + map.put("S", "inline"); + map.put("SAMP", "inline"); + map.put("SCRIPT", "inline"); + map.put("SECTION", "inline"); + map.put("SELECT", "inline-block"); + map.put("SMALL", "inline"); + map.put("SUP", "inline"); + map.put("SOURCE", "inline"); map.put("SPAN", "inline"); + map.put("STRIKE", "inline"); + map.put("STRONG", "inline"); + map.put("SUB", "inline"); + map.put("SUMMARY", "inline"); + map.put("SUP", "inline"); map.put("TABLE", "table"); map.put("TBODY", "table-row-group"); @@ -212,6 +227,11 @@ map.put("OPTION", "block"); map.put("PARAM", "none"); map.put("PROGRESS", "inline-block"); + map.put("RUBY", "inline"); + map.put("RT", "inline"); + map.put("SCRIPT", "none"); + map.put("SECTION", "block"); + map.put("SELECT", "inline"); DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-09 11:44:19 UTC (rev 8382) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-09 16:05:40 UTC (rev 8383) @@ -766,6 +766,96 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { "inline", "inline", "inline" }, + IE = { "ruby", "ruby-text", "inline" }) + public void defaultDisplayValues_R() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <ruby id='ruby'>\n" + + " <rt id='rt'>\n" + + " <rp id='rp'></rp>\n" + + " </rt>\n" + + " </ruby> \n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " x('ruby');\n" + + " x('rt');\n" + + " x('rp');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "inline", "inline", "none", "block", "inline", "inline", + "inline", "inline", "inline", "inline", "inline", "inline", "inline" }, + IE = { "inline", "inline", "inline", "inline", "inline-block", "inline", + "inline", "inline", "inline", "inline", "inline", "inline", "inline" }) + public void defaultDisplayValues_S() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <p>\n" + + " <s id='s'></s>\n" + + " <small id='small'></small>\n" + + " <span id='span'></span>\n" + + " <strike id='strike'></strike>\n" + + " <strong id='strong'></strong>\n" + + " <sub id='sub'></sub>\n" + + " <sup id='sup'></sup>\n" + + " </p> \n" + + + " <samp id='samp'></samp>\n" + + " <section id='section'></section>\n" + + " <summary id='summary'></summary>\n" + + + " <audio>\n" + + " <source id='source'>\n" + + " </audio>\n" + + + " <form>\n" + + " <select id='select'>\n" + + " <option></option>\n" + + " </select>\n" + + " </form>\n" + + + " <script id='script'>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " x('s');\n" + + " x('samp');\n" + + " x('script');\n" + + " x('section');\n" + + " x('select');\n" + + " x('small');\n" + + " x('source');\n" + + " x('span');\n" + + " x('strike');\n" + + " x('strong');\n" + + " x('sub');\n" + + " x('summary');\n" + + " x('sup');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts("table table-header-group table-row-group table-cell table-row table-cell block list-item") public void defaultDisplayValuesTable() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" |
From: <rb...@us...> - 2013-07-10 17:36:50
|
Revision: 8385 http://sourceforge.net/p/htmlunit/code/8385 Author: rbri Date: 2013-07-10 17:36:47 +0000 (Wed, 10 Jul 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-09 19:03:08 UTC (rev 8384) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-10 17:36:47 UTC (rev 8385) @@ -203,9 +203,15 @@ map.put("TABLE", "table"); map.put("TBODY", "table-row-group"); map.put("TD", "table-cell"); + map.put("TEXTAREA", "inline-block"); + map.put("TFOOT", "table-footer-group"); map.put("TH", "table-cell"); map.put("THEAD", "table-header-group"); + map.put("THEAD", "table-header-group"); + map.put("TIME", "inline"); map.put("TR", "table-row"); + map.put("TRACK", "inline"); + map.put("TT", "inline"); DEFAULT_DISPLAYS = Collections.unmodifiableMap(map); map = new HashMap<String, String>(map); @@ -232,6 +238,7 @@ map.put("SCRIPT", "none"); map.put("SECTION", "block"); map.put("SELECT", "inline"); + map.put("TEXTAREA", "inline"); DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-09 19:03:08 UTC (rev 8384) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-10 17:36:47 UTC (rev 8385) @@ -856,25 +856,50 @@ * @throws Exception if an error occurs */ @Test - @Alerts("table table-header-group table-row-group table-cell table-row table-cell block list-item") - public void defaultDisplayValuesTable() throws Exception { + @Alerts(DEFAULT = { "table", "table-row-group", "table-cell", "inline", "table-footer-group", + "table-cell", "table-header-group", "inline", "table-row", "inline", "inline" }, + IE = { "table", "table-row-group", "table-cell", "inline-block", "table-footer-group", + "table-cell", "table-header-group", "inline", "table-row", "inline", "inline" }) + public void defaultDisplayValues_T() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <table id='table'>\n" + " <thead id='thead'><tr id='tr'><th id='th'>header</th></tr></thead>\n" + + " <tfoot id='tfoot'><tr><td>footer</td></tr></tfoot>\n" + " <tbody id='tbody'><tr><td id='td'>body</td></tr></tbody>\n" + " </table>\n" - + " <ul id='ul'><li id='li'>blah</li></ul>\n" + + " <form>\n" + + " <textarea id='textarea'></textarea>\n" + + " </form>\n" - + " <script>\n" + + " <p>\n" + + " <time id='time'></time>\n" + + " <tt id='tt'></tt>\n" + + " </p> \n" + + + " <video>\n" + + " <track id='track'>\n" + + " </video>\n" + + + " <script id='script'>\n" + " function x(id) {\n" + " var e = document.getElementById(id);\n" - + " return e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + " }\n" + " </script>\n" + " <script>\n" - + " alert(x('table') + ' ' + x('thead') + ' ' + x('tbody') + ' ' + x('th') + ' ' + x('tr') +\n" - + " ' ' + x('td') + ' ' + x('ul') + ' ' + x('li'));\n" + + " x('table');\n" + + " x('tbody');\n" + + " x('td');\n" + + " x('textarea');\n" + + " x('tfoot');\n" + + " x('th');\n" + + " x('thead');\n" + + " x('time');\n" + + " x('tr');\n" + + " x('track');\n" + + " x('tt');\n" + " </script>\n" + "</body></html>"; loadPageWithAlerts2(html); |
From: <rb...@us...> - 2013-07-10 17:51:49
|
Revision: 8386 http://sourceforge.net/p/htmlunit/code/8386 Author: rbri Date: 2013-07-10 17:51:45 +0000 (Wed, 10 Jul 2013) Log Message: ----------- more defaults for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-10 17:36:47 UTC (rev 8385) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-10 17:51:45 UTC (rev 8386) @@ -212,6 +212,10 @@ map.put("TR", "table-row"); map.put("TRACK", "inline"); map.put("TT", "inline"); + map.put("U", "inline"); + map.put("VAR", "inline"); + map.put("VIDEO", "inline"); + map.put("WBR", "inline"); DEFAULT_DISPLAYS = Collections.unmodifiableMap(map); map = new HashMap<String, String>(map); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-10 17:36:47 UTC (rev 8385) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-10 17:51:45 UTC (rev 8386) @@ -909,6 +909,43 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { "inline", "block", "inline", "inline", "inline" }) + public void defaultDisplayValues_UVW() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><body>\n" + + " <p>\n" + + " <u id='u'></u>\n" + + " <wbr id='wbr'></wbr>\n" + + " </p> \n" + + + " <ul id='ul'>\n" + + " <li></li>\n" + + " </ul>\n" + + + " <var id='var'></var>\n" + + " <video id='video'></video>\n" + + + " <script id='script'>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " var disp = e.currentStyle ? e.currentStyle.display : window.getComputedStyle(e, '').display;\n" + + " alert(disp);\n" + + " }\n" + + " </script>\n" + + " <script>\n" + + " x('u');\n" + + " x('ul');\n" + + " x('var');\n" + + " x('video');\n" + + " x('wbr');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(IE = { "transparent", "red", "white" }, FF = { "transparent", "rgb(255, 0, 0)", "rgb(255, 255, 255)" }) public void backgroundColor() throws Exception { |
From: <mgu...@us...> - 2013-07-11 08:59:55
|
Revision: 8388 http://sourceforge.net/p/htmlunit/code/8388 Author: mguillem Date: 2013-07-11 08:59:48 +0000 (Thu, 11 Jul 2013) Log Message: ----------- JavaScript: add support for XPathEvaluator (FF & Chrome). Issue 1516 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-10 17:54:18 UTC (rev 8387) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-11 08:59:48 UTC (rev 8388) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="update" dev="mguillem" issue="1516"> + JavaScript: add support for XPathEvaluator (FF & Chrome). + </action> <action type="fix" dev="rbri"> The display property now returns the correct default value for all html tags. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2013-07-10 17:54:18 UTC (rev 8387) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2013-07-11 08:59:48 UTC (rev 8388) @@ -82,6 +82,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.UIEvent; import com.gargoylesoftware.htmlunit.javascript.host.WebSocket; import com.gargoylesoftware.htmlunit.javascript.host.Window; +import com.gargoylesoftware.htmlunit.javascript.host.XPathEvaluator; import com.gargoylesoftware.htmlunit.javascript.host.XPathNSResolver; import com.gargoylesoftware.htmlunit.javascript.host.XPathResult; import com.gargoylesoftware.htmlunit.javascript.host.XSLTProcessor; @@ -338,8 +339,8 @@ StaticNodeList.class, Storage.class, StyleSheetList.class, Text.class, TextRange.class, TreeWalker.class, UIEvent.class, Uint16Array.class, Uint32Array.class, Uint8Array.class, Uint8ClampedArray.class, WebSocket.class, Window.class, XMLAttr.class, XMLDocument.class, XMLDOMParseError.class, - XMLHttpRequest.class, XMLSerializer.class, XPathNSResolver.class, XPathResult.class, XSLTProcessor.class, - XSLTemplate.class}; + XMLHttpRequest.class, XMLSerializer.class, XPathEvaluator.class, XPathNSResolver.class, XPathResult.class, + XSLTProcessor.class, XSLTemplate.class}; /** Cache of browser versions and their corresponding JavaScript configurations. */ private static final Map<BrowserVersion, JavaScriptConfiguration> ConfigurationMap_ = Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java 2013-07-11 08:59:48 UTC (rev 8388) @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; + +/** + * A JavaScript object for XPathEvaluator. + * + * @version $Revision$ + * @author Marc Guillemot + */ +@JsxClass(browsers = @WebBrowser(value = FF, minVersion = 17)) +public class XPathEvaluator extends SimpleScriptable { + + /** + * JavaScript constructor. + */ + @JsxConstructor + public void jsConstructor() { + // Empty + } + + /** + * Adapts any DOM node to resolve namespaces so that an XPath expression can be easily + * evaluated relative to the context of the node where it appeared within the document. + * @param nodeResolver the node to be used as a context for namespace resolution + * @return an XPathNSResolver which resolves namespaces with respect to the definitions + * in scope for a specified node + */ + @JsxFunction(@WebBrowser(FF)) + public XPathNSResolver createNSResolver(final Node nodeResolver) { + final XPathNSResolver resolver = new XPathNSResolver(); + resolver.setElement(nodeResolver); + resolver.setParentScope(getWindow()); + resolver.setPrototype(getPrototype(resolver.getClass())); + return resolver; + } + + /** + * Evaluates an XPath expression string and returns a result of the specified type if possible. + * @param expression the XPath expression string to be parsed and evaluated + * @param contextNode the context node for the evaluation of this XPath expression + * @param resolver the resolver permits translation of all prefixes, including the XML namespace prefix, + * within the XPath expression into appropriate namespace URIs. + * @param type If a specific type is specified, then the result will be returned as the corresponding type + * @param result the result object which may be reused and returned by this method + * @return the result of the evaluation of the XPath expression + */ + @JsxFunction(@WebBrowser(FF)) + public XPathResult evaluate(final String expression, final Node contextNode, + final Object resolver, final int type, final Object result) { + XPathResult xPathResult = (XPathResult) result; + if (xPathResult == null) { + xPathResult = new XPathResult(); + xPathResult.setParentScope(getParentScope()); + xPathResult.setPrototype(getPrototype(xPathResult.getClass())); + } + xPathResult.init(contextNode.getDomNodeOrDie().getByXPath(expression), type); + return xPathResult; + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java 2013-07-11 08:59:48 UTC (rev 8388) @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link XPathEvaluator}. + * + * @version $Revision$ + * @author Marc Guillemot + */ +@RunWith(BrowserRunner.class) +public class XPathEvaluatorTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "function", "[object XPathEvaluator]", "[object XPathNSResolver]", "first", "second" }, + IE = { "undefined", "exception" }, FF3_6 = { "undefined", "exception" }) + public void simple() throws Exception { + final String html = "<html><body>\n" + + "<span id='first'>hello</span>\n" + + "<div><span id='second'>world</span></div>\n" + + "<script>\n" + + "try {\n" + + " alert(typeof window.XPathEvaluator);\n" + + " var xpe = new XPathEvaluator();\n" + + " alert(xpe);\n" + + " var nsResolver = xpe.createNSResolver(document.documentElement);\n" + + " alert(nsResolver);\n" + + " var result = xpe.evaluate('//span', document.body, nsResolver, 0, null);\n" + + " var found = [];\n" + + " var res;\n" + + " while (res = result.iterateNext()) {\n" + + " alert(res.id);\n" + + " }\n" + + "} catch(e) { alert('exception'); }\n" + + "</script></body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |
From: <rb...@us...> - 2013-07-11 16:48:59
|
Revision: 8390 http://sourceforge.net/p/htmlunit/code/8390 Author: rbri Date: 2013-07-11 16:48:56 +0000 (Thu, 11 Jul 2013) Log Message: ----------- last default for the display property fixed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-11 13:28:40 UTC (rev 8389) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-11 16:48:56 UTC (rev 8390) @@ -174,7 +174,7 @@ map.put("MARK", "inline"); map.put("METER", "inline"); map.put("NAV", "inline"); - // map.put("NOSCRIPT", "inline"); + map.put("NOSCRIPT", "inline"); map.put("OBJECT", "inline"); map.put("OPTGROUP", "inline"); map.put("OPTION", "inline"); @@ -231,7 +231,7 @@ map.put("LEGEND", "block"); map.put("METER", "inline-block"); map.put("NAV", "block"); - // map.put("NOSCRIPT", "none"); + map.put("NOSCRIPT", "none"); map.put("OPTGROUP", "block"); map.put("OPTION", "block"); map.put("PARAM", "none"); @@ -683,12 +683,19 @@ } private String getDefaultStyleDisplay() { + final String tagName = getElement().getTagName(); + if ("NOSCRIPT".equals(tagName)) { + final DomNode node = getDomNodeOrNull(); + if (node != null && !node.getPage().getWebClient().getOptions().isJavaScriptEnabled()) { + return "block"; + } + } + Map<String, String> map = DEFAULT_DISPLAYS; if (getBrowserVersion().hasFeature(CSS_DISPLAY_DEFAULT)) { map = DEFAULT_DISPLAYS_CSS; } - final String tagName = getElement().getTagName(); final String defaultValue = map.get(tagName); if (defaultValue == null) { return "block"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-11 13:28:40 UTC (rev 8389) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-11 16:48:56 UTC (rev 8390) @@ -680,7 +680,6 @@ @Test @Alerts(DEFAULT = { "block", "none", "inline", "block", "block", "block", "inline" }, IE = { "inline", "inline", "inline", "block", "inline", "inline", "inline" }) - @NotYetImplemented public void defaultDisplayValues_NO() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <nav id='nav'>\n" |
From: <mgu...@us...> - 2013-07-12 09:16:36
|
Revision: 8392 http://sourceforge.net/p/htmlunit/code/8392 Author: mguillem Date: 2013-07-12 09:16:33 +0000 (Fri, 12 Jul 2013) Log Message: ----------- Ensure that onchange event isn't called at focus lost after usage of HtmlInput.setValueAttribute Issue 1518 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-12 09:16:33 UTC (rev 8392) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="update" dev="mguillem" issue="1518"> + Ensure that onchange event isn't called at focus lost after usage of HtmlInput.setValueAttribute. + </action> <action type="update" dev="mguillem" issue="1516"> JavaScript: add support for XPathEvaluator (FF & Chrome). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -47,7 +47,6 @@ private static final String DEFAULT_VALUE = "on"; private boolean defaultCheckedState_; - private boolean valueAtFocus_; private boolean forceChecked_; /** @@ -255,27 +254,16 @@ return clone; } - /** - * {@inheritDoc} - */ @Override - public void focus() { - super.focus(); - valueAtFocus_ = isChecked(); + Object getInternalValue() { + return isChecked(); } - /** - * {@inheritDoc} - */ - @Override - void removeFocus() { - super.removeFocus(); - + void handleFocusLostValueChanged() { final boolean fireOnChange = hasFeature(EVENT_ONCHANGE_LOSING_FOCUS); - if (fireOnChange && valueAtFocus_ != isChecked()) { + if (fireOnChange) { executeOnChangeHandlerIfAppropriate(this); } - valueAtFocus_ = isChecked(); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -42,7 +42,6 @@ private String contentType_; private byte[] data_; - private String valueAtFocus_; /** * Creates an instance. @@ -187,24 +186,4 @@ public String getContentType() { return contentType_; } - - /** - * {@inheritDoc} - */ - @Override - public void focus() { - super.focus(); - // store current value to trigger onchange when needed at focus lost - valueAtFocus_ = getValueAttribute(); - } - - @Override - void removeFocus() { - super.removeFocus(); - - if (!valueAtFocus_.equals(getValueAttribute())) { - executeOnChangeHandlerIfAppropriate(this); - } - valueAtFocus_ = null; - } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -53,6 +53,7 @@ private String originalName_; private Collection<String> previousNames_ = Collections.emptySet(); private boolean createdByJavascript_ = false; + private Object valueAtFocus_; /** * Creates an instance. @@ -90,7 +91,9 @@ WebAssert.notNull("newValue", newValue); setAttribute("value", newValue); - return executeOnChangeHandlerIfAppropriate(this); + final Page page = executeOnChangeHandlerIfAppropriate(this); + valueAtFocus_ = getInternalValue(); + return page; } /** @@ -556,4 +559,32 @@ public boolean wasCreatedByJavascript() { return createdByJavascript_; } + + /** + * {@inheritDoc} + */ + @Override + public final void focus() { + super.focus(); + // store current value to trigger onchange when needed at focus lost + valueAtFocus_ = getInternalValue(); + } + + @Override + final void removeFocus() { + super.removeFocus(); + + if (!valueAtFocus_.equals(getInternalValue())) { + handleFocusLostValueChanged(); + } + valueAtFocus_ = null; + } + + void handleFocusLostValueChanged() { + executeOnChangeHandlerIfAppropriate(this); + } + + Object getInternalValue() { + return getValueAttribute(); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -35,8 +35,6 @@ */ public class HtmlPasswordInput extends HtmlInput implements SelectableTextInput { - private String valueAtFocus_; - private final SelectionDelegate selectionDelegate_ = new SelectionDelegate(this); private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor() { @@ -140,28 +138,6 @@ * {@inheritDoc} */ @Override - public void focus() { - super.focus(); - // store current value to trigger onchange when needed at focus lost - valueAtFocus_ = getValueAttribute(); - } - - /** - * {@inheritDoc} - */ - @Override - void removeFocus() { - super.removeFocus(); - if (!valueAtFocus_.equals(getValueAttribute())) { - executeOnChangeHandlerIfAppropriate(this); - } - valueAtFocus_ = null; - } - - /** - * {@inheritDoc} - */ - @Override protected Object clone() throws CloneNotSupportedException { return new HtmlPasswordInput(getNamespaceURI(), getQualifiedName(), getPage(), getAttributesMap()); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -51,7 +51,6 @@ private static final String DEFAULT_VALUE = "on"; private boolean defaultCheckedState_; - private boolean valueAtFocus_; private boolean forceChecked_; /** @@ -316,27 +315,16 @@ return clone; } - /** - * {@inheritDoc} - */ @Override - public void focus() { - super.focus(); - valueAtFocus_ = isChecked(); + Object getInternalValue() { + return isChecked(); } - /** - * {@inheritDoc} - */ - @Override - void removeFocus() { - super.removeFocus(); - + void handleFocusLostValueChanged() { final boolean fireOnChange = hasFeature(EVENT_ONCHANGE_LOSING_FOCUS); - if (fireOnChange && valueAtFocus_ != isChecked()) { + if (fireOnChange) { executeOnChangeHandlerIfAppropriate(this); } - valueAtFocus_ = isChecked(); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -36,8 +36,6 @@ */ public class HtmlTextInput extends HtmlInput implements SelectableTextInput { - private String valueAtFocus_; - private final SelectionDelegate selectionDelegate_ = new SelectionDelegate(this); private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor() { @@ -157,28 +155,6 @@ * {@inheritDoc} */ @Override - public void focus() { - super.focus(); - // store current value to trigger onchange when needed at focus lost - valueAtFocus_ = getValueAttribute(); - } - - /** - * {@inheritDoc} - */ - @Override - void removeFocus() { - super.removeFocus(); - if (!valueAtFocus_.equals(getValueAttribute())) { - executeOnChangeHandlerIfAppropriate(this); - } - valueAtFocus_ = null; - } - - /** - * {@inheritDoc} - */ - @Override protected Object clone() throws CloneNotSupportedException { return new HtmlTextInput(getNamespaceURI(), getQualifiedName(), getPage(), getAttributesMap()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2013-07-11 21:31:48 UTC (rev 8391) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2013-07-12 09:16:33 UTC (rev 8392) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.html; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Writer; @@ -457,4 +458,25 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("changed") + public void firingOnchange() throws Exception { + final String html = "<html><body>\n" + + "<form onchange='alert(\"changed\")'>\n" + + " <input type='file' id='file1'>\n" + + "</form>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + final File tmpFile = File.createTempFile("htmlunit-test", ".txt"); + driver.findElement(By.id("file1")).sendKeys(tmpFile.getAbsolutePath()); + tmpFile.delete(); + driver.findElement(By.tagName("body")).click(); + + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } } |
From: <rb...@us...> - 2013-07-16 20:27:41
|
Revision: 8395 http://sourceforge.net/p/htmlunit/code/8395 Author: rbri Date: 2013-07-16 20:27:37 +0000 (Tue, 16 Jul 2013) Log Message: ----------- Support for the label property added to the optgroup element. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-16 18:37:03 UTC (rev 8394) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-16 20:27:37 UTC (rev 8395) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Support for the label property added to the optgroup element. + </action> <action type="update" dev="mguillem" issue="1518"> Ensure that onchange event isn't called at focus lost after usage of HtmlInput.setValueAttribute. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java 2013-07-16 18:37:03 UTC (rev 8394) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElement.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DISPLAY_DEFAULT; +import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.HtmlOptionGroup; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; @@ -50,6 +51,28 @@ } /** + * Returns the value of the "label" property. + * @return the value of the "label" property + */ + @JsxGetter + public String getLabel() { + final String label = getDomNodeOrDie().getAttribute("label"); + if (DomElement.ATTRIBUTE_NOT_DEFINED == label) { + return ""; + } + return label; + } + + /** + * Updates the value of the "label" property. + * @param newLabel the new value + */ + @JsxSetter + public void setLabel(final String newLabel) { + getDomNodeOrDie().setAttribute("label", newLabel); + } + + /** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> * {@inheritDoc} */ Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptGroupElementTest.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Unit tests for {@link HTMLOptGroupElement}. + * + * @version $Revision: 7931 $ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HTMLOptGroupElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "false", "true", "true", "false", "true" }) + public void disabledAttribute() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var test1 = document.getElementById('test1');\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = false;\n" + + " alert(test1.disabled);\n" + + + " var test2 = document.getElementById('test2');\n" + + " alert(test2.disabled);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <form name='form1'>\n" + + " <select>\n" + + " <optgroup id='test1'>\n" + + " <option value='group1'>Group1</option>\n" + + " </optgroup>\n" + + " <optgroup id='test2' disabled>\n" + + " <option value='group2'>Group2</option>\n" + + " </optgroup>\n" + + " </select>\n" + + " </form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "", "newLabel", "", "label" }) + public void labelAttribute() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var test1 = document.getElementById('test1');\n" + + " alert(test1.label);\n" + + " test1.label = 'newLabel';\n" + + " alert(test1.label);\n" + + " test1.label = '';\n" + + " alert(test1.label);\n" + + + " var test2 = document.getElementById('test2');\n" + + " alert(test2.label);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <form name='form1'>\n" + + " <select>\n" + + " <optgroup id='test1'>\n" + + " <option value='group1'>Group1</option>\n" + + " </optgroup>\n" + + " <optgroup id='test2' label='label'>\n" + + " <option value='group2'>Group2</option>\n" + + " </optgroup>\n" + + " </select>\n" + + " </form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } +} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2013-07-16 18:37:03 UTC (rev 8394) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -363,4 +363,40 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "false", "true", "true", "false", "true" }) + public void disabledAttribute() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var test1 = document.getElementById('test1');\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = true;\n" + + " alert(test1.disabled);\n" + + " test1.disabled = false;\n" + + " alert(test1.disabled);\n" + + + " var test2 = document.getElementById('test2');\n" + + " alert(test2.disabled);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <form name='form1'>\n" + + " <select>\n" + + " <option id='test1' value='option1'>Option1</option>\n" + + " <option id='test2' value='option2' disabled>Option2</option>\n" + + " </select>\n" + + " </form>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLPreElementTest.java 2013-07-16 20:27:37 UTC (rev 8395) @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.html; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Unit tests for {@link HTMLPreElement}. + * + * @version $Revision: 7931 $ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HTMLPreElementTest extends WebDriverTestCase { + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(FF = { "0", "number", "100", "77", "number", "123" }, + IE = { "", "string", "100", "77", "string", "123" }) + @NotYetImplemented + public void testWidth() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var testPre = document.getElementById('testPre');\n" + + " alert(testPre.width);\n" + + " alert(typeof testPre.width);\n" + + " testPre.width = 100;\n" + + " alert(testPre.width);\n" + + + " var testPre = document.getElementById('testPreWidth');\n" + + " alert(testPreWidth.width);\n" + + " alert(typeof testPreWidth.width);\n" + + " testPreWidth.width = 123;\n" + + " alert(testPreWidth.width);\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'>\n" + + " <pre id='testPre'>pre content</pre>\n" + + " <pre id='testPreWidth' width='77'>pre content</pre>\n" + + " </body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } +} |
From: <rb...@us...> - 2013-07-17 20:58:35
|
Revision: 8397 http://sourceforge.net/p/htmlunit/code/8397 Author: rbri Date: 2013-07-17 20:58:30 +0000 (Wed, 17 Jul 2013) Log Message: ----------- improving namespace support for XPath expressions; Patch by Chuck Dumont Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XPathDomNodeList.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/xpath/XPathUtils.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathNSResolver.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlUtil.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocumentTest.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NativeFunctionPrefixResolver.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -1369,5 +1369,9 @@ /** Indicates if XUL is supported (FF only). */ @BrowserFeature(@WebBrowser(value = FF, maxVersion = 3.6f)) - XUL_SUPPORT; + XUL_SUPPORT, + + /** Indicates that the 'SelectionNamespaces' property is supported by XPath expressions. */ + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(CHROME) }) + XPATH_SELECTION_NAMESPACES; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.DOM_NORMALIZE_REMOVE_CHILDREN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.NODE_APPEND_CHILD_SELF_IGNORE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XPATH_SELECTION_NAMESPACES; import java.io.IOException; import java.io.PrintWriter; @@ -26,16 +27,19 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.atomic.AtomicBoolean; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; +import org.apache.xml.utils.PrefixResolver; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.CSSParseException; import org.w3c.css.sac.ErrorHandler; @@ -61,6 +65,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; +import com.gargoylesoftware.htmlunit.xml.XmlPage; import com.steadystate.css.parser.CSSOMParser; import com.steadystate.css.parser.SACParserCSS3; @@ -83,6 +88,7 @@ * @author Sudhan Moghe * @author <a href="mailto:tom...@un...">Tom Anderson</a> * @author Ronald Brill + * @author Chuck Dumont */ public abstract class DomNode implements Cloneable, Serializable, Node { @@ -1434,6 +1440,29 @@ } /** + * Parses the SelectionNamespaces property into a map of prefix/namespace pairs. + * The default namespace (specified by xmlns=) is placed in the map using the + * empty string ("") key. + * + * @param selectionNS the value of the SelectionNamespaces property + * @return map of prefix/namespace value pairs + */ + private static Map<String, String> parseSelectionNamespaces(final String selectionNS) { + final Map<String, String> result = new HashMap<String, String>(); + final String[] toks = selectionNS.split("\\s"); + for (String tok : toks) { + if (tok.startsWith("xmlns=")) { + result.put("", tok.substring(7, tok.length() - 7)); + } + else if (tok.startsWith("xmlns:")) { + final String prefix[] = tok.substring(6).split("="); + result.put(prefix[0], prefix[1].substring(1, prefix[1].length() - 1)); + } + } + return result.size() > 0 ? result : null; + } + + /** * Evaluates the specified XPath expression from this node, returning the matching elements. * * @param xpathExpr the XPath expression to evaluate @@ -1442,10 +1471,64 @@ * @see #getCanonicalXPath() */ public List<?> getByXPath(final String xpathExpr) { - return XPathUtils.getByXPath(this, xpathExpr); + PrefixResolver prefixResolver = null; + if (hasFeature(XPATH_SELECTION_NAMESPACES)) { + /* + * See if the document has the SelectionNamespaces property defined. If so, then + * create a PrefixResolver that resolves the defined namespaces. + */ + final Document doc = getOwnerDocument(); + if (doc instanceof XmlPage) { + final ScriptableObject scriptable = ((XmlPage) doc).getScriptObject(); + if (ScriptableObject.hasProperty(scriptable, "getProperty")) { + final Object selectionNS = + ScriptableObject.callMethod(scriptable, "getProperty", new Object[]{"SelectionNamespaces"}); + if (selectionNS != null && selectionNS.toString().length() > 0) { + final Map<String, String> namespaces = parseSelectionNamespaces(selectionNS.toString()); + if (namespaces != null) { + prefixResolver = new PrefixResolver() { + @Override + public String getBaseIdentifier() { + return namespaces.get(""); + } + + @Override + public String getNamespaceForPrefix(final String prefix) { + return namespaces.get(prefix); + } + + @Override + public String getNamespaceForPrefix(final String prefix, final Node node) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean handlesNullPrefixes() { + return false; + } + }; + } + } + } + } + } + return XPathUtils.getByXPath(this, xpathExpr, prefixResolver); } /** + * Evaluates the specified XPath expression from this node, returning the matching elements. + * + * @param xpathExpr the XPath expression to evaluate + * @param resolver the prefix resolver to use for resolving namespace prefixes, or null + * @return the elements which match the specified XPath expression + * @see #getFirstByXPath(String) + * @see #getCanonicalXPath() + */ + public List<?> getByXPath(final String xpathExpr, final PrefixResolver resolver) { + return XPathUtils.getByXPath(this, xpathExpr, resolver); + } + + /** * Evaluates the specified XPath expression from this node, returning the first matching element, * or <tt>null</tt> if no node matches the specified XPath expression. * @@ -1455,9 +1538,24 @@ * @see #getByXPath(String) * @see #getCanonicalXPath() */ + public <X> X getFirstByXPath(final String xpathExpr) { + return getFirstByXPath(xpathExpr, null); + } + + /** + * Evaluates the specified XPath expression from this node, returning the first matching element, + * or <tt>null</tt> if no node matches the specified XPath expression. + * + * @param xpathExpr the XPath expression + * @param <X> the expression type + * @param resolver the prefix resolver to use for resolving namespace prefixes, or null + * @return the first element matching the specified XPath expression + * @see #getByXPath(String) + * @see #getCanonicalXPath() + */ @SuppressWarnings("unchecked") - public <X> X getFirstByXPath(final String xpathExpr) { - final List<?> results = getByXPath(xpathExpr); + public <X> X getFirstByXPath(final String xpathExpr, final PrefixResolver resolver) { + final List<?> results = getByXPath(xpathExpr, resolver); if (results.isEmpty()) { return null; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XPathDomNodeList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XPathDomNodeList.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XPathDomNodeList.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -84,7 +84,7 @@ private List<Object> getNodes() { if (cachedElements_ == null) { if (node_ != null) { - cachedElements_ = XPathUtils.getByXPath(node_, xpath_); + cachedElements_ = XPathUtils.getByXPath(node_, xpath_, null); } else { cachedElements_ = new ArrayList<Object>(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/xpath/XPathUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/xpath/XPathUtils.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/xpath/XPathUtils.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -37,6 +37,7 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Chuck Dumont */ public final class XPathUtils { @@ -59,9 +60,10 @@ * * @param node the node to start searching from * @param xpathExpr the XPath expression + * @param resolver the prefix resolver to use for resolving namespace prefixes, or null * @return the list of objects found */ - public static List<Object> getByXPath(final DomNode node, final String xpathExpr) { + public static List<Object> getByXPath(final DomNode node, final String xpathExpr, final PrefixResolver resolver) { if (xpathExpr == null) { throw new NullPointerException("Null is not a valid XPath expression"); } @@ -69,7 +71,7 @@ PROCESS_XPATH_.set(Boolean.TRUE); final List<Object> list = new ArrayList<Object>(); try { - final XObject result = evaluateXPath(node, xpathExpr); + final XObject result = evaluateXPath(node, xpathExpr, resolver); if (result instanceof XNodeSet) { final NodeList nodelist = ((XNodeSet) result).nodelist(); @@ -111,10 +113,12 @@ * Evaluates an XPath expression to an XObject. * @param contextNode the node to start searching from * @param str a valid XPath string + * @param a prefix resolver to use for resolving namespace prefixes, or null * @return an XObject, which can be used to obtain a string, number, nodelist, etc (should never be <tt>null</tt>) * @throws TransformerException if a syntax or other error occurs */ - private static XObject evaluateXPath(final DomNode contextNode, final String str) throws TransformerException { + private static XObject evaluateXPath(final DomNode contextNode, + final String str, final PrefixResolver prefixResolver) throws TransformerException { final XPathContext xpathSupport = new XPathContext(); final Node xpathExpressionContext; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { @@ -123,9 +127,14 @@ else { xpathExpressionContext = contextNode; } - final PrefixResolver prefixResolver = new HtmlUnitPrefixResolver(xpathExpressionContext); + + PrefixResolver resolver = prefixResolver; + if (resolver == null) { + resolver = new HtmlUnitPrefixResolver(xpathExpressionContext); + } + final boolean caseSensitive = contextNode.getPage().hasCaseSensitiveTagNames(); - final XPathAdapter xpath = new XPathAdapter(str, null, prefixResolver, null, caseSensitive); + final XPathAdapter xpath = new XPathAdapter(str, null, resolver, null, caseSensitive); final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -51,6 +51,7 @@ * @version $Revision$ * @author <a href="mailto:bc...@es...">Ben Curren</a> * @author Ahmed Ashour + * @author Chuck Dumont */ @JsxClass(browsers = @WebBrowser(IE)) public class ActiveXObject extends SimpleScriptable { @@ -230,6 +231,7 @@ addFunction(document, "createCDATASection"); addFunction(document, "createProcessingInstruction"); addFunction(document, "getElementsByTagName"); + addFunction(document, "getProperty"); addFunction(document, "load"); addFunction(document, "loadXML"); addFunction(document, "nodeFromID"); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -26,9 +26,11 @@ import java.util.regex.Pattern; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.NativeFunction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xml.utils.PrefixResolver; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.BrowserVersionFeatures; @@ -73,6 +75,7 @@ * @author Ahmed Ashour * @author Rob Di Marco * @author Ronald Brill + * @author Chuck Dumont * @see <a href="http://msdn.microsoft.com/en-us/library/ms531073.aspx">MSDN documentation</a> * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-7068919">W3C Dom Level 1</a> */ @@ -393,7 +396,15 @@ xPathResult.setParentScope(getParentScope()); xPathResult.setPrototype(getPrototype(xPathResult.getClass())); } - xPathResult.init(contextNode.getDomNodeOrDie().getByXPath(expression), type); + + PrefixResolver prefixResolver = null; + if (resolver instanceof NativeFunction) { + prefixResolver = new NativeFunctionPrefixResolver((NativeFunction) resolver, contextNode.getParentScope()); + } + else if (resolver instanceof PrefixResolver) { + prefixResolver = (PrefixResolver) resolver; + } + xPathResult.init(contextNode.getDomNodeOrDie().getByXPath(expression, prefixResolver), type); return xPathResult; } Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NativeFunctionPrefixResolver.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NativeFunctionPrefixResolver.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NativeFunctionPrefixResolver.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host; + +import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.NativeFunction; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; + +import org.apache.xml.utils.PrefixResolver; + +/** + * A special {@link PrefixResolver} for {@link NativeFunction}s. + * + * @version $Revision$ + * @author Chuck Dumont + */ +public class NativeFunctionPrefixResolver implements PrefixResolver { + + private NativeFunction resolverFn_; + private Scriptable scope_; + + /** + * Constructor. + * + * @param resolverFn the {@link NativeFunction} this resolver is for + * @param scope the scope + */ + public NativeFunctionPrefixResolver(final NativeFunction resolverFn, final Scriptable scope) { + resolverFn_ = resolverFn; + scope_ = scope; + } + + /** + * {@inheritDoc} + */ + @Override + public String getBaseIdentifier() { + final Object result = Context.call(null, resolverFn_, scope_, null, new Object[]{}); + return result != null ? result.toString() : null; + } + + /** + * {@inheritDoc} + */ + @Override + public String getNamespaceForPrefix(final String prefix) { + final Object result = Context.call(null, resolverFn_, scope_, null, new Object[]{prefix}); + return result != null ? result.toString() : null; + } + + /** + * {@inheritDoc} + */ + @Override + public String getNamespaceForPrefix(final String prefix, final org.w3c.dom.Node node) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean handlesNullPrefixes() { + return false; + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/NativeFunctionPrefixResolver.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathNSResolver.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathNSResolver.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathNSResolver.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -16,6 +16,8 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import org.apache.xml.utils.PrefixResolver; + import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; @@ -28,9 +30,10 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Chuck Dumont */ @JsxClass(browsers = @WebBrowser(FF)) -public class XPathNSResolver extends SimpleScriptable { +public class XPathNSResolver extends SimpleScriptable implements PrefixResolver { private Object element_; @@ -53,4 +56,35 @@ return XmlUtil.lookupNamespaceURI((DomElement) ((SimpleScriptable) element_).getDomNodeOrDie(), prefix); } + /** + * {@inheritDoc} + */ + @Override + public String getBaseIdentifier() { + return XmlUtil.lookupNamespaceURI((DomElement) ((SimpleScriptable) element_).getDomNodeOrDie(), ""); + } + + /** + * {@inheritDoc} + */ + @Override + public String getNamespaceForPrefix(final String prefix) { + return lookupNamespaceURI(prefix); + } + + /** + * {@inheritDoc} + */ + @Override + public String getNamespaceForPrefix(final String prefix, final org.w3c.dom.Node context) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean handlesNullPrefixes() { + return false; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -21,7 +21,9 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import net.sourceforge.htmlunit.corejs.javascript.Context; @@ -60,6 +62,7 @@ * @author Marc Guillemot * @author Sudhan Moghe * @author Ronald Brill + * @author Chuck Dumont */ @JsxClass(browsers = @WebBrowser(FF)) public class XMLDocument extends Document { @@ -69,6 +72,7 @@ private boolean async_ = true; private boolean preserveWhiteSpace_; private XMLDOMParseError parseError_; + private Map<String, String> properties_ = new HashMap<String, String>(); /** * Creates a new instance. JavaScript objects must have a default constructor. @@ -266,10 +270,21 @@ */ @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) public void setProperty(final String name, final String value) { - //empty implementation + properties_.put(name, value); } /** + * Returns the value of the property set by {@link #setProperty(String, String)}. + * + * @param name the name of the property to get + * @return the property value + */ + @JsxFunction({ @WebBrowser(IE), @WebBrowser(CHROME) }) + public String getProperty(final String name) { + return properties_.get(name); + } + + /** * Applies the specified XPath expression to this node's context and returns the generated list of matching nodes. * @param expression a string specifying an XPath expression * @return list of the found elements Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlUtil.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlUtil.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlUtil.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -65,6 +65,7 @@ * @author Ahmed Ashour * @author Sudhan Moghe * @author Ronald Brill + * @author Chuck Dumont */ public final class XmlUtil { @@ -301,12 +302,19 @@ /** * Search for the namespace URI of the given prefix, starting from the specified element. + * The default namespace can be searched for by specifying "" as the prefix. * @param element the element to start searching from * @param prefix the namespace prefix * @return the namespace URI bound to the prefix; or null if there is no such namespace */ public static String lookupNamespaceURI(final DomElement element, final String prefix) { - String uri = element.getAttribute("xmlns:" + prefix); + String uri = DomElement.ATTRIBUTE_NOT_DEFINED; + if (prefix.length() == 0) { + uri = element.getAttribute("xmlns"); + } + else { + uri = element.getAttribute("xmlns:" + prefix); + } if (uri == DomElement.ATTRIBUTE_NOT_DEFINED) { final DomNode parentNode = element.getParentNode(); if (parentNode instanceof DomElement) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocumentTest.java 2013-07-17 05:20:45 UTC (rev 8396) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocumentTest.java 2013-07-17 20:58:30 UTC (rev 8397) @@ -34,6 +34,7 @@ * @version $Revision$ * @author Ahmed Ashour * @author Marc Guillemot + * @author Chuck Dumont */ @RunWith(BrowserRunner.class) public class XMLDocumentTest extends WebDriverTestCase { @@ -695,7 +696,6 @@ */ @Test @Alerts(IE = "1", FF = "0") - @NotYetImplemented(IE) public void xpathWithNamespaces() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + " function test() {\n" @@ -703,7 +703,7 @@ + " doc.async = false;\n" + " doc.load('" + URL_SECOND + "');\n" + " try {\n" - + " alert(doc.selectNodes('//book').length);\n" + + " alert(doc.selectNodes('//soap:book').length);\n" + " } catch (e) {\n" + " alert(doc.evaluate('count(//book)', doc.documentElement, " + "null, XPathResult.NUMBER_TYPE, null).numberValue);\n" @@ -736,6 +736,46 @@ * @throws Exception if the test fails */ @Test + @Browsers(IE) + @Alerts("1") + public void selectionNamespaces() throws Exception { + final String html = "<html><head><title>foo</title><script>\n" + + " var selectionNamespaces = 'xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " + + "xmlns:ns1=\"http://www.example.com/ns1\"';\n" + + " function test() {\n" + + " if (window.ActiveXObject) {" + + " var doc = new ActiveXObject('Microsoft.XMLDOM');\n" + + " doc.setProperty('SelectionNamespaces', selectionNamespaces);" + + " doc.async = false;\n" + + " doc.load('" + URL_SECOND + "');\n" + + " try {\n" + + " alert(doc.selectNodes('/s:Envelope/ns1:books/s:book').length);\n" + + " } catch (e) {\n" + + " alert(doc.evaluate('count(//book)', doc.documentElement, " + + "null, XPathResult.NUMBER_TYPE, null).numberValue);\n" + + " }}\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + final String xml + = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>\n" + + " <books xmlns='http://www.example.com/ns1'>\n" + + " <soap:book>\n" + + " <title>Immortality</title>\n" + + " <author>John Smith</author>\n" + + " </soap:book>\n" + + " </books>\n" + + "</soap:Envelope>"; + + getMockWebConnection().setResponse(URL_SECOND, xml, "text/xml"); + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(IE = "null", FF = "[object HTMLDivElement]") public void nodeFromID() throws Exception { final String html = "<html><head><title>foo</title><script>\n" |
From: <rb...@us...> - 2013-07-18 20:26:14
|
Revision: 8405 http://sourceforge.net/p/htmlunit/code/8405 Author: rbri Date: 2013-07-18 20:26:10 +0000 (Thu, 18 Jul 2013) Log Message: ----------- Fix the way we search for some java methods when creating a XMLDocument from ActiveXObject. This should work with all JavaVMs now. Issue 1521 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-18 18:49:24 UTC (rev 8404) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-18 20:26:10 UTC (rev 8405) @@ -8,7 +8,11 @@ <body> <release version="2.13" date="???" description="Bugfixes"> - <action type="update" dev="rbri" issue="1519, 1522" due-to="Chuck Dumont"> + <action type="fix" dev="rbri" issue="1521"> + Fix the way we search for some java methods when creating a XML document from ActiveXObject. + This should work with all JavaVMs now. + </action> + <action type="fix" dev="rbri" issue="1519, 1522" due-to="Chuck Dumont"> Improved namespace support for XPath expressions. </action> <action type="update" dev="rbri"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java 2013-07-18 18:49:24 UTC (rev 8404) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java 2013-07-18 20:26:10 UTC (rev 8405) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Locale; import java.util.Map; @@ -37,6 +38,9 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest; @@ -52,6 +56,7 @@ * @author <a href="mailto:bc...@es...">Ben Curren</a> * @author Ahmed Ashour * @author Chuck Dumont + * @author Ronald Brill */ @JsxClass(browsers = @WebBrowser(IE)) public class ActiveXObject extends SimpleScriptable { @@ -260,7 +265,7 @@ } private static void addFunction(final SimpleScriptable scriptable, final String methodName) { - final Method javaFunction = getMethod(scriptable.getClass(), methodName); + final Method javaFunction = getMethod(scriptable.getClass(), methodName, JsxFunction.class); final FunctionObject fo = new FunctionObject(null, javaFunction, scriptable); scriptable.defineProperty(methodName, fo, READONLY); } @@ -289,26 +294,37 @@ static void addProperty(final SimpleScriptable scriptable, final String propertyName, final String getterMethodName, final String setterMethodName) { scriptable.defineProperty(propertyName, null, - getMethod(scriptable.getClass(), getterMethodName), - getMethod(scriptable.getClass(), setterMethodName), PERMANENT); + getMethod(scriptable.getClass(), getterMethodName, JsxGetter.class), + getMethod(scriptable.getClass(), setterMethodName, JsxSetter.class), PERMANENT); } /** * Gets the first method found of the class with the given name + * and the correct annotation * @param clazz the class to search on * @param name the name of the searched method + * @param annotationClass the class of the annotation required * @return <code>null</code> if not found */ - static Method getMethod(final Class<? extends SimpleScriptable> clazz, final String name) { + static Method getMethod(final Class<? extends SimpleScriptable> clazz, + final String name, final Class<? extends Annotation> annotationClass) { if (name == null) { return null; } + Method foundByNameOnly = null; for (final Method method : clazz.getMethods()) { if (method.getName().equals(name)) { - return method; + if (null != method.getAnnotation(annotationClass)) { + return method; + } + if (null != foundByNameOnly) { + throw new IllegalArgumentException("Found at least two methods for name '" + + name + "' in class '" + clazz + "'."); + } + foundByNameOnly = method; } } - return null; + return foundByNameOnly; } /** |
From: <rb...@us...> - 2013-07-21 09:11:07
|
Revision: 8412 http://sourceforge.net/p/htmlunit/code/8412 Author: rbri Date: 2013-07-21 09:11:04 +0000 (Sun, 21 Jul 2013) Log Message: ----------- StyleSheetListTest migrated to webdriver; fix: Using a wrong index when addressing an StyleSheetList always throws an Exception in IE. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-21 09:11:04 UTC (rev 8412) @@ -8,6 +8,10 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Using a wrong index when addressing an StyleSheetList always throws an Exception + in IE. + </action> <action type="fix" dev="rbri" issue="1521"> Fix the way we search for some java methods when creating a XML document from ActiveXObject. This should work with all JavaVMs now. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-07-21 09:11:04 UTC (rev 8412) @@ -1093,6 +1093,9 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) JS_SET_ATTRIBUTE_SUPPORTS_EVENT_HANDLERS, + @BrowserFeature(@WebBrowser(IE)) + JS_STYLESHEET_LIST_EXEPTION_FOR_ALL_INVALID_INDEXES, + /** IE supports accessing unsupported style elements via getter * like val = elem.style.htmlunit;. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2013-07-21 09:11:04 UTC (rev 8412) @@ -17,6 +17,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import com.gargoylesoftware.htmlunit.BrowserVersionFeatures; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -119,6 +120,10 @@ throw Context.reportRuntimeError("Invalid negative index: " + index); } else if (index >= nodes_.getLength()) { + if (getWindow().getWebWindow().getWebClient().getBrowserVersion().hasFeature( + BrowserVersionFeatures.JS_STYLESHEET_LIST_EXEPTION_FOR_ALL_INVALID_INDEXES)) { + throw Context.reportRuntimeError("Invalid index: " + index); + } return Context.getUndefinedValue(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2013-07-21 09:11:04 UTC (rev 8412) @@ -22,7 +22,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.SimpleWebTestCase; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.util.NameValuePair; /** @@ -32,9 +32,10 @@ * @author Daniel Gredler * @author Ahmed Ashour * @author Marc Guillemot + * @author Ronald Brill */ @RunWith(BrowserRunner.class) -public class StyleSheetListTest extends SimpleWebTestCase { +public class StyleSheetListTest extends WebDriverTestCase { /** * @throws Exception if an error occurs @@ -56,7 +57,7 @@ + " </body>\n" + "</html>"; - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -89,14 +90,15 @@ final String css = "div {color:red}"; getMockWebConnection().setDefaultResponse(css, "text/css"); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** * @throws Exception if an error occurs */ @Test - @Alerts({ "0", "undefined", "undefined", "exception for -2" }) + @Alerts(DEFAULT = { "0", "undefined", "undefined", "exception for -2" }, + IE = { "0", "exception for 0", "exception for 46", "exception for -2" }) public void arrayIndexOutOfBoundAccess() throws Exception { final String html = "<html>\n" @@ -104,9 +106,23 @@ + " <script>\n" + " function test() {\n" + " alert(document.styleSheets.length);\n" - + " alert(document.styleSheets[0]);\n" - + " alert(document.styleSheets[46]);\n" + + " try {\n" + + " alert(document.styleSheets[0]);\n" + + " }\n" + + " catch (e) {\n" + + " alert('exception for 0');\n" + + " }\n" + + + + " try {\n" + + " alert(document.styleSheets[46]);\n" + + " }\n" + + " catch (e) {\n" + + " alert('exception for 46');\n" + + " }\n" + + + " try {\n" + " alert(document.styleSheets[-2]);\n" + " }\n" + " catch (e) {\n" @@ -119,7 +135,7 @@ + " </body>\n" + "</html>"; - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -145,7 +161,7 @@ + "</html>"; getMockWebConnection().setDefaultResponse("Not Found", 404, "Not Found", "text/html"); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -178,7 +194,7 @@ headers.add(new NameValuePair("Content-Encoding", "gzip")); getMockWebConnection().setDefaultResponse(css, 200, "OK", "text/css", headers); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -210,6 +226,6 @@ headers.add(new NameValuePair("Content-Encoding", "gzip")); getMockWebConnection().setDefaultResponse(css, 200, "OK", "text/css", headers); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } } |
From: <rb...@us...> - 2013-07-21 12:34:48
|
Revision: 8416 http://sourceforge.net/p/htmlunit/code/8416 Author: rbri Date: 2013-07-21 12:34:44 +0000 (Sun, 21 Jul 2013) Log Message: ----------- Method document.createStyleSheet is more compatible with the IE; now the associated link node is also created and inserted at the right place in the header. The new link node is the ownerNode of the stylesheet. Issue 1520 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Document2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-21 09:30:10 UTC (rev 8415) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-21 12:34:44 UTC (rev 8416) @@ -8,6 +8,11 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1520"> + Method document.createStyleSheet is more compatible with the IE; now the associated + link node is also created and inserted at the right place in the header. The new link + node is the ownerNode of the stylesheet. + </action> <action type="fix" dev="rbri"> Using a wrong index when addressing an StyleSheetList always throws an Exception in IE. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2013-07-21 09:30:10 UTC (rev 8415) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2013-07-21 12:34:44 UTC (rev 8416) @@ -58,6 +58,19 @@ private HTMLCollection nodes_; /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * + * Verifies if the provided node is a link node pointing to a stylesheet. + * + * @param domNode the mode to check + * @return true if the provided node is a stylesheet link + */ + public static boolean isStyleSheetLink(final DomNode domNode) { + return domNode instanceof HtmlLink + && "stylesheet".equalsIgnoreCase(((HtmlLink) domNode).getRelAttribute()); + } + + /** * Rhino requires default constructors. */ public StyleSheetList() { @@ -79,8 +92,7 @@ @Override protected boolean isMatching(final DomNode node) { return node instanceof HtmlStyle - || (node instanceof HtmlLink - && "stylesheet".equalsIgnoreCase(((HtmlLink) node).getRelAttribute())); + || isStyleSheetLink(node); } @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-07-21 09:30:10 UTC (rev 8415) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-07-21 12:34:44 UTC (rev 8416) @@ -46,6 +46,7 @@ import static com.gargoylesoftware.htmlunit.util.StringUtils.parseHttpDate; import java.io.IOException; +import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.text.SimpleDateFormat; @@ -69,12 +70,14 @@ import net.sourceforge.htmlunit.corejs.javascript.FunctionObject; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; +import net.sourceforge.htmlunit.corejs.javascript.Undefined; import net.sourceforge.htmlunit.corejs.javascript.UniqueTag; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.css.sac.CSSException; +import org.w3c.css.sac.InputSource; import org.w3c.dom.DOMException; import org.w3c.dom.DocumentType; @@ -97,6 +100,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlHead; import com.gargoylesoftware.htmlunit.html.HtmlImage; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlScript; @@ -1222,11 +1226,41 @@ * @return the newly created stylesheet */ @JsxFunction(@WebBrowser(IE)) - public CSSStyleSheet createStyleSheet(final String url, final int index) { - // minimal implementation - final CSSStyleSheet stylesheet = new CSSStyleSheet(); + public CSSStyleSheet createStyleSheet(final String url, final Object index) { + final HTMLLinkElement link = (HTMLLinkElement) createElement("link"); + link.setHref(url); + link.setRel("stylesheet"); + + int insertPos = Integer.MAX_VALUE; + if (Undefined.instance != index) { + try { + insertPos = ((Double) index).intValue(); + } + catch (final NumberFormatException e) { + // ignore + } + } + final InputSource source = new InputSource(new StringReader("")); + final CSSStyleSheet stylesheet = new CSSStyleSheet(link, source, url); stylesheet.setPrototype(getPrototype(CSSStyleSheet.class)); stylesheet.setParentScope(getWindow()); + + final HTMLCollection heads = getElementsByTagName("head"); + if (heads.getLength() > 0) { + final HtmlHead head = (HtmlHead) heads.item(0); + + int stylesheetPos = -1; + for (DomNode domNode : head.getChildNodes()) { + if (StyleSheetList.isStyleSheetLink(domNode)) { + stylesheetPos++; + if (insertPos <= stylesheetPos) { + domNode.insertBefore(link.getDomNodeOrDie()); + return stylesheet; + } + } + } + head.appendChild(link.getDomNodeOrDie()); + } return stylesheet; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Document2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Document2Test.java 2013-07-21 09:30:10 UTC (rev 8415) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Document2Test.java 2013-07-21 12:34:44 UTC (rev 8416) @@ -465,4 +465,89 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "style.css", "LINK" }, + DEFAULT = { }) + public void createStyleSheet() throws Exception { + final String html + = "<html><head><title>First</title>\n" + + "<script>\n" + + " function doTest() {\n" + + " if (document.createStyleSheet) {\n" + + " document.createStyleSheet('style.css');\n" + + " for (var si = 0; si < document.styleSheets.length; si++) {\n" + + " var sheet = document.styleSheets[si];\n" + + " alert(sheet.href);\n" + + " alert(sheet.owningElement.tagName);\n" + + " }\n" + + " }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='doTest()'>\n" + + " <div id='id1'></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "null", "" }, + DEFAULT = { }) + public void createStyleSheet_emptyUrl() throws Exception { + final String html + = "<html><head><title>First</title>\n" + + "<script>\n" + + " function doTest() {\n" + + " if (document.createStyleSheet) {\n" + + " document.createStyleSheet(null);\n" + + " document.createStyleSheet('');\n" + + " for (var si = 0; si < document.styleSheets.length; si++) {\n" + + " var sheet = document.styleSheets[si];\n" + + " alert(sheet.href);\n" + + " }\n" + + " }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='doTest()'>\n" + + " <div id='id1'></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "zero.css", "minus1.css", "seven.css", "none.css" }, + DEFAULT = { }) + public void createStyleSheet_insertAt() throws Exception { + final String html + = "<html><head><title>First</title>\n" + + "<script>\n" + + " function doTest() {\n" + + " if (document.createStyleSheet) {\n" + + " document.createStyleSheet('minus1.css', -1);\n" + + " document.createStyleSheet('zero.css', 0);\n" + + " document.createStyleSheet('seven.css', 7);\n" + + " document.createStyleSheet('none.css');\n" + + " for (var si = 0; si < document.styleSheets.length; si++) {\n" + + " var sheet = document.styleSheets[si];\n" + + " alert(sheet.href);\n" + + " }\n" + + " }\n" + + " }\n" + + "</script></head>\n" + + "<body onload='doTest()'>\n" + + " <div id='id1'></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2013-07-24 19:05:29
|
Revision: 8420 http://sourceforge.net/p/htmlunit/code/8420 Author: rbri Date: 2013-07-24 19:05:25 +0000 (Wed, 24 Jul 2013) Log Message: ----------- base name support (wip) Issue 1525 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-07-21 21:23:24 UTC (rev 8419) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-07-24 19:05:25 UTC (rev 8420) @@ -929,6 +929,20 @@ } /** + * Returns the base name of this element. + * @return the base name of this element + */ + @JsxGetter(@WebBrowser(IE)) + public Object getBaseName() { + final DomElement domElem = getDomNodeOrDie(); + final boolean isXmlPage = domElem.getOwnerDocument() instanceof XmlPage; + if (isXmlPage) { + return domElem.getLocalName(); + } + return Undefined.instance; + } + + /** * {@inheritDoc} */ @Override Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2013-07-21 21:23:24 UTC (rev 8419) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2013-07-24 19:05:25 UTC (rev 8420) @@ -465,6 +465,26 @@ "[object],undefined", "[object],undefined" }, + DEFAULT = {"[object HTMLDivElement],undefined", + "[object HTMLUnknownElement],undefined", + "[object Element],undefined", + "[object HTMLDivElement],undefined", + "[object HTMLUnknownElement],undefined" + }) + public void html_baseName() throws Exception { + html("baseName"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = {"[object],undefined", + "[object],undefined", + "createElementNS() is not defined", + "[object],undefined", + "[object],undefined" + }, DEFAULT = {"[object HTMLDivElement],http://www.w3.org/1999/xhtml", "[object HTMLUnknownElement],http://www.w3.org/1999/xhtml", "[object Element],http://www.appcelerator.org", @@ -729,6 +749,24 @@ * @throws Exception if the test fails */ @Test + @Alerts(IE = {"[object]", "dIv", + "[object]", "html", + "[object]", "div", + "[object]", "dIv" + }, + DEFAULT = {"[object Element]", "undefined", + "[object HTMLHtmlElement]", "undefined", + "[object HTMLDivElement]", "undefined", + "[object HTMLUnknownElement]", "undefined" + }) + public void xml_baseName() throws Exception { + xml("baseName"); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(IE = {"[object]", "", "[object]", "http://www.w3.org/1999/xhtml", "[object]", "http://www.w3.org/1999/xhtml", @@ -763,7 +801,9 @@ + " debug(doc.documentElement.childNodes[1].childNodes[1]);\n" + " }\n" + " function debug(e) {\n" - + " alert(e);\n" + + " try {\n" + + " alert(e);\n" + + " } catch(ex) {alert(ex)};\n" + " alert(e." + methodName + ");\n" + " }\n" + " </script>\n" |
From: <rb...@us...> - 2013-07-25 17:30:49
|
Revision: 8421 http://sourceforge.net/p/htmlunit/code/8421 Author: rbri Date: 2013-07-25 17:30:45 +0000 (Thu, 25 Jul 2013) Log Message: ----------- XPathResult types STRING_TYPE, NUMBER_TYPE and BOOLEAN_TYPE don't work (patch by Chuck Dumont) Issue 1527 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-24 19:05:25 UTC (rev 8420) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-25 17:30:45 UTC (rev 8421) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1527" due-to="Chuck Dumont"> + XPathResult types STRING_TYPE, NUMBER_TYPE and BOOLEAN_TYPE don't work. + </action> <action type="fix" dev="rbri" issue="1520"> Method document.createStyleSheet is more compatible with the IE; now the associated link node is also created and inserted at the right place in the header. The new link Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java 2013-07-24 19:05:25 UTC (rev 8420) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResult.java 2013-07-25 17:30:45 UTC (rev 8421) @@ -20,6 +20,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Context; +import com.gargoylesoftware.htmlunit.html.DomAttr; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; @@ -33,6 +34,8 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Chuck Dumont + * @author Ronald Brill */ @JsxClass(browsers = @WebBrowser(FF)) public class XPathResult extends SimpleScriptable { @@ -222,7 +225,15 @@ if (resultType_ != NUMBER_TYPE) { throw Context.reportRuntimeError("Cannot get numberValue for type: " + resultType_); } - return ((Number) result_.get(0)).doubleValue(); + final String asString = asString(); + Double answer; + try { + answer = Double.parseDouble(asString); + } + catch (final NumberFormatException e) { + answer = Double.NaN; + } + return answer; } /** @@ -234,7 +245,7 @@ if (resultType_ != BOOLEAN_TYPE) { throw Context.reportRuntimeError("Cannot get booleanValue for type: " + resultType_); } - return ((Boolean) result_.get(0)).booleanValue(); + return Boolean.parseBoolean(asString()); } /** @@ -246,6 +257,17 @@ if (resultType_ != STRING_TYPE) { throw Context.reportRuntimeError("Cannot get stringValue for type: " + resultType_); } - return (String) result_.get(0); + return asString(); } + + private String asString() { + final Object resultObj = result_.get(0); + if (resultObj instanceof DomAttr) { + return ((DomAttr) resultObj).getValue(); + } + if (resultObj instanceof DomNode) { + return ((DomNode) resultObj).asText(); + } + return resultObj.toString(); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java 2013-07-24 19:05:25 UTC (rev 8420) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.java 2013-07-25 17:30:45 UTC (rev 8421) @@ -30,6 +30,8 @@ * @version $Revision$ * @author Ahmed Ashour * @author Marc Guillemot + * @author Chuck Dumont + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class XPathResultTest extends SimpleWebTestCase { @@ -193,4 +195,82 @@ loadPageWithAlerts(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(FF) + @Alerts({"bar", "foo", "foo" }) + public void stringType() throws Exception { + final String html = "<html><head><title attr=\"bar\">foo</title><script>\n" + + " function test() {\n" + + " var result = document.evaluate('//title/@attr', document, null, " + + "XPathResult.STRING_TYPE, null);\n" + + " alert(result.stringValue);\n" + + " result = document.evaluate('//title', document, null, " + + "XPathResult.STRING_TYPE, null);\n" + + " alert(result.stringValue);\n" + + " var result = document.evaluate('//title/text()', document, null, " + + "XPathResult.STRING_TYPE, null);\n" + + " alert(result.stringValue);\n" + + "}" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(FF) + @Alerts({ "true", "true", "true", "true" }) + public void numberType() throws Exception { + final String html = "<html><head><title attr=\"1234\">4321.5</title><span>foo</span><script>\n" + + " function test() {\n" + + " var result = document.evaluate('//title/@attr', document, null, " + + "XPathResult.NUMBER_TYPE, null);\n" + + " alert(result.numberValue === 1234);\n" + + " result = document.evaluate('//title', document, null, " + + "XPathResult.NUMBER_TYPE, null);\n" + + " alert(result.numberValue === 4321.5);\n" + + " result = document.evaluate('//title/text()', document, null, " + + "XPathResult.NUMBER_TYPE, null);\n" + + " alert(result.numberValue === 4321.5);\n" + + " result = document.evaluate('//span', document, null, " + + "XPathResult.NUMBER_TYPE, null);\n" + + " alert(isNaN(result.numberValue));\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(FF) + @Alerts({ "true", "true", "true" }) + public void booleanType() throws Exception { + final String html = "<html><head><title>foo</title><span attr=\"true\">true</span><script>\n" + + " function test() {\n" + + " var result = document.evaluate('//title', document, null, " + + "XPathResult.BOOLEAN_TYPE, null);\n" + + " alert(result.booleanValue === false);\n" + + " result = document.evaluate('//span', document, null, " + + "XPathResult.BOOLEAN_TYPE, null);\n" + + " alert(result.booleanValue === true);\n" + + " result = document.evaluate('//span/@attr', document, null, " + + "XPathResult.BOOLEAN_TYPE, null);\n" + + " alert(result.booleanValue === true);\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts(html); + } } |
From: <rb...@us...> - 2013-07-25 18:36:31
|
Revision: 8422 http://sourceforge.net/p/htmlunit/code/8422 Author: rbri Date: 2013-07-25 18:36:28 +0000 (Thu, 25 Jul 2013) Log Message: ----------- XPathEvaluator.evaluate() ignores namespace resolver (patch by Chuck Dumont) Issue 1528 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-25 17:30:45 UTC (rev 8421) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-25 18:36:28 UTC (rev 8422) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1528" due-to="Chuck Dumont"> + XPathEvaluator.evaluate() ignores namespace resolver. + </action> <action type="fix" dev="rbri" issue="1527" due-to="Chuck Dumont"> XPathResult types STRING_TYPE, NUMBER_TYPE and BOOLEAN_TYPE don't work. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java 2013-07-25 17:30:45 UTC (rev 8421) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluator.java 2013-07-25 18:36:28 UTC (rev 8422) @@ -15,7 +15,11 @@ package com.gargoylesoftware.htmlunit.javascript.host; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import net.sourceforge.htmlunit.corejs.javascript.NativeArray; +import net.sourceforge.htmlunit.corejs.javascript.NativeFunction; +import org.apache.xml.utils.PrefixResolver; + import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -27,6 +31,8 @@ * * @version $Revision$ * @author Marc Guillemot + * @author Chuck Dumont + * @author Ronald Brill */ @JsxClass(browsers = @WebBrowser(value = FF, minVersion = 17)) public class XPathEvaluator extends SimpleScriptable { @@ -58,7 +64,7 @@ /** * Evaluates an XPath expression string and returns a result of the specified type if possible. * @param expression the XPath expression string to be parsed and evaluated - * @param contextNode the context node for the evaluation of this XPath expression + * @param contextNodeObj the context node for the evaluation of this XPath expression * @param resolver the resolver permits translation of all prefixes, including the XML namespace prefix, * within the XPath expression into appropriate namespace URIs. * @param type If a specific type is specified, then the result will be returned as the corresponding type @@ -66,7 +72,7 @@ * @return the result of the evaluation of the XPath expression */ @JsxFunction(@WebBrowser(FF)) - public XPathResult evaluate(final String expression, final Node contextNode, + public XPathResult evaluate(final String expression, final Object contextNodeObj, final Object resolver, final int type, final Object result) { XPathResult xPathResult = (XPathResult) result; if (xPathResult == null) { @@ -74,7 +80,23 @@ xPathResult.setParentScope(getParentScope()); xPathResult.setPrototype(getPrototype(xPathResult.getClass())); } - xPathResult.init(contextNode.getDomNodeOrDie().getByXPath(expression), type); + // contextNodeObj can be either a node or an array with the node as the first element. + Node contextNode = null; + if (contextNodeObj instanceof NativeArray) { + contextNode = (Node) ((NativeArray) contextNodeObj).get(0); + } + else { + contextNode = (Node) contextNodeObj; + } + PrefixResolver prefixResolver = null; + if (resolver instanceof PrefixResolver) { + prefixResolver = (PrefixResolver) resolver; + } + else if (resolver instanceof NativeFunction) { + prefixResolver = new NativeFunctionPrefixResolver((NativeFunction) resolver, contextNode.getParentScope()); + } + xPathResult.init(contextNode.getDomNodeOrDie().getByXPath(expression, prefixResolver), type); return xPathResult; } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java 2013-07-25 17:30:45 UTC (rev 8421) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathEvaluatorTest.java 2013-07-25 18:36:28 UTC (rev 8422) @@ -26,6 +26,8 @@ * * @version $Revision$ * @author Marc Guillemot + * @author Chuck Dumont + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class XPathEvaluatorTest extends WebDriverTestCase { @@ -58,4 +60,68 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "Immortality" }, IE = { }, FF3_6 = { }) + public void namespacesWithNodeInArray() throws Exception { + final String html = "<html><head><title>foo</title><script>\n" + + " var xml = " + + " '<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + + " <soap:books>" + + " <soap:book>" + + " <title>Immortality</title>" + + " <author>John Smith</author>" + + " </soap:book>" + + " </soap:books>" + + " </soap:Envelope>';\n" + + " function test() {\n" + + " if (window.XPathEvaluator) {" + + " var doc = (new DOMParser).parseFromString(xml);" + + " var xpe = new XPathEvaluator();\n" + + " var nsResolver = xpe.createNSResolver(doc.documentElement);\n" + + " var result = xpe.evaluate('/soap:Envelope/soap:books/soap:book/title/text()', " + + "[doc.documentElement], nsResolver, XPathResult.STRING_TYPE, null);\n" + + " alert(result.stringValue);\n" + + " }}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "Immortality" }, IE = { }, FF3_6 = { }) + public void namespacesWithCustomNSResolver() throws Exception { + final String html = "<html><head><title>foo</title><script>\n" + + " function nsResolver(prefix) {" + + " return {s : 'http://schemas.xmlsoap.org/soap/envelope/'}[prefix] || null;" + + " }" + + " var xml = " + + " '<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + + " <soap:books>" + + " <soap:book>" + + " <title>Immortality</title>" + + " <author>John Smith</author>" + + " </soap:book>" + + " </soap:books>" + + " </soap:Envelope>';\n" + + " function test() {\n" + + " if (window.XPathEvaluator) {" + + " var doc = (new DOMParser).parseFromString(xml);" + + " var xpe = new XPathEvaluator();\n" + + " var result = xpe.evaluate('/s:Envelope/s:books/s:book/title/text()', " + + "doc.documentElement, nsResolver, XPathResult.STRING_TYPE, null);\n" + + " alert(result.stringValue);\n" + + " }}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |