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