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.css;
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 CSSKeyframesRule}.
24   *
25   * @author Ronald Brill
26   */
27  public class CSSKeyframesRuleTest extends WebDriverTestCase {
28  
29      /**
30       * @throws Exception if an error occurs
31       */
32      @Test
33      @Alerts("TypeError")
34      public void ctor() throws Exception {
35          final String html = DOCTYPE_HTML
36              + "<html><body>\n"
37              + LOG_TEXTAREA
38              + "<script>\n"
39              + LOG_TEXTAREA_FUNCTION
40              + "try {\n"
41              + "  var rule = new CSSKeyframesRule();\n"
42              + "  log(rule);\n"
43              + "} catch(e) { logEx(e); }\n"
44              + "</script></body></html>";
45  
46          loadPageVerifyTextArea2(html);
47      }
48  
49      /**
50       * @throws Exception if an error occurs
51       */
52      @Test
53      @Alerts({"[object CSSKeyframesRule]", "7"})
54      public void simple() throws Exception {
55          final String html = DOCTYPE_HTML
56              + "<html><body>\n"
57  
58              + "<style>\n"
59              + "  @keyframes identifier { 0% { top: 0; left: 0; } 100% { top: 100px; left: 100%; }}\n"
60              + "</style>\n"
61  
62              + "<script>\n"
63              + LOG_TITLE_FUNCTION
64              + "  var styleSheet = document.styleSheets[0];\n"
65              + "  if (styleSheet.cssRules) {\n"
66              + "    var rule = styleSheet.cssRules[0];\n"
67              + "    log(rule);\n"
68              + "    log(rule.type);\n"
69              + "  } else {\n"
70              + "    log('Your browser does not support this example');\n"
71              + "  }\n"
72              + "</script>\n"
73  
74              + "</body></html>";
75  
76          loadPageVerifyTitle2(html);
77      }
78  
79      /**
80       * @throws Exception if an error occurs
81       */
82      @Test
83      @Alerts({"[object CSSKeyframesRule]", "identifier"})
84      @HtmlUnitNYI(CHROME = {"[object CSSKeyframesRule]", "undefined"},
85              EDGE = {"[object CSSKeyframesRule]", "undefined"},
86              FF = {"[object CSSKeyframesRule]", "undefined"},
87              FF_ESR = {"[object CSSKeyframesRule]", "undefined"})
88      public void name() throws Exception {
89          final String html = DOCTYPE_HTML
90              + "<html><body>\n"
91  
92              + "<style>\n"
93              + "  @keyframes identifier { 0% { top: 0; left: 0; } 100% { top: 100px; left: 100%; }}\n"
94              + "</style>\n"
95  
96              + "<script>\n"
97              + LOG_TITLE_FUNCTION
98              + "  var styleSheet = document.styleSheets[0];\n"
99              + "  if (styleSheet.cssRules) {\n"
100             + "    var rule = styleSheet.cssRules[0];\n"
101             + "    log(rule);\n"
102             + "    log(rule.name);\n"
103             + "  } else {\n"
104             + "    log('Your browser does not support this example');\n"
105             + "  }\n"
106             + "</script>\n"
107 
108             + "</body></html>";
109 
110         loadPageVerifyTitle2(html);
111     }
112 
113     /**
114      * @throws Exception if an error occurs
115      */
116     @Test
117     @Alerts("[object CSSRuleList]")
118     @HtmlUnitNYI(CHROME = "undefined",
119             EDGE = "undefined",
120             FF = "undefined",
121             FF_ESR = "undefined")
122     public void cssRules() throws Exception {
123         final String html = DOCTYPE_HTML
124             + "<html><body>\n"
125 
126             + "<style>\n"
127             + "  @keyframes identifier { 0% { top: 0; left: 0; } 100% { top: 100px; left: 100%; }}\n"
128             + "</style>\n"
129 
130             + "<script>\n"
131             + LOG_TITLE_FUNCTION
132             + "  var styleSheet = document.styleSheets[0];\n"
133             + "  if (styleSheet.cssRules) {\n"
134             + "    var rule = styleSheet.cssRules[0];\n"
135             + "    log(rule.cssRules);\n"
136             + "  } else {\n"
137             + "    log('Your browser does not support this example');\n"
138             + "  }\n"
139             + "</script>\n"
140 
141             + "</body></html>";
142 
143         loadPageVerifyTitle2(html);
144     }
145 }