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.junit.jupiter.api.Test;
20  
21  /**
22   * Tests for {@link SVGSVGElement}.
23   *
24   * @author Ahmed Ashour
25   * @author Frank Danek
26   * @author Ronald Brill
27   * @author Natasha Lazarova
28   */
29  public class SVGSVGElementTest extends WebDriverTestCase {
30  
31      /**
32       * @throws Exception if the test fails
33       */
34      @Test
35      @Alerts("[object SVGRect]")
36      public void createSVGRect() throws Exception {
37          final String html = DOCTYPE_HTML
38              + "<html><head>\n"
39              + "<script>\n"
40              + LOG_TITLE_FUNCTION
41              + "  function test() {\n"
42              + "    log(document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect());\n"
43              + "  }\n"
44              + "</script>\n"
45              + "</head><body onload='test()'>\n"
46              + "</body></html>";
47  
48          loadPageVerifyTitle2(html);
49      }
50  
51      /**
52       * @throws Exception if an error occurs
53       */
54      @Test
55      @Alerts("undefined")
56      public void getInnerTextOfSvg() throws Exception {
57          final String html = DOCTYPE_HTML
58                  + "<html><body>\n"
59                  + "  <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'></svg>\n"
60                  + "  <script>\n"
61                  + LOG_TITLE_FUNCTION
62                  + "    var svg =  document.getElementById('myId');\n"
63                  + "    log(svg.innerText);\n"
64                  + "  </script>\n"
65                  + "</body></html>";
66  
67          loadPageVerifyTitle2(html);
68      }
69  
70      /**
71       * @throws Exception if the test fails
72       */
73      @Test
74      @Alerts("")
75      public void getInnerTextOfElementContainingSvg() throws Exception {
76          final String html = DOCTYPE_HTML
77                  + "<html><body>\n"
78                  + "  <div id='myDivId'><svg xmlns='http://www.w3.org/2000/svg' version='1.1'></svg></div>\n"
79                  + "  <script>\n"
80                  + LOG_TITLE_FUNCTION
81                  + "    var div = document.getElementById('myDivId');\n"
82                  + "    log(div.innerText);\n"
83                  + "  </script>\n"
84                  + "</body></html>";
85  
86          loadPageVerifyTitle2(html);
87      }
88  }