From: <rb...@us...> - 2017-09-10 11:33:54
|
Revision: 14823 http://sourceforge.net/p/htmlunit/code/14823 Author: rbri Date: 2017-09-10 11:33:51 +0000 (Sun, 10 Sep 2017) Log Message: ----------- getComputedTextLength() support added for svg text elements Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElement.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTSpanElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextPathElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-09-10 10:18:34 UTC (rev 14822) +++ trunk/htmlunit/src/changes/changes.xml 2017-09-10 11:33:51 UTC (rev 14823) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 61"> + <action type="add" dev="rbri"> + JavaScript: getComputedTextLength() support added for svg text elements. + </action> <action type="fix" dev="rbri"> JavaScript: document.createElementNS is now able to create svg elements also. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElement.java 2017-09-10 10:18:34 UTC (rev 14822) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElement.java 2017-09-10 11:33:51 UTC (rev 14823) @@ -21,11 +21,13 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; /** * A JavaScript object for {@code SVGTextContentElement}. * * @author Ahmed Ashour + * @author Ronald Brill */ @JsxClass public class SVGTextContentElement extends SVGGraphicsElement { @@ -47,4 +49,12 @@ public SVGTextContentElement() { } + /** + * @return the length of the text + */ + @JsxFunction + public float getComputedTextLength() { + // just a fake for the moment + return 1.0f; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElement.java 2017-09-10 10:18:34 UTC (rev 14822) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElement.java 2017-09-10 11:33:51 UTC (rev 14823) @@ -26,6 +26,7 @@ * A JavaScript object for {@code SVGTextElement}. * * @author Ahmed Ashour + * @author Ronald Brill */ @JsxClass(domClass = SvgText.class) public class SVGTextElement extends SVGTextPositioningElement { Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTSpanElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTSpanElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTSpanElementTest.java 2017-09-10 11:33:51 UTC (rev 14823) @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2002-2017 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link SVGTextElement}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class SVGTSpanElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGTSpanElement]", + FF = "function SVGTSpanElement() {\n [native code]\n}", + CHROME = "function SVGTSpanElement() { [native code] }") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(window.SVGTSpanElement);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"[object SVGTSpanElement]", "true"}) + public void getComputedTextLengthAvailable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (window.SVGPathElement) {\n" + + " var text = document.getElementById('myId');\n" + + " alert(text);\n" + + " alert(text.getComputedTextLength() > 0);\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n" + + " <text fill='limegreen' font-size='20'>\n" + + " <tSpan id='myId'x='50' y='50 55 60 60 60 55 50 45 40 35 30 25'>SVG forever!</tSpan>\n" + + " </text>\n" + + "</svg>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"[object SVGTSpanElement]", "109.4"}) + @NotYetImplemented + public void getComputedTextLength() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (window.SVGTextElement) {\n" + + " var text = document.getElementById('myId');\n" + + " alert(text);\n" + + " var length = text.getComputedTextLength();\n" + + " alert(length.toFixed(1));\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n" + + " <text fill='limegreen' font-size='20'>\n" + + " <tSpan id='myId'x='50' y='50 55 60 60 60 55 50 45 40 35 30 25'>SVG forever!</tSpan>\n" + + " </text>\n" + + "</svg>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTSpanElementTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElementTest.java 2017-09-10 11:33:51 UTC (rev 14823) @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2002-2017 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link SVGTextContentElement}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class SVGTextContentElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGTextContentElement]", + FF = "function SVGTextContentElement() {\n [native code]\n}", + CHROME = "function SVGTextContentElement() { [native code] }") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(window.SVGTextContentElement);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextContentElementTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElementTest.java 2017-09-10 11:33:51 UTC (rev 14823) @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2002-2017 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link SVGTextElement}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class SVGTextElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGTextElement]", + FF = "function SVGTextElement() {\n [native code]\n}", + CHROME = "function SVGTextElement() { [native code] }") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(window.SVGTextElement);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"[object SVGTextElement]", "true"}) + public void getComputedTextLengthAvailable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (window.SVGPathElement) {\n" + + " var text = document.getElementById('myId');\n" + + " alert(text);\n" + + " alert(text.getComputedTextLength() > 0);\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n" + + " <text id='myId' x='0' y='4' fill='orange'>HtmlUnit is great!</text>\n" + + "</svg>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"[object SVGTextElement]", "117.3"}) + @NotYetImplemented + public void getComputedTextLength() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (window.SVGTextElement) {\n" + + " var text = document.getElementById('myId');\n" + + " alert(text);\n" + + " var length = text.getComputedTextLength();\n" + + " alert(length.toFixed(1));\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n" + + " <text id='myId' x='0' y='4' fill='orange'>HtmlUnit is great!</text>\n" + + "</svg>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextElementTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextPathElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextPathElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextPathElementTest.java 2017-09-10 11:33:51 UTC (rev 14823) @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2002-2017 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link SVGTextPathElement}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class SVGTextPathElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGTextPathElement]", + FF = "function SVGTextPathElement() {\n [native code]\n}", + CHROME = "function SVGTextPathElement() { [native code] }") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(window.SVGTextPathElement);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"[object SVGTextPathElement]", "true"}) + public void getComputedTextLengthAvailable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (window.SVGPathElement) {\n" + + " var text = document.getElementById('myId');\n" + + " alert(text);\n" + + " alert(text.getComputedTextLength() > 0);\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n" + + " <defs>\n" + + " <path id='myTextPath' d='M 50,100 Q 150,50 250,100' />\n" + + " </defs>\n" + + " <text fill='steelblue' font-size='20'>\n" + + " <textPath id='myId' xlink:href='#myTextPath'>Heho</textPath>\n" + + " </text>\n" + + "</svg>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"[object SVGTextPathElement]", "43.3"}, + IE = {"[object SVGTextPathElement]", "49.3"}) + @NotYetImplemented + public void getComputedTextLength() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (window.SVGTextElement) {\n" + + " var text = document.getElementById('myId');\n" + + " alert(text);\n" + + " var length = text.getComputedTextLength();\n" + + " alert(length.toFixed(1));\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n" + + " <defs>\n" + + " <path id='myTextPath' d='M 50,100 Q 150,50 250,100' />\n" + + " </defs>\n" + + " <text fill='steelblue' font-size='20'>\n" + + " <textPath id='myId' xlink:href='#myTextPath'>Heho</textPath>\n" + + " </text>\n" + + "</svg>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGTextPathElementTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |