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.libraries;
16  
17  import java.util.List;
18  
19  import org.htmlunit.WebServerTestCase;
20  import org.htmlunit.junit.BrowserRunner;
21  import org.junit.BeforeClass;
22  import org.junit.Test;
23  import org.junit.runner.RunWith;
24  import org.openqa.selenium.By;
25  import org.openqa.selenium.WebDriver;
26  import org.openqa.selenium.WebElement;
27  
28  /**
29   * Tests for compatibility with version 1.6.0 of
30   * <a href="http://www.prototypejs.org/">Prototype JavaScript library</a>.
31   *
32   * @author Ahmed Ashour
33   * @author Marc Guillemot
34   * @author Ronald Brill
35   */
36  @RunWith(BrowserRunner.class)
37  public class Prototype160Test extends PrototypeTestBase {
38  
39      /**
40       * @throws Exception if an error occurs
41       */
42      @BeforeClass
43      public static void aaa_startSesrver() throws Exception {
44          SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/prototype/1.6.0/", null);
45      }
46  
47      /**
48       * {@inheritDoc}
49       */
50      @Override
51      protected String getVersion() {
52          return "1.6.0";
53      }
54  
55      /**
56       * @return the resource base url
57       */
58      @Override
59      protected String getBaseUrl() {
60          return URL_FIRST + "test/unit/";
61      }
62  
63      @Override
64      protected boolean testFinished(final WebDriver driver) {
65          final List<WebElement> status = driver.findElements(By.cssSelector("div#logsummary"));
66          for (final WebElement webElement : status) {
67              if (!webElement.getText().contains("errors")) {
68                  return false;
69              }
70          }
71          return true;
72      }
73  
74      /**
75       * @throws Exception if test fails
76       */
77      @Test
78      public void ajax() throws Exception {
79          test("ajax.html");
80      }
81  
82      /**
83       * @throws Exception if test fails
84       */
85      @Test
86      public void array() throws Exception {
87          test("array.html");
88      }
89  
90      /**
91       * @throws Exception if test fails
92       */
93      @Test
94      public void base() throws Exception {
95          test("base.html");
96      }
97  
98      /**
99       * Note: <tt>testElementGetDimensions:</tt>, <tt>testElementGetStyle</tt>, <tt>testElementGetHeight</tt>,
100      *       <tt>testElementScrollTo:</tt>, <tt>testPositionedOffset</tt>, <tt>testViewportOffset</tt>,
101      *       <tt>testViewportDimensions</tt>, <tt>testViewportScrollOffsets</tt>
102      *       and <tt>testElementGetWidth</tt> are expected to fail with HtmlUnit,
103      *       as they need calculating width and height of all elements.
104      *
105      * Other tests succeed.
106      *
107      * @throws Exception if test fails
108      */
109     @Test
110     public void dom() throws Exception {
111         test("dom.html");
112     }
113 
114     /**
115      * Depends on {@link org.htmlunit.javascript.HtmlUnitScriptable2Test#parentProtoFeature()}.
116      *
117      * @throws Exception if test fails
118      */
119     @Test
120     public void elementMixins() throws Exception {
121         test("element_mixins.html");
122     }
123 
124     /**
125      * @throws Exception if test fails
126      */
127     @Test
128     public void enumerable() throws Exception {
129         test("enumerable.html");
130     }
131 
132     /**
133      * @throws Exception if test fails
134      */
135     @Test
136     public void event() throws Exception {
137         test("event.html");
138     }
139 
140     /**
141      * @throws Exception if test fails
142      */
143     @Test
144     public void form() throws Exception {
145         test("form.html");
146     }
147 
148     /**
149      * @throws Exception if test fails
150      */
151     @Test
152     public void hash() throws Exception {
153         test("hash.html");
154     }
155 
156     /**
157      * @throws Exception if test fails
158      */
159     @Test
160     public void number() throws Exception {
161         test("number.html");
162     }
163 
164     /**
165      * @throws Exception if test fails
166      */
167     @Test
168     public void position() throws Exception {
169         test("position.html");
170     }
171 
172     /**
173      * @throws Exception if test fails
174      */
175     @Test
176     public void range() throws Exception {
177         test("range.html");
178     }
179 
180     /**
181      * @throws Exception if test fails
182      */
183     @Test
184     public void selector() throws Exception {
185         test("selector.html");
186     }
187 
188     /**
189      * @throws Exception if test fails
190      */
191     @Test
192     public void string() throws Exception {
193         test("string.html");
194     }
195 
196     /**
197      * 1 expected failure is because the server port is other than 4711.
198      * @throws Exception if test fails
199      */
200     @Test
201     public void unitTests() throws Exception {
202         test("unit_tests.html");
203     }
204 }