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.html;
16  
17  import org.htmlunit.HttpHeader;
18  import org.htmlunit.WebDriverTestCase;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.junit.jupiter.api.Test;
21  
22  /**
23   * Unit tests for {@link HTMLMetaElement}.
24   *
25   * @author Ahmed Ashour
26   * @author Ronald Brill
27   * @author Frank Danek
28   */
29  public class HTMLMetaElementTest extends WebDriverTestCase {
30  
31      /**
32       * @throws Exception if an error occurs
33       */
34      @Test
35      @Alerts({"undefined", "text/html; charset=utf-8", HttpHeader.CONTENT_TYPE, "", "", "undefined", ""})
36      public void name() throws Exception {
37          final String html = DOCTYPE_HTML
38              + "<html>\n"
39              + "  <head>\n"
40              + "    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n"
41              + "    <script>\n"
42              + LOG_TITLE_FUNCTION
43              + "      function test() {\n"
44              + "        var meta = document.getElementsByTagName('meta')[0];\n"
45              + "        log(meta.charset);\n"
46              + "        log(meta.content);\n"
47              + "        log(meta.httpEquiv);\n"
48              + "        log(meta.name);\n"
49              + "        log(meta.scheme);\n"
50              + "        log(meta.url);\n"
51              + "        log(meta.media);\n"
52              + "      }\n"
53              + "    </script>\n"
54              + "  </head>\n"
55              + "  <body onload='test()'></body>\n"
56              + "</html>";
57  
58          loadPageVerifyTitle2(html);
59      }
60  
61      /**
62       * @throws Exception if an error occurs
63       */
64      @Test
65      @Alerts("only screen and (max-width: 600px)")
66      public void media() throws Exception {
67          final String html = DOCTYPE_HTML
68              + "<html>\n"
69              + "  <head>\n"
70              + "    <meta http-equiv='Content-Type' media='only screen and (max-width: 600px)'>\n"
71              + "    <script>\n"
72              + LOG_TITLE_FUNCTION
73              + "      function test() {\n"
74              + "        var meta = document.getElementsByTagName('meta')[0];\n"
75              + "        log(meta.media);\n"
76              + "      }\n"
77              + "    </script>\n"
78              + "  </head>\n"
79              + "  <body onload='test()'></body>\n"
80              + "</html>";
81  
82          loadPageVerifyTitle2(html);
83      }
84  }