From: <rb...@us...> - 2017-10-07 14:09:15
|
Revision: 14861 http://sourceforge.net/p/htmlunit/code/14861 Author: rbri Date: 2017-10-07 14:09:12 +0000 (Sat, 07 Oct 2017) Log Message: ----------- simple impl for CanvasRenderingContext.fillText added Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/AwtRenderingBackend.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/GaeRenderingBackend.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2DTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-10-07 11:02:10 UTC (rev 14860) +++ trunk/htmlunit/src/changes/changes.xml 2017-10-07 14:09:12 UTC (rev 14861) @@ -8,7 +8,13 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 61"> + <action type="add" dev="rbri"> + JavaScript: simple impl for CanvasRenderingContext.fillText added. + </action> <action type="fix" dev="rbri"> + JavaScript: various fixes for the Promise implementation. + </action> + <action type="fix" dev="rbri"> JavaScript: writing to an iFrame triggers the onload event now for chrome also </action> <action type="fix" dev="rbri"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java 2017-10-07 11:02:10 UTC (rev 14860) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java 2017-10-07 14:09:12 UTC (rev 14861) @@ -392,11 +392,14 @@ } /** - * Dummy placeholder. + * Fills a given text at the given (x, y) position. + * @param text the text + * @param x the x + * @param y the y */ @JsxFunction - public void fillText() { - //empty + public void fillText(final String text, final int x, final int y) { + getRenderingBackend().fillText(text, x, y); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/AwtRenderingBackend.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/AwtRenderingBackend.java 2017-10-07 11:02:10 UTC (rev 14860) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/AwtRenderingBackend.java 2017-10-07 14:09:12 UTC (rev 14861) @@ -113,6 +113,14 @@ * {@inheritDoc} */ @Override + public void fillText(final String text, final int x, final int y) { + graphics2D_.drawString(text, x, y); + } + + /** + * {@inheritDoc} + */ + @Override public void drawImage(final ImageReader imageReader, final int dxI, final int dyI) throws IOException { if (imageReader.getNumImages(true) != 0) { final BufferedImage img = imageReader.read(0); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/GaeRenderingBackend.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/GaeRenderingBackend.java 2017-10-07 11:02:10 UTC (rev 14860) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/GaeRenderingBackend.java 2017-10-07 14:09:12 UTC (rev 14861) @@ -65,6 +65,13 @@ * {@inheritDoc} */ @Override + public void fillText(final String text, final int x, final int y) { + } + + /** + * {@inheritDoc} + */ + @Override public void drawImage(final ImageReader imageReader, final int dxI, final int dyI) throws IOException { } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java 2017-10-07 11:02:10 UTC (rev 14860) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java 2017-10-07 14:09:12 UTC (rev 14861) @@ -61,6 +61,14 @@ void strokeRect(int x, int y, int w, int h); /** + * Fills a given text at the given (x, y) position. + * @param text the text + * @param x the x + * @param y the y + */ + void fillText(String text, int x, int y); + + /** * Draws images onto the context. * * @param imageReader the reader to read the image from 8the first one) Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2DTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2DTest.java 2017-10-07 11:02:10 UTC (rev 14860) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/CanvasRenderingContext2DTest.java 2017-10-07 14:09:12 UTC (rev 14861) @@ -361,4 +361,46 @@ + "</html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(CHROME = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAYAAADFw8lbAAABVUl" + + "EQVRYR+3UMS9lURTF8Z+vwBcQDZ1ESyWZMSPRUChQk1FNohPVRDeJaCRaodAoJRoVrZrOF1BrZct9yXW" + + "D916yzTT7Vveec/c6a//POmfE22cSizhoDa8172f4hjs8deq6n2P4hb/YwiUemp9ibh+7H+i0a8PPc9S" + + "ODGH0Ajs4+mKjbUu/e00OYzQETnGMc/zE90Z1G3tYwBzuByT6A0tYbXTatTe4xhXW3jMaJqY7pNfRJjq" + + "FDUTHM43JiEiMzzfUB9n6MDqBP5j9rHYYol2j44jc9haIxXoZPxmC6CNu+9X+C6PLLWqxUe3GYhe+xGj" + + "cBkHyEKMDEg1zUbfZxOk1c82B7Gc0Du9KZLhLtM+t8/+my2g2+yJaRLMJZOtVRotoNoFsvcpoEc0mkK1" + + "XGS2i2QSy9SqjRTSbQLZeZbSIZhPI1quMFtFsAtl6ldEimk0gW+8FX3djZf6IgMoAAAAASUVORK5CYII=", + FF = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAYAAADFw8lbAAAAn0lEQVR" + + "Yhe3S4Q2DIBCG4W+WzuEgTuIozOIw7kJ/FJLzehSpJibmfRJixOP8BKW9SVJyc6nMS9KiMdvBvr31X3o" + + "Nmws7L/o3aNOvhqukXK61LpexmOf2Y44Etb1b69coaA6G39FaV9ma6AR6QW24uhHSBUfv67bBeh80BfO" + + "3BJU+u/5y91GvS4L6f3Qk6Kz97zSfCQoAAAAAAAAAwMO9AbwlTKQXMPMUAAAAAElFTkSuQmCC", + IE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAYAAADFw8lbAAAAAXNSR0I" + + "Ars4c6QAAAARnQU1BAACxjwv8YQUAAADvSURBVFhH7ZJBDsFAFIbLURrHwBJHwMqWA3AGDmBtxxGwsHE" + + "NbUTcg/+v92QibdKRWPm/5PNPTeZ15nWSD9pw/xq+mZtkbVmHhyXrsW6Iz1Xh80NYrG3yJ4Kp5a9pWE4" + + "sozbq3bxAnpTPPDnlqX3MubqwBjse1iFepw/PMC3bKCd9IV1CMrNsWfYgTz6CGxt3YBfGcIJeZ8w/jB0" + + "8QNbMyzbKSS50F7CMo+Ud+piklk5uGZJZkpsl61QSe0e/4QrDTvGT8vpEEbtRdiL2JSvILvtV2sIBrA" + + "O/RnFHiychhBBCCCGEEEIIIYQQ4l9Ikiccki+D/HzKtwAAAABJRU5ErkJggg==") + @NotYetImplemented + public void fillText() throws Exception { + final String html = + "<html>\n" + + " <head>\n" + + " <script>\n" + + " function test() {\n" + + " var canvas = document.getElementById('myCanvas');\n" + + " if (canvas.getContext){\n" + + " var context = canvas.getContext('2d');\n" + + " context.fillText('HtmlUnit', 3, 7);\n" + + " alert(canvas.toDataURL());\n" + + " }\n" + + " }\n" + + " </script>\n" + + " </head>\n" + + " <body onload='test()'><canvas id='myCanvas' width='42' height='42'></canvas></body>\n" + + "</html>"; + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2017-10-07 14:42:03
|
Revision: 14862 http://sourceforge.net/p/htmlunit/code/14862 Author: rbri Date: 2017-10-07 14:42:01 +0000 (Sat, 07 Oct 2017) Log Message: ----------- throw a type error if the url property is requested from the WebSocket prototype Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-10-07 14:09:12 UTC (rev 14861) +++ trunk/htmlunit/src/changes/changes.xml 2017-10-07 14:42:01 UTC (rev 14862) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 61"> + <action type="fix" dev="rbri"> + JavaScript: throw a type error if the url property is requested from the WebSocket prototype. + </action> <action type="add" dev="rbri"> JavaScript: simple impl for CanvasRenderingContext.fillText added. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2017-10-07 14:09:12 UTC (rev 14861) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2017-10-07 14:42:01 UTC (rev 14862) @@ -49,6 +49,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.ContextAction; import net.sourceforge.htmlunit.corejs.javascript.Function; +import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.Undefined; @@ -278,6 +279,9 @@ */ @JsxGetter public String getUrl() { + if (url_ == null) { + throw ScriptRuntime.typeError("invalid call"); + } return url_.toString(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-10-07 14:09:12 UTC (rev 14861) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-10-07 14:42:01 UTC (rev 14862) @@ -519,4 +519,21 @@ stopWebServers(); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("true") + public void prototypeUrl() throws Exception { + final String html = "<html><head><script>\n" + + " function test() {\n" + + " try {\n" + + " var u = WebSocket.prototype.url;\n" + + " alert(u);\n" + + " } catch(e) { alert(e instanceof TypeError) }\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2017-10-07 17:33:01
|
Revision: 14863 http://sourceforge.net/p/htmlunit/code/14863 Author: rbri Date: 2017-10-07 17:32:58 +0000 (Sat, 07 Oct 2017) Log Message: ----------- fix Promise for many then calls on the same async one Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-10-07 14:42:01 UTC (rev 14862) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-10-07 17:32:58 UTC (rev 14863) @@ -18,6 +18,9 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; +import java.util.ArrayList; +import java.util.List; + import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.background.BasicJavaScriptJob; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; @@ -52,7 +55,7 @@ /** To be set only by {@link #all(Context, Scriptable, Object[], Function)}. */ private Promise[] all_; - private BasicJavaScriptJob settledAction_; + private List<BasicJavaScriptJob> settledJobs_; private Promise dependentPromise_; /** @@ -186,9 +189,11 @@ state_ = PromiseState.REJECTED; } - if (settledAction_ != null) { - window.getWebWindow().getJobManager().addJob(settledAction_, window.getDocument().getPage()); - settledAction_ = null; + if (settledJobs_ != null) { + for (BasicJavaScriptJob job : settledJobs_) { + window.getWebWindow().getJobManager().addJob(job, window.getDocument().getPage()); + } + settledJobs_ = null; } if (dependentPromise_ != null) { @@ -248,7 +253,7 @@ final Promise thisPromise = this; - settledAction_ = new BasicJavaScriptJob() { + final BasicJavaScriptJob job = new BasicJavaScriptJob() { @Override public void run() { @@ -300,9 +305,14 @@ }; if (state_ == PromiseState.FULFILLED || state_ == PromiseState.REJECTED) { - window.getWebWindow().getJobManager().addJob(settledAction_, window.getDocument().getPage()); - settledAction_ = null; + window.getWebWindow().getJobManager().addJob(job, window.getDocument().getPage()); } + else { + if (settledJobs_ == null) { + settledJobs_ = new ArrayList<BasicJavaScriptJob>(2); + } + settledJobs_.add(job); + } return returnPromise; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-10-07 14:42:01 UTC (rev 14862) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-10-07 17:32:58 UTC (rev 14863) @@ -518,6 +518,88 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = {"done", "1 yes", "2 yes"}, + IE = {}) + public void thenTwice() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = Promise.resolve('yes');\n" + + "\n" + + " p.then(function(value) {\n" + + " log('1 ' + value);\n" + + " })\n" + + " p.then(function(value) {\n" + + " log('2 ' + value);\n" + + " })\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "1 yes", "2 yes"}, + IE = {}) + public void thenTwiceAsync() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('yes');\n" + + " }, 20);\n" + + " })\n" + + "\n" + + " p.then(function(value) {\n" + + " log('1 ' + value);\n" + + " })\n" + + " p.then(function(value) {\n" + + " log('2 ' + value);\n" + + " })\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = {"Success", "string", "oh, no!", "after catch"}, IE = {}) public void catchTest() throws Exception { |
From: <rb...@us...> - 2017-10-08 13:07:31
|
Revision: 14865 http://sourceforge.net/p/htmlunit/code/14865 Author: rbri Date: 2017-10-08 13:07:28 +0000 (Sun, 08 Oct 2017) Log Message: ----------- first simple Promise.all cases are working Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-10-07 17:39:00 UTC (rev 14864) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-10-08 13:07:28 UTC (rev 14865) @@ -37,6 +37,7 @@ import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; +import net.sourceforge.htmlunit.corejs.javascript.TopLevel; import net.sourceforge.htmlunit.corejs.javascript.Undefined; /** @@ -181,7 +182,16 @@ return; } + if (all_ != null) { + settleAll(window); + return; + } + settleThis(fulfilled, newValue, window); + } + + private void settleThis(final boolean fulfilled, final Object newValue, final Window window) { value_ = newValue; + if (fulfilled) { state_ = PromiseState.FULFILLED; } @@ -202,6 +212,24 @@ } } + private void settleAll(final Window window) { + final ArrayList<Object> values = new ArrayList<>(all_.length); + for (Promise promise : all_) { + if (promise.state_ == PromiseState.REJECTED) { + settleThis(false, promise.value_, window); + return; + } + else if (promise.state_ == PromiseState.PENDING) { + return; + } + values.add(promise.value_); + } + + final NativeArray jsValues = new NativeArray(values.toArray()); + ScriptRuntime.setBuiltinProtoAndParent(jsValues, window, TopLevel.Builtins.Array); + settleThis(true, jsValues, window); + } + /** * Returns a {@link Promise} that resolves when all of the promises in the iterable argument have resolved, * or rejects with the reason of the first passed promise that rejects. @@ -215,28 +243,33 @@ @JsxStaticFunction public static Promise all(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { - final Promise promise = new Promise(); - promise.state_ = PromiseState.FULFILLED; + final Window window = getWindow(thisObj); + final Promise returnPromise = new Promise(window); + if (args.length == 0) { - promise.all_ = new Promise[0]; + returnPromise.all_ = new Promise[0]; } - else { + else if (args[0] instanceof NativeArray) { final NativeArray array = (NativeArray) args[0]; final int length = (int) array.getLength(); - promise.all_ = new Promise[length]; + returnPromise.all_ = new Promise[length]; for (int i = 0; i < length; i++) { final Object o = array.get(i); if (o instanceof Promise) { - promise.all_[i] = (Promise) o; + returnPromise.all_[i] = (Promise) o; + returnPromise.all_[i].dependentPromise_ = returnPromise; } else { - promise.all_[i] = resolve(null, thisObj, new Object[] {o}, null); + returnPromise.all_[i] = create(thisObj, new Object[] {o}, PromiseState.FULFILLED); } } } - promise.setParentScope(thisObj.getParentScope()); - promise.setPrototype(getWindow(thisObj).getPrototype(promise.getClass())); - return promise; + else { + // TODO + } + + returnPromise.settleAll(window); + return returnPromise; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-10-07 17:39:00 UTC (rev 14864) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-10-08 13:07:28 UTC (rev 14865) @@ -14,9 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; - import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -24,7 +21,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -101,14 +97,103 @@ final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); assertEquals(String.join("\n", getExpectedAlerts()), text); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(CHROME = { "function () { [native code] }", + "function () { [native code] }", + "[object Window]", + "done", "resolved value"}, + FF = { "function () {\n [native code]\n}", + "function () {\n [native code]\n}", + "[object Window]", + "done", "resolved value"}, + IE = {}) + public void constructor() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = new Promise(function(resolve, reject) {\n" + + " log(resolve);\n" + + " log(reject);\n" + + " log(this);\n" + + " resolve('resolved value');\n" + + " });\n" + + " p.then(function(value) {log(value);});\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + /** * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"done", "Resolved"}, + @Alerts(DEFAULT = {"true", "true", "true"}, IE = {}) - public void resolve() throws Exception { + public void constructorWithoutFunction() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " try{\n" + + " var p = new Promise();\n" + + " log('done');\n" + + " } catch(e) { log(e instanceof TypeError); }\n" + + " try{\n" + + " var p = new Promise([1, 2, 4]);\n" + + " log('done');\n" + + " } catch(e) { log(e instanceof TypeError); }\n" + + " try{\n" + + " var original = Promise.resolve(42);\n" + + " var p = new Promise(original);\n" + + " log('done');\n" + + " } catch(e) { log(e instanceof TypeError); }\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "Rejected"}, + IE = {}) + public void reject() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -115,10 +200,10 @@ + " <script>\n" + " function test() {\n" + " if (window.Promise) {\n" - + " Promise.resolve('Resolved').then(function(value) {\n" + + " Promise.reject('Rejected').then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + " log(value);\n" - + " }, function(value) {\n" - + " log('failure');\n" + " });\n" + " log('done');\n" + " }\n" @@ -143,9 +228,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"done", "Rejected"}, + @Alerts(DEFAULT = {"done", "false", "[object Promise]"}, IE = {}) - public void reject() throws Exception { + public void rejectPromise() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -152,12 +237,15 @@ + " <script>\n" + " function test() {\n" + " if (window.Promise) {\n" - + " Promise.reject('Rejected').then(function(value) {\n" - + " log('failure');\n" + + " var original = Promise.reject(42);\n" + + " var cast = Promise.reject(original);\n" + + " cast.then(function(v) {\n" + + " log('failure');\n" + " }, function(value) {\n" - + " log(value);\n" + + " log(value);\n" + " });\n" + " log('done');\n" + + " log(original === cast);\n" + " }\n" + " }\n" + " function log(x) {\n" @@ -180,9 +268,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"done", "false", "[object Promise]"}, + @Alerts(DEFAULT = {"done", "Resolved"}, IE = {}) - public void rejectPromise() throws Exception { + public void resolve() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -189,15 +277,12 @@ + " <script>\n" + " function test() {\n" + " if (window.Promise) {\n" - + " var original = Promise.reject(42);\n" - + " var cast = Promise.reject(original);\n" - + " cast.then(function(v) {\n" - + " log('failure');\n" + + " Promise.resolve('Resolved').then(function(value) {\n" + + " log(value);\n" + " }, function(value) {\n" - + " log(value);\n" + + " log('failure');\n" + " });\n" + " log('done');\n" - + " log(original === cast);\n" + " }\n" + " }\n" + " function log(x) {\n" @@ -729,7 +814,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "Success", + @Alerts(DEFAULT = {"done", "Success"}, IE = "") public void thenInsideEventHandler() throws Exception { final String html = "<html>\n" @@ -736,29 +821,35 @@ + "<head>\n" + " <script>\n" + " function test() {\n" - + " if(!window.Promise) {\n" - + " return;\n" + + " if (window.Promise) {\n" + + " document.getElementById('btn1').onclick = function() {\n" + + " new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 20);\n" + + " }).then(function(value) {\n" + + " log(value);\n" + + " });\n" + + " log('done');\n" + + " };\n" + " }\n" - + " document.getElementById('btn1').onclick = function() {\n" - + " new Promise(function(resolve, reject) {\n" - + " window.setTimeout( function() {\n" - + " resolve('Success');\n" - + " }, 0);\n" - + " }).then(function(value) {\n" - + " document.title += value;\n" - + " });\n" - + " };\n" + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + " </script>\n" + "</head>\n" + "<body onload='test()'>\n" - + "<button id='btn1'>BTN1</button>\n" + + " <button id='btn1'>BTN1</button>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + "</body>\n" - + "</html>"; + + "</html>\n"; final WebDriver driver = loadPage2(html); driver.findElement(By.id("btn1")).click(); Thread.sleep(200); - assertEquals(getExpectedAlerts()[0], driver.getTitle()); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); } /** @@ -767,10 +858,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"object", "3", "3,1337,foo"}, + @Alerts(DEFAULT = {"done", "object", "3", "3,1337,Success"}, IE = {}) - @NotYetImplemented({CHROME, FF}) - public void all() throws Exception { + public void allAsync() throws Exception { final String html = "<html>\n" + "<head>\n" + " <script>\n" @@ -779,14 +869,17 @@ + " var p1 = Promise.resolve(3);\n" + " var p2 = 1337;\n" + " var p3 = new Promise(function(resolve, reject) {\n" - + " setTimeout(resolve, 100, \"foo\");\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 20);\n" + " });\n" + "\n" - + " Promise.all([ p1, p2, p3 ]).then(function(values) {\n" + + " Promise.all([p1, p2, p3]).then(function(values) {\n" + " log(typeof values);\n" + " log(values.length);\n" + " log(values);\n" + " });\n" + + " log('done');\n" + " }\n" + " }\n" + "\n" @@ -806,44 +899,45 @@ } /** + * Test for Bug #1780. + * * @throws Exception if an error occurs */ @Test - @Alerts(CHROME = { "function () { [native code] }", - "function () { [native code] }", - "[object Window]", - "done", "resolved value"}, - FF = { "function () {\n [native code]\n}", - "function () {\n [native code]\n}", - "[object Window]", - "done", "resolved value"}, + @Alerts(DEFAULT = {"done", "string", "Failed"}, IE = {}) - public void constructor() throws Exception { + public void allRejectAsync() throws Exception { final String html = "<html>\n" - + "<head>\n" - + " <script>\n" - + " function test() {\n" - + " if (window.Promise) {\n" - + " var p = new Promise(function(resolve, reject) {\n" - + " log(resolve);\n" - + " log(reject);\n" - + " log(this);\n" - + " resolve('resolved value');\n" - + " });\n" - + " p.then(function(value) {log(value);});\n" - + " log('done');\n" - + " }\n" - + " }\n" - + "\n" - + " function log(x) {\n" - + " document.getElementById('log').value += x + '\\n';\n" - + " }\n" - + " </script>\n" - + "</head>\n" - + "<body onload='test()'>\n" - + " <textarea id='log' cols='80' rows='40'></textarea>\n" - + "</body>\n" - + "</html>"; + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = Promise.resolve(3);\n" + + " var p2 = 1337;\n" + + " var p3 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " reject('Failed');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.all([p1, p2, p3]).then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + + " log(typeof value);\n" + + " log(value);\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; final WebDriver driver = loadPage2(html); Thread.sleep(200); @@ -850,48 +944,4 @@ final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); assertEquals(String.join("\n", getExpectedAlerts()), text); } - - /** - * @throws Exception if an error occurs - */ - @Test - @Alerts(DEFAULT = {"true", "true", "true"}, - IE = {}) - public void constructorWithoutFunction() throws Exception { - final String html = "<html>\n" - + "<head>\n" - + " <script>\n" - + " function test() {\n" - + " if (window.Promise) {\n" - + " try{\n" - + " var p = new Promise();\n" - + " log('done');\n" - + " } catch(e) { log(e instanceof TypeError); }\n" - + " try{\n" - + " var p = new Promise([1, 2, 4]);\n" - + " log('done');\n" - + " } catch(e) { log(e instanceof TypeError); }\n" - + " try{\n" - + " var original = Promise.resolve(42);\n" - + " var p = new Promise(original);\n" - + " log('done');\n" - + " } catch(e) { log(e instanceof TypeError); }\n" - + " }\n" - + " }\n" - + "\n" - + " function log(x) {\n" - + " document.getElementById('log').value += x + '\\n';\n" - + " }\n" - + " </script>\n" - + "</head>\n" - + "<body onload='test()'>\n" - + " <textarea id='log' cols='80' rows='40'></textarea>\n" - + "</body>\n" - + "</html>"; - - final WebDriver driver = loadPage2(html); - - final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); - assertEquals(String.join("\n", getExpectedAlerts()), text); - } } |
From: <rb...@us...> - 2017-10-08 13:21:39
|
Revision: 14866 http://sourceforge.net/p/htmlunit/code/14866 Author: rbri Date: 2017-10-08 13:21:36 +0000 (Sun, 08 Oct 2017) Log Message: ----------- first simple Promise.race cases are working Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-10-08 13:07:28 UTC (rev 14865) +++ trunk/htmlunit/src/changes/changes.xml 2017-10-08 13:21:36 UTC (rev 14866) @@ -7,7 +7,7 @@ </properties> <body> - <release version="2.28" date="???" description="Bugfixes, Chrome 61"> + <release version="2.28" date="???" description="Bugfixes, Chrome 61, improved Promise impl"> <action type="fix" dev="rbri"> JavaScript: throw a type error if the url property is requested from the WebSocket prototype. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-10-08 13:07:28 UTC (rev 14865) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-10-08 13:21:36 UTC (rev 14866) @@ -53,7 +53,8 @@ private enum PromiseState { PENDING, FULFILLED, REJECTED } private PromiseState state_ = PromiseState.PENDING; private Object value_; - /** To be set only by {@link #all(Context, Scriptable, Object[], Function)}. */ + + private boolean race_; private Promise[] all_; private List<BasicJavaScriptJob> settledJobs_; @@ -213,6 +214,20 @@ } private void settleAll(final Window window) { + if (race_) { + for (Promise promise : all_) { + if (promise.state_ == PromiseState.REJECTED) { + settleThis(false, promise.value_, window); + return; + } + else if (promise.state_ == PromiseState.FULFILLED) { + settleThis(true, promise.value_, window); + return; + } + } + return; + } + final ArrayList<Object> values = new ArrayList<>(all_.length); for (Promise promise : all_) { if (promise.state_ == PromiseState.REJECTED) { @@ -243,6 +258,26 @@ @JsxStaticFunction public static Promise all(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + return all(false, thisObj, args); + } + + /** + * Returns a {@link Promise} that that resolves or rejects as soon as one of the promises + * in the iterable resolves or rejects, with the value or reason from that promise. + * + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + * @return a {@link Promise} + */ + @JsxStaticFunction + public static Promise race(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + return all(true, thisObj, args); + } + + private static Promise all(final boolean race, final Scriptable thisObj, final Object[] args) { final Window window = getWindow(thisObj); final Promise returnPromise = new Promise(window); @@ -267,6 +302,7 @@ else { // TODO } + returnPromise.race_ = race; returnPromise.settleAll(window); return returnPromise; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-10-08 13:07:28 UTC (rev 14865) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-10-08 13:21:36 UTC (rev 14866) @@ -853,8 +853,6 @@ } /** - * Test for Bug #1780. - * * @throws Exception if an error occurs */ @Test @@ -899,8 +897,6 @@ } /** - * Test for Bug #1780. - * * @throws Exception if an error occurs */ @Test @@ -944,4 +940,98 @@ final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); assertEquals(String.join("\n", getExpectedAlerts()), text); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "Success 2"}, + IE = {}) + public void raceAsync() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 40);\n" + + " });\n" + + " var p2 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success 2');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.race([p1, p2]).then(function(value) {\n" + + " log(value);\n" + + " }, function(value) {\n" + + " log('failure');\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "Failed"}, + IE = {}) + public void raceRejectAsync() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 40);\n" + + " });\n" + + " var p2 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " reject('Failed');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.race([p1, p2]).then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + + " log(value);\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } } |
From: <rb...@us...> - 2017-10-12 18:51:44
|
Revision: 14870 http://sourceforge.net/p/htmlunit/code/14870 Author: rbri Date: 2017-10-12 18:51:42 +0000 (Thu, 12 Oct 2017) Log Message: ----------- selector specificity calculation fixed for selectors using the general sibling combinator (~) Issue 1925 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-10-10 15:22:04 UTC (rev 14869) +++ trunk/htmlunit/src/changes/changes.xml 2017-10-12 18:51:42 UTC (rev 14870) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 61, improved Promise impl"> + <action type="fix" dev="rbri" issue="1925"> + Selector specificity calculation fixed for selectors using the general sibling combinator (~). + </action> <action type="fix" dev="rbri" issue="1924" due-to="Colin Alworth"> JavaScript: window.onerror provides now a valid error object. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-10-10 15:22:04 UTC (rev 14869) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-10-12 18:51:42 UTC (rev 14870) @@ -417,22 +417,6 @@ final DomElement element, final String pseudoElement, final boolean fromQuerySelectorAll) { switch (selector.getSelectorType()) { case Selector.SAC_ANY_NODE_SELECTOR: - if (selector instanceof GeneralAdjacentSelectorImpl) { - final SiblingSelector ss = (SiblingSelector) selector; - final Selector ssSelector = ss.getSelector(); - final SimpleSelector ssSiblingSelector = ss.getSiblingSelector(); - for (DomNode prev = element.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) { - if (prev instanceof HtmlElement - && selects(browserVersion, ssSelector, (HtmlElement) prev, - pseudoElement, fromQuerySelectorAll) - && selects(browserVersion, ssSiblingSelector, element, - pseudoElement, fromQuerySelectorAll)) { - return true; - } - } - return false; - } - return true; case Selector.SAC_CHILD_SELECTOR: final DomNode parentNode = element.getParentNode(); @@ -478,6 +462,21 @@ return HtmlHtml.TAG_NAME.equalsIgnoreCase(element.getTagName()); case Selector.SAC_DIRECT_ADJACENT_SELECTOR: final SiblingSelector ss = (SiblingSelector) selector; + + if (selector instanceof GeneralAdjacentSelectorImpl) { + final SimpleSelector ssSiblingSelector = ss.getSiblingSelector(); + for (DomNode prev = element.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) { + if (prev instanceof HtmlElement + && selects(browserVersion, ss.getSelector(), (HtmlElement) prev, + pseudoElement, fromQuerySelectorAll) + && selects(browserVersion, ssSiblingSelector, element, + pseudoElement, fromQuerySelectorAll)) { + return true; + } + } + return false; + } + DomNode prev = element.getPreviousSibling(); while (prev != null && !(prev instanceof HtmlElement)) { prev = prev.getPreviousSibling(); @@ -1482,11 +1481,6 @@ return isValidSelector(ss.getSelector(), documentMode, domNode) && isValidSelector(ss.getSiblingSelector(), documentMode, domNode); case Selector.SAC_ANY_NODE_SELECTOR: - if (selector instanceof SiblingSelector) { - final SiblingSelector sibling = (SiblingSelector) selector; - return isValidSelector(sibling.getSelector(), documentMode, domNode) - && isValidSelector(sibling.getSiblingSelector(), documentMode, domNode); - } //$FALL-THROUGH$ default: LOG.warn("Unhandled CSS selector type '" + selector.getSelectorType() + "'. Accepting it silently."); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2.java 2017-10-10 15:22:04 UTC (rev 14869) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2.java 2017-10-12 18:51:42 UTC (rev 14870) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.css; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLLINK_CHECK_TYPE_FOR_STYLESHEET; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NO_TARGET; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTOR_CSS3_PSEUDO_REQUIRE_ATTACHED_NODE; @@ -538,6 +539,15 @@ if (link != null) { // Use link. request = link.getWebRequest(); + + if (element.getBrowserVersion().hasFeature(HTMLLINK_CHECK_TYPE_FOR_STYLESHEET)) { + final String type = link.getTypeAttribute(); + if (StringUtils.isNotBlank(type) && !"text/css".equals(type)) { + final InputSource source = new InputSource(new StringReader("")); + return new CSSStyleSheet2(element, source, uri); + } + } + // our cache is a bit strange; // loadWebResponse check the cache for the web response // AND also fixes the request url for the following cache lookups @@ -665,20 +675,6 @@ final DomElement element, final String pseudoElement) { switch (selector.getSelectorType()) { case Selector.SAC_ANY_NODE_SELECTOR: - if (selector instanceof GeneralAdjacentSelectorImpl) { - final SiblingSelector ss = (SiblingSelector) selector; - final Selector ssSelector = ss.getSelector(); - final SimpleSelector ssSiblingSelector = ss.getSiblingSelector(); - for (DomNode prev = element.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) { - if (prev instanceof HtmlElement - && selects(browserVersion, ssSelector, (HtmlElement) prev) - && selects(browserVersion, ssSiblingSelector, element)) { - return true; - } - } - return false; - } - return true; case Selector.SAC_CHILD_SELECTOR: final DomNode parentNode = element.getParentNode(); @@ -721,6 +717,20 @@ return HtmlHtml.TAG_NAME.equalsIgnoreCase(element.getTagName()); case Selector.SAC_DIRECT_ADJACENT_SELECTOR: final SiblingSelector ss = (SiblingSelector) selector; + + if (selector instanceof GeneralAdjacentSelectorImpl) { + final Selector ssSelector = ss.getSelector(); + final SimpleSelector ssSiblingSelector = ss.getSiblingSelector(); + for (DomNode prev = element.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) { + if (prev instanceof HtmlElement + && selects(browserVersion, ssSelector, (HtmlElement) prev) + && selects(browserVersion, ssSiblingSelector, element)) { + return true; + } + } + return false; + } + DomNode prev = element.getPreviousSibling(); while (prev != null && !(prev instanceof HtmlElement)) { prev = prev.getPreviousSibling(); @@ -1136,11 +1146,6 @@ return isValidSelector(ss.getSelector(), documentMode, domNode) && isValidSelector(ss.getSiblingSelector(), documentMode, domNode); case Selector.SAC_ANY_NODE_SELECTOR: - if (selector instanceof SiblingSelector) { - final SiblingSelector sibling = (SiblingSelector) selector; - return isValidSelector(sibling.getSelector(), documentMode, domNode) - && isValidSelector(sibling.getSiblingSelector(), documentMode, domNode); - } default: LOG.warn("Unhandled CSS selector type '" + selector.getSelectorType() + "'. Accepting it silently."); return true; // at least in a first time to break less stuff Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java 2017-10-10 15:22:04 UTC (rev 14869) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java 2017-10-12 18:51:42 UTC (rev 14870) @@ -76,6 +76,13 @@ assertTrue(specificy11.compareTo(specificy21) < 0); assertTrue(specificy11.compareTo(specificy100) < 0); } + /** + * @throws Exception if the test fails + */ + @Test + public void selectorSpecifitySiblingCombinator() throws Exception { + selectorSpecifity(".cls ~ p", "0,0,1,1"); + } private SelectorSpecificity selectorSpecifity(final String selector, final String expectedSpecificity) throws Exception { |
From: <rb...@us...> - 2017-10-21 10:33:47
|
Revision: 14874 http://sourceforge.net/p/htmlunit/code/14874 Author: rbri Date: 2017-10-21 10:33:44 +0000 (Sat, 21 Oct 2017) Log Message: ----------- simplification Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XmlSerializer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-10-12 19:55:21 UTC (rev 14873) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-10-21 10:33:44 UTC (rev 14874) @@ -39,6 +39,7 @@ * @author Ronald Brill */ public class HtmlLink extends HtmlElement { + // private static final Log LOG = LogFactory.getLog(HtmlLink.class); /** The HTML tag represented by this element. */ public static final String TAG_NAME = "link"; @@ -153,20 +154,6 @@ } /** - * <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE RESOURCE - USE AT YOUR OWN RISK.</span><br> - * If the linked content is not already downloaded it triggers a download. Then it stores the response - * for later use.<br> - * - * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously - * @return {@code null} if no download should be performed and when this wasn't already done; the response - * received when performing a request for the content referenced by this tag otherwise - * @throws IOException if an error occurs while downloading the content - */ - public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { - return getWebResponse(downloadIfNeeded, null); - } - - /** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * If the linked content is not already downloaded it triggers a download. Then it stores the response Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XmlSerializer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XmlSerializer.java 2017-10-12 19:55:21 UTC (rev 14873) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/XmlSerializer.java 2017-10-21 10:33:44 UTC (rev 14874) @@ -241,7 +241,7 @@ final String protocol = link.getWebRequest().getUrl().getProtocol(); if ("http".equals(protocol) || "https".equals(protocol)) { final File file = createFile(hrefAttr.getValue(), ".css"); - FileUtils.writeStringToFile(file, link.getWebResponse(true).getContentAsString(), ISO_8859_1); + FileUtils.writeStringToFile(file, link.getWebResponse(true, null).getContentAsString(), ISO_8859_1); hrefAttr.setValue(outputDir_.getName() + FILE_SEPARATOR + file.getName()); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java 2017-10-12 19:55:21 UTC (rev 14873) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java 2017-10-21 10:33:44 UTC (rev 14874) @@ -43,7 +43,7 @@ final HtmlPage page = loadPage(html); final HtmlLink link = page.getFirstByXPath("//link"); - final WebResponse respCss = link.getWebResponse(true); + final WebResponse respCss = link.getWebResponse(true, null); assertEquals(page.getUrl().toExternalForm(), respCss.getWebRequest().getAdditionalHeaders().get("Referer")); } } |
From: <rb...@us...> - 2017-10-21 16:51:42
|
Revision: 14875 http://sourceforge.net/p/htmlunit/code/14875 Author: rbri Date: 2017-10-21 16:51:39 +0000 (Sat, 21 Oct 2017) Log Message: ----------- document.currentScript added Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-10-21 10:33:44 UTC (rev 14874) +++ trunk/htmlunit/src/changes/changes.xml 2017-10-21 16:51:39 UTC (rev 14875) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 61, improved Promise impl"> + <action type="add" dev="rbri"> + JavaScript: document.currentScript added. + </action> <action type="fix" dev="rbri" issue="1925"> Selector specificity calculation fixed for selectors using the general sibling combinator (~). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java 2017-10-21 10:33:44 UTC (rev 14874) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java 2017-10-21 16:51:39 UTC (rev 14875) @@ -375,7 +375,18 @@ if (charset == null) { charset = page.getCharset(); } - final JavaScriptLoadResult result = page.loadExternalJavaScriptFile(src, charset); + + JavaScriptLoadResult result = null; + final Window win = page.getEnclosingWindow().getScriptableObject(); + final Document doc = win.getDocument(); + try { + doc.setCurrentScript(getScriptableObject()); + result = page.loadExternalJavaScriptFile(src, charset); + } + finally { + doc.setCurrentScript(null); + } + if (result == JavaScriptLoadResult.SUCCESS) { executeEvent(Event.TYPE_LOAD); } @@ -391,7 +402,15 @@ } else if (getFirstChild() != null) { // <script>[code]</script> - executeInlineScriptIfNeeded(); + final Window win = page.getEnclosingWindow().getScriptableObject(); + final Document doc = win.getDocument(); + try { + doc.setCurrentScript(getScriptableObject()); + executeInlineScriptIfNeeded(); + } + finally { + doc.setCurrentScript(null); + } if (hasFeature(EVENT_ONLOAD_INTERNAL_JAVASCRIPT)) { executeEvent(Event.TYPE_LOAD); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript2Test.java 2017-10-21 10:33:44 UTC (rev 14874) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript2Test.java 2017-10-21 16:51:39 UTC (rev 14875) @@ -410,4 +410,156 @@ getMockWebConnection().setResponse(URL_SECOND, script, "application/javascript", UTF_8); loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + public void onLoad() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.js"), ""); + onLoadOnError("src='simple.js' type='text/javascript'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"onLoad", "body onLoad"}, + IE = "body onLoad") + public void onLoadTypeWhitespace() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.js"), ""); + onLoadOnError("src='simple.js' type='\t text/javascript '"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onError", "body onLoad"}) + public void onError() throws Exception { + onLoadOnError("src='unknown.js' type='text/javascript'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onError", "body onLoad"}) + public void onLoadOnErrorWithoutType() throws Exception { + onLoadOnError("src='unknown.js'"); + } + + private void onLoadOnError(final String attribs) throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + " <script " + attribs + + " onload='alert(\"onLoad\")' onerror='alert(\"onError\")'></script>\n" + + "</head>\n" + + "<body onload='alert(\"body onLoad\")'>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"from script", "onLoad [object Event]"}) + public void onLoadDynamic() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.js"), "log('from script');"); + final String html + = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var dynScript = document.createElement('script');\n" + + " dynScript.type = 'text/javascript';\n" + + " dynScript.onload = function (e) { log(\"onLoad \" + e) };\n" + + " document.head.appendChild(dynScript);\n" + + " dynScript.src = 'simple.js';" + + " }\n" + + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "[object HTMLScriptElement]", + IE = "undefined") + public void currentScriptInline() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + " <script id='tester'>\n" + + " alert(document.currentScript);\n" + + " </script>\n" + + "</head>\n" + + "<body>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "null", + IE = "undefined") + public void currentScriptFunction() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + " <script id='tester'>\n" + + " function test() {\n" + + " alert(document.currentScript);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "[object HTMLScriptElement]", + IE = "undefined") + public void currentScriptExternal() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.js"), "alert(document.currentScript);"); + final String html + = "<html>\n" + + "<head>\n" + + " <script id='tester' src='simple.js' type='text/javascript'></script>\n" + + "</head>\n" + + "<body>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2017-10-24 19:05:21
|
Revision: 14878 http://sourceforge.net/p/htmlunit/code/14878 Author: rbri Date: 2017-10-24 19:05:18 +0000 (Tue, 24 Oct 2017) Log Message: ----------- trigger load/error event when loading stylesheets Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-10-22 08:18:05 UTC (rev 14877) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-10-24 19:05:18 UTC (rev 14878) @@ -21,10 +21,16 @@ import java.net.URL; import java.util.Map; +import org.apache.http.HttpStatus; + import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; +import com.gargoylesoftware.htmlunit.javascript.host.event.Event; +import com.gargoylesoftware.htmlunit.javascript.host.event.Event2; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement2; /** * Wrapper for the HTML element "link". <b>Note:</b> This is not a clickable link, @@ -165,15 +171,28 @@ * received when performing a request for the content referenced by this tag otherwise * @throws IOException if an error occurs while downloading the content */ - public WebResponse getWebResponse(final boolean downloadIfNeeded, final WebRequest request) throws IOException { + public WebResponse getWebResponse(final boolean downloadIfNeeded, WebRequest request) throws IOException { if (downloadIfNeeded && cachedWebResponse_ == null) { final WebClient webclient = getPage().getWebClient(); if (null == request) { - cachedWebResponse_ = webclient.loadWebResponse(getWebRequest()); + request = getWebRequest(); } - else { + try { cachedWebResponse_ = webclient.loadWebResponse(request); + final int statusCode = cachedWebResponse_.getStatusCode(); + final boolean successful = statusCode >= HttpStatus.SC_OK + && statusCode < HttpStatus.SC_MULTIPLE_CHOICES; + if (successful) { + executeEvent(Event.TYPE_LOAD); + } + else { + executeEvent(Event.TYPE_ERROR); + } } + catch (final IOException e) { + executeEvent(Event.TYPE_ERROR); + throw e; + } } return cachedWebResponse_; } @@ -215,4 +234,53 @@ public boolean mayBeDisplayed() { return false; } + + private void executeEvent(final String type) { + final Object scriptable = getScriptableObject(); + if (scriptable instanceof HTMLLinkElement2) { + final HTMLLinkElement2 script = (HTMLLinkElement2) scriptable; + final Event2 event = new Event2(this, type); + script.executeEventLocally(event); + } + else { + final HTMLLinkElement link = (HTMLLinkElement) scriptable; + final Event event = new Event(this, type); + link.executeEventLocally(event); + } + } + +// /** +// * {@inheritDoc} +// */ +// @Override +// protected void onAllChildrenAddedToPage(final boolean postponed) { +// if (getOwnerDocument() instanceof XmlPage) { +// return; +// } +// if (LOG.isDebugEnabled()) { +// LOG.debug("Link node added: " + asXml()); +// } +// +// final PostponedAction action = new PostponedAction(getPage(), "Loading of link " + this) { +// @Override +// public void execute() { +// } +// }; +// +// final AbstractJavaScriptEngine<?> engine = getPage().getWebClient().getJavaScriptEngine(); +// if (postponed) { +// engine.addPostponedAction(action); +// } +// else { +// try { +// action.execute(); +// } +// catch (final RuntimeException e) { +// throw e; +// } +// catch (final Exception e) { +// throw new RuntimeException(e); +// } +// } +// } } 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 2017-10-22 08:18:05 UTC (rev 14877) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2017-10-24 19:05:18 UTC (rev 14878) @@ -74,8 +74,15 @@ * @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()); + if (domNode instanceof HtmlLink) { + final HtmlLink link = (HtmlLink) domNode; + String rel = link.getRelAttribute(); + if (rel != null) { + rel = rel.trim(); + } + return "stylesheet".equalsIgnoreCase(rel); + } + return false; } /** @@ -87,7 +94,11 @@ public boolean isActiveStyleSheetLink(final DomNode domNode) { if (domNode instanceof HtmlLink) { final HtmlLink link = (HtmlLink) domNode; - if ("stylesheet".equalsIgnoreCase(link.getRelAttribute())) { + String rel = link.getRelAttribute(); + if (rel != null) { + rel = rel.trim(); + } + if ("stylesheet".equalsIgnoreCase(rel)) { final String media = link.getMediaAttribute(); if (StringUtils.isBlank(media)) { return true; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java 2017-10-22 08:18:05 UTC (rev 14877) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java 2017-10-24 19:05:18 UTC (rev 14878) @@ -14,6 +14,11 @@ */ package com.gargoylesoftware.htmlunit.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + +import java.net.URL; + import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -22,6 +27,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -94,4 +100,110 @@ final boolean displayed = driver.findElement(By.id("l")).isDisplayed(); assertFalse(displayed); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + public void onLoad() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='stylesheet' href='simple.css'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + public void onLoadRelCase() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='sTYLeSheet' href='simple.css'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + public void onLoadMediaScreen() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='stylesheet' href='simple.css' media='screen'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + @NotYetImplemented(CHROME) + public void onLoadMediaPrint() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='stylesheet' href='simple.css' media='print'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + public void onLoadMediaQueryMatch() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='stylesheet' href='simple.css' media='(min-width: 100px)'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + @NotYetImplemented(CHROME) + public void onLoadMediaQueryNotMatch() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='stylesheet' href='simple.css' media='(max-width: 10px)'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad", "body onLoad"}) + public void onLoadRelWhitespace() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); + onLoadOnError("rel='\t stylesheet ' href='simple.css'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"onError", "body onLoad"}, + IE = {"onLoad", "body onLoad"}) + @NotYetImplemented(IE) + public void onError() throws Exception { + onLoadOnError("rel='stylesheet' href='unknown.css'"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts("body onLoad") + public void onLoadOnErrorWithoutRel() throws Exception { + onLoadOnError("href='unknown.css'"); + } + + private void onLoadOnError(final String attribs) throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + " <link " + attribs + + " onload='alert(\"onLoad\")' onerror='alert(\"onError\")'>\n" + + "</head>\n" + + "<body onload='window.getComputedStyle(document.body); alert(\"body onLoad\")'>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2017-10-31 10:29:22
|
Revision: 14880 http://sourceforge.net/p/htmlunit/code/14880 Author: rbri Date: 2017-10-31 10:29:19 +0000 (Tue, 31 Oct 2017) Log Message: ----------- stylesheets are always loaded on page load Issue 1927 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLinkElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-10-27 17:39:23 UTC (rev 14879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-10-31 10:29:19 UTC (rev 14880) @@ -21,6 +21,8 @@ import java.net.URL; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.http.HttpStatus; import com.gargoylesoftware.htmlunit.SgmlPage; @@ -27,10 +29,15 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; +import com.gargoylesoftware.htmlunit.javascript.AbstractJavaScriptEngine; +import com.gargoylesoftware.htmlunit.javascript.PostponedAction; +import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet; +import com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.Event2; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement2; +import com.gargoylesoftware.htmlunit.xml.XmlPage; /** * Wrapper for the HTML element "link". <b>Note:</b> This is not a clickable link, @@ -45,7 +52,7 @@ * @author Ronald Brill */ public class HtmlLink extends HtmlElement { - // private static final Log LOG = LogFactory.getLog(HtmlLink.class); + private static final Log LOG = LogFactory.getLog(HtmlLink.class); /** The HTML tag represented by this element. */ public static final String TAG_NAME = "link"; @@ -249,38 +256,44 @@ } } -// /** -// * {@inheritDoc} -// */ -// @Override -// protected void onAllChildrenAddedToPage(final boolean postponed) { -// if (getOwnerDocument() instanceof XmlPage) { -// return; -// } -// if (LOG.isDebugEnabled()) { -// LOG.debug("Link node added: " + asXml()); -// } -// -// final PostponedAction action = new PostponedAction(getPage(), "Loading of link " + this) { -// @Override -// public void execute() { -// } -// }; -// -// final AbstractJavaScriptEngine<?> engine = getPage().getWebClient().getJavaScriptEngine(); -// if (postponed) { -// engine.addPostponedAction(action); -// } -// else { -// try { -// action.execute(); -// } -// catch (final RuntimeException e) { -// throw e; -// } -// catch (final Exception e) { -// throw new RuntimeException(e); -// } -// } -// } + /** + * {@inheritDoc} + */ + @Override + protected void onAllChildrenAddedToPage(final boolean postponed) { + if (getOwnerDocument() instanceof XmlPage) { + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Link node added: " + asXml()); + } + + if (!StyleSheetList.isStyleSheetLink(this)) { + return; + } + + final PostponedAction action = new PostponedAction(getPage(), "Loading of link " + this) { + @Override + public void execute() { + final HTMLLinkElement linkElem = HtmlLink.this.getScriptableObject(); + CSSStyleSheet.loadStylesheet(linkElem, HtmlLink.this, null); + } + }; + + final AbstractJavaScriptEngine<?> engine = getPage().getWebClient().getJavaScriptEngine(); + if (postponed) { + engine.addPostponedAction(action); + } + else { + try { + action.execute(); + } + catch (final RuntimeException e) { + throw e; + } + catch (final Exception e) { + throw new RuntimeException(e); + } + } + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-10-27 17:39:23 UTC (rev 14879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-10-31 10:29:19 UTC (rev 14880) @@ -102,7 +102,6 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.host.Element; -import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.gargoylesoftware.htmlunit.util.UrlUtils; @@ -277,7 +276,7 @@ final String uri = (uri_ != null) ? uri_ : e.getPage().getUrl().toExternalForm(); final String href = importRule.getHref(); final String url = UrlUtils.resolveUrl(uri, href); - sheet = loadStylesheet(getWindow(), ownerNode_, null, url); + sheet = loadStylesheet(ownerNode_, null, url); imports_.put(importRule, sheet); } @@ -301,14 +300,12 @@ /** * Loads the stylesheet at the specified link or href. - * @param window the current window * @param element the parent DOM element * @param link the stylesheet's link (may be {@code null} if a <tt>url</tt> is specified) * @param url the stylesheet's url (may be {@code null} if a <tt>link</tt> is specified) * @return the loaded stylesheet */ - public static CSSStyleSheet loadStylesheet(final Window window, final HTMLElement element, - final HtmlLink link, final String url) { + public static CSSStyleSheet loadStylesheet(final HTMLElement element, final HtmlLink link, final String url) { CSSStyleSheet sheet; final HtmlPage page = (HtmlPage) element.getDomNodeOrDie().getPage(); String uri = page.getUrl().toExternalForm(); // fallback uri for exceptions Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLinkElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLinkElement.java 2017-10-27 17:39:23 UTC (rev 14879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLinkElement.java 2017-10-31 10:29:19 UTC (rev 14880) @@ -141,7 +141,7 @@ */ public CSSStyleSheet getSheet() { if (sheet_ == null) { - sheet_ = CSSStyleSheet.loadStylesheet(getWindow(), this, (HtmlLink) getDomNodeOrDie(), null); + sheet_ = CSSStyleSheet.loadStylesheet(this, (HtmlLink) getDomNodeOrDie(), null); } return sheet_; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java 2017-10-27 17:39:23 UTC (rev 14879) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLink2Test.java 2017-10-31 10:29:19 UTC (rev 14880) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import java.net.URL; @@ -136,7 +135,6 @@ */ @Test @Alerts({"onLoad", "body onLoad"}) - @NotYetImplemented(CHROME) public void onLoadMediaPrint() throws Exception { getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); onLoadOnError("rel='stylesheet' href='simple.css' media='print'"); @@ -157,7 +155,6 @@ */ @Test @Alerts({"onLoad", "body onLoad"}) - @NotYetImplemented(CHROME) public void onLoadMediaQueryNotMatch() throws Exception { getMockWebConnection().setResponse(new URL(URL_FIRST, "simple.css"), ""); onLoadOnError("rel='stylesheet' href='simple.css' media='(max-width: 10px)'"); @@ -200,10 +197,42 @@ + " <link " + attribs + " onload='alert(\"onLoad\")' onerror='alert(\"onError\")'>\n" + "</head>\n" - + "<body onload='window.getComputedStyle(document.body); alert(\"body onLoad\")'>\n" + + "<body onload='alert(\"body onLoad\")'>\n" + "</body>\n" + "</html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"onLoad1", "onLoadJs1", "onLoad2", "body onLoad;"}) + public void onLoadOrder() throws Exception { + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple1.css"), ""); + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple2.css"), ""); + getMockWebConnection().setResponse(new URL(URL_FIRST, "simple1.js"), "var x=1;"); + + final String html + = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function log(x) {\n" + + " document.title += x + ';';\n" + + " }\n" + + " </script>\n" + + " <link rel='stylesheet' href='simple1.css' onload='log(\"onLoad1\")'>\n" + + " <script type='text/javascript' src='simple1.js' onload='log(\"onLoadJs1\")'></script>\n" + + " <link rel='stylesheet' href='simple2.css' onload='log(\"onLoad2\")'>\n" + + "</head>\n" + + "<body onload='log(\"body onLoad\")'>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.getTitle(); + assertEquals(String.join(";", getExpectedAlerts()), text); + } } |
From: <rb...@us...> - 2017-11-03 15:04:44
|
Revision: 14899 http://sourceforge.net/p/htmlunit/code/14899 Author: rbri Date: 2017-11-03 15:04:41 +0000 (Fri, 03 Nov 2017) Log Message: ----------- revert some cleanup because the method is (more or less) part of the public api Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-11-01 16:18:28 UTC (rev 14898) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-11-03 15:04:41 UTC (rev 14899) @@ -167,6 +167,20 @@ } /** + * <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE RESOURCE - USE AT YOUR OWN RISK.</span><br> + * If the linked content is not already downloaded it triggers a download. Then it stores the response + * for later use.<br> + * + * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously + * @return {@code null} if no download should be performed and when this wasn't already done; the response + * received when performing a request for the content referenced by this tag otherwise + * @throws IOException if an error occurs while downloading the content + */ + public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { + return getWebResponse(downloadIfNeeded, null); + } + + /** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * If the linked content is not already downloaded it triggers a download. Then it stores the response Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java 2017-11-01 16:18:28 UTC (rev 14898) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java 2017-11-03 15:04:41 UTC (rev 14899) @@ -43,7 +43,7 @@ final HtmlPage page = loadPage(html); final HtmlLink link = page.getFirstByXPath("//link"); - final WebResponse respCss = link.getWebResponse(true, null); + final WebResponse respCss = link.getWebResponse(true); assertEquals(page.getUrl().toExternalForm(), respCss.getWebRequest().getAdditionalHeaders().get("Referer")); } } |
From: <rb...@us...> - 2017-11-03 16:23:11
|
Revision: 14900 http://sourceforge.net/p/htmlunit/code/14900 Author: rbri Date: 2017-11-03 16:23:08 +0000 (Fri, 03 Nov 2017) Log Message: ----------- more Promise fixes Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-11-03 15:04:41 UTC (rev 14899) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-11-03 16:23:08 UTC (rev 14900) @@ -58,7 +58,7 @@ private Promise[] all_; private List<BasicJavaScriptJob> settledJobs_; - private Promise dependentPromise_; + private List<Promise> dependentPromises_; /** * Default constructor. @@ -207,9 +207,11 @@ settledJobs_ = null; } - if (dependentPromise_ != null) { - dependentPromise_.settle(fulfilled, newValue, window); - dependentPromise_ = null; + if (dependentPromises_ != null) { + for (Promise promise : dependentPromises_) { + promise.settle(fulfilled, newValue, window); + } + dependentPromises_ = null; } } @@ -292,7 +294,10 @@ final Object o = array.get(i); if (o instanceof Promise) { returnPromise.all_[i] = (Promise) o; - returnPromise.all_[i].dependentPromise_ = returnPromise; + if (returnPromise.all_[i].dependentPromises_ == null) { + returnPromise.all_[i].dependentPromises_ = new ArrayList<Promise>(2); + } + returnPromise.all_[i].dependentPromises_.add(returnPromise); } else { returnPromise.all_[i] = create(thisObj, new Object[] {o}, PromiseState.FULFILLED); @@ -349,7 +354,10 @@ returnPromise.settle(false, resultPromise.value_, window); } else { - resultPromise.dependentPromise_ = returnPromise; + if (resultPromise.dependentPromises_ == null) { + resultPromise.dependentPromises_ = new ArrayList<Promise>(2); + } + resultPromise.dependentPromises_.add(returnPromise); } } else { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-11-03 15:04:41 UTC (rev 14899) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-11-03 16:23:08 UTC (rev 14900) @@ -160,10 +160,12 @@ + " var p = new Promise();\n" + " log('done');\n" + " } catch(e) { log(e instanceof TypeError); }\n" + + " try{\n" + " var p = new Promise([1, 2, 4]);\n" + " log('done');\n" + " } catch(e) { log(e instanceof TypeError); }\n" + + " try{\n" + " var original = Promise.resolve(42);\n" + " var p = new Promise(original);\n" @@ -901,6 +903,51 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = {"done", "first 3,1337,Success", "second 3,Success"}, + IE = {}) + public void allAsync2() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = Promise.resolve(3);\n" + + " var p2 = 1337;\n" + + " var p3 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.all([p1, p2, p3]).then(function(values) {\n" + + " log('first ' + values);\n" + + " });\n" + + " Promise.all([p1, p3]).then(function(values) {\n" + + " log('second ' + values);\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = {"done", "string", "Failed"}, IE = {}) public void allRejectAsync() throws Exception { @@ -946,6 +993,55 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = {"done", "first Failed", "second Failed"}, + IE = {}) + public void allRejectAsync2() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = Promise.resolve(3);\n" + + " var p2 = 1337;\n" + + " var p3 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " reject('Failed');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.all([p1, p2, p3]).then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + + " log('first ' + value);\n" + + " });\n" + + " Promise.all([p1, p3]).then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + + " log('second ' + value);\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = {"done", "Success 2"}, IE = {}) public void raceAsync() throws Exception { @@ -993,6 +1089,58 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = {"done", "first Success 2", "second Success 2"}, + IE = {}) + public void raceAsync2() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 40);\n" + + " });\n" + + " var p2 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success 2');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.race([p1, p2]).then(function(value) {\n" + + " log('first ' + value);\n" + + " }, function(value) {\n" + + " log('failure');\n" + + " });\n" + + " Promise.race([p1, p2]).then(function(value) {\n" + + " log('second ' + value);\n" + + " }, function(value) {\n" + + " log('failure');\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = {"done", "Failed"}, IE = {}) public void raceRejectAsync() throws Exception { @@ -1035,4 +1183,56 @@ final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); assertEquals(String.join("\n", getExpectedAlerts()), text); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "first Failed", "second Failed"}, + IE = {}) + public void raceRejectAsync2() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p1 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('Success');\n" + + " }, 40);\n" + + " });\n" + + " var p2 = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " reject('Failed');\n" + + " }, 20);\n" + + " });\n" + + "\n" + + " Promise.race([p1, p2]).then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + + " log('first ' + value);\n" + + " });\n" + + " Promise.race([p1, p2]).then(function(value) {\n" + + " log('failure');\n" + + " }, function(value) {\n" + + " log('second ' + value);\n" + + " });\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } } |
From: <rb...@us...> - 2017-11-03 18:00:14
|
Revision: 14902 http://sourceforge.net/p/htmlunit/code/14902 Author: rbri Date: 2017-11-03 18:00:11 +0000 (Fri, 03 Nov 2017) Log Message: ----------- more Promise fixes and test Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-11-03 16:55:04 UTC (rev 14901) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-11-03 18:00:11 UTC (rev 14902) @@ -321,7 +321,7 @@ * @return {@link Promise} */ @JsxFunction - public Promise then(final Function onFulfilled, final Function onRejected) { + public Promise then(final Object onFulfilled, final Object onRejected) { final Window window = getWindow(); final Promise returnPromise = new Promise(window); @@ -334,40 +334,47 @@ Context.enter(); try { Function toExecute = null; - if (thisPromise.state_ == PromiseState.FULFILLED) { - toExecute = onFulfilled; + if (thisPromise.state_ == PromiseState.FULFILLED && onFulfilled instanceof Function) { + toExecute = (Function) onFulfilled; } - else if (thisPromise.state_ == PromiseState.REJECTED) { - toExecute = onRejected; + else if (thisPromise.state_ == PromiseState.REJECTED && onRejected instanceof Function) { + toExecute = (Function) onRejected; } - if (toExecute != null) { - try { - final Object callbackResult = toExecute.call(Context.getCurrentContext(), + try { + final Object callbackResult; + if (toExecute == null) { + final Promise dummy = new Promise(); + dummy.state_ = thisPromise.state_; + dummy.value_ = thisPromise.value_; + callbackResult = dummy; + } + else { + callbackResult = toExecute.call(Context.getCurrentContext(), window, thisPromise, new Object[] {value_}); - if (callbackResult instanceof Promise) { - final Promise resultPromise = (Promise) callbackResult; - if (resultPromise.state_ == PromiseState.FULFILLED) { - returnPromise.settle(true, resultPromise.value_, window); - } - else if (resultPromise.state_ == PromiseState.REJECTED) { - returnPromise.settle(false, resultPromise.value_, window); - } - else { - if (resultPromise.dependentPromises_ == null) { - resultPromise.dependentPromises_ = new ArrayList<Promise>(2); - } - resultPromise.dependentPromises_.add(returnPromise); - } + } + if (callbackResult instanceof Promise) { + final Promise resultPromise = (Promise) callbackResult; + if (resultPromise.state_ == PromiseState.FULFILLED) { + returnPromise.settle(true, resultPromise.value_, window); } + else if (resultPromise.state_ == PromiseState.REJECTED) { + returnPromise.settle(false, resultPromise.value_, window); + } else { - returnPromise.settle(true, callbackResult, window); + if (resultPromise.dependentPromises_ == null) { + resultPromise.dependentPromises_ = new ArrayList<Promise>(2); + } + resultPromise.dependentPromises_.add(returnPromise); } } - catch (final JavaScriptException e) { - returnPromise.settle(false, e.getValue(), window); + else { + returnPromise.settle(true, callbackResult, window); } } + catch (final JavaScriptException e) { + returnPromise.settle(false, e.getValue(), window); + } } finally { Context.exit(); @@ -401,7 +408,7 @@ * @return {@link Promise} */ @JsxFunction(functionName = "catch") - public Promise catch_js(final Function onRejected) { + public Promise catch_js(final Object onRejected) { return then(null, onRejected); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-11-03 16:55:04 UTC (rev 14901) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PromiseTest.java 2017-11-03 18:00:11 UTC (rev 14902) @@ -910,6 +910,140 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = {"done", "Success first"}, + IE = {}) + public void thenTestAsyncChainedResolve() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('first');\n" + + " }, 20);\n" + + " })\n" + + " var p2 = p.then(undefined, function(value) {\n" + + " log(value);\n" + + " })\n" + + " p2.then(function(value) {\n" + + " log('Success ' + value);\n" + + " }," + + " function(value) {\n" + + " log('Failure ' + value);\n" + + " })\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "Failure first"}, + IE = {}) + public void thenTestAsyncChainedReject() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " reject('first');\n" + + " }, 20);\n" + + " })\n" + + " var p2 = p.then(function(value) {\n" + + " log(value);\n" + + " }, undefined)\n" + + " p2.then(function(value) {\n" + + " log('Success ' + value);\n" + + " }," + + " function(value) {\n" + + " log('Failure ' + value);\n" + + " })\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"done", "Success first"}, + IE = {}) + public void thenTestAsyncChainedNotAFunction() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('first');\n" + + " }, 20);\n" + + " })\n" + + " var p2 = p.then(7);\n" + + " var p3 = p2.then('test');\n" + + " p3.then(function(value) {\n" + + " log('Success ' + value);\n" + + " }," + + " function(value) {\n" + + " log('Failure ' + value);\n" + + " })\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = {"Success", "string", "oh, no!", "after catch"}, IE = {}) public void catchTest() throws Exception { @@ -1003,6 +1137,51 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = {"done", "Success first"}, + IE = {}) + public void catchTestAsyncChained() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (window.Promise) {\n" + + " var p = new Promise(function(resolve, reject) {\n" + + " window.setTimeout( function() {\n" + + " resolve('first');\n" + + " }, 20);\n" + + " })\n" + + " var p2 = p.catch(function(value) {\n" + + " log(value);\n" + + " })\n" + + " p2.then(function(value) {\n" + + " log('Success ' + value);\n" + + " }," + + " function(value) {\n" + + " log('Failure ' + value);\n" + + " })\n" + + " log('done');\n" + + " }\n" + + " }\n" + + "\n" + + " function log(x) {\n" + + " document.getElementById('log').value += x + '\\n';\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='log' cols='80' rows='40'></textarea>\n" + + "</body>\n" + + "</html>"; + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = {"done", "Success"}, IE = "") public void thenInsideEventHandler() throws Exception { |
From: <rb...@us...> - 2017-11-11 13:02:01
|
Revision: 14927 http://sourceforge.net/p/htmlunit/code/14927 Author: rbri Date: 2017-11-11 13:01:58 +0000 (Sat, 11 Nov 2017) Log Message: ----------- FF52 and Chrome version update Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-10 19:36:05 UTC (rev 14926) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-11 13:01:58 UTC (rev 14927) @@ -173,13 +173,13 @@ 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, 48, 50, 51, 52, 53, 53, 55, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 84, 85, 86, 87, 88, 89, 90, 91, 93, 94, 95, 96, 96, 98, 99, 100, 101, 103, 104, 105, 106, 106, 108, 109, 111, 112, 113, 115, - 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 131, 132, 133, 135, 136, 138, 139, + 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 183, 131, 132, 133, 135, 136, 138, 139, 139, 141, 142, 143, 144, 146, 147, 148, 149}; // FF52 FIREFOX_52.applicationVersion_ = "5.0 (Windows)"; FIREFOX_52.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0"; - FIREFOX_52.buildId_ = "20170802111520"; + FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection", "Upgrade-Insecure-Requests"}; @@ -190,7 +190,7 @@ 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, 48, 50, 51, 52, 53, 53, 55, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 84, 85, 86, 87, 88, 89, 90, 91, 93, 94, 95, 96, 96, 98, 99, 100, 101, 103, 104, 105, 106, 106, 108, 109, 111, 112, 113, 115, - 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 131, 132, 133, 135, 136, 138, 139, + 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 183, 131, 132, 133, 135, 136, 138, 139, 139, 141, 142, 143, 144, 146, 147, 148, 149}; // IE @@ -209,7 +209,7 @@ 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, 112, 113, 114, - 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, + 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 128, 129, 183, 131, 132, 133, 135, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147}; // EDGE @@ -217,8 +217,8 @@ EDGE.userAgent_ = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"; // CHROME - CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"; - CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"; + CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36"; + CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36"; CHROME.applicationCodeName_ = "Mozilla"; CHROME.vendor_ = "Google Inc."; @@ -237,7 +237,7 @@ 27, 28, 30, 31, 32, 33, 34, 36, 37, 37, 38, 40, 42, 43, 44, 45, 47, 48, 48, 49, 51, 52, 53, 54, 55, 57, 58, 58, 59, 60, 62, 63, 64, 65, 67, 69, 69, 70, 71, 73, 74, 75, 76, 77, 79, 79, 80, 81, 83, 84, 85, 86, 87, 89, 90, 90, 91, 93, 94, 96, 97, 98, 100, 101, 101, 102, 103, 105, 106, 107, 108, 110, 111, 111, 112, - 113, 115, 116, 117, 118, 119, 121, 122, 123, 124, 126, 127, 128, 129, 130, 132, 132, 133, 134, 136, 137, + 113, 115, 116, 117, 118, 119, 121, 122, 123, 124, 126, 127, 128, 129, 183, 132, 132, 133, 134, 136, 137, 138, 139, 140, 142, 142, 143, 144, 145, 147}; // default file upload mime types @@ -358,19 +358,19 @@ CHROME.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 27.0 r0", "27.0.0.130", "NPSWF32_27_0_0_130.dll"); + "Shockwave Flash 27.0 r0", "27.0.0.183", "NPSWF32_27_0_0_183.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_45.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 27.0 r0", "27.0.0.130", "NPSWF64_27_0_0_130.dll"); + "Shockwave Flash 27.0 r0", "27.0.0.183", "NPSWF64_27_0_0_183.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_52.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 27.0 r0", "27.0.0.130", "Flash32_27_0_0_130.ocx"); + "Shockwave Flash 27.0 r0", "27.0.0.183", "Flash32_27_0_0_183.ocx"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); INTERNET_EXPLORER.getPlugins().add(flash); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-11-10 19:36:05 UTC (rev 14926) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-11-11 13:01:58 UTC (rev 14927) @@ -216,10 +216,10 @@ * @throws Exception on test failure */ @Test - @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 27.0 r0", "27.0.0.130", "NPSWF32_27_0_0_130.dll"}, - FF52 = {"Shockwave Flash", "Shockwave Flash 27.0 r0", "27.0.0.130", "NPSWF64_27_0_0_130.dll"}, + @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 27.0 r0", "27.0.0.183", "NPSWF32_27_0_0_183.dll"}, + FF52 = {"Shockwave Flash", "Shockwave Flash 27.0 r0", "27.0.0.183", "NPSWF64_27_0_0_183.dll"}, CHROME = {"Shockwave Flash", "Shockwave Flash 24.0 r0", "undefined", "internal-not-yet-present"}, - IE = {"Shockwave Flash", "Shockwave Flash 27.0 r0", "27.0.0.130", "Flash32_27_0_0_130.ocx"}, + IE = {"Shockwave Flash", "Shockwave Flash 27.0 r0", "27.0.0.183", "Flash32_27_0_0_183.ocx"}, EDGE = {"Shockwave Flash", "Shockwave Flash 18.0 r0", "18.0.0.232", "Flash.ocx"}) public void pluginsShockwaveFlash() throws Exception { final String html = "<html>\n" @@ -382,7 +382,7 @@ @Test @Alerts(DEFAULT = "undefined", FF45 = "20170411115307", - FF52 = "20170802111520") + FF52 = "20170921064520") public void buildID() throws Exception { final String html = "<html><head><title>First</title>\n" |
From: <rb...@us...> - 2017-11-12 18:36:20
|
Revision: 14940 http://sourceforge.net/p/htmlunit/code/14940 Author: rbri Date: 2017-11-12 18:36:17 +0000 (Sun, 12 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2017-11-12 18:35:47 UTC (rev 14939) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2017-11-12 18:36:17 UTC (rev 14940) @@ -52,6 +52,7 @@ import com.gargoylesoftware.htmlunit.util.EncodingSniffer; import com.gargoylesoftware.htmlunit.util.NameValuePair; import com.gargoylesoftware.htmlunit.util.UrlUtils; +import com.google.common.net.HttpHeaders; /** * Wrapper for the HTML element "form". @@ -309,7 +310,7 @@ if (HttpMethod.POST == method && browser.hasFeature(FORM_SUBMISSION_HEADER_ORIGIN)) { referer = StringUtils.stripEnd(referer, "/"); - request.setAdditionalHeader("Origin", referer); + request.setAdditionalHeader(HttpHeaders.ORIGIN, referer); } if (HttpMethod.POST == method && browser.hasFeature(FORM_SUBMISSION_HEADER_CACHE_CONTROL_MAX_AGE)) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java 2017-11-12 18:35:47 UTC (rev 14939) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement2Test.java 2017-11-12 18:36:17 UTC (rev 14940) @@ -39,6 +39,7 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -768,7 +769,7 @@ @Alerts(DEFAULT = {"", ""}, IE = {"undefined", "something"}) public void origin() throws Exception { - attribute("origin", "something"); + attribute(HttpHeader.ORIGIN_LC, "something"); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java 2017-11-12 18:35:47 UTC (rev 14939) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java 2017-11-12 18:36:17 UTC (rev 14940) @@ -35,6 +35,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -230,7 +231,7 @@ } response.setCharacterEncoding(UTF_8.name()); response.setContentType("text/xml"); - String origin = request.getHeader("Origin"); + String origin = request.getHeader(HttpHeader.ORIGIN); if (origin == null) { origin = "No Origin!"; } @@ -461,7 +462,7 @@ if (ACCESS_CONTROL_ALLOW_HEADERS_ != null) { response.setHeader("Access-Control-Allow-Headers", ACCESS_CONTROL_ALLOW_HEADERS_); } - options_origin_ = request.getHeader("Origin"); + options_origin_ = request.getHeader(HttpHeader.ORIGIN); options_method_ = request.getHeader("Access-Control-Request-Method"); options_headers_ = request.getHeader("Access-Control-Request-Headers"); } @@ -478,7 +479,7 @@ response.setContentType("text/xml"); final Writer writer = response.getWriter(); - final String origin = request.getHeader("Origin"); + final String origin = request.getHeader(HttpHeader.ORIGIN); writer.write("<result>" + "<origin>" + origin + "</origin>" + "<options_origin>" + options_origin_ + "</options_origin>" @@ -911,7 +912,7 @@ } response.setCharacterEncoding(UTF_8.name()); response.setContentType("text/xml"); - String origin = request.getHeader("Origin"); + String origin = request.getHeader(HttpHeader.ORIGIN); if (origin == null) { origin = "No Origin!"; } |
From: <rb...@us...> - 2017-11-12 19:07:33
|
Revision: 14942 http://sourceforge.net/p/htmlunit/code/14942 Author: rbri Date: 2017-11-12 19:07:30 +0000 (Sun, 12 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAreaTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrameSetTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageDownloadTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScriptTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.http.HttpStatus; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; @@ -462,7 +463,7 @@ final URL url = page.getFullyQualifiedUrl(src); final String accept = webclient.getBrowserVersion().getImgAcceptHeader(); final WebRequest request = new WebRequest(url, accept); - request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); + request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -29,6 +29,7 @@ import org.apache.commons.lang3.StringUtils; import com.gargoylesoftware.htmlunit.ElementNotFoundException; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; @@ -215,7 +216,7 @@ final URL url = page.getFullyQualifiedUrl(src); final String accept = webclient.getBrowserVersion().getImgAcceptHeader(); final WebRequest request = new WebRequest(url, accept); - request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); + request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.http.HttpStatus; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; @@ -227,7 +228,7 @@ final WebRequest request = new WebRequest(url); - request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); + request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); final String accept = page.getWebClient().getBrowserVersion().getCssAcceptHeader(); request.setAdditionalHeader("Accept", accept); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -66,6 +66,7 @@ import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.History; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.OnbeforeunloadHandler; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ScriptResult; @@ -1015,7 +1016,7 @@ final BrowserVersion browser = client.getBrowserVersion(); final WebRequest request = new WebRequest(url, browser.getScriptAcceptHeader()); request.setAdditionalHeaders(new HashMap<>(referringRequest.getAdditionalHeaders())); - request.setAdditionalHeader("Referer", referringRequest.getUrl().toString()); + request.setAdditionalHeader(HttpHeader.REFERER, referringRequest.getUrl().toString()); request.setAdditionalHeader("Accept", client.getBrowserVersion().getScriptAcceptHeader()); // our cache is a bit strange; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -34,6 +34,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; @@ -231,7 +232,7 @@ } final WebRequest request = new WebRequest(url); - request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); + request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); final WebWindow webWindow = window_.getWebWindow(); webWindow.getWebClient().download(webWindow, "", request, true, false, "JS set location"); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -77,6 +77,7 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Cache; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; @@ -336,7 +337,7 @@ final String accept = client.getBrowserVersion().getCssAcceptHeader(); request = new WebRequest(new URL(url), accept); final String referer = page.getUrl().toExternalForm(); - request.setAdditionalHeader("Referer", referer); + request.setAdditionalHeader(HttpHeader.REFERER, referer); // our cache is a bit strange; // loadWebResponse check the cache for the web response Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -64,6 +64,7 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.ElementNotFoundException; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; @@ -356,7 +357,7 @@ String referrer = ""; final WebResponse webResponse = getPage().getWebResponse(); if (webResponse != null) { - referrer = webResponse.getWebRequest().getAdditionalHeaders().get("Referer"); + referrer = webResponse.getWebRequest().getAdditionalHeaders().get(HttpHeader.REFERER); if (referrer == null) { referrer = ""; } 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 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -134,7 +134,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList("accept-charset", "accept-encoding", "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", - "host", "keep-alive", "referer", "te", "trailer", "transfer-encoding", "upgrade", "user-agent", "via"); + "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", + "upgrade", "user-agent", "via"); private int state_; private Function stateChangeHandler_; @@ -538,7 +539,7 @@ final WebRequest request = new WebRequest(fullUrl, getBrowserVersion().getXmlHttpRequestAcceptHeader()); request.setCharset(UTF_8); - request.setAdditionalHeader("Referer", containingPage_.getUrl().toExternalForm()); + request.setAdditionalHeader(HttpHeader.REFERER, containingPage_.getUrl().toExternalForm()); if (!isSameOrigin(originUrl, fullUrl)) { final StringBuilder origin = new StringBuilder().append(originUrl.getProtocol()).append("://") @@ -881,7 +882,8 @@ return true; } if ("accept".equals(name) || "accept-language".equals(name) || "content-language".equals(name) - || "referer".equals(name) || "accept-encoding".equals(name) || HttpHeader.ORIGIN_LC.equals(name)) { + || HttpHeader.REFERER_LC.equals(name) || "accept-encoding".equals(name) + || HttpHeader.ORIGIN_LC.equals(name)) { return false; } return true; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -91,14 +91,14 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - "Accept", "Referer", "Accept-Encoding", "Accept-Language", + "Accept", HttpHeader.REFERER, "Accept-Encoding", "Accept-Language", "Cookie"}, - FF45 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", + FF45 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}, - FF52 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", + FF52 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}, - IE = {"Accept", "Referer", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", - "Cookie"}) + IE = {"Accept", HttpHeader.REFERER, "Accept-Language", "User-Agent", "Accept-Encoding", "Host", + "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -39,6 +39,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -1180,7 +1181,7 @@ assertEquals(expectedHeaders[1], "" + headers.get("Accept-Encoding")); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); assertEquals(expectedHeaders[3], "" + headers.get("Host")); - assertEquals(expectedHeaders[4], "" + headers.get("Referer")); + assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } } @@ -1216,7 +1217,7 @@ assertEquals(expectedHeaders[1], "" + headers.get("Accept-Encoding")); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); assertEquals(expectedHeaders[3], "" + headers.get("Host")); - assertEquals(expectedHeaders[4], "" + headers.get("Referer")); + assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor2Test.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -27,6 +27,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; @@ -381,7 +382,7 @@ a.click(); final Map<String, String> lastAdditionalHeaders = conn.getLastAdditionalHeaders(); - assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get("Referer")); + assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get(HttpHeader.REFERER)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAreaTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAreaTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAreaTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -28,6 +28,7 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -80,7 +81,7 @@ driver.findElement(By.id("third")).click(); final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders(); - assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get("Referer")); + assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get(HttpHeader.REFERER)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -35,6 +35,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.ElementNotFoundException; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; @@ -1010,7 +1011,7 @@ button.click(); final Map<String, String> lastAdditionalHeaders = webConnection.getLastAdditionalHeaders(); - assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get("Referer")); + assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get(HttpHeader.REFERER)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrameSetTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrameSetTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrameSetTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -25,6 +25,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.WebClient; @@ -239,7 +240,7 @@ assertEquals("First", firstPage.getTitleText()); final Map<String, String> lastAdditionalHeaders = webConnection.getLastAdditionalHeaders(); - assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get("Referer")); + assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get(HttpHeader.REFERER)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageDownloadTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageDownloadTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageDownloadTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -29,6 +29,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebServerTestCase; @@ -117,7 +118,7 @@ assertNull(htmlImage.getWebResponse(false)); final WebResponse resp = htmlImage.getWebResponse(true); assertNotNull(resp); - assertEquals(url.toExternalForm(), resp.getWebRequest().getAdditionalHeaders().get("Referer")); + assertEquals(url.toExternalForm(), resp.getWebRequest().getAdditionalHeaders().get(HttpHeader.REFERER)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlLinkTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -18,6 +18,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.WebResponse; @@ -44,6 +45,7 @@ final HtmlLink link = page.getFirstByXPath("//link"); final WebResponse respCss = link.getWebResponse(true); - assertEquals(page.getUrl().toExternalForm(), respCss.getWebRequest().getAdditionalHeaders().get("Referer")); + assertEquals(page.getUrl().toExternalForm(), + respCss.getWebRequest().getAdditionalHeaders().get(HttpHeader.REFERER)); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScriptTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScriptTest.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScriptTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -29,6 +29,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.WebClient; @@ -152,7 +153,7 @@ client.getPage(URL_FIRST); final Map<String, String> lastAdditionalHeaders = conn.getLastAdditionalHeaders(); - assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get("Referer")); + assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get(HttpHeader.REFERER)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -25,6 +25,7 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; @@ -1116,10 +1117,10 @@ final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders(); if (expectedAlerts.length == 0) { - assertNull(lastAdditionalHeaders.get("Referer")); + assertNull(lastAdditionalHeaders.get(HttpHeader.REFERER)); } else { - assertEquals(expectedAlerts[0], lastAdditionalHeaders.get("Referer")); + assertEquals(expectedAlerts[0], lastAdditionalHeaders.get(HttpHeader.REFERER)); } } 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 2017-11-12 18:46:10 UTC (rev 14941) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-12 19:07:30 UTC (rev 14942) @@ -37,6 +37,7 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.BrowserRunner.Tries; @@ -903,7 +904,7 @@ final WebRequest request = getMockWebConnection().getLastWebRequest(); assertEquals(urlPage2, request.getUrl()); - assertEquals(URL_FIRST.toExternalForm(), request.getAdditionalHeaders().get("Referer")); + assertEquals(URL_FIRST.toExternalForm(), request.getAdditionalHeaders().get(HttpHeader.REFERER)); } /** @@ -1288,7 +1289,7 @@ final String[] headers = {"accept-charset", "accept-encoding", "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", - "expect", "host", "keep-alive", "referer", "te", "trailer", "transfer-encoding", "upgrade", + "expect", "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", "user-agent", "via" }; for (final String header : headers) { assertFalse(XMLHttpRequest.isAuthorizedHeader(header)); |
From: <rb...@us...> - 2017-11-13 17:18:07
|
Revision: 14945 http://sourceforge.net/p/htmlunit/code/14945 Author: rbri Date: 2017-11-13 17:18:04 +0000 (Mon, 13 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -163,7 +163,7 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}; + "Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +182,7 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + "Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,7 +198,7 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - "Accept", HttpHeader.REFERER, "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", + "Accept", HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", "Cookie"}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; @@ -226,7 +226,7 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", HttpHeader.REFERER, "Accept-Encoding", "Accept-Language", "Cookie"}; + "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -34,6 +34,11 @@ /** Cache-Control. */ public static final String CACHE_CONTROL = "Cache-Control"; + /** Accept-Language. */ + public static final String ACCEPT_LANGUAGE = "Accept-Language"; + /** accept-language. */ + public static final String ACCEPT_LANGUAGE_LC = "accept-language"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -788,7 +788,7 @@ else if ("Accept".equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptHeaderHttpRequestInterceptor(requestHeaders.get(header))); } - else if ("Accept-Language".equals(header) && requestHeaders.get(header) != null) { + else if (HttpHeader.ACCEPT_LANGUAGE.equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptLanguageHeaderHttpRequestInterceptor(requestHeaders.get(header))); } else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) { @@ -878,7 +878,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("Accept-Language", value_); + request.setHeader(HttpHeader.ACCEPT_LANGUAGE, value_); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -1459,8 +1459,8 @@ */ private void addDefaultHeaders(final WebRequest wrs) { // Add standard HtmlUnit headers. - if (!wrs.isAdditionalHeader("Accept-Language")) { - wrs.setAdditionalHeader("Accept-Language", getBrowserVersion().getBrowserLanguage()); + if (!wrs.isAdditionalHeader(HttpHeader.ACCEPT_LANGUAGE)) { + wrs.setAdditionalHeader(HttpHeader.ACCEPT_LANGUAGE, getBrowserVersion().getBrowserLanguage()); } if (getBrowserVersion().hasFeature(HTTP_HEADER_UPGRADE_INSECURE_REQUEST) && !wrs.isAdditionalHeader("Upgrade-Insecure-Requests")) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -658,8 +658,11 @@ } return true; } - if ("accept".equals(name) || "accept-language".equals(name) || "content-language".equals(name) - || HttpHeader.REFERER_LC.equals(name) || "accept-encoding".equals(name) + if ("accept".equals(name) + || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) + || "content-language".equals(name) + || HttpHeader.REFERER_LC.equals(name) + || "accept-encoding".equals(name) || HttpHeader.ORIGIN_LC.equals(name)) { return false; } 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 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -881,8 +881,11 @@ } return true; } - if ("accept".equals(name) || "accept-language".equals(name) || "content-language".equals(name) - || HttpHeader.REFERER_LC.equals(name) || "accept-encoding".equals(name) + if ("accept".equals(name) + || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) + || "content-language".equals(name) + || HttpHeader.REFERER_LC.equals(name) + || "accept-encoding".equals(name) || HttpHeader.ORIGIN_LC.equals(name)) { return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -204,7 +204,7 @@ private static String headersToString(final WebRequest request) { // why doesn't HtmlUnit send these headers whereas Firefox does? final List<String> ignoredHeaders = Arrays.asList("accept", "accept-charset", "accept-encoding", - "accept-language", "keep-alive"); + HttpHeader.ACCEPT_LANGUAGE_LC, "keep-alive"); final List<String> caseInsensitiveHeaders = Arrays.asList("connection"); // ensure ordering for comparison Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -48,11 +48,11 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - "Accept", "Accept-Encoding", "Accept-Language"}, - FF45 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Connection"}, - FF52 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", + "Accept", "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE}, + FF45 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", "Connection"}, + FF52 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", "Connection", "Upgrade-Insecure-Requests"}, - IE = {"Accept", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection"}) + IE = {"Accept", HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection"}) @NotYetImplemented(IE) public void headers() throws Exception { final String response = "HTTP/1.1 200 OK\r\n" @@ -91,13 +91,13 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - "Accept", HttpHeader.REFERER, "Accept-Encoding", "Accept-Language", + "Accept", HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, "Cookie"}, - FF45 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", HttpHeader.REFERER, "Cookie", - "Connection"}, - FF52 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", HttpHeader.REFERER, "Cookie", - "Connection", "Upgrade-Insecure-Requests"}, - IE = {"Accept", HttpHeader.REFERER, "Accept-Language", "User-Agent", "Accept-Encoding", "Host", + FF45 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + HttpHeader.REFERER, "Cookie", "Connection"}, + FF52 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}, + IE = {"Accept", HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -247,7 +247,8 @@ loadPageWithAlerts(html); // browsers are using different casing, but this is not relevant for this test assertEquals("en-us", - getMockWebConnection().getLastAdditionalHeaders().get("Accept-Language").toLowerCase(Locale.ROOT)); + getMockWebConnection().getLastAdditionalHeaders() + .get(HttpHeader.ACCEPT_LANGUAGE).toLowerCase(Locale.ROOT)); } /** @@ -267,7 +268,8 @@ loadPageWithAlerts(html); // browsers are using different casing, but this is not relevant for this test assertEquals("fr", - getMockWebConnection().getLastAdditionalHeaders().get("Accept-Language").toLowerCase(Locale.ROOT)); + getMockWebConnection().getLastAdditionalHeaders() + .get(HttpHeader.ACCEPT_LANGUAGE).toLowerCase(Locale.ROOT)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2017-11-13 17:11:16 UTC (rev 14944) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2017-11-13 17:18:04 UTC (rev 14945) @@ -42,6 +42,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; @@ -150,7 +151,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); assertEquals("text/javascript, application/javascript, */*", headers.get("Accept")); - assertEquals("ar-eg", headers.get("Accept-Language")); + assertEquals("ar-eg", headers.get(HttpHeader.ACCEPT_LANGUAGE)); } /** |
From: <rb...@us...> - 2017-11-13 17:24:51
|
Revision: 14946 http://sourceforge.net/p/htmlunit/code/14946 Author: rbri Date: 2017-11-13 17:24:48 +0000 (Mon, 13 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -163,7 +163,7 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}; + "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +182,7 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,7 +198,7 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - "Accept", HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", + HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", "Cookie"}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; @@ -226,7 +226,7 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; + "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", HttpHeader.ACCEPT, HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -34,6 +34,11 @@ /** Cache-Control. */ public static final String CACHE_CONTROL = "Cache-Control"; + /** Accept. */ + public static final String ACCEPT = "Accept"; + /** accept. */ + public static final String ACCEPT_LC = "accept"; + /** Accept-Language. */ public static final String ACCEPT_LANGUAGE = "Accept-Language"; /** accept-language. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -785,7 +785,7 @@ else if ("User-Agent".equals(header)) { list.add(new UserAgentHeaderHttpRequestInterceptor(userAgent)); } - else if ("Accept".equals(header) && requestHeaders.get(header) != null) { + else if (HttpHeader.ACCEPT.equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptHeaderHttpRequestInterceptor(requestHeaders.get(header))); } else if (HttpHeader.ACCEPT_LANGUAGE.equals(header) && requestHeaders.get(header) != null) { @@ -865,7 +865,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("Accept", value_); + request.setHeader(HttpHeader.ACCEPT, value_); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -75,7 +75,7 @@ */ public WebRequest(final URL url, final String acceptHeader) { setUrl(url); - setAdditionalHeader("Accept", acceptHeader); + setAdditionalHeader(HttpHeader.ACCEPT, acceptHeader); setAdditionalHeader("Accept-Encoding", "gzip, deflate"); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -658,7 +658,7 @@ } return true; } - if ("accept".equals(name) + if (HttpHeader.ACCEPT_LC.equals(name) || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) || "content-language".equals(name) || HttpHeader.REFERER_LC.equals(name) Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -296,7 +296,7 @@ } final WebRequest request = new WebRequest(url, method); - request.setAdditionalHeader("Accept", browser.getHtmlAcceptHeader()); + request.setAdditionalHeader(HttpHeader.ACCEPT, browser.getHtmlAcceptHeader()); request.setAdditionalHeader("Accept-Encoding", "gzip, deflate"); request.setRequestParameters(parameters); if (HttpMethod.POST == method) { @@ -846,7 +846,7 @@ * @return the value of the attribute {@code accept} or an empty string if that attribute isn't defined */ public final String getAcceptAttribute() { - return getAttribute("accept"); + return getAttribute(HttpHeader.ACCEPT_LC); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.Map; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.SgmlPage; @@ -346,7 +347,7 @@ * or an empty string if that attribute isn't defined. */ public final String getAcceptAttribute() { - return getAttribute("accept"); + return getAttribute(HttpHeader.ACCEPT_LC); } /** @@ -671,7 +672,7 @@ * @return the value of the {@code accept} attribute */ public String getAccept() { - return getAttribute("accept"); + return getAttribute(HttpHeader.ACCEPT_LC); } /** @@ -680,7 +681,7 @@ * @param accept the {@code accept} attribute */ public void setAccept(final String accept) { - setAttribute("accept", accept); + setAttribute(HttpHeader.ACCEPT_LC, accept); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -231,7 +231,7 @@ request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); final String accept = page.getWebClient().getBrowserVersion().getCssAcceptHeader(); - request.setAdditionalHeader("Accept", accept); + request.setAdditionalHeader(HttpHeader.ACCEPT, accept); return request; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -1017,7 +1017,7 @@ final WebRequest request = new WebRequest(url, browser.getScriptAcceptHeader()); request.setAdditionalHeaders(new HashMap<>(referringRequest.getAdditionalHeaders())); request.setAdditionalHeader(HttpHeader.REFERER, referringRequest.getUrl().toString()); - request.setAdditionalHeader("Accept", client.getBrowserVersion().getScriptAcceptHeader()); + request.setAdditionalHeader(HttpHeader.ACCEPT, client.getBrowserVersion().getScriptAcceptHeader()); // our cache is a bit strange; // loadWebResponse check the cache for the web response 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 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -881,7 +881,7 @@ } return true; } - if ("accept".equals(name) + if (HttpHeader.ACCEPT_LC.equals(name) || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) || "content-language".equals(name) || HttpHeader.REFERER_LC.equals(name) Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -396,7 +396,7 @@ for (final Entry<String, String> headerEntry : headers.entrySet()) { final String headerName = headerEntry.getKey(); final String headerNameLower = headerName.toLowerCase(Locale.ROOT); - if ("accept".equals(headerNameLower)) { + if (HttpHeader.ACCEPT_LC.equals(headerNameLower)) { sb.append(headerName); sb.append(": "); sb.append(headerEntry.getValue()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -203,7 +203,7 @@ private static String headersToString(final WebRequest request) { // why doesn't HtmlUnit send these headers whereas Firefox does? - final List<String> ignoredHeaders = Arrays.asList("accept", "accept-charset", "accept-encoding", + final List<String> ignoredHeaders = Arrays.asList(HttpHeader.ACCEPT_LC, "accept-charset", "accept-encoding", HttpHeader.ACCEPT_LANGUAGE_LC, "keep-alive"); final List<String> caseInsensitiveHeaders = Arrays.asList("connection"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -48,11 +48,13 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - "Accept", "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE}, - FF45 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", "Connection"}, - FF52 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + HttpHeader.ACCEPT, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE}, + FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + "Accept-Encoding", "Connection"}, + FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", "Connection", "Upgrade-Insecure-Requests"}, - IE = {"Accept", HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection"}) + IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", + "Accept-Encoding", "Host", "DNT", "Connection"}) @NotYetImplemented(IE) public void headers() throws Exception { final String response = "HTTP/1.1 200 OK\r\n" @@ -91,14 +93,14 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - "Accept", HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT, HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, "Cookie"}, - FF45 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}, - FF52 = {"Host", "User-Agent", "Accept", HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}, - IE = {"Accept", HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", - "DNT", "Connection", "Cookie"}) + IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", + "Accept-Encoding", "Host", "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -1177,7 +1177,7 @@ if (getExpectedAlerts().length > 1) { final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); - assertEquals(expectedHeaders[0], "" + headers.get("Accept")); + assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get("Accept-Encoding")); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); assertEquals(expectedHeaders[3], "" + headers.get("Host")); @@ -1213,7 +1213,7 @@ if (getExpectedAlerts().length > 1) { final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); - assertEquals(expectedHeaders[0], "" + headers.get("Accept")); + assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get("Accept-Encoding")); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); assertEquals(expectedHeaders[3], "" + headers.get("Host")); @@ -1286,7 +1286,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); assertEquals(expectedHeaders[0], String.valueOf(headers.get("foo"))); - assertEquals(expectedHeaders[1], String.valueOf(headers.get("Accept"))); + assertEquals(expectedHeaders[1], String.valueOf(headers.get(HttpHeader.ACCEPT))); assertEquals(expectedHeaders[2], String.valueOf(headers.get("ValueEmpty"))); assertEquals(expectedHeaders[3], String.valueOf(headers.get("ValueBlank"))); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -44,6 +44,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.FormEncodingType; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -377,7 +378,7 @@ final Writer writer = response.getWriter(); final String html = "<html><head><script>\n" + "function test() {\n" - + " alert('" + request.getHeader("Accept") + "');\n" + + " alert('" + request.getHeader(HttpHeader.ACCEPT) + "');\n" + "}\n" + "</script></head><body onload='test()'></body></html>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2017-11-13 17:18:04 UTC (rev 14945) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2017-11-13 17:24:48 UTC (rev 14946) @@ -150,7 +150,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); - assertEquals("text/javascript, application/javascript, */*", headers.get("Accept")); + assertEquals("text/javascript, application/javascript, */*", headers.get(HttpHeader.ACCEPT)); assertEquals("ar-eg", headers.get(HttpHeader.ACCEPT_LANGUAGE)); } |
From: <rb...@us...> - 2017-11-13 17:30:05
|
Revision: 14947 http://sourceforge.net/p/htmlunit/code/14947 Author: rbri Date: 2017-11-13 17:30:02 +0000 (Mon, 13 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -163,7 +163,7 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection"}; + "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +182,7 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,7 +198,7 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", + HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection", "Cookie"}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; @@ -226,7 +226,7 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", HttpHeader.ACCEPT, HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; + "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -44,6 +44,11 @@ /** accept-language. */ public static final String ACCEPT_LANGUAGE_LC = "accept-language"; + /** Accept-Encoding. */ + public static final String ACCEPT_ENCODING = "Accept-Encoding"; + /** accept-encoding. */ + public static final String ACCEPT_ENCODING_LC = "accept-encoding"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -791,7 +791,7 @@ else if (HttpHeader.ACCEPT_LANGUAGE.equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptLanguageHeaderHttpRequestInterceptor(requestHeaders.get(header))); } - else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) { + else if (HttpHeader.ACCEPT_ENCODING.equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptEncodingHeaderHttpRequestInterceptor(requestHeaders.get(header))); } else if ("Upgrade-Insecure-Requests".equals(header) && requestHeaders.get(header) != null) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -76,7 +76,7 @@ public WebRequest(final URL url, final String acceptHeader) { setUrl(url); setAdditionalHeader(HttpHeader.ACCEPT, acceptHeader); - setAdditionalHeader("Accept-Encoding", "gzip, deflate"); + setAdditionalHeader(HttpHeader.ACCEPT_ENCODING, "gzip, deflate"); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -107,7 +107,8 @@ "status", "statusText", "abort", "getAllResponseHeaders", "getResponseHeader", "open", "send", "setRequestHeader"}; - private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList("accept-charset", "accept-encoding", + private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( + "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", "user-agent", "via"); @@ -662,7 +663,7 @@ || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) || "content-language".equals(name) || HttpHeader.REFERER_LC.equals(name) - || "accept-encoding".equals(name) + || HttpHeader.ACCEPT_ENCODING_LC.equals(name) || HttpHeader.ORIGIN_LC.equals(name)) { return false; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -297,7 +297,7 @@ final WebRequest request = new WebRequest(url, method); request.setAdditionalHeader(HttpHeader.ACCEPT, browser.getHtmlAcceptHeader()); - request.setAdditionalHeader("Accept-Encoding", "gzip, deflate"); + request.setAdditionalHeader(HttpHeader.ACCEPT_ENCODING, "gzip, deflate"); request.setRequestParameters(parameters); if (HttpMethod.POST == method) { request.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute())); 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 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -132,7 +132,8 @@ "status", "statusText", "abort", "getAllResponseHeaders", "getResponseHeader", "open", "send", "setRequestHeader"}; - private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList("accept-charset", "accept-encoding", + private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( + "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", "user-agent", "via"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -203,7 +203,8 @@ private static String headersToString(final WebRequest request) { // why doesn't HtmlUnit send these headers whereas Firefox does? - final List<String> ignoredHeaders = Arrays.asList(HttpHeader.ACCEPT_LC, "accept-charset", "accept-encoding", + final List<String> ignoredHeaders = Arrays.asList( + HttpHeader.ACCEPT_LC, "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, HttpHeader.ACCEPT_LANGUAGE_LC, "keep-alive"); final List<String> caseInsensitiveHeaders = Arrays.asList("connection"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -48,13 +48,13 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - HttpHeader.ACCEPT, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE}, + HttpHeader.ACCEPT, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE}, FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - "Accept-Encoding", "Connection"}, - FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + HttpHeader.ACCEPT_ENCODING, "Connection"}, + FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, "Connection", "Upgrade-Insecure-Requests"}, IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", - "Accept-Encoding", "Host", "DNT", "Connection"}) + HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection"}) @NotYetImplemented(IE) public void headers() throws Exception { final String response = "HTTP/1.1 200 OK\r\n" @@ -93,14 +93,14 @@ */ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", - HttpHeader.ACCEPT, HttpHeader.REFERER, "Accept-Encoding", HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}, - FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}, - FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "Accept-Encoding", + FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}, IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", - "Accept-Encoding", "Host", "DNT", "Connection", "Cookie"}) + HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -201,7 +201,7 @@ public void accept_encoding() throws Exception { final URL url = new URL("http://localhost/"); final WebRequest request = new WebRequest(url); - assertEquals("gzip, deflate", request.getAdditionalHeaders().get("Accept-Encoding")); + assertEquals("gzip, deflate", request.getAdditionalHeaders().get(HttpHeader.ACCEPT_ENCODING)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -151,7 +151,7 @@ startWebServer("src/test/resources/pjl-comp-filter", null); final WebRequest request = new WebRequest(new URL("http://localhost:" + PORT + "/index.html")); - request.setAdditionalHeader("Accept-Encoding", "deflate"); + request.setAdditionalHeader(HttpHeader.ACCEPT_ENCODING, "deflate"); final WebClient webClient = getWebClient(); final HtmlPage page = webClient.getPage(request); assertEquals("Hello Compressed World!", page.asText()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -1178,7 +1178,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); - assertEquals(expectedHeaders[1], "" + headers.get("Accept-Encoding")); + assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); assertEquals(expectedHeaders[3], "" + headers.get("Host")); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); @@ -1214,7 +1214,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); - assertEquals(expectedHeaders[1], "" + headers.get("Accept-Encoding")); + assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); assertEquals(expectedHeaders[3], "" + headers.get("Host")); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -905,7 +905,7 @@ final Writer writer = response.getWriter(); final String html = "<html><head><script>\n" + "function test() {\n" - + " alert('" + request.getHeader("Accept-Encoding") + "');\n" + + " alert('" + request.getHeader(HttpHeader.ACCEPT_ENCODING) + "');\n" + "}\n" + "</script></head><body onload='test()'></body></html>"; 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 2017-11-13 17:24:48 UTC (rev 14946) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-13 17:30:02 UTC (rev 14947) @@ -1287,7 +1287,7 @@ assertTrue(XMLHttpRequest.isAuthorizedHeader("Foo")); assertTrue(XMLHttpRequest.isAuthorizedHeader("Content-Type")); - final String[] headers = {"accept-charset", "accept-encoding", + final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", "user-agent", "via" }; |
From: <rb...@us...> - 2017-11-14 17:41:17
|
Revision: 14948 http://sourceforge.net/p/htmlunit/code/14948 Author: rbri Date: 2017-11-14 17:41:14 +0000 (Tue, 14 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -163,7 +163,7 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}; + HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +182,7 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - "Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,7 +198,7 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection", + HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection", "Cookie"}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; @@ -226,7 +226,7 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; + HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -49,6 +49,16 @@ /** accept-encoding. */ public static final String ACCEPT_ENCODING_LC = "accept-encoding"; + /** User-Agent. */ + public static final String USER_AGENT = "User-Agent"; + /** user-agent. */ + public static final String USER_AGENT_LC = "user-agent"; + + /** Host. */ + public static final String HOST = "Host"; + /** host. */ + public static final String HOST_LC = "host"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -779,10 +779,10 @@ final String[] headerNames = webClient_.getBrowserVersion().getHeaderNamesOrdered(); if (headerNames != null) { for (final String header : headerNames) { - if ("Host".equals(header)) { + if (HttpHeader.HOST.equals(header)) { list.add(new HostHeaderHttpRequestInterceptor(host.toString())); } - else if ("User-Agent".equals(header)) { + else if (HttpHeader.USER_AGENT.equals(header)) { list.add(new UserAgentHeaderHttpRequestInterceptor(userAgent)); } else if (HttpHeader.ACCEPT.equals(header) && requestHeaders.get(header) != null) { @@ -839,7 +839,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("Host", value_); + request.setHeader(HttpHeader.HOST, value_); } } @@ -852,7 +852,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("User-Agent", value_); + request.setHeader(HttpHeader.USER_AGENT, value_); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -95,7 +95,7 @@ // connection.setUseCaches(false); connection.setConnectTimeout(webClient_.getOptions().getTimeout()); - connection.addRequestProperty("User-Agent", webClient_.getBrowserVersion().getUserAgent()); + connection.addRequestProperty(HttpHeader.USER_AGENT, webClient_.getBrowserVersion().getUserAgent()); connection.setInstanceFollowRedirects(false); // copy the headers from WebRequestSettings Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -110,8 +110,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", - "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", - "user-agent", "via"); + HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", + HttpHeader.USER_AGENT_LC, "via"); private int state_ = STATE_UNSENT; private Function stateChangeHandler_; 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 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -135,8 +135,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", - "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", - "upgrade", "user-agent", "via"); + HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", + "upgrade", HttpHeader.USER_AGENT_LC, "via"); private int state_; private Function stateChangeHandler_; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/DefaultCredentialsProviderTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -44,17 +44,19 @@ provider.addCredentials("username", "password"); UsernamePasswordCredentials credentials = - (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("username", credentials.getUserName()); assertEquals("password", credentials.getPassword()); provider.addCredentials("username", "new password"); - credentials = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + credentials = (UsernamePasswordCredentials) provider + .getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("username", credentials.getUserName()); assertEquals("new password", credentials.getPassword()); provider.addCredentials("new username", "other password"); - credentials = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + credentials = (UsernamePasswordCredentials) provider + .getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("new username", credentials.getUserName()); assertEquals("other password", credentials.getPassword()); } @@ -82,16 +84,17 @@ final String scheme = new BasicScheme().getSchemeName(); final DefaultCredentialsProvider provider = new DefaultCredentialsProvider(); - provider.addCredentials("username", "password", "host", 80, realm); + provider.addCredentials("username", "password", HttpHeader.HOST_LC, 80, realm); UsernamePasswordCredentials credentials = - (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertEquals("username", credentials.getUserName()); assertEquals("password", credentials.getPassword()); - provider.removeCredentials(new AuthScope("host", 80, realm, scheme)); + provider.removeCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); - credentials = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope("host", 80, realm, scheme)); + credentials = (UsernamePasswordCredentials) provider + .getCredentials(new AuthScope(HttpHeader.HOST_LC, 80, realm, scheme)); assertNull(credentials); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -223,7 +223,7 @@ if (caseInsensitiveHeaders.contains(headerNameLower)) { sb.append(headerEntry.getValue().toLowerCase(Locale.ROOT)); } - else if ("user-agent".equals(headerNameLower)) { + else if (HttpHeader.USER_AGENT_LC.equals(headerNameLower)) { // ignore the 64bit difference sb.append(headerEntry.getValue().replace("WOW64; ", "")); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -47,14 +47,14 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", + @Alerts(CHROME = {HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE}, - FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, "Connection"}, - FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, - "Connection", "Upgrade-Insecure-Requests"}, - IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", - HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection"}) + FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, "Connection", "Upgrade-Insecure-Requests"}, + IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, + HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection"}) @NotYetImplemented(IE) public void headers() throws Exception { final String response = "HTTP/1.1 200 OK\r\n" @@ -92,15 +92,16 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", + @Alerts(CHROME = {HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}, - FF45 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, - HttpHeader.REFERER, "Cookie", "Connection"}, - FF52 = {"Host", "User-Agent", HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, - HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}, - IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, "User-Agent", - HttpHeader.ACCEPT_ENCODING, "Host", "DNT", "Connection", "Cookie"}) + FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}, + FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", + "Upgrade-Insecure-Requests"}, + IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, + HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -351,7 +351,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "Host", + @Alerts(DEFAULT = HttpHeader.HOST, IE = {}) public void hostHeaderFirst() throws Exception { final Logger logger = Logger.getLogger("org.apache.http.headers"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -1180,7 +1180,7 @@ assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); - assertEquals(expectedHeaders[3], "" + headers.get("Host")); + assertEquals(expectedHeaders[3], "" + headers.get(HttpHeader.HOST)); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } } @@ -1216,7 +1216,7 @@ assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); - assertEquals(expectedHeaders[3], "" + headers.get("Host")); + assertEquals(expectedHeaders[3], "" + headers.get(HttpHeader.HOST)); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } } 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 2017-11-13 17:30:02 UTC (rev 14947) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-14 17:41:14 UTC (rev 14948) @@ -1289,8 +1289,9 @@ final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC, "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", - "expect", "host", "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", - "user-agent", "via" }; + "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, + "te", "trailer", "transfer-encoding", "upgrade", + HttpHeader.USER_AGENT_LC, "via" }; for (final String header : headers) { assertFalse(XMLHttpRequest.isAuthorizedHeader(header)); assertFalse(XMLHttpRequest.isAuthorizedHeader(header.toUpperCase(Locale.ROOT))); |
From: <rb...@us...> - 2017-11-14 20:15:15
|
Revision: 14952 http://sourceforge.net/p/htmlunit/code/14952 Author: rbri Date: 2017-11-14 20:15:12 +0000 (Tue, 14 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitDomainHandler.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager4Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient5Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -163,7 +163,7 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}; + HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +182,7 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,8 +198,8 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection", - "Cookie"}; + HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, HttpHeader.DNT, HttpHeader.CONNECTION, + HttpHeader.COOKIE}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; INTERNET_EXPLORER.cssAcceptHeader_ = "text/css, */*"; @@ -226,7 +226,7 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}; + HttpHeader.HOST, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.COOKIE}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -59,6 +59,19 @@ /** host. */ public static final String HOST_LC = "host"; + /** Cookie. */ + public static final String COOKIE = "Cookie"; + /** cookie. */ + public static final String COOKIE_LC = "cookie"; + + /** Connection. */ + public static final String CONNECTION = "Connection"; + /** connection. */ + public static final String CONNECTION_LC = "connection"; + + /** DNT. */ + public static final String DNT = "DNT"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -800,13 +800,13 @@ else if (HttpHeader.REFERER.equals(header) && requestHeaders.get(header) != null) { list.add(new RefererHeaderHttpRequestInterceptor(requestHeaders.get(header))); } - else if ("Connection".equals(header)) { + else if (HttpHeader.CONNECTION.equals(header)) { list.add(new RequestClientConnControl()); } - else if ("Cookie".equals(header)) { + else if (HttpHeader.COOKIE.equals(header)) { list.add(new RequestAddCookies()); } - else if ("DNT".equals(header) && webClient_.getOptions().isDoNotTrackEnabled()) { + else if (HttpHeader.DNT.equals(header) && webClient_.getOptions().isDoNotTrackEnabled()) { list.add(new DntHeaderHttpRequestInterceptor("1")); } } @@ -930,7 +930,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("DNT", value_); + request.setHeader(HttpHeader.DNT, value_); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -178,7 +178,7 @@ } cookieNb++; } - connection.setRequestProperty("Cookie", cookieHeader.toString()); + connection.setRequestProperty(HttpHeader.COOKIE, cookieHeader.toString()); } private void saveCookies(final String domain, final List<NameValuePair> headers) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -593,7 +593,7 @@ * @see #removeRequestHeader(String) */ public void addRequestHeader(final String name, final String value) { - if ("cookie".equalsIgnoreCase(name)) { + if (HttpHeader.COOKIE_LC.equalsIgnoreCase(name)) { throw new IllegalArgumentException("Do not add 'Cookie' header, use .getCookieManager() instead"); } requestHeaders_.put(name, value); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -109,7 +109,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, - "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", + HttpHeader.CONNECTION_LC, "content-length", HttpHeader.COOKIE_LC, "cookie2", + "content-transfer-encoding", "date", "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", HttpHeader.USER_AGENT_LC, "via"); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitDomainHandler.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitDomainHandler.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitDomainHandler.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -29,6 +29,7 @@ import org.apache.http.util.TextUtils; import com.gargoylesoftware.htmlunit.BrowserVersion; +import com.gargoylesoftware.htmlunit.HttpHeader; /** * Customized BasicDomainHandler for HtmlUnit. @@ -46,7 +47,7 @@ @Override public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { - Args.notNull(cookie, "Cookie"); + Args.notNull(cookie, HttpHeader.COOKIE); if (TextUtils.isBlank(value)) { throw new MalformedCookieException("Blank or null value for domain attribute"); } 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 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -134,7 +134,8 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, - "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", + HttpHeader.CONNECTION_LC, "content-length", HttpHeader.COOKIE_LC, "cookie2", + "content-transfer-encoding", "date", "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", HttpHeader.USER_AGENT_LC, "via"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager4Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager4Test.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManager4Test.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -452,11 +452,11 @@ loadPageWithAlerts2(new URL(URL_HOST1)); WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); - assertNull(lastRequest.getAdditionalHeaders().get("Cookie")); + assertNull(lastRequest.getAdditionalHeaders().get(HttpHeader.COOKIE)); webDriver.findElement(By.linkText("next page")).click(); lastRequest = getMockWebConnection().getLastWebRequest(); - assertEquals("c1=1; c2=2", lastRequest.getAdditionalHeaders().get("Cookie")); + assertEquals("c1=1; c2=2", lastRequest.getAdditionalHeaders().get(HttpHeader.COOKIE)); } /** @@ -486,7 +486,7 @@ loadPageWithAlerts2(new URL(URL_HOST1)); assertEquals(2, getMockWebConnection().getRequestCount() - startCount); final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); - assertEquals("c1=1; c2=2", lastRequest.getAdditionalHeaders().get("Cookie")); + assertEquals("c1=1; c2=2", lastRequest.getAdditionalHeaders().get(HttpHeader.COOKIE)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -116,7 +116,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); assertEquals("exampleCookie=currentPath; exampleCookie=rootPath", - lastRequest.getAdditionalHeaders().get("Cookie")); + lastRequest.getAdditionalHeaders().get(HttpHeader.COOKIE)); } /** @@ -166,7 +166,7 @@ driver.get(URL_SECOND.toExternalForm()); // strange check, but there is no order - final String lastCookies = getMockWebConnection().getLastAdditionalHeaders().get("Cookie"); + final String lastCookies = getMockWebConnection().getLastAdditionalHeaders().get(HttpHeader.COOKIE); assertEquals(26, lastCookies.length()); assertTrue("lastCookies: " + lastCookies, lastCookies.contains("key=value") && lastCookies.contains("test=\"aa= xx==\"") @@ -222,7 +222,7 @@ final WebDriver driver = loadPageWithAlerts2(URL_FIRST); driver.get(URL_SECOND.toExternalForm()); - final String lastCookie = getMockWebConnection().getLastAdditionalHeaders().get("Cookie"); + final String lastCookie = getMockWebConnection().getLastAdditionalHeaders().get(HttpHeader.COOKIE); assertEquals(cookie, lastCookie); } @@ -567,7 +567,7 @@ final Map<String, String> lastHeaders = getMockWebConnection().getLastAdditionalHeaders(); // strange check, but there is no order - final String lastCookies = lastHeaders.get("Cookie"); + final String lastCookies = lastHeaders.get(HttpHeader.COOKIE); assertEquals(17, lastCookies.length()); assertTrue("lastCookies: " + lastCookies, lastCookies.contains("first=1") && lastCookies.contains("second=2") Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -206,7 +206,7 @@ final List<String> ignoredHeaders = Arrays.asList( HttpHeader.ACCEPT_LC, "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, HttpHeader.ACCEPT_LANGUAGE_LC, "keep-alive"); - final List<String> caseInsensitiveHeaders = Arrays.asList("connection"); + final List<String> caseInsensitiveHeaders = Arrays.asList(HttpHeader.CONNECTION_LC); // ensure ordering for comparison final Map<String, String> headers = new TreeMap<>(request.getAdditionalHeaders()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -47,14 +47,14 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, + @Alerts(CHROME = {HttpHeader.HOST, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE}, FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - HttpHeader.ACCEPT_ENCODING, "Connection"}, + HttpHeader.ACCEPT_ENCODING, HttpHeader.CONNECTION}, FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - HttpHeader.ACCEPT_ENCODING, "Connection", "Upgrade-Insecure-Requests"}, + HttpHeader.ACCEPT_ENCODING, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests"}, IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, - HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection"}) + HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, HttpHeader.DNT, HttpHeader.CONNECTION}) @NotYetImplemented(IE) public void headers() throws Exception { final String response = "HTTP/1.1 200 OK\r\n" @@ -92,16 +92,17 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {HttpHeader.HOST, "Connection", "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, + @Alerts(CHROME = {HttpHeader.HOST, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, "Cookie"}, FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection"}, + HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION}, FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, "Cookie", "Connection", + HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests"}, IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, - HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, "DNT", "Connection", "Cookie"}) + HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, HttpHeader.DNT, HttpHeader.CONNECTION, + HttpHeader.COOKIE}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -193,7 +193,7 @@ } private static String headersToString(final WebRequest request) { - final Set<String> caseInsensitiveHeaders = new HashSet<>(Arrays.asList("Connection")); + final Set<String> caseInsensitiveHeaders = new HashSet<>(Arrays.asList(HttpHeader.CONNECTION)); final StringBuilder sb = new StringBuilder(); // ensure ordering for comparison Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient5Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient5Test.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient5Test.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -45,7 +45,7 @@ @Test public void addRequestHeader_Cookie() throws Exception { try (WebClient wc = new WebClient()) { - wc.addRequestHeader("Cookie", "some_value"); + wc.addRequestHeader(HttpHeader.COOKIE, "some_value"); fail("Should have thrown an exception "); } catch (final IllegalArgumentException e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.AlertsStandards; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; @@ -1079,7 +1080,7 @@ @Test @Alerts("exception") public void connection() throws Exception { - test("Connection"); + test(HttpHeader.CONNECTION); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -47,6 +47,7 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebClient; @@ -335,7 +336,8 @@ @Override public void onWebSocketText(final String data) { try { - final String cookie = session_.getUpgradeRequest().getHeaders().get("Cookie").get(0) + counter_++; + final String cookie = session_.getUpgradeRequest().getHeaders() + .get(HttpHeader.COOKIE).get(0) + counter_++; for (final CookiesWebSocket webSocket : webSockets_) { webSocket.session_.getRemote().sendString(cookie); } 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 2017-11-14 19:46:16 UTC (rev 14951) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-14 20:15:12 UTC (rev 14952) @@ -1288,7 +1288,8 @@ assertTrue(XMLHttpRequest.isAuthorizedHeader("Content-Type")); final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC, - "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", + HttpHeader.CONNECTION_LC, "content-length", HttpHeader.COOKIE_LC, "cookie2", + "content-transfer-encoding", "date", "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", HttpHeader.USER_AGENT_LC, "via" }; |
From: <rb...@us...> - 2017-11-14 20:20:02
|
Revision: 14953 http://sourceforge.net/p/htmlunit/code/14953 Author: rbri Date: 2017-11-14 20:19:59 +0000 (Tue, 14 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -163,7 +163,14 @@ FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.productSub_ = "20100101"; FIREFOX_45.headerNamesOrdered_ = new String[] { - HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION}; + HttpHeader.HOST, + HttpHeader.USER_AGENT, + HttpHeader.ACCEPT, + HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, + HttpHeader.REFERER, + HttpHeader.COOKIE, + HttpHeader.CONNECTION}; FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; @@ -182,7 +189,15 @@ FIREFOX_52.buildId_ = "20170921064520"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { - HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests"}; + HttpHeader.HOST, + HttpHeader.USER_AGENT, + HttpHeader.ACCEPT, + HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.ACCEPT_ENCODING, + HttpHeader.REFERER, + HttpHeader.COOKIE, + HttpHeader.CONNECTION, + "Upgrade-Insecure-Requests"}; FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; FIREFOX_52.fontHeights_ = new int[] { @@ -198,7 +213,14 @@ INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { - HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, HttpHeader.DNT, HttpHeader.CONNECTION, + HttpHeader.ACCEPT, + HttpHeader.REFERER, + HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.USER_AGENT, + HttpHeader.ACCEPT_ENCODING, + HttpHeader.HOST, + HttpHeader.DNT, + HttpHeader.CONNECTION, HttpHeader.COOKIE}; INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; @@ -226,7 +248,15 @@ CHROME.cpuClass_ = null; CHROME.productSub_ = "20030107"; CHROME.headerNamesOrdered_ = new String[] { - HttpHeader.HOST, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.COOKIE}; + HttpHeader.HOST, + HttpHeader.CONNECTION, + "Upgrade-Insecure-Requests", + HttpHeader.USER_AGENT, + HttpHeader.ACCEPT, + HttpHeader.REFERER, + HttpHeader.ACCEPT_ENCODING, + HttpHeader.ACCEPT_LANGUAGE, + HttpHeader.COOKIE}; CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -59,6 +59,11 @@ /** host. */ public static final String HOST_LC = "host"; + /** Content-Length. */ + public static final String CONTENT_LENGTH = "Content-Length"; + /** content-length. */ + public static final String CONTENT_LENGTH_LC = "content-length"; + /** Cookie. */ public static final String COOKIE = "Cookie"; /** cookie. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -109,7 +109,7 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, - HttpHeader.CONNECTION_LC, "content-length", HttpHeader.COOKIE_LC, "cookie2", + HttpHeader.CONNECTION_LC, HttpHeader.CONTENT_LENGTH_LC, HttpHeader.COOKIE_LC, "cookie2", "content-transfer-encoding", "date", "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", HttpHeader.USER_AGENT_LC, "via"); 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 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -134,7 +134,7 @@ private static Collection<String> PROHIBITED_HEADERS_ = Arrays.asList( "accept-charset", HttpHeader.ACCEPT_ENCODING_LC, - HttpHeader.CONNECTION_LC, "content-length", HttpHeader.COOKIE_LC, "cookie2", + HttpHeader.CONNECTION_LC, HttpHeader.CONTENT_LENGTH_LC, HttpHeader.COOKIE_LC, "cookie2", "content-transfer-encoding", "date", "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", HttpHeader.USER_AGENT_LC, "via"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -244,7 +244,7 @@ final byte[] content = new byte[] {-1}; final List<NameValuePair> headers = new ArrayList<>(); headers.add(new NameValuePair("Content-Encoding", "gzip")); - headers.add(new NameValuePair("Content-Length", String.valueOf(content.length))); + headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, String.valueOf(content.length))); final MockWebConnection conn = getMockWebConnection(); conn.setResponse(URL_FIRST, content, 404, "OK", "text/html", headers); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -438,7 +438,7 @@ final List<NameValuePair> headers = new ArrayList<>(); headers.add(new NameValuePair("Content-Encoding", "deflate")); - headers.add(new NameValuePair("Content-Length", String.valueOf(compressedDataLength))); + headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, String.valueOf(compressedDataLength))); final MockWebConnection conn = getMockWebConnection(); conn.setResponse(URL_SECOND, content, 200, "OK", "text/javascript", headers); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -101,7 +101,7 @@ headers.add(new NameValuePair("Content-Encoding", "gzip")); if (contentLength != -1) { - headers.add(new NameValuePair("Content-Length", String.valueOf(contentLength))); + headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, String.valueOf(contentLength))); } if (contentType != null) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -214,7 +214,7 @@ page.getWebResponse().getContentAsString(UTF_8)); assertEquals("gzip", page.getWebResponse().getResponseHeaderValue("Content-Encoding")); - assertEquals("73", page.getWebResponse().getResponseHeaderValue("Content-Length")); + assertEquals("73", page.getWebResponse().getResponseHeaderValue(HttpHeader.CONTENT_LENGTH)); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequestTest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -1179,7 +1179,7 @@ final Map<String, String> headers = lastRequest.getAdditionalHeaders(); assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); - assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); + assertEquals(expectedHeaders[2], "" + headers.get(HttpHeader.CONTENT_LENGTH)); assertEquals(expectedHeaders[3], "" + headers.get(HttpHeader.HOST)); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } @@ -1215,7 +1215,7 @@ final Map<String, String> headers = lastRequest.getAdditionalHeaders(); assertEquals(expectedHeaders[0], "" + headers.get(HttpHeader.ACCEPT)); assertEquals(expectedHeaders[1], "" + headers.get(HttpHeader.ACCEPT_ENCODING)); - assertEquals(expectedHeaders[2], "" + headers.get("Content-Length")); + assertEquals(expectedHeaders[2], "" + headers.get(HttpHeader.CONTENT_LENGTH)); assertEquals(expectedHeaders[3], "" + headers.get(HttpHeader.HOST)); assertEquals(expectedHeaders[4], "" + headers.get(HttpHeader.REFERER)); } @@ -1320,7 +1320,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); - assertEquals(contentLength, headers.get("Content-Length")); + assertEquals(contentLength, headers.get(HttpHeader.CONTENT_LENGTH)); } private void property(final String property) throws Exception { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -36,6 +36,7 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.ScriptException; @@ -355,7 +356,7 @@ bytes.write("".getBytes("ASCII")); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Content-Length", "0")); + headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, "0")); headers.add(new NameValuePair("Content-Encoding", "gzip")); webConnection.setResponse(new URL(URL_FIRST, "foo.js"), bytes.toByteArray(), 200, "OK", "text/javascript", headers); 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 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -192,7 +193,7 @@ getMockWebConnection().setDefaultResponse(css, "text/css"); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Content-Length", "0")); + headers.add(new NameValuePair(HttpHeader.CONTENT_LENGTH, "0")); headers.add(new NameValuePair("Content-Encoding", "gzip")); getMockWebConnection().setDefaultResponse(css, 200, "OK", "text/css", headers); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -184,7 +184,7 @@ final WebRequest lastRequest = getMockWebConnection().getLastWebRequest(); final Map<String, String> headers = lastRequest.getAdditionalHeaders(); - assertEquals("" + body.length(), headers.get("Content-Length")); + assertEquals("" + body.length(), headers.get(HttpHeader.CONTENT_LENGTH)); } /** 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 2017-11-14 20:15:12 UTC (rev 14952) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-14 20:19:59 UTC (rev 14953) @@ -1288,7 +1288,7 @@ assertTrue(XMLHttpRequest.isAuthorizedHeader("Content-Type")); final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC, - HttpHeader.CONNECTION_LC, "content-length", HttpHeader.COOKIE_LC, "cookie2", + HttpHeader.CONNECTION_LC, HttpHeader.CONTENT_LENGTH_LC, HttpHeader.COOKIE_LC, "cookie2", "content-transfer-encoding", "date", "expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding", "upgrade", |
From: <rb...@us...> - 2017-11-14 20:27:25
|
Revision: 14954 http://sourceforge.net/p/htmlunit/code/14954 Author: rbri Date: 2017-11-14 20:27:22 +0000 (Tue, 14 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/MockWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnection.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMetaElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -64,6 +64,14 @@ /** content-length. */ public static final String CONTENT_LENGTH_LC = "content-length"; + /** Content-Type. */ + public static final String CONTENT_TYPE = "Content-Type"; + /** content-type. */ + public static final String CONTENT_TYPE_LC = "content-type"; + + /** content-language. */ + public static final String CONTENT_LANGUAGE_LC = "content-language"; + /** Cookie. */ public static final String COOKIE = "Cookie"; /** cookie. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/MockWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/MockWebConnection.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/MockWebConnection.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -79,7 +79,7 @@ compiledHeaders.addAll(headers); } if (contentType != null) { - compiledHeaders.add(new NameValuePair("Content-Type", contentType)); + compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, contentType)); } return compiledHeaders; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -69,7 +69,7 @@ private static WebResponseData getWebResponseData(final String contentString, final Charset charset) { final byte[] content = TextUtil.stringToByteArray(contentString, charset); final List<NameValuePair> compiledHeaders = new ArrayList<>(); - compiledHeaders.add(new NameValuePair("Content-Type", "text/html; charset=" + charset)); + compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, "text/html; charset=" + charset)); return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -112,7 +112,7 @@ if (HttpMethod.POST == httpMethod || HttpMethod.PUT == httpMethod || HttpMethod.PATCH == httpMethod) { connection.setDoOutput(true); final Charset charset = webRequest.getCharset(); - connection.addRequestProperty("Content-Type", FormEncodingType.URL_ENCODED.getName()); + connection.addRequestProperty(HttpHeader.CONTENT_TYPE, FormEncodingType.URL_ENCODED.getName()); try (OutputStream outputStream = connection.getOutputStream()) { final List<NameValuePair> pairs = webRequest.getRequestParameters(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -1150,7 +1150,7 @@ catch (final DecoderException e) { throw new IOException(e.getMessage()); } - responseHeaders.add(new NameValuePair("content-type", + responseHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC, connection.getMediaType() + ";charset=" + connection.getCharset())); try (InputStream is = connection.getInputStream()) { @@ -1195,7 +1195,7 @@ if (!file.exists()) { // construct 404 final List<NameValuePair> compiledHeaders = new ArrayList<>(); - compiledHeaders.add(new NameValuePair("Content-Type", "text/html")); + compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, "text/html")); final WebResponseData responseData = new WebResponseData( TextUtil.stringToByteArray("File: " + file.getAbsolutePath(), UTF_8), @@ -1207,7 +1207,7 @@ final DownloadedContent content = new DownloadedContent.OnFile(file, false); final List<NameValuePair> compiledHeaders = new ArrayList<>(); - compiledHeaders.add(new NameValuePair("Content-Type", contentType)); + compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, contentType)); final WebResponseData responseData = new WebResponseData(content, 200, "OK", compiledHeaders); return new WebResponse(responseData, webRequest, 0); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -135,7 +135,7 @@ * @return the content type returned from the server, e.g. "text/html" */ public String getContentType() { - final String contentTypeHeader = getResponseHeaderValue("content-type"); + final String contentTypeHeader = getResponseHeaderValue(HttpHeader.CONTENT_TYPE_LC); if (contentTypeHeader == null) { // Not technically legal but some servers don't return a content-type return ""; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -651,7 +651,7 @@ * @param value header value */ private static boolean isPreflightHeader(final String name, final String value) { - if ("content-type".equals(name)) { + if (HttpHeader.CONTENT_TYPE_LC.equals(name)) { final String lcValue = value.toLowerCase(Locale.ROOT); if (lcValue.startsWith(FormEncodingType.URL_ENCODED.getName()) || lcValue.startsWith(FormEncodingType.MULTIPART.getName()) @@ -662,7 +662,7 @@ } if (HttpHeader.ACCEPT_LC.equals(name) || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) - || "content-language".equals(name) + || HttpHeader.CONTENT_LANGUAGE_LC.equals(name) || HttpHeader.REFERER_LC.equals(name) || HttpHeader.ACCEPT_ENCODING_LC.equals(name) || HttpHeader.ORIGIN_LC.equals(name)) { 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 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -874,7 +874,7 @@ * @param value header value */ private static boolean isPreflightHeader(final String name, final String value) { - if ("content-type".equals(name)) { + if (HttpHeader.CONTENT_TYPE_LC.equals(name)) { final String lcValue = value.toLowerCase(Locale.ROOT); if (lcValue.startsWith(FormEncodingType.URL_ENCODED.getName()) || lcValue.startsWith(FormEncodingType.MULTIPART.getName()) @@ -885,7 +885,7 @@ } if (HttpHeader.ACCEPT_LC.equals(name) || HttpHeader.ACCEPT_LANGUAGE_LC.equals(name) - || "content-language".equals(name) + || HttpHeader.CONTENT_LANGUAGE_LC.equals(name) || HttpHeader.REFERER_LC.equals(name) || "accept-encoding".equals(name) || HttpHeader.ORIGIN_LC.equals(name)) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -36,6 +36,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.gargoylesoftware.htmlunit.HttpHeader; + /** * Sniffs encoding settings from HTML, XML or other content. The HTML encoding sniffing algorithm is based on the * <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#determining-the-character-encoding">HTML5 @@ -497,7 +499,7 @@ static boolean contentTypeEndsWith(final List<NameValuePair> headers, final String... contentTypeEndings) { for (final NameValuePair pair : headers) { final String name = pair.getName(); - if ("content-type".equalsIgnoreCase(name)) { + if (HttpHeader.CONTENT_TYPE_LC.equalsIgnoreCase(name)) { String value = pair.getValue(); final int i = value.indexOf(';'); if (i != -1) { @@ -617,7 +619,7 @@ public static Charset sniffEncodingFromHttpHeaders(final List<NameValuePair> headers) { for (final NameValuePair pair : headers) { final String name = pair.getName(); - if ("content-type".equalsIgnoreCase(name)) { + if (HttpHeader.CONTENT_TYPE_LC.equalsIgnoreCase(name)) { final Charset encoding = extractEncodingFromContentType(pair.getValue()); if (encoding != null) { if (LOG.isDebugEnabled()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnection.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnection.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebConnection; import com.gargoylesoftware.htmlunit.WebRequest; @@ -110,7 +111,7 @@ protected WebResponse createWebResponse(final WebRequest wr, final String content, final String contentType, final int responseCode, final String responseMessage) throws IOException { final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("content-type", contentType + "; charset=" + UTF_8)); + headers.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC, contentType + "; charset=" + UTF_8)); final byte[] body = content.getBytes(UTF_8); final WebResponseData wrd = new WebResponseData(body, responseCode, responseMessage, headers); return new WebResponse(wrd, wr.getUrl(), wr.getHttpMethod(), 0); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -719,7 +719,7 @@ boolean charsetInContentType = false; for (final NameValuePair responseHeader : resp.getHeaders()) { final String headerName = responseHeader.getName(); - if ("Content-Type".equals(headerName) && responseHeader.getValue().contains("charset=")) { + if (HttpHeader.CONTENT_TYPE.equals(headerName) && responseHeader.getValue().contains("charset=")) { charsetInContentType = true; } response.addHeader(headerName, responseHeader.getValue()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseDataTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -105,7 +105,7 @@ } if (contentType != null) { - headers.add(new NameValuePair("Content-Type", contentType)); + headers.add(new NameValuePair(HttpHeader.CONTENT_TYPE, contentType)); } final WebResponseData data = new WebResponseData("".getBytes(), statusCode, "OK", headers); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -114,7 +114,7 @@ private void illegalCharset(final String cntTypeHeader, final Charset expectedCharset) throws Exception { final MockWebConnection conn = new MockWebConnection(); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Content-Type", cntTypeHeader)); + headers.add(new NameValuePair(HttpHeader.CONTENT_TYPE, cntTypeHeader)); conn.setDefaultResponse("<html/>", 200, "OK", "text/html", headers); final WebClient webClient = getWebClient(); webClient.setWebConnection(conn); @@ -121,7 +121,7 @@ final Page page = webClient.getPage(URL_FIRST); assertEquals(expectedCharset, page.getWebResponse().getContentCharset()); - assertEquals(cntTypeHeader, page.getWebResponse().getResponseHeaderValue("Content-Type")); + assertEquals(cntTypeHeader, page.getWebResponse().getResponseHeaderValue(HttpHeader.CONTENT_TYPE)); assertEquals("<html/>", page.getWebResponse().getContentAsString()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -44,6 +44,7 @@ import org.openqa.selenium.ie.InternetExplorerDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.WebRequest; @@ -425,7 +426,7 @@ driver.findElement(By.id("mySubmit")).click(); final WebRequest request = getMockWebConnection().getLastWebRequest(); - final String contentType = request.getAdditionalHeaders().get("Content-Type"); + final String contentType = request.getAdditionalHeaders().get(HttpHeader.CONTENT_TYPE); assertTrue(StringUtils.isNotBlank(contentType)); assertFalse(StringUtils.containsIgnoreCase(contentType, "charset")); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -31,6 +31,7 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.MockWebConnection; @@ -1126,7 +1127,7 @@ getMockWebConnection().setDefaultResponse(""); loadPageWithAlerts2(html); String headerValue = getMockWebConnection().getLastWebRequest().getAdditionalHeaders() - .get("Content-Type"); + .get(HttpHeader.CONTENT_TYPE); // Can't test equality for multipart/form-data as it will have the form: // multipart/form-data; boundary=---------------------------42937861433140731107235900 headerValue = StringUtils.substringBefore(headerValue, ";"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMetaElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMetaElementTest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMetaElementTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -18,6 +18,7 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -35,8 +36,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"undefined", "text/html; charset=utf-8", "Content-Type", "", "", "undefined"}, - IE = {"", "text/html; charset=utf-8", "Content-Type", "", "", ""}) + @Alerts(DEFAULT = {"undefined", "text/html; charset=utf-8", HttpHeader.CONTENT_TYPE, "", "", "undefined"}, + IE = {"", "text/html; charset=utf-8", HttpHeader.CONTENT_TYPE, "", "", ""}) public void name() throws Exception { final String html = "<html>\n" 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 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -1104,7 +1104,7 @@ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { resp.setStatus(200); - resp.addHeader("Content-Type", "text/html"); + resp.addHeader(HttpHeader.CONTENT_TYPE, "text/html"); try { for (int i = 0; i < 10; i++) { resp.getOutputStream().print(String.valueOf(i)); @@ -1154,7 +1154,7 @@ } resp.setStatus(200); - resp.addHeader("Content-Type", "text/plain"); + resp.addHeader(HttpHeader.CONTENT_TYPE, "text/plain"); resp.getOutputStream().print(authToken); resp.flushBuffer(); } @@ -1285,7 +1285,7 @@ @Test public void isAuthorizedHeader() throws Exception { assertTrue(XMLHttpRequest.isAuthorizedHeader("Foo")); - assertTrue(XMLHttpRequest.isAuthorizedHeader("Content-Type")); + assertTrue(XMLHttpRequest.isAuthorizedHeader(HttpHeader.CONTENT_TYPE)); final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC, HttpHeader.CONNECTION_LC, HttpHeader.CONTENT_LENGTH_LC, HttpHeader.COOKIE_LC, "cookie2", Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java 2017-11-14 20:19:59 UTC (rev 14953) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java 2017-11-14 20:27:22 UTC (rev 14954) @@ -26,6 +26,8 @@ import org.junit.Test; +import com.gargoylesoftware.htmlunit.HttpHeader; + /** * Unit tests for {@link EncodingSniffer}. * @@ -41,10 +43,10 @@ public void fromHttpHeaders() throws Exception { header(null, null, null); header(null, "foo", "bar"); - header(null, "Content-Type", "blah"); - header(null, "Content-Type", "text/html;charset=blah"); - header(UTF_8, "Content-Type", "text/html;charset=utf-8"); - header(UTF_8, "Content-Type", "text/html;charset=utf-8;"); + header(null, HttpHeader.CONTENT_TYPE, "blah"); + header(null, HttpHeader.CONTENT_TYPE, "text/html;charset=blah"); + header(UTF_8, HttpHeader.CONTENT_TYPE, "text/html;charset=utf-8"); + header(UTF_8, HttpHeader.CONTENT_TYPE, "text/html;charset=utf-8;"); } private static void header(final Charset expectedEncoding, final String headerName, final String headerValue) { |
From: <rb...@us...> - 2017-11-14 20:32:00
|
Revision: 14955 http://sourceforge.net/p/htmlunit/code/14955 Author: rbri Date: 2017-11-14 20:31:58 +0000 (Tue, 14 Nov 2017) Log Message: ----------- use constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:27:22 UTC (rev 14954) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2017-11-14 20:31:58 UTC (rev 14955) @@ -85,6 +85,9 @@ /** DNT. */ public static final String DNT = "DNT"; + /** Upgrade-Insecure-Requests. */ + public static final String UPGRADE_INSECURE_REQUESTS = "Upgrade-Insecure-Requests"; + private HttpHeader() { } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-14 20:27:22 UTC (rev 14954) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-11-14 20:31:58 UTC (rev 14955) @@ -794,7 +794,7 @@ else if (HttpHeader.ACCEPT_ENCODING.equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptEncodingHeaderHttpRequestInterceptor(requestHeaders.get(header))); } - else if ("Upgrade-Insecure-Requests".equals(header) && requestHeaders.get(header) != null) { + else if (HttpHeader.UPGRADE_INSECURE_REQUESTS.equals(header) && requestHeaders.get(header) != null) { list.add(new UpgradeInsecureRequestHeaderHttpRequestInterceptor(requestHeaders.get(header))); } else if (HttpHeader.REFERER.equals(header) && requestHeaders.get(header) != null) { @@ -891,7 +891,7 @@ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - request.setHeader("Upgrade-Insecure-Requests", value_); + request.setHeader(HttpHeader.UPGRADE_INSECURE_REQUESTS, value_); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-14 20:27:22 UTC (rev 14954) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-11-14 20:31:58 UTC (rev 14955) @@ -1463,8 +1463,8 @@ wrs.setAdditionalHeader(HttpHeader.ACCEPT_LANGUAGE, getBrowserVersion().getBrowserLanguage()); } if (getBrowserVersion().hasFeature(HTTP_HEADER_UPGRADE_INSECURE_REQUEST) - && !wrs.isAdditionalHeader("Upgrade-Insecure-Requests")) { - wrs.setAdditionalHeader("Upgrade-Insecure-Requests", "1"); + && !wrs.isAdditionalHeader(HttpHeader.UPGRADE_INSECURE_REQUESTS)) { + wrs.setAdditionalHeader(HttpHeader.UPGRADE_INSECURE_REQUESTS, "1"); } // Add user-specified headers last so that they can override HtmlUnit defaults. wrs.getAdditionalHeaders().putAll(requestHeaders_); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-14 20:27:22 UTC (rev 14954) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-11-14 20:31:58 UTC (rev 14955) @@ -47,12 +47,13 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {HttpHeader.HOST, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, + @Alerts(CHROME = {HttpHeader.HOST, HttpHeader.CONNECTION, HttpHeader.UPGRADE_INSECURE_REQUESTS, + HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE}, FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - HttpHeader.ACCEPT_ENCODING, HttpHeader.CONNECTION}, + HttpHeader.ACCEPT_ENCODING, HttpHeader.CONNECTION}, FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, - HttpHeader.ACCEPT_ENCODING, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests"}, + HttpHeader.ACCEPT_ENCODING, HttpHeader.CONNECTION, HttpHeader.UPGRADE_INSECURE_REQUESTS}, IE = {HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, HttpHeader.DNT, HttpHeader.CONNECTION}) @NotYetImplemented(IE) @@ -92,14 +93,15 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {HttpHeader.HOST, HttpHeader.CONNECTION, "Upgrade-Insecure-Requests", HttpHeader.USER_AGENT, + @Alerts(CHROME = {HttpHeader.HOST, HttpHeader.CONNECTION, HttpHeader.UPGRADE_INSECURE_REQUESTS, + HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_ENCODING, HttpHeader.ACCEPT_LANGUAGE, - "Cookie"}, + HttpHeader.COOKIE}, FF45 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION}, FF52 = {HttpHeader.HOST, HttpHeader.USER_AGENT, HttpHeader.ACCEPT, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.ACCEPT_ENCODING, HttpHeader.REFERER, HttpHeader.COOKIE, HttpHeader.CONNECTION, - "Upgrade-Insecure-Requests"}, + HttpHeader.UPGRADE_INSECURE_REQUESTS}, IE = {HttpHeader.ACCEPT, HttpHeader.REFERER, HttpHeader.ACCEPT_LANGUAGE, HttpHeader.USER_AGENT, HttpHeader.ACCEPT_ENCODING, HttpHeader.HOST, HttpHeader.DNT, HttpHeader.CONNECTION, HttpHeader.COOKIE}) |
From: <rb...@us...> - 2017-11-15 17:30:35
|
Revision: 14958 http://sourceforge.net/p/htmlunit/code/14958 Author: rbri Date: 2017-11-15 17:30:32 +0000 (Wed, 15 Nov 2017) Log Message: ----------- hope i have found it Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MimeTypeTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-15 16:38:05 UTC (rev 14957) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-11-15 17:30:32 UTC (rev 14958) @@ -17,7 +17,6 @@ import java.io.File; import java.io.Serializable; import java.lang.reflect.Field; -import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -754,7 +753,7 @@ * @return the available plugins */ public Set<PluginConfiguration> getPlugins() { - return Collections.unmodifiableSet(plugins_); + return plugins_; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MimeTypeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MimeTypeTest.java 2017-11-15 16:38:05 UTC (rev 14957) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MimeTypeTest.java 2017-11-15 17:30:32 UTC (rev 14958) @@ -23,7 +23,6 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.PluginConfiguration; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; @@ -81,7 +80,7 @@ createTestPageForRealBrowserIfNeeded(html, expectedAlerts); final List<String> collectedAlerts = new ArrayList<>(); - final Set<PluginConfiguration> plugins = new HashSet<>(BrowserVersion.FIREFOX_45.getPlugins()); + final Set<PluginConfiguration> plugins = new HashSet<>(getBrowserVersion().getPlugins()); getBrowserVersion().getPlugins().clear(); try { loadPage(html, collectedAlerts); @@ -88,7 +87,7 @@ assertEquals(expectedAlerts, collectedAlerts); } finally { - BrowserVersion.FIREFOX_45.getPlugins().addAll(plugins); + getBrowserVersion().getPlugins().addAll(plugins); } } } |