View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.svg;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.htmlunit.junit.annotation.HtmlUnitNYI;
21  import org.junit.Test;
22  import org.junit.runner.RunWith;
23  
24  /**
25   * Tests for {@link SVGPathElement}.
26   *
27   * @author Ronald Brill
28   */
29  @RunWith(BrowserRunner.class)
30  public class SVGPathElementTest extends WebDriverTestCase {
31  
32      /**
33       * @throws Exception if the test fails
34       */
35      @Test
36      @Alerts("function SVGPathElement() { [native code] }")
37      public void simpleScriptable() throws Exception {
38          final String html = DOCTYPE_HTML
39              + "<html><head>\n"
40              + "<script>\n"
41              + LOG_TITLE_FUNCTION
42              + "  function test() {\n"
43              + "    log(window.SVGPathElement);\n"
44              + "  }\n"
45              + "</script>\n"
46              + "</head><body onload='test()'>\n"
47              + "</body></html>";
48  
49          loadPageVerifyTitle2(html);
50      }
51  
52      /**
53       * @throws Exception if the test fails
54       */
55      @Test
56      @Alerts({"[object SVGPathElement]", "true"})
57      public void getTotalLengthAvailable() throws Exception {
58          final String html = DOCTYPE_HTML
59              + "<html><head>\n"
60              + "<script>\n"
61              + LOG_TITLE_FUNCTION
62              + "  function test() {\n"
63              + "    if (window.SVGPathElement) {\n"
64              + "      var path = document.getElementById('myId');\n"
65              + "      log(path);\n"
66              + "      log(path.getTotalLength() > 0);\n"
67              + "    }\n"
68              + "  }\n"
69              + "</script>\n"
70              + "</head><body onload='test()'>\n"
71              + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
72              + "  <path id='myId' d='M 100 100 L 300 100 L 200 300 z' stroke='black' stroke-width='3' />\n"
73              + "</svg>\n"
74              + "</body></html>";
75  
76          loadPageVerifyTitle2(html);
77      }
78  
79      /**
80       * @throws Exception if the test fails
81       */
82      @Test
83      @Alerts({"[object SVGPathElement]", "647.213623046875"})
84      @HtmlUnitNYI(CHROME = {"[object SVGPathElement]", "1"},
85              EDGE = {"[object SVGPathElement]", "1"},
86              FF = {"[object SVGPathElement]", "1"},
87              FF_ESR = {"[object SVGPathElement]", "1"})
88      public void getTotalLength() throws Exception {
89          final String html = DOCTYPE_HTML
90              + "<html><head>\n"
91              + "<script>\n"
92              + LOG_TITLE_FUNCTION
93              + "  function test() {\n"
94              + "    if (window.SVGPathElement) {\n"
95              + "      var path = document.getElementById('myId');\n"
96              + "      log(path);\n"
97              + "      log(path.getTotalLength());\n"
98              + "    }\n"
99              + "  }\n"
100             + "</script>\n"
101             + "</head><body onload='test()'>\n"
102             + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
103             + "  <path id='myId' d='M 100 100 L 300 100 L 200 300 z' stroke='black' stroke-width='3' />\n"
104             + "</svg>\n"
105             + "</body></html>";
106 
107         loadPageVerifyTitle2(html);
108     }
109 }