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.5.0-rc1 of
049: * <a href="http://prototype.conio.net/">Prototype JavaScript library</a>.
050: *
051: * @version $Revision: 2146 $
052: * @author Daniel Gredler
053: * @author Ahmed Ashour
054: */
055: public class Prototype150rc1Test extends WebTestCase {
056:
057: /**
058: * @param name The name of the test.
059: */
060: public Prototype150rc1Test(final String name) {
061: super (name);
062: }
063:
064: /**
065: * @throws Exception If test fails.
066: */
067: public void testAjax() throws Exception {
068: if (notYetImplemented()) {
069: return;
070: }
071: final String filename = "ajax.html";
072: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 3, 5, 2, 2);
073: test(BrowserVersion.FIREFOX_2, filename, 3, 11, 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, 12, 49, 0,
082: 0);
083: test(BrowserVersion.FIREFOX_2, filename, 12, 49, 0, 0);
084: }
085:
086: /**
087: * @throws Exception If test fails.
088: */
089: public void testBase() throws Exception {
090: final String filename = "base.html";
091: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 4, 48, 0,
092: 0);
093: test(BrowserVersion.FIREFOX_2, filename, 4, 48, 0, 0);
094: }
095:
096: /**
097: * @throws Exception If test fails.
098: */
099: public void testDom() throws Exception {
100: if (notYetImplemented()) {
101: return;
102: }
103: final String filename = "dom.html";
104: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 25, 253,
105: 1, 0);
106: test(BrowserVersion.FIREFOX_2, filename, 25, 254, 0, 0);
107: }
108:
109: /**
110: * @throws Exception If test fails.
111: */
112: public void testElementMixins() throws Exception {
113: final String filename = "element_mixins.html";
114: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 4, 7, 0, 0);
115: test(BrowserVersion.FIREFOX_2, filename, 4, 7, 0, 0);
116: }
117:
118: /**
119: * @throws Exception If test fails.
120: */
121: public void testEnumerable() throws Exception {
122: final String filename = "enumerable.html";
123: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 23, 67, 0,
124: 0);
125: test(BrowserVersion.FIREFOX_2, filename, 23, 67, 0, 0);
126: }
127:
128: /**
129: * @throws Exception If test fails.
130: */
131: public void testForm() throws Exception {
132: if (notYetImplemented()) {
133: return;
134: }
135: final String filename = "form.html";
136: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 4, 21, 0,
137: 0);
138: test(BrowserVersion.FIREFOX_2, filename, 4, 21, 0, 0);
139: }
140:
141: /**
142: * Blocked by Rhino bug 370279
143: * https://bugzilla.mozilla.org/show_bug.cgi?id=370279
144: * @throws Exception If test fails.
145: */
146: public void testHash() throws Exception {
147: final String filename = "hash.html";
148: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 5, 19, 0,
149: 0);
150: test(BrowserVersion.FIREFOX_2, filename, 5, 19, 0, 0);
151: }
152:
153: /**
154: * @throws Exception If test fails.
155: */
156: public void testPosition() throws Exception {
157: if (notYetImplemented()) {
158: return;
159: }
160: final String filename = "position.html";
161: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 5, 25, 3,
162: 0);
163: test(BrowserVersion.FIREFOX_2, filename, 5, 28, 0, 0);
164: }
165:
166: /**
167: * @throws Exception If test fails.
168: */
169: public void testRange() throws Exception {
170: final String filename = "range.html";
171: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 6, 21, 0,
172: 0);
173: test(BrowserVersion.FIREFOX_2, filename, 6, 21, 0, 0);
174: }
175:
176: /**
177: * @throws Exception If test fails.
178: */
179: public void testSelector() throws Exception {
180: final String filename = "selector.html";
181: //HtmlUnit with IE succeeds for all :)
182: // It should be test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 18, 35, 9, 1);
183: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 18, 46, 0,
184: 0);
185: test(BrowserVersion.FIREFOX_2, filename, 18, 46, 0, 0);
186: }
187:
188: /**
189: * Blocked by Rhino bug 369860
190: * https://bugzilla.mozilla.org/show_bug.cgi?id=369860
191: * @throws Exception If test fails.
192: */
193: public void testString() throws Exception {
194: if (notYetImplemented()) {
195: return;
196: }
197: final String filename = "string.html";
198: test(BrowserVersion.INTERNET_EXPLORER_7_0, filename, 19, 76, 0,
199: 0);
200: test(BrowserVersion.FIREFOX_2, filename, 19, 76, 0, 0);
201: }
202:
203: private void test(final BrowserVersion browserVersion,
204: final String filename, final int tests,
205: final int assertions, final int failures, final int errors)
206: throws Exception {
207: final WebClient client = new WebClient(browserVersion);
208: final URL url = getClass().getClassLoader().getResource(
209: "prototype/1.5.0-rc1/test/unit/" + filename);
210: assertNotNull(url);
211:
212: final HtmlPage page = (HtmlPage) client.getPage(url);
213: page.getEnclosingWindow().getThreadManager().joinAll(10000);
214:
215: final String summary = page.getHtmlElementById("logsummary")
216: .asText();
217: final String expected = tests + " tests, " + assertions
218: + " assertions, " + failures + " failures, " + errors
219: + " errors";
220: assertEquals(expected, summary);
221: }
222:
223: }
|