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.htmlunit.junit.annotation.HtmlUnitNYI;
21  import org.junit.Test;
22  import org.junit.runner.RunWith;
23  
24  /**
25   * Tests for {@link HTMLEmbedElement}.
26   *
27   * @author Ronald Brill
28   * @author Frank Danek
29   */
30  @RunWith(BrowserRunner.class)
31  public class HTMLEmbedElementTest extends WebDriverTestCase {
32  
33      /**
34       * @throws Exception if an error occurs
35       */
36      @Test
37      @Alerts(DEFAULT = {"left", "right", "bottom", "middle", "top",
38                         "absbottom", "absmiddle", "baseline", "texttop", "wrong", ""},
39              FF = {"left", "right", "bottom", "middle", "top",
40                    "absbottom", "absmiddle", "bottom", "texttop", "wrong", ""},
41              FF_ESR = {"left", "right", "bottom", "middle", "top",
42                        "absbottom", "absmiddle", "bottom", "texttop", "wrong", ""})
43      @HtmlUnitNYI(FF = {"left", "right", "bottom", "middle", "top",
44                         "absbottom", "absmiddle", "baseline", "texttop", "wrong", ""},
45              FF_ESR = {"left", "right", "bottom", "middle", "top",
46                        "absbottom", "absmiddle", "baseline", "texttop", "wrong", ""})
47      public void getAlign() throws Exception {
48          final String html = DOCTYPE_HTML
49              + "<html><body>\n"
50              + "  <embed id='e1' align='left' ></embed>\n"
51              + "  <embed id='e2' align='right' ></embed>\n"
52              + "  <embed id='e3' align='bottom' ></embed>\n"
53              + "  <embed id='e4' align='middle' ></embed>\n"
54              + "  <embed id='e5' align='top' ></embed>\n"
55              + "  <embed id='e6' align='absbottom' ></embed>\n"
56              + "  <embed id='e7' align='absmiddle' ></embed>\n"
57              + "  <embed id='e8' align='baseline' ></embed>\n"
58              + "  <embed id='e9' align='texttop' ></embed>\n"
59              + "  <embed id='e10' align='wrong' ></embed>\n"
60              + "  <embed id='e11' ></embed>\n"
61  
62              + "<script>\n"
63              + LOG_TITLE_FUNCTION
64              + "  for (var i = 1; i <= 11; i++) {\n"
65              + "    log(document.getElementById('e' + i).align);\n"
66              + "  }\n"
67              + "</script>\n"
68              + "</body></html>";
69  
70          loadPageVerifyTitle2(html);
71      }
72  
73      /**
74       * @throws Exception if an error occurs
75       */
76      @Test
77      @Alerts(DEFAULT = {"CenTer", "8", "foo", "left", "right", "bottom", "middle", "top",
78                         "absbottom", "absmiddle", "baseline", "texttop"},
79              FF = {"CenTer", "8", "foo", "left", "right", "bottom", "middle", "top",
80                    "absbottom", "absmiddle", "bottom", "texttop"},
81              FF_ESR = {"CenTer", "8", "foo", "left", "right", "bottom", "middle", "top",
82                        "absbottom", "absmiddle", "bottom", "texttop"})
83      @HtmlUnitNYI(FF = {"CenTer", "8", "foo", "left", "right", "bottom", "middle", "top",
84                         "absbottom", "absmiddle", "baseline", "texttop"},
85              FF_ESR = {"CenTer", "8", "foo", "left", "right", "bottom", "middle", "top",
86                        "absbottom", "absmiddle", "baseline", "texttop"})
87      public void setAlign() throws Exception {
88          final String html = DOCTYPE_HTML
89              + "<html><body>\n"
90              + "  <embed id='e1' align='left' ></embed>\n"
91  
92              + "<script>\n"
93              + LOG_TITLE_FUNCTION
94              + "  function setAlign(elem, value) {\n"
95              + "    try {\n"
96              + "      elem.align = value;\n"
97              + "    } catch(e) { logEx(e); }\n"
98              + "    log(elem.align);\n"
99              + "  }\n"
100 
101             + "  var elem = document.getElementById('e1');\n"
102             + "  setAlign(elem, 'CenTer');\n"
103 
104             + "  setAlign(elem, '8');\n"
105             + "  setAlign(elem, 'foo');\n"
106 
107             + "  setAlign(elem, 'left');\n"
108             + "  setAlign(elem, 'right');\n"
109             + "  setAlign(elem, 'bottom');\n"
110             + "  setAlign(elem, 'middle');\n"
111             + "  setAlign(elem, 'top');\n"
112             + "  setAlign(elem, 'absbottom');\n"
113             + "  setAlign(elem, 'absmiddle');\n"
114             + "  setAlign(elem, 'baseline');\n"
115             + "  setAlign(elem, 'texttop');\n"
116             + "</script>\n"
117             + "</body></html>";
118 
119         loadPageVerifyTitle2(html);
120     }
121 
122     /**
123      * @throws Exception if an error occurs
124      */
125     @Test
126     @Alerts({"10px", "20em", "80%", "40", "wrong", ""})
127     public void getHeight() throws Exception {
128         final String html = DOCTYPE_HTML
129             + "<html><body>\n"
130             + "  <embed id='e1' height='10px' ></embed>\n"
131             + "  <embed id='e2' height='20em' ></embed>\n"
132             + "  <embed id='e3' height='80%' ></embed>\n"
133             + "  <embed id='e4' height='40' ></embed>\n"
134             + "  <embed id='e5' height='wrong' ></embed>\n"
135             + "  <embed id='e6' ></embed>\n"
136 
137             + "<script>\n"
138             + LOG_TITLE_FUNCTION
139             + "  for (var i = 1; i <= 6; i++) {\n"
140             + "    log(document.getElementById('e' + i).height);\n"
141             + "  }\n"
142             + "</script>\n"
143             + "</body></html>";
144 
145         loadPageVerifyTitle2(html);
146     }
147 
148     /**
149      * @throws Exception if an error occurs
150      */
151     @Test
152     @Alerts({"20px", "8", "foo"})
153     public void setHeight() throws Exception {
154         final String html = DOCTYPE_HTML
155             + "<html><body>\n"
156             + "  <embed id='e1' height='10px' ></embed>\n"
157 
158             + "<script>\n"
159             + LOG_TITLE_FUNCTION
160             + "  function setHeight(elem, value) {\n"
161             + "    try {\n"
162             + "      elem.height = value;\n"
163             + "    } catch(e) { logEx(e); }\n"
164             + "    log(elem.height);\n"
165             + "  }\n"
166 
167             + "  var elem = document.getElementById('e1');\n"
168             + "  setHeight(elem, '20px');\n"
169 
170             + "  setHeight(elem, '8');\n"
171             + "  setHeight(elem, 'foo');\n"
172 
173             + "</script>\n"
174             + "</body></html>";
175 
176         loadPageVerifyTitle2(html);
177     }
178 
179     /**
180      * @throws Exception if an error occurs
181      */
182     @Test
183     @Alerts({"10px", "20em", "80%", "40", "wrong", ""})
184     public void getWidth() throws Exception {
185         final String html = DOCTYPE_HTML
186             + "<html><body>\n"
187             + "  <embed id='e1' width='10px' ></embed>\n"
188             + "  <embed id='e2' width='20em' ></embed>\n"
189             + "  <embed id='e3' width='80%' ></embed>\n"
190             + "  <embed id='e4' width='40' ></embed>\n"
191             + "  <embed id='e5' width='wrong' ></embed>\n"
192             + "  <embed id='e6' ></embed>\n"
193 
194             + "<script>\n"
195             + LOG_TITLE_FUNCTION
196             + "  for (var i = 1; i <= 6; i++) {\n"
197             + "    log(document.getElementById('e' + i).width);\n"
198             + "  }\n"
199             + "</script>\n"
200             + "</body></html>";
201 
202         loadPageVerifyTitle2(html);
203     }
204 
205     /**
206      * @throws Exception if an error occurs
207      */
208     @Test
209     @Alerts({"20px", "8", "foo"})
210     public void setWidth() throws Exception {
211         final String html = DOCTYPE_HTML
212             + "<html><body>\n"
213             + "  <embed id='e1' width='10px' ></embed>\n"
214 
215             + "<script>\n"
216             + LOG_TITLE_FUNCTION
217             + "  function setWidth(elem, value) {\n"
218             + "    try {\n"
219             + "      elem.width = value;\n"
220             + "    } catch(e) { logEx(e); }\n"
221             + "    log(elem.width);\n"
222             + "  }\n"
223 
224             + "  var elem = document.getElementById('e1');\n"
225             + "  setWidth(elem, '20px');\n"
226 
227             + "  setWidth(elem, '8');\n"
228             + "  setWidth(elem, 'foo');\n"
229 
230             + "</script>\n"
231             + "</body></html>";
232 
233         loadPageVerifyTitle2(html);
234     }
235 }