001: /*
002: * Copyright (c) 2002-2008 Gargoyle Software Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: * 2. Redistributions in binary form must reproduce the above copyright notice,
010: * this list of conditions and the following disclaimer in the documentation
011: * and/or other materials provided with the distribution.
012: * 3. The end-user documentation included with the redistribution, if any, must
013: * include the following acknowledgment:
014: *
015: * "This product includes software developed by Gargoyle Software Inc.
016: * (http://www.GargoyleSoftware.com/)."
017: *
018: * Alternately, this acknowledgment may appear in the software itself, if
019: * and wherever such third-party acknowledgments normally appear.
020: * 4. The name "Gargoyle Software" must not be used to endorse or promote
021: * products derived from this software without prior written permission.
022: * For written permission, please contact info@GargoyleSoftware.com.
023: * 5. Products derived from this software may not be called "HtmlUnit", nor may
024: * "HtmlUnit" appear in their name, without prior written permission of
025: * Gargoyle Software Inc.
026: *
027: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
028: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
029: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
030: * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
031: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
032: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
033: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
036: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: */
038: package com.gargoylesoftware.htmlunit.libraries;
039:
040: import java.net.URL;
041:
042: import com.gargoylesoftware.htmlunit.BrowserVersion;
043: import com.gargoylesoftware.htmlunit.WebClient;
044: import com.gargoylesoftware.htmlunit.WebTestCase;
045: import com.gargoylesoftware.htmlunit.html.HtmlPage;
046:
047: /**
048: * Tests for compatibility with version 1.6.0 of
049: * <a href="http://prototype.conio.net/">Prototype JavaScript library</a>.
050: *
051: * @version $Revision: 2154 $
052: * @author ahmed Ashour
053: */
054: public class Prototype160Test extends WebTestCase {
055:
056: /**
057: * @param name The name of the test.
058: */
059: public Prototype160Test(final String name) {
060: super (name);
061: }
062:
063: /**
064: * @throws Exception If test fails.
065: */
066: public void testAjax() throws Exception {
067: if (notYetImplemented()) {
068: return;
069: }
070: final String filename = "ajax.html";
071: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 15, 14,
072: 10, 7);
073: test(BrowserVersion.FIREFOX_2, filename, 15, 32, 0, 0);
074: }
075:
076: /**
077: * @throws Exception If test fails.
078: */
079: public void testArray() throws Exception {
080: final String filename = "array.html";
081: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 19, 97, 0,
082: 0);
083: test(BrowserVersion.FIREFOX_2, filename, 19, 97, 0, 0);
084: }
085:
086: /**
087: * @throws Exception If test fails.
088: */
089: public void testBase() throws Exception {
090: if (notYetImplemented()) {
091: return;
092: }
093: final String filename = "base.html";
094: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 35, 255,
095: 0, 0);
096: test(BrowserVersion.FIREFOX_2, filename, 35, 225, 0, 0);
097: }
098:
099: /**
100: * @throws Exception If test fails.
101: */
102: public void testDom() throws Exception {
103: if (notYetImplemented()) {
104: return;
105: }
106: final String filename = "dom.html";
107: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 87, 819,
108: 3, 0);
109: test(BrowserVersion.FIREFOX_2, filename, 87, 811, 0, 0);
110: }
111:
112: /**
113: * @throws Exception If test fails.
114: */
115: public void testElementMixins() throws Exception {
116: final String filename = "element_mixins.html";
117: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 4, 12, 0,
118: 0);
119: test(BrowserVersion.FIREFOX_2, filename, 4, 12, 0, 0);
120: }
121:
122: /**
123: * @throws Exception If test fails.
124: */
125: public void testEnumerable() throws Exception {
126: final String filename = "enumerable.html";
127: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 25, 82, 0,
128: 0);
129: test(BrowserVersion.FIREFOX_2, filename, 25, 82, 0, 0);
130: }
131:
132: /**
133: * @throws Exception If test fails.
134: */
135: public void testEvent() throws Exception {
136: if (notYetImplemented()) {
137: return;
138: }
139: final String filename = "event.html";
140: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 12, 43, 1,
141: 0);
142: test(BrowserVersion.FIREFOX_2, filename, 12, 44, 0, 0);
143: }
144:
145: /**
146: * @throws Exception If test fails.
147: */
148: public void testForm() throws Exception {
149: if (notYetImplemented()) {
150: return;
151: }
152: final String filename = "form.html";
153: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 15, 110,
154: 0, 0);
155: test(BrowserVersion.FIREFOX_2, filename, 15, 109, 0, 0);
156: }
157:
158: /**
159: * @throws Exception If test fails.
160: */
161: public void testHash() throws Exception {
162: if (notYetImplemented()) {
163: return;
164: }
165: final String filename = "hash.html";
166: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 16, 87, 0,
167: 0);
168: test(BrowserVersion.FIREFOX_2, filename, 16, 87, 0, 0);
169: }
170:
171: /**
172: * @throws Exception If test fails.
173: */
174: public void testNumber() throws Exception {
175: final String filename = "number.html";
176: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 4, 20, 0,
177: 0);
178: test(BrowserVersion.FIREFOX_2, filename, 4, 20, 0, 0);
179: }
180:
181: /**
182: * @throws Exception If test fails.
183: */
184: public void testPosition() throws Exception {
185: if (notYetImplemented()) {
186: return;
187: }
188: final String filename = "position.html";
189: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 2, 16, 0,
190: 0);
191: test(BrowserVersion.FIREFOX_2, filename, 2, 16, 0, 0);
192: }
193:
194: /**
195: * @throws Exception If test fails.
196: */
197: public void testRange() throws Exception {
198: final String filename = "range.html";
199: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 6, 21, 0,
200: 0);
201: test(BrowserVersion.FIREFOX_2, filename, 6, 21, 0, 0);
202: }
203:
204: /**
205: * @throws Exception If test fails.
206: */
207: public void testSelector() throws Exception {
208: if (notYetImplemented()) {
209: return;
210: }
211: final String filename = "selector.html";
212: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 37, 169,
213: 0, 0);
214: test(BrowserVersion.FIREFOX_2, filename, 37, 171, 0, 0);
215: }
216:
217: /**
218: * @throws Exception If test fails.
219: */
220: public void testString() throws Exception {
221: if (notYetImplemented()) {
222: return;
223: }
224: final String filename = "string.html";
225: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 40, 220,
226: 0, 0);
227: test(BrowserVersion.FIREFOX_2, filename, 40, 220, 0, 0);
228: }
229:
230: /**
231: * @throws Exception If test fails.
232: */
233: public void testUnitTests() throws Exception {
234: if (notYetImplemented()) {
235: return;
236: }
237: final String filename = "unit_tests.html";
238: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 10, 38, 0,
239: 0);
240: test(BrowserVersion.FIREFOX_2, filename, 10, 38, 0, 0);
241: }
242:
243: private void test(final BrowserVersion browserVersion,
244: final String filename, final int tests,
245: final int assertions, final int failures, final int errors)
246: throws Exception {
247: final WebClient client = new WebClient(browserVersion);
248: final URL url = getClass().getClassLoader().getResource(
249: "prototype/1.6.0/test/unit/" + filename);
250: assertNotNull(url);
251:
252: final HtmlPage page = (HtmlPage) client.getPage(url);
253: page.getEnclosingWindow().getThreadManager().joinAll(10000);
254:
255: final String summary = page.getHtmlElementById("logsummary")
256: .asText();
257: final String expected = tests + " tests, " + assertions
258: + " assertions, " + failures + " failures, " + errors
259: + " errors";
260: assertEquals(expected, summary);
261: }
262:
263: }
|