From: <asa...@us...> - 2013-10-08 10:46:20
|
Revision: 8614 http://sourceforge.net/p/htmlunit/code/8614 Author: asashour Date: 2013-10-08 10:46:17 +0000 (Tue, 08 Oct 2013) Log Message: ----------- JavaScript: TextRange: add getBookmark() and moveToBookmark(). Issue 1499 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-08 10:17:16 UTC (rev 8613) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-08 10:46:17 UTC (rev 8614) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="add" dev="asashour" issue="1499"> + JavaScript: TextRange: add getBookmark() and moveToBookmark(). + </action> <action type="fix" dev="rbri"> JavaScript: .outerHTML don't check for correct tag closing in FF mode. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java 2013-10-08 10:17:16 UTC (rev 8613) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java 2013-10-08 10:46:17 UTC (rev 8614) @@ -316,4 +316,26 @@ } return moveBy; } + + /** + * Retrieves a bookmark (opaque string) that can be used with {@link #moveToBookmark} + * to return to the same range. + * The current implementation return empty string + * @return the bookmark + */ + @JsxFunction + public String getBookmark() { + return ""; + } + + /** + * Moves to a bookmark. + * The current implementation does nothing + * @param bookmark the bookmark + */ + @JsxFunction + public boolean moveToBookmark(final String bookmark) { + return false; + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java 2013-10-08 10:17:16 UTC (rev 8613) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java 2013-10-08 10:46:17 UTC (rev 8614) @@ -37,8 +37,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "", "bla bla", "bla blabli bli" }) + @Alerts(DEFAULT = "exception", IE = { "", "bla bla", "bla blabli bli" }) public void text() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -70,8 +69,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = "BODY") + @Alerts(DEFAULT = "exception", IE = "BODY") public void parentElement() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -95,8 +93,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "hello", "" }) + @Alerts(DEFAULT = "exception", IE = { "hello", "" }) public void collapse() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -128,8 +125,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = "") + @Alerts(DEFAULT = "exception", IE = "") public void select() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -155,8 +151,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "hello", "hell", "ell" }) + @Alerts(DEFAULT = "exception", IE = { "hello", "hell", "ell" }) public void moveEnd() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -189,8 +184,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "hello", "hell", "ell", "1", "-1", "hello" }) + @Alerts(DEFAULT = "exception", IE = { "hello", "hell", "ell", "1", "-1", "hello" }) public void moveOutOfBounds_input() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -226,8 +220,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "true", "true", "false", "true" }) + @Alerts(DEFAULT = "exception", IE = { "true", "true", "false", "true" }) public void inRange() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -260,8 +253,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = "false") + @Alerts(DEFAULT = "exception", IE = "false") public void inRange2() throws Exception { final String html = "<html><body>" + "<form name='f'><input name='q' value=''></form>" @@ -330,8 +322,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "exception", - IE = "BODY") + @Alerts(DEFAULT = "exception", IE = "BODY") public void createRangeParentElement() throws Exception { final String html = "<html><body>\n" @@ -350,8 +341,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "exception", - IE = "") + @Alerts(DEFAULT = "exception", IE = "") public void createRangeHtmlText() throws Exception { final String html = "<html><body>\n" @@ -365,4 +355,23 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "exception", IE = "ok") + public void moveToBookmark() throws Exception { + final String html = + "<html><body>\n" + + "<script>\n" + + "try {\n" + + " var rng = document.body.createTextRange();\n" + + " rng.moveToBookmark(rng.getBookmark());\n" + + " alert('ok');\n" + + "} catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } |