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.annotation.Alerts;
19  import org.htmlunit.junit.annotation.HtmlUnitNYI;
20  import org.junit.jupiter.api.Test;
21  
22  /**
23   * Tests for {@link SVGPathElement}.
24   *
25   * @author Ronald Brill
26   */
27  public class SVGPathElementTest extends WebDriverTestCase {
28  
29      /**
30       * @throws Exception if the test fails
31       */
32      @Test
33      @Alerts("function SVGPathElement() { [native code] }")
34      public void simpleScriptable() throws Exception {
35          final String html = DOCTYPE_HTML
36              + "<html><head>\n"
37              + "<script>\n"
38              + LOG_TITLE_FUNCTION
39              + "  function test() {\n"
40              + "    log(window.SVGPathElement);\n"
41              + "  }\n"
42              + "</script>\n"
43              + "</head><body onload='test()'>\n"
44              + "</body></html>";
45  
46          loadPageVerifyTitle2(html);
47      }
48  
49      /**
50       * @throws Exception if the test fails
51       */
52      @Test
53      @Alerts({"[object SVGPathElement]", "true"})
54      public void getTotalLengthAvailable() throws Exception {
55          final String html = DOCTYPE_HTML
56              + "<html><head>\n"
57              + "<script>\n"
58              + LOG_TITLE_FUNCTION
59              + "  function test() {\n"
60              + "    if (window.SVGPathElement) {\n"
61              + "      var path = document.getElementById('myId');\n"
62              + "      log(path);\n"
63              + "      log(path.getTotalLength() > 0);\n"
64              + "    }\n"
65              + "  }\n"
66              + "</script>\n"
67              + "</head><body onload='test()'>\n"
68              + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
69              + "  <path id='myId' d='M 100 100 L 300 100 L 200 300 z' stroke='black' stroke-width='3' />\n"
70              + "</svg>\n"
71              + "</body></html>";
72  
73          loadPageVerifyTitle2(html);
74      }
75  
76      /**
77       * @throws Exception if the test fails
78       */
79      @Test
80      @Alerts({"[object SVGPathElement]", "647.213623046875"})
81      @HtmlUnitNYI(CHROME = {"[object SVGPathElement]", "1"},
82              EDGE = {"[object SVGPathElement]", "1"},
83              FF = {"[object SVGPathElement]", "1"},
84              FF_ESR = {"[object SVGPathElement]", "1"})
85      public void getTotalLength() throws Exception {
86          final String html = DOCTYPE_HTML
87              + "<html><head>\n"
88              + "<script>\n"
89              + LOG_TITLE_FUNCTION
90              + "  function test() {\n"
91              + "    if (window.SVGPathElement) {\n"
92              + "      var path = document.getElementById('myId');\n"
93              + "      log(path);\n"
94              + "      log(path.getTotalLength());\n"
95              + "    }\n"
96              + "  }\n"
97              + "</script>\n"
98              + "</head><body onload='test()'>\n"
99              + "<svg width='100%' height='100%' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'>\n"
100             + "  <path id='myId' d='M 100 100 L 300 100 L 200 300 z' stroke='black' stroke-width='3' />\n"
101             + "</svg>\n"
102             + "</body></html>";
103 
104         loadPageVerifyTitle2(html);
105     }
106 }