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