From: <rb...@us...> - 2017-05-29 15:25:59
|
Revision: 14484 http://sourceforge.net/p/htmlunit/code/14484 Author: rbri Date: 2017-05-29 15:25:56 +0000 (Mon, 29 May 2017) Log Message: ----------- the svg elemnet is now an ordinary html element Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -92,6 +92,7 @@ HtmlSource.TAG_NAME, HtmlSpan.TAG_NAME, HtmlStrike.TAG_NAME, HtmlStrong.TAG_NAME, HtmlStyle.TAG_NAME, HtmlSubscript.TAG_NAME, HtmlSummary.TAG_NAME, HtmlSuperscript.TAG_NAME, + HtmlSvg.TAG_NAME, HtmlTable.TAG_NAME, HtmlTableColumn.TAG_NAME, HtmlTableColumnGroup.TAG_NAME, HtmlTableBody.TAG_NAME, HtmlTableDataCell.TAG_NAME, HtmlTableHeaderCell.TAG_NAME, HtmlTableRow.TAG_NAME, HtmlTextArea.TAG_NAME, HtmlTableFooter.TAG_NAME, @@ -646,6 +647,10 @@ element = new HtmlSuperscript(qualifiedName, page, attributeMap); break; + case HtmlSvg.TAG_NAME: + element = new HtmlSvg(qualifiedName, page, attributeMap); + break; + case HtmlTable.TAG_NAME: element = new HtmlTable(qualifiedName, page, attributeMap); break; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -352,16 +352,15 @@ * @param namespaceURI the namespace URI * @param qualifiedName the qualified name * @param insideHtml is the node inside HTML or not + * @param insideSvg is the node inside an SVG node or not * @return the pre-registered element factory corresponding to the specified tag, or an UnknownElementFactory */ static ElementFactory getElementFactory(final SgmlPage page, final String namespaceURI, - final String qualifiedName, final boolean insideHtml) { - final String qualifiedNameLower = qualifiedName.toLowerCase(Locale.ROOT); - if (SVG_NAMESPACE.equals(namespaceURI) - || (SVG_FACTORY.isSupported(qualifiedNameLower)) - && !ELEMENT_FACTORIES.containsKey(qualifiedNameLower)) { + final String qualifiedName, final boolean insideHtml, final boolean insideSvg) { + if (insideSvg) { return SVG_FACTORY; } + if (namespaceURI == null || namespaceURI.isEmpty() || !qualifiedName.contains(":") || namespaceURI.equals(XHTML_NAMESPACE)) { @@ -406,6 +405,8 @@ private HtmlElement body_; private boolean lastTagWasSynthesized_; private HtmlForm formWaitingForLostChildren_; + private boolean insideSvg_; + private static final String FEATURE_AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations"; private static final String FEATURE_PARSE_NOSCRIPT = "http://cyberneko.org/html/features/parse-noscript-content"; @@ -555,7 +556,7 @@ } // add a head if none was there else if (headParsed_ == HeadParsed.NO && ("body".equals(tagLower) || "frameset".equals(tagLower))) { - final ElementFactory factory = getElementFactory(page_, namespaceURI, "head", true); + final ElementFactory factory = getElementFactory(page_, namespaceURI, "head", true, insideSvg_); final DomElement newElement = factory.createElement(page_, "head", null); currentNode_.appendChild(newElement); headParsed_ = HeadParsed.SYNTHESIZED; @@ -584,7 +585,8 @@ tagLower = "select"; qName = "select"; } - final ElementFactory factory = getElementFactory(page_, namespaceURI, qName, isInsideHtml()); + + final ElementFactory factory = getElementFactory(page_, namespaceURI, qName, isInsideHtml(), insideSvg_); if (factory == SVG_FACTORY) { namespaceURI = SVG_NAMESPACE; } @@ -594,6 +596,10 @@ // parse can't replace everything as it does not buffer elements while parsing addNodeToRightParent(currentNode_, newElement); + if ("svg".equals(tagLower)) { + insideSvg_ = true; + } + // If we had an old synthetic body and we just added a real body element, quietly // remove the old body and move its children to the real body element we just added. if (oldBody != null) { @@ -767,6 +773,10 @@ } } + if ("svg".equals(tagLower)) { + insideSvg_ = false; + } + // Need to reset this at each closing form tag because a valid form could start afterwards. if ("form".equals(tagLower)) { formWaitingForLostChildren_ = null; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -156,7 +156,20 @@ */ protected HtmlElement(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { - super(HTMLParser.XHTML_NAMESPACE, qualifiedName, page, attributes); + this(HTMLParser.XHTML_NAMESPACE, qualifiedName, page, attributes); + } + /** + * Creates an instance of a DOM element that can have a namespace. + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name of the element type to instantiate + * @param page the page that contains this element + * @param attributes a map ready initialized with the attributes for this element, or + * {@code null}. The map will be stored as is, not copied. + */ + protected HtmlElement(final String namespaceURI, final String qualifiedName, final SgmlPage page, + final Map<String, DomAttr> attributes) { + super(namespaceURI, qualifiedName, page, attributes); attributeListeners_ = new LinkedHashSet<>(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -565,7 +565,7 @@ */ @Override public DomElement createElementNS(final String namespaceURI, final String qualifiedName) { - return HTMLParser.getElementFactory(this, namespaceURI, qualifiedName, true) + return HTMLParser.getElementFactory(this, namespaceURI, qualifiedName, true, false) .createElementNS(this, namespaceURI, qualifiedName, null, true); } Copied: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java (from rev 14479, trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java) =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -0,0 +1,44 @@ +/* + * 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.html; + +import java.util.Map; + +import com.gargoylesoftware.htmlunit.SgmlPage; + +/** + * Wrapper for the SVG element {@code svg}. + * + * @author Ahmed Ashour + * @author Ronald Brill + */ +public class HtmlSvg extends HtmlElement { + + /** The tag represented by this element. */ + public static final String TAG_NAME = "svg"; + + /** + * Creates a new instance. + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name of the element type to instantiate + * @param page the page that contains this element + * @param attributes the initial attributes + */ + HtmlSvg(final String qualifiedName, final SgmlPage page, + final Map<String, DomAttr> attributes) { + super(HTMLParser.SVG_NAMESPACE, qualifiedName, page, attributes); + } +} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -51,6 +51,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlTextArea; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.html.HtmlTitle; +import com.gargoylesoftware.htmlunit.html.HtmlSvg; import com.gargoylesoftware.htmlunit.javascript.host.Element2; import com.gargoylesoftware.htmlunit.javascript.host.Window2; import com.gargoylesoftware.htmlunit.javascript.host.dom.Attr2; @@ -80,7 +81,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTitleElement2; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLUnknownElement2; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGSVGElement2; -import com.gargoylesoftware.htmlunit.svg.SvgSvg; import com.gargoylesoftware.js.nashorn.internal.objects.Global; import com.gargoylesoftware.js.nashorn.internal.runtime.ScriptObject; @@ -295,7 +295,7 @@ host = HTMLStyleElement2.constructor(true, global); host.setDomNode(domNode); } - else if (domNode instanceof SvgSvg) { + else if (domNode instanceof HtmlSvg) { host = SVGSVGElement2.constructor(true, global); host.setDomNode(domNode); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -18,11 +18,11 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; +import com.gargoylesoftware.htmlunit.html.HtmlSvg; 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; -import com.gargoylesoftware.htmlunit.svg.SvgSvg; /** * A JavaScript object for {@code SVGSVGElement}. @@ -29,7 +29,7 @@ * * @author Ahmed Ashour */ -@JsxClass(domClass = SvgSvg.class) +@JsxClass(domClass = HtmlSvg.class) public class SVGSVGElement extends SVGGraphicsElement { /** The constant {@code SVG_ZOOMANDPAN_UNKNOWN}. */ Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1,44 +0,0 @@ -/* - * 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.svg; - -import java.util.Map; - -import com.gargoylesoftware.htmlunit.SgmlPage; -import com.gargoylesoftware.htmlunit.html.DomAttr; - -/** - * Wrapper for the SVG element {@code svg}. - * - * @author Ahmed Ashour - */ -public class SvgSvg extends SvgElement { - - /** The tag represented by this element. */ - public static final String TAG_NAME = "svg"; - - /** - * Creates a new instance. - * - * @param namespaceURI the URI that identifies an XML namespace - * @param qualifiedName the qualified name of the element type to instantiate - * @param page the page that contains this element - * @param attributes the initial attributes - */ - SvgSvg(final String namespaceURI, final String qualifiedName, final SgmlPage page, - final Map<String, DomAttr> attributes) { - super(namespaceURI, qualifiedName, page, attributes); - } -} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1330,6 +1330,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSuperscript}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts({"3", "2", "2", "3", "2", "2"}) + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1393,6 +1393,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSuperscript}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts("1") + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -110,6 +110,7 @@ "HtmlSource", "HtmlSpan", "HtmlStrike", "HtmlStrong", "HtmlStyle", "HtmlSubscript", "HtmlSummary", "HtmlSuperscript", + "HtmlSvg", "HtmlTable", "HtmlTableColumn", "HtmlTableColumnGroup", "HtmlTableBody", "HtmlTableDataCell", "HtmlTableHeaderCell", "HtmlTableRow", "HtmlTextArea", "HtmlTableFooter", Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -28,7 +28,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -388,6 +387,36 @@ * @throws Exception if the test fails */ @Test + @Alerts({"[object SVGSVGElement]", "http://www.w3.org/2000/svg", + "[object SVGRectElement]", "http://www.w3.org/2000/svg"}) + public void htmlPageEmbeddedSvgWithoutNamespace() throws Exception { + final String content + = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + + "<head>\n" + + "<title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('mySvg'));\n" + + " alert(document.getElementById('mySvg').namespaceURI);\n" + + " alert(document.getElementById('myRect'));\n" + + " alert(document.getElementById('myRect').namespaceURI);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <svg id='mySvg'>\n" + + " <rect id='myRect' />\n" + + " </svg>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(content); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts("HTML") public void htmlPage() throws Exception { final String content @@ -414,7 +443,6 @@ */ @Test @Alerts("[object HTMLHtmlElement]") - @NotYetImplemented public void htmlSvgPage() throws Exception { final String content = "<html xmlns=\"http://www.w3.org/2000/svg\">\n" Copied: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java (from rev 14479, trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java) =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -0,0 +1,118 @@ +/* + * 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.html; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link HtmlSvg}. + * + * @author Ahmed Ashour + * @author Frank Danek + */ +@RunWith(BrowserRunner.class) +public class HtmlSvgTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("[object SVGSVGElement]") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('myId'));\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "</body></html>"; + + final WebDriver driver = loadPageWithAlerts2(html); + if (driver instanceof HtmlUnitDriver) { + final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage(); + assertTrue(HtmlSvg.class.isInstance(page.getElementById("myId"))); + } + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("false") + public void style() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " alert(document.getElementById('myId').style == undefined);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"function", "function"}) + public void functions() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + " alert(typeof svg.getScreenCTM);\n" + + " alert(typeof svg.createSVGMatrix);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("[object SVGMatrix]") + public void getScreenCTM() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + " try {\n" + + " alert(svg.getScreenCTM());\n" + + " } catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1,120 +0,0 @@ -/* - * 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.svg; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.htmlunit.HtmlUnitDriver; - -import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.WebDriverTestCase; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlPageTest; - -/** - * Tests for {@link SvgSvg}. - * - * @author Ahmed Ashour - * @author Frank Danek - */ -@RunWith(BrowserRunner.class) -public class SvgSvgTest extends WebDriverTestCase { - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("[object SVGSVGElement]") - public void simpleScriptable() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><head>\n" - + "<script>\n" - + " function test() {\n" - + " alert(document.getElementById('myId'));\n" - + " }\n" - + "</script>\n" - + "</head><body onload='test()'>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "</body></html>"; - - final WebDriver driver = loadPageWithAlerts2(html); - if (driver instanceof HtmlUnitDriver) { - final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage(); - assertTrue(SvgSvg.class.isInstance(page.getElementById("myId"))); - } - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("false") - public void style() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><body>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "<script>\n" - + " alert(document.getElementById('myId').style == undefined);\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({"function", "function"}) - public void functions() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><body>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "<script>\n" - + " var svg = document.getElementById('myId');\n" - + " alert(typeof svg.getScreenCTM);\n" - + " alert(typeof svg.createSVGMatrix);\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("[object SVGMatrix]") - public void getScreenCTM() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><body>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "<script>\n" - + " var svg = document.getElementById('myId');\n" - + " try {\n" - + " alert(svg.getScreenCTM());\n" - + " } catch(e) { alert('exception'); }\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } -} |