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