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