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.WebDriverTestCase;
18  import org.htmlunit.junit.annotation.Alerts;
19  import org.junit.jupiter.api.Test;
20  
21  /**
22   * Unit tests for {@link HTMLParamElement}.
23   *
24   * @author Ronald Brill
25   */
26  public class HTMLParamElementTest extends WebDriverTestCase {
27  
28      /**
29       * @throws Exception if the test fails
30       */
31      @Test
32      @Alerts({"myValue", "", "", ""})
33      public void value() throws Exception {
34          final String html = DOCTYPE_HTML
35              + "<html><head>\n"
36              + "<script>\n"
37              + LOG_TITLE_FUNCTION
38              + "  function test() {\n"
39              + "    for(var i = 1; i < 5; i++) {\n"
40              + "      var param = document.getElementById('tester' + i);\n"
41              + "      log(param.value);\n"
42              + "    }\n"
43              + "  }\n"
44              + "</script>\n"
45              + "</head>\n"
46              + "<body onload='test()'>\n"
47              + "  <object>\n"
48              + "    <param id='tester1' name='testParam' value='myValue'/>\n"
49              + "    <param id='tester2' name='testParam' value=''/>\n"
50              + "    <param id='tester3' name='testParam' />\n"
51              + "    <param id='tester4' />\n"
52              + "  </object>\n"
53              + "</body></html>";
54  
55          loadPageVerifyTitle2(html);
56      }
57  
58      /**
59       * @throws Exception if the test fails
60       */
61      @Test
62      @Alerts({"testParam", "", "", ""})
63      public void name() throws Exception {
64          final String html = DOCTYPE_HTML
65              + "<html><head>\n"
66              + "<script>\n"
67              + LOG_TITLE_FUNCTION
68              + "  function test() {\n"
69              + "    for(var i = 1; i < 5; i++) {\n"
70              + "      var param = document.getElementById('tester' + i);\n"
71              + "      log(param.name);\n"
72              + "    }\n"
73              + "  }\n"
74              + "</script>\n"
75              + "</head>\n"
76              + "<body onload='test()'>\n"
77              + "  <object>\n"
78              + "    <param id='tester1' name='testParam' value='myValue'/>\n"
79              + "    <param id='tester2' name='' value='myValue'/>\n"
80              + "    <param id='tester3' value='myValue'/>\n"
81              + "    <param id='tester4' />\n"
82              + "  </object>\n"
83              + "</body></html>";
84  
85          loadPageVerifyTitle2(html);
86      }
87  
88      /**
89       * @throws Exception if the test fails
90       */
91      @Test
92      @Alerts({"ttt", "", "", "", "ttt", "", "", "", "ttt", "ttt", "ttt"})
93      public void type() throws Exception {
94          final String html = DOCTYPE_HTML
95              + "<html><head>\n"
96              + "<script>\n"
97              + LOG_TITLE_FUNCTION
98              + "  function test() {\n"
99              + "    for(var i = 1; i < 12; i++) {\n"
100             + "      var param = document.getElementById('tester' + i);\n"
101             + "      log(param.type);\n"
102             + "    }\n"
103             + "  }\n"
104             + "</script>\n"
105             + "</head>\n"
106             + "<body onload='test()'>\n"
107             + "  <object>\n"
108             + "    <param id='tester1' type='ttt' value='myValue'/>\n"
109             + "    <param id='tester2' type='' value='myValue'/>\n"
110             + "    <param id='tester3' value='myValue'/>\n"
111             + "    <param id='tester4' />\n"
112 
113             + "    <param id='tester5' type='ttt' value='myValue' valueType='ref'/>\n"
114             + "    <param id='tester6' type='' value='myValue' valueType='ref'/>\n"
115             + "    <param id='tester7' value='myValue' valueType='ref'/>\n"
116             + "    <param id='tester8' valueType='ref'/>\n"
117 
118             + "    <param id='tester9' type='ttt' value='myValue' valueType='data'/>\n"
119             + "    <param id='tester10' type='ttt' value='myValue' valueType='object'/>\n"
120             + "    <param id='tester11' type='ttt' value='myValue' valueType='foo'/>\n"
121             + "  </object>\n"
122             + "</body></html>";
123 
124         loadPageVerifyTitle2(html);
125     }
126 
127     /**
128      * @throws Exception if the test fails
129      */
130     @Test
131     @Alerts({"ref", "object", "data", "foo"})
132     public void valueType() throws Exception {
133         final String html = DOCTYPE_HTML
134             + "<html><head>\n"
135             + "<script>\n"
136             + LOG_TITLE_FUNCTION
137             + "  function test() {\n"
138             + "    for(var i = 1; i < 5; i++) {\n"
139             + "      var param = document.getElementById('tester' + i);\n"
140             + "      log(param.valueType);\n"
141             + "    }\n"
142             + "  }\n"
143             + "</script>\n"
144             + "</head>\n"
145             + "<body onload='test()'>\n"
146             + "  <object>\n"
147             + "    <param id='tester1' valuetype='ref' value='myValue'/>\n"
148             + "    <param id='tester2' valuetype='object' value='myValue'/>\n"
149             + "    <param id='tester3' valuetype='data' value='myValue'/>\n"
150             + "    <param id='tester4' valuetype='foo' value='myValue'/>\n"
151             + "  </object>\n"
152             + "</body></html>";
153 
154         loadPageVerifyTitle2(html);
155     }
156 }