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.html;
16  
17  import java.util.ArrayList;
18  import java.util.List;
19  
20  import org.htmlunit.CollectingAlertHandler;
21  import org.htmlunit.MockWebConnection;
22  import org.htmlunit.SimpleWebTestCase;
23  import org.htmlunit.WebClient;
24  import org.htmlunit.junit.annotation.Alerts;
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Tests for {@link HtmlObject}.
29   *
30   * @author Ahmed Ashour
31   * @author Ronald Brill
32   */
33  public class HtmlObjectTest extends SimpleWebTestCase {
34      /**
35       * @throws Exception if the test fails
36       */
37      @Test
38      @Alerts("undefined")
39      public void classid() throws Exception {
40          final String html = DOCTYPE_HTML
41              + "<html><head>\n"
42              // Window Media Player CLASSID
43              + "<object id='wm' classid='clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6'></object>\n"
44              + "<script>\n"
45              + "  function test() {\n"
46              + "    alert(document.all.wm.fullScreen);\n"
47              + "  }\n"
48              + "</script>\n"
49              + "</head><body onload='test()'>\n"
50              + "</body></html>";
51  
52          final WebClient client = getWebClient();
53          final List<String> collectedAlerts = new ArrayList<>();
54          client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
55  
56          final MockWebConnection webConnection = new MockWebConnection();
57          webConnection.setResponse(URL_FIRST, html);
58          client.setWebConnection(webConnection);
59  
60          client.getPage(URL_FIRST);
61          assertEquals(getExpectedAlerts(), collectedAlerts);
62      }
63  }