From: <rb...@us...> - 2018-01-19 08:43:08
|
Revision: 15084 http://sourceforge.net/p/htmlunit/code/15084 Author: rbri Date: 2018-01-19 08:43:06 +0000 (Fri, 19 Jan 2018) Log Message: ----------- Setter for history.scrollRestoration added Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/History.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-01-19 07:47:59 UTC (rev 15083) +++ trunk/htmlunit/src/changes/changes.xml 2018-01-19 08:43:06 UTC (rev 15084) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators"> + <action type="add" dev="rbri"> + JavaScript: Setter for history.scrollRestoration added. + </action> <action type="fix" dev="rbri" issue="1674"> Fix the broken initialization of the canvas context that empties the canvas every time canvas.getContext("2d") was called. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/History.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/History.java 2018-01-19 07:47:59 UTC (rev 15083) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/History.java 2018-01-19 08:43:06 UTC (rev 15084) @@ -32,6 +32,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import net.sourceforge.htmlunit.corejs.javascript.Context; @@ -47,7 +48,11 @@ */ @JsxClass public class History extends SimpleScriptable { + private static final String SCROLL_RESTAURATION_AUTO = "auto"; + private static final String SCROLL_RESTAURATION_MANUAL = "manual"; + private String scrollRestoration_ = SCROLL_RESTAURATION_AUTO; + /** * Creates an instance. */ @@ -165,7 +170,21 @@ */ @JsxGetter({CHROME, FF52}) public String getScrollRestoration() { - return "auto"; + return scrollRestoration_; } + /** + * @param scrollRestoration the new value + */ + @JsxSetter({CHROME, FF52}) + public void setScrollRestoration(final String scrollRestoration) { + if (SCROLL_RESTAURATION_AUTO.equals(scrollRestoration)) { + scrollRestoration_ = SCROLL_RESTAURATION_AUTO; + return; + } + if (SCROLL_RESTAURATION_MANUAL.equals(scrollRestoration)) { + scrollRestoration_ = SCROLL_RESTAURATION_MANUAL; + return; + } + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java 2018-01-19 07:47:59 UTC (rev 15083) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java 2018-01-19 08:43:06 UTC (rev 15084) @@ -767,4 +767,39 @@ loadPage2(html2, URL_SECOND); assertEquals("page2", driver.getTitle()); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"auto", "manual", "auto", "auto", "auto", "auto"}, + FF45 = {"undefined", "manual", "auto", "MaNUaL", "unknown", "undefined"}, + IE = {"undefined", "manual", "auto", "MaNUaL", "unknown", "undefined"}) + public void scrollRestoration() throws Exception { + final String html = "<html><head><script>\n" + + " function test() {\n" + + " alert(history.scrollRestoration);\n" + + + " history.scrollRestoration = 'manual';\n" + + " alert(history.scrollRestoration);\n" + + + " history.scrollRestoration = 'auto';\n" + + " alert(history.scrollRestoration);\n" + + + " history.scrollRestoration = 'MaNUaL';\n" + + " alert(history.scrollRestoration);\n" + + + " history.scrollRestoration = 'unknown';\n" + + " alert(history.scrollRestoration);\n" + + + " history.scrollRestoration = undefined;\n" + + " alert(history.scrollRestoration);\n" + + + " }\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |