jenkins-htmlunit-2.6-jenkins-6/0000775000175000017500000000000011650253660017146 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/pom.xml0000664000175000017500000006615111650253660020474 0ustar jamespagejamespage 4.0.0 org.jenkins-ci htmlunit 2.6-jenkins-6 HtmlUnit Gargoyle Software Inc. http://www.GargoyleSoftware.com/ jar A headless browser intended for use in testing web-based applications. http://htmlunit.sourceforge.net UTF-8 org.apache.maven.plugins maven-compiler-plugin 2.0.2 1.5 1.5 **/CodeChecker.java org.apache.maven.plugins maven-checkstyle-plugin 2.3 checkstyle.xml checkstyle_suppressions.xml true true true org.apache.maven.plugins maven-jar-plugin 2.2 true true org.apache.maven.plugins maven-site-plugin 2.0.1 ${basedir}/src/site/maven-site.vm org.apache.maven.plugins maven-assembly-plugin 2.2-beta-4 make-assembly package single ${basedir}/src/assembly/bin-distribution.xml ${basedir}/src/assembly/src-distribution.xml org.apache.maven.plugins maven-source-plugin 2.0.4 attach-sources jar maven-antrun-plugin 1.3 moveFiles package run without-library-tests withoutLibs org.apache.maven.plugins maven-surefire-plugin 2.4.3 **/libraries/*.java -Xmx512m -Xms128m htmlunit.webdriver src/test/resources **/applets/**/*.* **/com/**/*.* **/objects/**/*.* **/pjl-comp-filter/**/*.* **/testfiles/**/*.* *.* with-library-tests true org.apache.maven.plugins maven-surefire-plugin 2.4.3 -Xmx512m -Xms128m htmlunit.webdriver org.apache.maven.plugins maven-javadoc-plugin 2.6 com.gargoylesoftware.htmlunit.javascript:com.gargoylesoftware.htmlunit.protocol:com.gargoylesoftware.htmlunit.ssl:com.gargoylesoftware.htmlunit.html.xpath:com.gargoylesoftware.htmlunit.html.applets:com.gargoylesoftware.htmlunit.html.impl http://java.sun.com/j2se/1.5.0/docs/api/ http://commons.apache.org/logging/apidocs/ http://commons.apache.org/codec/apidocs/ http://hc.apache.org/httpclient-3.x/apidocs/ maven org.apache.maven.plugins maven-jxr-plugin org.apache.maven.plugins maven-pmd-plugin 1.5 org.apache.maven.plugins maven-changelog-plugin org.apache.maven.plugins maven-changes-plugin 2.1 changes-report http://sourceforge.net/support/tracker.php?aid=%ISSUE% org.codehaus.mojo jdepend-maven-plugin org.apache.maven.plugins maven-surefire-report-plugin 2.4.2 false sourceforge http://sourceforge.net/tracker/?group_id=47038 2002 Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo scm:svn:https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit scm:svn:https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit http://htmlunit.svn.sourceforge.net/viewvc/htmlunit Cruise Control http://build.canoo.com/htmlunit HtmlUnit Users http://lists.sourceforge.net/lists/listinfo/htmlunit-user http://lists.sourceforge.net/lists/listinfo/htmlunit-user http://lists.sourceforge.net/lists/listinfo/htmlunit-user htmlunit-user@lists.sourceforge.net http://www.nabble.com/HtmlUnit---General-f2599.html http://htmlunit.markmail.org/ http://marc.info/?l=htmlunit-user HtmlUnit Developers http://lists.sourceforge.net/lists/listinfo/htmlunit-develop http://lists.sourceforge.net/lists/listinfo/htmlunit-develop http://lists.sourceforge.net/lists/listinfo/htmlunit-develop htmlunit-develop@lists.sourceforge.net http://www.nabble.com/HtmlUnit---Dev-f2598.html http://htmlunit.markmail.org/ http://marc.info/?l=htmlunit-develop Mike Bowler mbowler mbowler@GargoyleSoftware.com Gargoyle Software Inc. http://www.sphericalimprovement.com/blogs/mbowler/ -5 David K. Taylor dktaylor Brad Clarke bradclarke bradclarke@users.sourceforge.net http://www.bradclarke.com/ -6 Marc Guillemot mguillem mguillem@users.sourceforge.net http://mguillem.wordpress.com/ +1 Chris Erskine cerskine cerskine@users.sourceforge.net -7 Daniel Gredler sdanig sdanig@users.sourceforge.net http://daniel.gredler.net/ -5 Ahmed Ashour asashour asashour@users.sourceforge.net http://asashour.blogspot.com/ +3 Sudhan Moghe sudhan_moghe sudhan_moghe@users.sourceforge.net +5.5 Noboru Sinohara Mike J. Bresnahan gudujarlson@sf.net Dominique Broeglin Alex Nikiforoff Barnaby Court Andreas Hangler Jun Chen chen_jun@users.sourceforge.net Christian Sell cse@dynabean.de Darrell DeBoer David D. Kilzer Ben Curren bcurren@esomnie.com Mike Williams Mike Gallaher Dierk Koenig Mike Bresnahan Sergey Gorelkin Chris Eldredge Hans Donner Michael Ottati George Murnock Kent Tong Alfred Nathaniel Bruce Faulkner Ray Suliteanu Denis N. Antonioli Stefan Anzinger Lothar Märkle Ian Lovejoy Paul King Vikram Shitole Mark van Leeuwen Brad Murray Julien Henry Andre Soereng Karel Kolman Bruce Chapman Kristian Muntau Sam Hough Deryk Sinotte Martin Tamme Philip Graf Rodney Gitzel Matt Ryall Rob Di Marco Gareth Davis David Bylsma Dmitri Zoubkov Stuart Begg Rene Schwietzke Ethan Glasser-Camp Marco Cova Mike Dirolf Mirko Friedenhagen xalan xalan 2.7.1 xerces xercesImpl commons-collections commons-collections 3.2.1 commons-lang commons-lang 2.4 commons-httpclient commons-httpclient 3.1 commons-codec commons-codec 1.4 org.jvnet.hudson htmlunit-core-js 2.6-hudson-1 xerces xercesImpl 2.9.1 net.sourceforge.nekohtml nekohtml 1.9.13 xerces xercesImpl net.sourceforge.cssparser cssparser 0.9.5 commons-io commons-io 1.4 commons-logging commons-logging 1.1.1 junit junit 4.7 test gsbase gsbase 2.0.1 test org.easymock easymock 2.5.1 test log4j log4j 1.2.14 test commons-fileupload commons-fileupload 1.2.1 test org.mortbay.jetty jetty 6.1.20 test org.slf4j slf4j-api 1.5.8 test org.slf4j slf4j-log4j12 1.5.8 test jfree jfreechart 1.0.12 test net.sourceforge.htmlunit webdriver 2.6 test net.sourceforge.htmlunit htmlunit org.seleniumhq.webdriver webdriver-firefox 0.9.7089 test org.seleniumhq.webdriver webdriver-ie 0.9.7089 test com.sun.jna jna maven.jenkins-ci.org http://maven.jenkins-ci.org:8081/content/repositories/releases jenkins-htmlunit-2.6-jenkins-6/src/0000775000175000017500000000000011650253660017735 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/assembly/0000775000175000017500000000000011650253660021554 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/assembly/bin-distribution.xml0000664000175000017500000000167611650253660025575 0ustar jamespagejamespage zip LICENSE.txt ${basedir}/target/${project.artifactId}-${project.version}.${project.packaging} /lib ${basedir}/target/site/apidocs /apidocs /lib jenkins-htmlunit-2.6-jenkins-6/src/assembly/src-distribution.xml0000664000175000017500000000144211650253660025603 0ustar jamespagejamespage src zip LICENSE.txt checkstyle.xml checkstyle_suppressions.xml pom.xml ${basedir}/src /src jenkins-htmlunit-2.6-jenkins-6/src/site/0000775000175000017500000000000011650253660020701 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/site/apt/0000775000175000017500000000000011650253660021465 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/site/xdoc/0000775000175000017500000000000011650253660021636 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/site/xdoc/codingConventions.xml0000664000175000017500000001627011650253660026057 0ustar jamespagejamespage HtmlUnit Coding Conventions Mike Bowler $Revision: 4314 $

This page outlines the coding conventions used in HtmlUnit. If you wish to contribute code to this project then the code will be expected to follow these conventions.

The purpose of having common coding conventions is to make the code easier to understand and therefore more easily maintained. I have worked on far too many projects where over time the code became brittle or difficult to maintain. The conventions in this document are the best practices that I have adopted over time to keep the code easily maintainable and robust.

We use checkstyle to check as many coding conventions as possible. Things covered by checkstyle are only documented below if we feel that they require explanation. You can run checkstyle with the following target: mvn checkstyle:checkstyle

All code must have 100% automated test coverage using the JUnit testing framework. It is strongly suggested that you write the code test-first but it is fine as long as there are full tests for everything. Run the tests with the following target: mvn test

Abbreviations obscure meaning and therefore they are not to be used in variable/method names. If you saw the following code, would you have any idea what it was doing?

cob.getTrh()

I didn't either - this was code that I have had to maintain..

There are some abbreviations that are so common that it doesn't make sense to exclude them. The following list contains all those abbreviations that are allowed. If it isn't in this list, it isn't allowed.

Abbreviation Description Comments
Util Utility Used only in class names. i.e. StringUtil
e Exception Used only in catch blocks. i.e. catch( MyException e )
i Loop variable

How do you add an abbreviation to the list? Bring it up on the mailing list and if none of the other maintainers object to it then it gets added.

The final keyword should be used wherever possible. It provides information to the compiler about your intended use of the code. This allows the compiler to generate move efficient code and identify potential errors.

Declare a variable to be final to indicate that it will only be assigned a value once. Final instance variables must have been given a value by the end of the last constructor. Final static variables must have been given a value by the end of the last static block. Final local variables must have been given a value before being used. private final int fooCount = 12;

Declare method parameters method final to indicate that they will not be changed. public void setFooList(final List fooList) {

Declare a method final to indicate that it may not be overridden public final int getFooCount() {

Declare a class final to indicate that it may not be subclassed public final class FooCounter {

Use fully qualified import statements not wildcards. In other words, use

import java.util.List; import java.util.ArrayList;

Instead of

import java.util.*;

Fully qualified import statements make it much easier to maintain the source. When I'm trying to learn someone else's code, one of the first things I do is expand all the .* imports so that I can figure out what class came from where. If they're already expanded then it makes it much easier to understand the code.

A common complaint about this convention is "how will I know if an import isn't needed anymore?". The answer is, use a tool that warns you about this. Eclipse and IDEA can be configured to warn you about unused imports. If your editor doesn't perform this check then the maven build will check it for you.

Indent by using spaces, not tabs. Indent four (4) spaces at a time.

From time to time code needs to be removed from public APIs. When possible we will deprecate the existing API (using the javadoc @deprecated tag). Code deprecated in this way should be left in the source for at least 6 months and at least 2 releases, meaning the time could be longer than 6 months if there are not 2 releases in a 6 month period but never less than 6 months. When deprecation is not possible a change log message containing "INCOMPATIBLE CHANGE" should be added to make these changes easy to find.

jenkins-htmlunit-2.6-jenkins-6/src/site/xdoc/gettingStarted.xml0000664000175000017500000001430011650253660025346 0ustar jamespagejamespage Getting Started with HtmlUnit Mike Bowler $Revision: 4314 $

The dependencies page lists all the jars that you will need to have in your classpath.

The class com.gargoylesoftware.htmlunit.WebClient is the main starting point. This simulates a web browser and will be used to execute all of the tests.

Most unit testing will be done within a framework like JUnit so all the examples here will assume that we are using that.

In the first sample, we create the web client and have it load the homepage from the HtmlUnit website. We then verify that this page has the correct title. Note that getPage() can return different types of pages based on the content type of the returned data. In this case we are expecting a content type of text/html so we cast the result to an com.gargoylesoftware.htmlunit.html.HtmlPage.

Often you will want to simulate a specific browser. This is done by passing a com.gargoylesoftware.htmlunit.BrowserVersion into the WebClient constructor. Constants have been provided for some common browsers but you can create your own specific version by instantiating a BrowserVersion.

Specifying this BrowserVersion will change the user agent header that is sent up to the server and will change the behavior of some of the JavaScript.

Once you have a reference to an HtmlPage, you can search for a specific HtmlElement by one of 'get' methods, or by using XPath.

Below is an example of finding a 'div' by an ID, and getting an anchor by name:

XPath is a suggested way for more complex searches, a brief tutorial can be found in W3Schools

divs = page.getByXPath("//div"); //get div which has a 'name' attribute of 'John' final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@name='John']").get(0); }]]>

The last WebClient constructor allows you to specify proxy server information in those cases where you need to connect through one.

Specifying this BrowserVersion will change the user agent header that is sent up to the server and will change the behavior of some of the JavaScript.

Frequently we want to change values in a form and submit the form back to the server. The following example shows how you might do this.

jenkins-htmlunit-2.6-jenkins-6/src/site/xdoc/professionalSupport.xml0000664000175000017500000000530611650253660026465 0ustar jamespagejamespage Professional support Marc Guillemot $Revision: 3198 $

Some HtmlUnit committers provide professional support beyond the free support provided on a volunteer basis by users and project members on HtmlUnit's mailing lists.

Marc Guillemot
Committer since 2004
Contact http://www.efficient-webtesting.com
Location Bornheim, Germany
Involvement in related projects committer to NekoHTML, contributor to Rhino
Involvement in other Open Source projects committer to Groovy and Canoo WebTest

Daniel Gredler
Committer since 2006
Contact sdanig at users.sourceforge.net
Location Atlanta, USA
Involvement in related projects committer to CSSParser, contributor to Rhino
Involvement in other Open Source projects committer to Tapestry
jenkins-htmlunit-2.6-jenkins-6/src/site/xdoc/frame-howto.xml0000664000175000017500000000410611650253660024611 0ustar jamespagejamespage Frames Tutorial Ahmed Ashour $Revision: 4314 $

Getting the page inside <frame> element or <iframe> element can be done by using HtmlPage.getFrames().
Suppose you have the following page:

\n" + ""; final List collectedAlerts = new ArrayList(); final String[] expectedAlerts = {"true", "true", "true"}; loadPage(content, collectedAlerts); createTestPageForRealBrowserIfNeeded(content, expectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Regression test to reproduce a known bug. * @throws Exception if the test fails */ @Test public void openWindow_emptyUrl() throws Exception { final String content = "\n" + ""; final String[] expectedAlerts = {"about:blank"}; final List collectedAlerts = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, content, collectedAlerts); createTestPageForRealBrowserIfNeeded(content, expectedAlerts); assertEquals(expectedAlerts, collectedAlerts); collectedAlerts.clear(); loadPage(BrowserVersion.INTERNET_EXPLORER_6, content, collectedAlerts); createTestPageForRealBrowserIfNeeded(content, expectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Verifies that window.open behaves correctly when popups are blocked. * @throws Exception if an error occurs */ @Test public void openWindow_blocked() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "
test
\n" + ""; final List actual = new ArrayList(); final WebClient client = new WebClient(); client.setPopupBlockerEnabled(true); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(html); client.setWebConnection(webConnection); final HtmlPage page = client.getPage("http://foo"); ((HtmlDivision) page.getHtmlElementById("d")).click(); final String[] expected = {"null"}; assertEquals(expected, actual); } /** * Regression test to reproduce a known bug. * @throws Exception if the test fails */ @Test public void alert_NoAlertHandler() throws Exception { final String firstContent = "First\n" + ""; LOG.warn("Warning for no alert handler expected next"); final HtmlPage firstPage = loadPage(firstContent); assertEquals("First", firstPage.getTitleText()); } /** * @throws Exception if the test fails */ @Test public void parentAndTop() throws Exception { final String firstContent = "First\n" + " \n" + ""; final String iframe = "\n" + "\n" + ""; final WebClient webClient = new WebClient(); final List collectedAlerts = new ArrayList(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, content); webConnection.setDefaultResponse(iframe); webClient.setWebConnection(webConnection); webClient.getPage(URL_FIRST); final String[] expectedAlerts = {"1"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Regression test for [ 1608555 ] JavaScript: window.eval does evaluate local scope. * See https://sourceforge.net/tracker/index.php?func=detail&aid=1608555&group_id=47038&atid=448266. * @throws Exception if the test fails */ @Test public void evalScopeLocal() throws Exception { final String content = "
\n" + "\n" + ""; final String[] expectedAlerts = {"elementValue", "elementValue", "elementValue"}; createTestPageForRealBrowserIfNeeded(content, expectedAlerts); final List collectedAlerts = new ArrayList(); loadPage(content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Verifies that eval() works correctly when triggered from an event handler. Event handlers are * executed in a child scope of the global window scope, so variables set from inside eval() * should go to this child scope, and not to the window scope. * @throws Exception if the test fails */ @Test public void evalScopeEvent() throws Exception { final String html = ""; final String[] expected = {"string"}; final List actual = new ArrayList(); loadPage(html, actual); assertEquals(expected, actual); } /** * @throws Exception if the test fails */ @Test public void functionEquality() throws Exception { final String content = "\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final String[] expectedAlerts = {"true"}; loadPage(content, collectedAlerts); createTestPageForRealBrowserIfNeeded(content, expectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Test for 1225021. * @throws Exception if the test fails */ @Test public void captureEvents() throws Exception { final String content = "foo\n" + "\n" + "
foo
\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, content, collectedAlerts); page.getHtmlElementById("theDiv").click(); final String[] expectedAlerts = {"123", "captured"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void getComputedStyle() throws Exception { testGetComputedStyle(BrowserVersion.FIREFOX_2); try { testGetComputedStyle(BrowserVersion.INTERNET_EXPLORER_6); fail("'getComputedStyle' is not defined for IE"); } catch (final Exception e) { //expected } } private void testGetComputedStyle(final BrowserVersion browserVersion) throws Exception { final String content = "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + ""; final String[] expectedAlerts = {"rgb(0, 0, 0)"}; final List collectedAlerts = new ArrayList(); loadPage(browserVersion, content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if an error occurs */ @Test public void getComputedStyle_WithComputedColor() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
foo bar
\n" + " \n" + ""; final String[] expectedAlerts = {"red"}; final List collectedAlerts = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Verifies that the onload handler is executed with "this" referring to the window. * * @throws Exception if an error occurs */ @Test public void onLoadContext() throws Exception { final String html = ""; final List collectedAlerts = new ArrayList(); loadPage(html, collectedAlerts); final String[] expectedAlerts = {"true"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Added test for [ 1727599 ] Bad context in evaluation of the JavaScript. * @throws Exception if the test fails */ @Test public void eval() throws Exception { final String content = "\n" + "\n" + "\n" + ""; final String[] expectedAlerts = {"INPUT"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(content, collectedAlerts); page.getHtmlElementById("myButton").click(); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void undefinedProperty() throws Exception { final String content = "foo\n" + ""; final String[] expectedAlerts = {"undefined", "undefined", "true"}; final List collectedAlerts = new ArrayList(); loadPage(content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if an error occurs */ @Test public void frames() throws Exception { final String framesetContent = "First\n" + "\n" + " \n" + " \n" + "\n" + ""; final String frameContent = "TopFrame\n" + "\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final WebClient webClient = new WebClient(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, framesetContent); webConnection.setResponse(URL_SECOND, frameContent); webClient.setWebConnection(webConnection); webClient.getPage(URL_FIRST); } /** * Verifies that this.arguments works from within a method invocation, in a * function defined on the Function prototype object. This usage is required by the * Ajax.NET Professional JavaScript library. * * @throws Exception if an error occurs */ @Test public void functionPrototypeArguments() throws Exception { if (notYetImplemented()) { return; } final String html = "\n" + "\n" + "\n" + "\n" + ""; final List actual = new ArrayList(); loadPage(html, actual); final String[] expected = {"true", "2"}; assertEquals(expected, actual); } /** * @throws Exception if the test fails */ @Test public void openWindow_numericName() throws Exception { final String html = "\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final String[] expectedAlerts = {"true"}; loadPage(html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PopupTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/PopupTest0000664000175000017500000000631211650253660034656 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import static org.junit.Assert.assertSame; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link Popup}. * * @version $Revision: 4463 $ * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class PopupTest extends WebTestCase { /** * Just test that a standard use of popup works without exception. * @throws Exception if the test fails * TODO: it should fail when simulating FF as createPopup() is only for IE */ @Test @Browsers(Browser.IE) public void testPopup() throws Exception { final String html = "First\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Test that the opened window becomes the current one. * @throws Exception if the test fails */ @Test public void testPopupWindowBecomesCurrent() throws Exception { final String content = "First\n" + "Push me\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), content, collectedAlerts); final HtmlElement button = page.getHtmlElementById("button"); final HtmlPage secondPage = button.click(); final String[] expectedAlerts = {"Pop-up window is Open"}; assertEquals(expectedAlerts, collectedAlerts); assertEquals("about:blank", secondPage.getWebResponse().getRequestSettings().getUrl()); assertSame(secondPage.getEnclosingWindow(), secondPage.getWebClient().getCurrentWindow()); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleSheetListTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleShee0000664000175000017500000001456511650253660034631 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import java.util.ArrayList; import java.util.List; import org.apache.commons.httpclient.NameValuePair; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Unit tests for {@link StyleSheetList}. * * @version $Revision: 4002 $ * @author Daniel Gredler * @author Ahmed Ashour * @author Marc Guillemot */ public class StyleSheetListTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test public void testLength() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final List actual = new ArrayList(); loadPage(html, actual); final String[] expected = {"4"}; assertEquals(expected, actual); } /** * @throws Exception if an error occurs */ @Test public void testGetComputedStyle_Link() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
\n" + "
\n" + " \n" + ""; final String css = "div {color:red}"; final String[] expectedAlerts = {"red", "red"}; final List collectedAlerts = new ArrayList(); final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); webConnection.setResponse(URL_SECOND, css, "text/css"); webClient.setWebConnection(webConnection); webClient.getPage(URL_FIRST); assertEquals(expectedAlerts, collectedAlerts); assertEquals(2, webConnection.getRequestCount()); } /** * @throws Exception if an error occurs */ @Test public void testArrayIndexOutOfBoundAccess() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final String[] expectedAlerts = {"0", "undefined", "undefined", "exception for -2"}; createTestPageForRealBrowserIfNeeded(html, expectedAlerts); final List actual = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, html, actual); assertEquals(expectedAlerts, actual); } /** * Test for a stylesheet link which points to a non-existent file (bug 2070940). * @throws Exception if an error occurs */ @Test public void testNonExistentStylesheet() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " abc\n" + ""; final WebClient client = new WebClient(); final List actual = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection conn = new MockWebConnection(); conn.setDefaultResponse(html); conn.setResponse(URL_SECOND, "Not Found", 404, "Not Found", "text/html", new ArrayList()); client.setWebConnection(conn); client.getPage(URL_FIRST); final String[] expected = new String[] {"1", "[object]", "[object]"}; assertEquals(expected, actual); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTe0000664000175000017500000010073011650253660034574 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; /** * Tests for {@link Element}. * * @version $Revision: 4731 $ * @author Ahmed Ashour * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class ElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "true", "1", "attrName attrValue", "attrValue", "null", "anotherValue", "1", "4", "changed" }) public void attributes() throws Exception { final String html = "foo\n" + ""; final String xml = "\n" + " \n" + " Immortality\n" + " John Smith\n" + " changed]]>\n" + " \n" + ""; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "true", "1", "title" }) public void selectNodes() throws Exception { final String html = "foo\n" + ""; final String xml = "\n" + " \n" + " Immortality\n" + " John Smith\n" + " \n" + ""; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "true", "2", "1" }) public void removeChild() throws Exception { final String html = "foo\n" + ""; final String xml = "ImmortalityJohn Smith"; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "lbl_SettingName", "outerHTML", "Item" }, FF = { "lbl_SettingName", "outerHTML", "undefined" }) public void getAttributeNode() throws Exception { final String html = "foo\n" + "
\n" + ""; final String xml = "\n" + " \n" + " Item\n" + " \n" + ""; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "book", "0", "1" }) public void selectNode_root() throws Exception { final String html = "foo\n" + ""; final String xml = "ImmortalityJohn Smith"; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "1", "1" }) public void getElementsByTagNameNS() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts("false") public void hasAttribute() throws Exception { final String html = "foo\n" + ""; final String xml = "\n" + " \n" + " Immortality\n" + " John Smith\n" + " \n" + ""; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("true") public void attributes2() throws Exception { final String html = "foo\n" + ""; final String xml = "\n" + " \n" + " Immortality\n" + " John Smith\n" + " \n" + ""; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "e\r\n", "e" }, FF = { "undefined", "undefined" }) public void xml() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],DIV", "[object],APP:DIV", "createElementNS() is not defined", "[object],DIV", "[object],APP:DIV" }, FF = {"[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object Element],app:dIv", "[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV" }) public void html_nodeName() throws Exception { html("nodeName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],DIV", "[object],APP:DIV", "createElementNS() is not defined", "[object],DIV", "[object],APP:DIV" }, FF = {"[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object Element],app:dIv", "[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV" }) public void html_tagName() throws Exception { html("tagName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],undefined", "[object],undefined", "createElementNS() is not defined", "[object],undefined", "[object],undefined" }, FF = {"[object HTMLDivElement],null", "[object HTMLUnknownElement],null", "[object Element],app", "[object HTMLDivElement],null", "[object HTMLUnknownElement],null" }) public void html_prefix() throws Exception { html("prefix"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],undefined", "[object],undefined", "createElementNS() is not defined", "[object],undefined", "[object],undefined" }, FF = {"[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object Element],dIv", "[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV" }) public void html_localName() throws Exception { html("localName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],undefined", "[object],undefined", "createElementNS() is not defined", "[object],undefined", "[object],undefined" }, FF = {"[object HTMLDivElement],null", "[object HTMLUnknownElement],null", "[object Element],http://www.appcelerator.org", "[object HTMLDivElement],null", "[object HTMLUnknownElement],null" }) public void html_namespaceURI() throws Exception { html("namespaceURI"); } private void html(final String methodName) throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
\n" + "alert(2)\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],DIV", "[object],dIv", "[object],ANOTHER:DIV", "createElementNS() is not defined", "[object],DIV", "[object],dIv", "[object],ANOTHER:DIV" }, FF = {"[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object HTMLUnknownElement],ANOTHER:DIV", "[object Element],app:dIv", "[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object HTMLUnknownElement],ANOTHER:DIV" }) public void namespace_nodeName() throws Exception { namespace("nodeName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],DIV", "[object],dIv", "[object],ANOTHER:DIV", "createElementNS() is not defined", "[object],DIV", "[object],dIv", "[object],ANOTHER:DIV" }, FF = {"[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object HTMLUnknownElement],ANOTHER:DIV", "[object Element],app:dIv", "[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object HTMLUnknownElement],ANOTHER:DIV" }) public void namespace_tagName() throws Exception { namespace("tagName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],undefined", "[object],undefined", "[object],undefined", "createElementNS() is not defined", "[object],undefined", "[object],undefined", "[object],undefined" }, FF = {"[object HTMLDivElement],null", "[object HTMLUnknownElement],null", "[object HTMLUnknownElement],null", "[object Element],app", "[object HTMLDivElement],null", "[object HTMLUnknownElement],null", "[object HTMLUnknownElement],null" }) public void namespace_prefix() throws Exception { namespace("prefix"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],undefined", "[object],undefined", "[object],undefined", "createElementNS() is not defined", "[object],undefined", "[object],undefined", "[object],undefined" }, FF = {"[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object HTMLUnknownElement],ANOTHER:DIV", "[object Element],dIv", "[object HTMLDivElement],DIV", "[object HTMLUnknownElement],APP:DIV", "[object HTMLUnknownElement],ANOTHER:DIV" }) public void namespace_localName() throws Exception { namespace("localName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object],undefined", "[object],undefined", "[object],undefined", "createElementNS() is not defined", "[object],undefined", "[object],undefined", "[object],undefined" }, FF = {"[object HTMLDivElement],null", "[object HTMLUnknownElement],null", "[object HTMLUnknownElement],null", "[object Element],http://www.appcelerator.org", "[object HTMLDivElement],null", "[object HTMLUnknownElement],null", "[object HTMLUnknownElement],null" }) public void namespace_namespaceURI() throws Exception { namespace("namespaceURI"); } private void namespace(final String methodName) throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object]", "dIv", "[object]", "html", "[object]", "div", "[object]", "dIv" }, FF = {"[object Element]", "dIv", "[object HTMLHtmlElement]", "html", "[object HTMLDivElement]", "div", "[object HTMLUnknownElement]", "dIv" }) public void xml_nodeName() throws Exception { xml("nodeName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object]", "dIv", "[object]", "html", "[object]", "div", "[object]", "dIv" }, FF = {"[object Element]", "dIv", "[object HTMLHtmlElement]", "html", "[object HTMLDivElement]", "div", "[object HTMLUnknownElement]", "dIv" }) public void xml_tagName() throws Exception { xml("tagName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object]", "", "[object]", "", "[object]", "", "[object]", "" }, FF = {"[object Element]", "null", "[object HTMLHtmlElement]", "null", "[object HTMLDivElement]", "null", "[object HTMLUnknownElement]", "null" }) public void xml_prefix() throws Exception { xml("prefix"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object]", "undefined", "[object]", "undefined", "[object]", "undefined", "[object]", "undefined" }, FF = {"[object Element]", "dIv", "[object HTMLHtmlElement]", "html", "[object HTMLDivElement]", "div", "[object HTMLUnknownElement]", "dIv" }) public void xml_localName() throws Exception { xml("localName"); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = {"[object]", "", "[object]", "http://www.w3.org/1999/xhtml", "[object]", "http://www.w3.org/1999/xhtml", "[object]", "http://www.w3.org/1999/xhtml" }, FF = {"[object Element]", "null", "[object HTMLHtmlElement]", "http://www.w3.org/1999/xhtml", "[object HTMLDivElement]", "http://www.w3.org/1999/xhtml", "[object HTMLUnknownElement]", "http://www.w3.org/1999/xhtml" }) public void xml_namespaceURI() throws Exception { xml("namespaceURI"); } private void xml(final String methodName) throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final String xml = "" + "
" + "" + "
" + "
" + "" + "
"; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "button", "getAttributeNS() not supported" }, FF = { "button", "", "false", "true" }) public void attributeNS() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF2) @Alerts(IE = "exception occured", FF2 = { "prototype found", "QueryInterface" }, FF3 = { "prototype found", "" }) public void enumeratedProperties() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("finished") public void removeAttribute() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final String xml = "\n" + " \n" + " Immortality\n" + " John Smith\n" + " \n" + ""; getMockWebConnection().setDefaultResponse(xml, "text/xml"); loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/OfflineResourceListTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/OfflineRe0000664000175000017500000000272211650253660034565 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link OfflineResourceList}. * * @version $Revision: 4772 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class OfflineResourceListTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(IE = "undefined", FF2 = "undefined", FF3 = "[object OfflineResourceList]") public void existence() throws Exception { final String html = ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventNodeTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventNode0000664000175000017500000000344611650253660034607 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; /** * Tests for {@link EventNode}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class EventNodeTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts("true") public void fireEvent() throws Exception { final String html = "\n" + "\n" + "\n" + "
\n" + "
\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NodeTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NodeTest.0000664000175000017500000011276111650253660034524 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import static org.junit.Assert.assertNotNull; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link Node}. * * @version $Revision: 4900 $ * @author Brad Clarke * @author George Murnock * @author Bruce Faulkner * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class NodeTest extends WebTestCase { /** * @throws Exception on test failure */ @Test @Alerts("true") public void test_hasChildNodes_true() throws Exception { final String html = "test_hasChildNodes\n" + "\n" + "\n" + "

hello worldChild Node

\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts("false") public void test_hasChildNodes_false() throws Exception { final String html = "test_hasChildNodes\n" + "\n" + "\n" + "

\n" + ""; loadPageWithAlerts(html); } /** * Regression test for removeChild. * @throws Exception if the test fails */ @Test @Alerts({ "true", "true" }) public void testRemoveChild() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Regression test for replaceChild. * @throws Exception if the test fails */ @Test @Alerts({ "true", "true", "true" }) public void testReplaceChild_Normal() throws Exception { final String html = "foo\n" + "
\n" + "
"; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test public void testReplaceChild_WithSameNode() throws Exception { final String html = "foo
"; final HtmlPage page = loadPageWithAlerts(html); assertNotNull(page.getHtmlElementById("b").getParentNode()); } /** * The common browsers always return node names in uppercase. Test this. * @throws Exception on test failure */ @Test @Alerts("DIV") public void testNodeNameIsUppercase() throws Exception { final String html = "\n" + "\n" + "\n" + "
hello worldChild Node
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts({ "2", "SPAN", "2", "#text", "H1", "H2" }) public void test_getChildNodes() throws Exception { final String html = "\n" + "\n" + "\n" + "
Child Node 1-A" + "

Child Node 1-B

" + "

Child Node 2-A

\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts({ "nb nodes: 2", "8", "1" }) public void testChildNodes_Comments() throws Exception { final String html = "test\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts({ "length: 5", "tempNode.name: undefined", "tempNode.name: input1", "tempNode.name: undefined", "tempNode.name: input2", "tempNode.name: undefined" }) public void test_getChildNodesProperties() throws Exception { final String html = "test_getChildNodes\n" + "\n" + "\n" + "
foo\n" // some text, because IE doesn't see "\n" as a text node here + "\n" + "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Regression test to verify that insertBefore correctly appends * the new child object when the reference child object is null. * @throws Exception if the test fails */ @Test @Alerts({ "3", "H2" }) public void test_insertBefore_nullRef() throws Exception { test_insertBefore("aNode.insertBefore(nodeToInsert, null);"); } /** * Regression test to verify that insertBefore correctly appends * the new child object when the reference child object is null. * @throws Exception if the test fails */ @Test @Alerts(FF = "exception", IE = { "3", "H2" }) public void test_insertBefore_noSecondArg() throws Exception { test_insertBefore("aNode.insertBefore(nodeToInsert);"); } /** * @throws Exception if the test fails */ void test_insertBefore(final String insertJSLine) throws Exception { final String html = "test_insertBefore\n" + "\n" + "\n" + "

Bottom

\n" + "
Child Node 1-A" + "

Child Node 2-A

\n" + ""; loadPageWithAlerts(html); } /** * The common browsers always return node names in uppercase. Test this. * @throws Exception on test failure */ @Test @Alerts({ "document: 9", "document.body: 1", "body child 1: 3", "body child 2: 8" }) public void testNodeType() throws Exception { final String html = "test\n" + "\n" + "\n" + "some text\n" + ""; loadPageWithAlerts(html); } /** * Test for bug 1716129. * @throws Exception on test failure */ @Test @Browsers(Browser.IE) public void testAttachEvent() throws Exception { final String html = "\n" + "First\n" + "\n" + "
bla
\n" + ""; final String[] expectedAlerts = {"in foo1", "in foo2"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); page.getHtmlElementById("div1").click(); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "true", "false" }, IE = { "isSameNode not supported" }) public void testIsSameNode() throws Exception { final String html = "foo\n" + "
\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test element.appendChild: If the parent has a null parentNode, * IE creates a DocumentFragment be the parent's parentNode. * * @throws Exception if the test fails */ @Test @Alerts(FF = { "null", "null" }, IE = { "null", "#document-fragment" }) public void testAppendChild_parentNode() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * Test element.appendChild: If the parent has a null parentNode, * IE creates a DocumentFragment be the parent's parentNode. * * @throws Exception if the test fails */ @Test @Alerts(FF = { "null", "null" }, IE = { "null", "#document-fragment" }) public void testInsertBefore_parentNode() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("2") public void testAppendChild_of_DocumentFragment() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "3", "3", "123", "3", "123", "456", "3", "undefined" }, IE = { "undefined", "not supported" }) public void testNodePrototype() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "
", "myDiv2", "
one
two
" }, IE = { "exception thrown" }) public void testReplaceChild() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "
", "myDiv2", "
" }, IE = { "exception thrown" }) public void testReplaceChild_EmptyDocumentFragment() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) public void event() throws Exception { final String firstHtml = "\n" + "First Page\n" + "\n" + "\n" + "\n" + " \n" + "
\n" + "\n" + ""; final String secondHtml = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final String[] expectedAlerts = {"[object]", "[object]"}; final WebClient client = getWebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, firstHtml); conn.setResponse(URL_SECOND, secondHtml); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); page.getHtmlElementById("myInput").click(); assertEquals(expectedAlerts, collectedAlerts); } /** * Verifies that attributes belonging to cloned nodes are available via JavaScript. * http://sourceforge.net/tracker/index.php?func=detail&aid=2024741&group_id=47038&atid=448266 * @throws Exception if an error occurs */ @Test @Alerts("id=bar") public void testCloneAttributesAvailable() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
\n" + " \n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlElement element = page.getHtmlElementById("bar"); final String value = element.getAttribute("id"); assertEquals("bar", value); } /** * Verifies that listeners are copied only for IE. * @throws Exception if an error occurs */ @Test @Alerts(FF = "in click", IE = { "in click", "in click", "in click" }) public void testCloneNode_copiesListenerOnlyForIE() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "1", "1", "2", "4", "8", "16", "32" }, IE = { "undefined", "not supported" }) public void testDocumentPositionConstants() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "0", "20", "20", "4", "10", "10", "2", "20" }) public void compareDocumentPosition() throws Exception { final String html = "\n" + "\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLTableColElement]") public void insertBefore() throws Exception { final String html = "\n" + "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "1", "2" }) public void eventListener() throws Exception { final String html = "\n" + "\n" + " Click me\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); //IE doesn't have specific order Collections.sort(collectedAlerts); assertEquals(getExpectedAlerts(), collectedAlerts); assertEquals(URL_SECOND.toExternalForm(), page2.getWebResponse().getRequestSettings().getUrl().toExternalForm()); } /** * @throws Exception if the test fails */ @Test @Alerts({ "1", "2" }) public void eventListener_return_false() throws Exception { final String html = "\n" + "\n" + " Click me\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); //IE doesn't have specific order Collections.sort(collectedAlerts); assertEquals(getExpectedAlerts(), collectedAlerts); final URL expectedURL; if (getBrowserVersion().isIE()) { expectedURL = URL_GARGOYLE; } else { expectedURL = URL_SECOND; } assertEquals(expectedURL.toExternalForm(), page2.getWebResponse().getRequestSettings().getUrl().toExternalForm()); } /** * @throws Exception if the test fails */ @Test @Alerts({ "1", "2" }) public void eventListener_returnValue_false() throws Exception { final String html = "\n" + "\n" + " Click me\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); //IE doesn't have specific order Collections.sort(collectedAlerts); assertEquals(getExpectedAlerts(), collectedAlerts); final URL expectedURL; if (getBrowserVersion().isIE()) { expectedURL = URL_GARGOYLE; } else { expectedURL = URL_SECOND; } assertEquals(expectedURL.toExternalForm(), page2.getWebResponse().getRequestSettings().getUrl().toExternalForm()); } /** * @throws Exception if the test fails */ @Test @Alerts("bk") public void prefix() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("") public void xml() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts(IE = "exception") public void insertBefore2() throws Exception { final String html = "foo\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts(FF = "exception") public void insertBefore3() throws Exception { final String html = "foo\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SelectionTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Selection0000664000175000017500000001722711650253660034647 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.AlertHandler; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSpan; /** * Unit tests for {@link Selection}. * * @version $Revision: 4450 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class SelectionTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) @Alerts(IE = "true") public void equality_IE() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) @Alerts(FF = "true") public void equality_FF() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void stringValue_FF() throws Exception { test("", "selection", "x", "", "cx"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void stringValue_IE() throws Exception { test("", "selection", "x", "[object]", "[object]"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void anchorNode() throws Exception { test("", "selection.anchorNode", "x ? x.parentNode.id : x", "null", "s1"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void anchorOffset() throws Exception { test("", "selection.anchorOffset", "x", "0", "2"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void focusNode() throws Exception { test("", "selection.focusNode", "x ? x.parentNode.id : x", "null", "s2"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void focusOffset() throws Exception { test("", "selection.focusOffset", "x", "0", "1"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void isCollapsed() throws Exception { test("", "selection.isCollapsed", "x", "true", "false"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void rangeCount() throws Exception { test("", "selection.rangeCount", "x", "0", "1"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void rangeCount2() throws Exception { test("selection.collapseToEnd()", "selection.rangeCount", "x", "0", "1"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void collapse() throws Exception { test("selection.collapse(s1, 1)", "selection.focusNode", "x ? x.id : x", "null", "s1"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void collapseToEnd() throws Exception { test("selection.collapseToEnd()", "selection.anchorNode", "x ? x.parentNode.id : x", "null", "s2"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void collapseToStart() throws Exception { test("selection.collapseToStart()", "selection.focusNode", "x ? x.parentNode.id : x", "null", "s1"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void extend() throws Exception { test("selection.extend(s2, 2)", "selection.focusOffset", "x", "0", "2"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void selectAllChildren() throws Exception { test("selection.selectAllChildren(document.body)", "selection.anchorOffset", "x", "0", "0"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) public void getRangeAt() throws Exception { test("", "selection.rangeCount > 0 ? selection.getRangeAt(0) : 'none'", "x", "none", "cx"); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void empty() throws Exception { test("selection.empty()", "selection.type", "x", "None", "None"); } private void test(final String action, final String x, final String alert, final String... expected) throws Exception { final String html = "\n" + "abcxyzfoo\n" + "\n" + "\n" + ""; final WebClient client = getWebClient(); final MockWebConnection conn = new MockWebConnection(); conn.setDefaultResponse(html); client.setWebConnection(conn); final List actual = new ArrayList(); final AlertHandler alertHandler = new CollectingAlertHandler(actual); client.setAlertHandler(alertHandler); final HtmlPage page = client.getPage(URL_FIRST); final HtmlSpan s1 = page.getHtmlElementById("s1"); final DomNode s1Text = s1.getFirstChild(); final HtmlSpan s2 = page.getHtmlElementById("s2"); final DomNode s2Text = s2.getFirstChild(); final HtmlInput input = page.getHtmlElementById("b"); page.getSelection().setStart(s1Text, 2); page.getSelection().setEnd(s2Text, 1); input.click(); assertEquals(expected, actual); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Node2Test.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Node2Test0000664000175000017500000001027411650253660034524 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link Node}, but with WebDriver. * * @version $Revision: 4779 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class Node2Test extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "4", "3", "abc", "def", "123456", "false", "0", "2", "123", "456", "1", "false" }, FF = { "4", "3", "abc", "def", "123456", "true", "0", "2", "123", "456", "1", "true" }) public void normalize() throws Exception { final String html = "foo"; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "0", "16" }, IE = "exception") public void compareDocumentPosition() throws Exception { final String html = "foo" + ""; loadPageWithAlerts2(html); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ScreenTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ScreenTes0000664000175000017500000000606511650253660034613 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link Screen}. * * @version $Revision: 4002 $ * @author Daniel Gredler * @author Marc Guillemot * @see MSDN documentation * @see Mozilla documentation */ @RunWith(BrowserRunner.class) public class ScreenTest extends WebTestCase { /** * Test all desired properties on screen (easy to copy and test in a real browser). * @throws Exception on test failure */ @Test @Alerts("16") public void testProperties() throws Exception { final String html = "test\n" + " \n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MouseEventTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MouseEven0000664000175000017500000000747411650253660034633 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import static org.junit.Assert.assertNotNull; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlTextArea; /** * Tests for mouse events support. * * @version $Revision: 4064 $ * @author Marc Guillemot */ public class MouseEventTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testEventCoordinates() throws Exception { testEventCoordinates(BrowserVersion.FIREFOX_2); testEventCoordinates(BrowserVersion.INTERNET_EXPLORER_6); } private void testEventCoordinates(final BrowserVersion browser) throws Exception { final URL url = getClass().getClassLoader().getResource("event_coordinates.html"); assertNotNull(url); final WebClient client = new WebClient(browser); final HtmlPage page = client.getPage(url); assertEquals("Mouse Event coordinates", page.getTitleText()); final HtmlTextArea textarea = page.getHtmlElementById("myTextarea"); assertEquals("", textarea.asText()); page.getHtmlElementById("div1").click(); assertEquals("Click on DIV(id=div1): true, true, false, false" + LINE_SEPARATOR, textarea.asText()); textarea.reset(); page.getHtmlElementById("span1").click(); assertEquals("Click on SPAN(id=span1): true, true, true, false" + LINE_SEPARATOR, textarea.asText()); textarea.reset(); page.getHtmlElementById("span2").click(); assertEquals("Click on SPAN(id=span2): true, false, false, true" + LINE_SEPARATOR, textarea.asText()); textarea.reset(); textarea.click(); assertEquals("Click on TEXTAREA(id=myTextarea): true, false, false, false" + LINE_SEPARATOR, textarea.asText()); } /** * @throws Exception if an error occurs */ @Test public void testInitMouseEvent() throws Exception { final String html = ""; final List actual = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, html, actual); final String[] expected = {"click", "true", "true", "true", "0", "0", "0", "0", "true", "true", "true"}; assertEquals(expected, actual); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleSheetTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StyleShee0000664000175000017500000003536111650253660034626 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import java.io.StringReader; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.Selector; import org.w3c.dom.css.CSSStyleSheet; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlStyle; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLStyleElement; import com.steadystate.css.parser.CSSOMParser; import com.steadystate.css.parser.SACParserCSS21; /** * Unit tests for {@link Stylesheet}. * * @version $Revision: 4655 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class StyleSheetTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.NONE) public void selects_miscSelectors() throws Exception { final String html = "test\n" + "\n" + "
\n" + "
\n" + "\n" + "
\n" + "
\n" + " First Name:
\n" + " Last Name: \n" + "
\n" + ""; final String html2 = "\n" + "foo"; final String[] expected = {"undefined", "Jane", "Smith", "sdg", "finished"}; final WebClient client = getWebClient(); final List actual = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html1); conn.setResponse(new URL(URL_FIRST.toExternalForm() + "myDialog.html"), html2); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); final HtmlElement button = page.getHtmlElementById("b"); final HtmlPage dialogPage = button.click(); final DialogWindow dialog = (DialogWindow) dialogPage.getEnclosingWindow(); dialog.close(); assertEquals(expected, actual); } /** * Basic test for the showModelessDialog method. See bug 2124916. * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void showModelessDialog() throws Exception { final String html1 = "\n" + " \n" + ""; final String html2 = "\n" + " Name: \n" + ""; final String[] expected = {"[object]", "a"}; final WebClient client = getWebClient(); final List actual = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html1); conn.setResponse(new URL(URL_FIRST.toExternalForm() + "myDialog.html"), html2); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); final HtmlElement button = page.getHtmlElementById("b"); final HtmlPage dialogPage = button.click(); final HtmlInput input = dialogPage.getHtmlElementById("name"); input.setValueAttribute("a"); final HtmlButtonInput button2 = (HtmlButtonInput) dialogPage.getHtmlElementById("b"); button2.click(); assertEquals(expected, actual); } /** * Verifies that properties added to Function.prototype are visible on window.onload. * See bug 2318508. * @throws Exception if an error occurs */ @Test @Alerts({ "a", "1" }) public void onload_prototype() throws Exception { final String html = "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "SGVsbG8gV29ybGQh", "Hello World!" }) public void atob() throws Exception { final String html = "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * In {@link net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime}, Rhino defines a bunch of properties * in the top scope (see lazilyNames). Not all make sense for HtmlUnit. * @throws Exception if the test fails */ @Test @Alerts({ "RegExp: function", "javax: undefined", "org: undefined", "com: undefined", "edu: undefined", "net: undefined", "JavaAdapter: undefined", "JavaImporter: undefined", "Continuation: undefined" }) public void rhino_lazilyNames() throws Exception { final String[] properties = {"RegExp", "javax", "org", "com", "edu", "net", "JavaAdapter", "JavaImporter", "Continuation"}; doTestRhinoLazilyNames(properties); } /** * The same as in {@link #rhino_lazilyNames()} but for properties with different expectations for IE and FF. * @throws Exception if the test fails */ @Test @Alerts(FF = { "java: object", "getClass: function" }, IE = { "java: undefined", "getClass: undefined" }) public void rhino_lazilyNames2() throws Exception { final String[] properties = {"java", "getClass"}; doTestRhinoLazilyNames(properties); } /** * The same as in {@link #rhino_lazilyNames()} but for properties where it doesn't work yet. * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF) @Alerts(FF = { "Packages: object", "XML: function", "XMLList: function", "Namespace: function", "QName: function" }, IE = { "Packages: undefined", "XML: undefined", "XMLList: undefined", "Namespace: undefined", "QName: undefined" }) public void rhino_lazilyNames3() throws Exception { final String[] properties = {"Packages", "XML", "XMLList", "Namespace", "QName"}; doTestRhinoLazilyNames(properties); } private void doTestRhinoLazilyNames(final String[] properties) throws Exception { final String html = "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "undefined", "function", "3" }, IE = { "null", "function", "3" }) public void onError() throws Exception { final String html = ""; final WebClient client = getWebClient(); client.setThrowExceptionOnScriptError(false); final List actual = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_GARGOYLE, html); client.setWebConnection(conn); client.getPage(URL_GARGOYLE); assertEquals(getExpectedAlerts(), actual); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = "exception", IE = "1") public void execScript2() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void open_FF() throws Exception { final String html = "foo\n" + " \n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlButtonInput input = page.getFirstByXPath("//input"); input.click(); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "function", FF = "undefined") public void collectGarbage() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "original", "changed" }) public void eval_localVariable() throws Exception { final String html = "foo\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test window properties that match Prototypes. * * @throws Exception if the test fails */ @Test @Alerts(IE = { "undefined", "undefined" }, FF2 = { "[Node]", "[Element]" }, FF3 = { "[object Node]", "[object Element]" }) public void windowProperties() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test that length of frames collection is retrieved. * @throws Exception if the test fails */ @Test @Alerts({ "0", "0" }) public void framesLengthZero() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * Test that length of frames collection is retrieved when there are frames. * @throws Exception if the test fails */ @Test @Alerts({ "2", "2", "frame1", "frame2" }) public void framesLengthAndFrameAccess() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "0", "0", "2", "2", "2", "true" }) public void windowFramesLive() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Regression test for https://sf.net/tracker/index.php?func=detail&aid=1153708&group_id=47038&atid=448266 * and https://bugzilla.mozilla.org/show_bug.cgi?id=443491. * @throws Exception if the test fails */ @Test public void overwriteFunctions_alert() throws Exception { final String html = ""; final HtmlPage page = loadPageWithAlerts(html); assertEquals("hello", page.getTitleText()); } /** * Regression test for https://sf.net/tracker/index.php?func=detail&aid=1153708&group_id=47038&atid=448266 * and https://bugzilla.mozilla.org/show_bug.cgi?id=443491. * @throws Exception if the test fails */ @Test @Alerts(FF2 = "hello", FF3 = "exception", IE = "hello") public void overwriteFunctions_navigator() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * Regression test for bug 2808901. * @throws Exception if an error occurs */ @Test @Alerts("x") public void onbeforeunload_setToFunction() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * Regression test for bug 2808901. * @throws Exception if an error occurs */ @Test @Alerts public void onbeforeunload_setToString() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * Regression test for bug 2808901. * @throws Exception if an error occurs */ @Test @Alerts({ "true", "true", "function" }) public void onbeforeunload_defined() throws Exception { onbeforeunload("onbeforeunload", "var x;"); } /** * Regression test for bug 2808901. * @throws Exception if an error occurs */ @Test @NotYetImplemented(Browser.FF) @Alerts(IE = { "true", "true", "object" }, FF = { "false", "false", "undefined" }) public void onbeforeunload_notDefined() throws Exception { onbeforeunload("onbeforeunload", null); } private void onbeforeunload(final String name, final String js) throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test public void serialization() throws Exception { final String html = ""; final HtmlPage page = loadPageWithAlerts(html); clone(page.getEnclosingWindow()); } /** * Verifies that window.frames basically returns a reference to the window. * Regression test for bug 2824436. * @throws Exception if an error occurs */ @Test @Alerts(FF = { "[object Window]", "[object Window]", "[object Window]", "1", "true", "true", "[object Window]", "true", "true", "no function", "undefined", "true", "true", "[object History]", "true", "true", "[object Window]", "true", "true" }, IE = { "[object]", "[object]", "[object]", "1", "true", "true", "[object]", "true", "true", "[object]", "true", "true", "undefined", "true", "true", "[object]", "true", "true", "[object]", "true", "true" }) public void framesAreWindows() throws Exception { final String html = ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange0000664000175000017500000001613511650253660034620 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; /** * Tests for {@link TextRange}. * * @version $Revision: 4800 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class TextRangeTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "", "bla bla", "bla blabli bli" }) public void text() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts("BODY") public void parentElement() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "hello", "" }) public void collapse() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Minimal test: just test that function is available. * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts("") public void select() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "hello", "hell", "ell" }) public void moveEnd() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "true", "true", "false", "true" }) public void inRange() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Regression test for * Bug 2836591. * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts("false") public void inRange2() throws Exception { final String html = "" + "
" + "" + ""; loadPageWithAlerts(html); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/0000775000175000017500000000000011650253660033732 5ustar jamespagejamespage././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLegendElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000477311650253660034434 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLLegendElement}. * * @version $Revision: 4772 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLLegendElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts({ "", "A", "a", "A", "a8", "8Afoo", "8", "@" }) public void accessKey() throws Exception { final String html = "a1a2"; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLFormElement]") public void form() throws Exception { final String html = "
a
"; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOListElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000645211650253660034430 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLOListElement}. * * @version $Revision: 4774 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLOListElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "false", "true", "true", "true", "null", "", "blah", "2", "true", "false", "true", "false", "", "null", "", "null" }, IE = { "false", "true", "true", "true", "false", "true", "true", "true", "true", "false", "true", "false", "true", "false", "true", "false" }) public void compact() throws Exception { final String html = "\n" + "
  1. a
  2. b
\n" + "
  1. a
  2. b
\n" + "
  1. a
  2. b
\n" + "
  1. a
  2. b
\n" + "\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/package.htmljenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/pack0000664000175000017500000000014311650253660034571 0ustar jamespagejamespageTest Classes Test for HTML-related classes. ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSpanElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000557411650253660034434 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLSpanElement}. * * @version $Revision: 4503 $ * @author Daniel Gredler * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLSpanElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(IE = "yes", FF = "no") public void doScroll() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " abc\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(IE6 = {"[object] undefined", "[object] undefined" }, IE7 = {"[object] ", "[object] undefined" }, FF = {"[object HTMLSpanElement] undefined", "[object HTMLSpanElement] undefined" }) public void cite() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableColElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000002411711650253660034426 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLTableColElement}. * * @version $Revision: 4503 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLTableColElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "left", "right", "3", "center", "8", "foo" }, IE = { "left", "right", "", "error", "error", "center", "right", "" }) public void align() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
abc
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "p", "po", ".", "u", "8", "U8" }, IE = { "", "", "", "u", "8", "U8" }) public void ch() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
abc
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "0", "4", "", "5", "0", "abc" }, IE = { "", "", "", "5.2", "-3", "abc" }) public void chOff() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
abc
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "1", "2", "1", "5", "1", "1" }, IE = { "1", "2", "1", "error", "error", "5", "2", "1" }) public void span() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
abc
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "top", "baseline", "3", "middle", "8", "bottom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) public void vAlign() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
abc
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "50", "75%", "foo", "0", "20", "", "80", "40", "abc", "0", "30%", "33" }, IE = { "50", "75%", "", "", "20", "", "error", "error", "80", "40", "", "", "30%", "33" }) public void width() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
abcd
\n" + "\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000012454011650253660034427 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import static org.junit.Assert.assertSame; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlOption; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSelect; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; /** * Tests for {@link HTMLSelectElement}. * * @version $Revision: 4861 $ * @author Mike Bowler * @author David K. Taylor * @author Marc Guillemot * @author Bruce Faulkner * @author Ahmed Ashour * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLSelectElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "3", "1" }) public void testGetSelectedIndex() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "3", "1", "3", "2" }) public void testSetSelectedIndex() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + "
\n" + ""; final HtmlPage page = loadPageWithAlerts(html); getMockWebConnection().setDefaultResponse(""); final HtmlSubmitInput button = page.getHtmlElementById("clickMe"); final HtmlPage newPage = button.click(); assertEquals("http://test/?submit=button", newPage.getWebResponse().getRequestSettings().getUrl()); assertSame("method", HttpMethod.GET, getMockWebConnection().getLastMethod()); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "-1", "2", "exception", "2", "exception", "2" }, IE = { "-1", "2", "-1", "-1" }) public void testSetSelectedIndexInvalidValue() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "value1", "One", "value2", "Two", "value3", "Three" }) public void testGetOptions() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "value1", "One", "value2", "Two", "value3", "Three" }) public void testGetOptionLabel() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "false", "true", "true", "false" }) public void testGetOptionSelected() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("true") public void testGetOptionByIndex() throws Exception { final String html = "first\n" + "
"; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("One") public void testGetOptionByOptionIndex() throws Exception { final String html = "first\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "4", "Four", "value4" }) public void testAddOption() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "1", "true", "4", "Four", "value4", "true", "3", "false" }) public void testAddOptionSelected() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "4", "Four", "value4" }) @Browsers(Browser.FF) public void testAddOptionWithAddMethod_FF() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test for bug 1570478. * @throws Exception if the test fails */ @Test @Alerts(FF = "exception", IE = { "4", "Four", "value4", "Three b", "value3b" }) public void testAddOptionWithAddMethod_IE() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Regression test for bug 1304741. * See https://sourceforge.net/tracker/index.php?func=detail&aid=1304741&group_id=47038&atid=448266. * @throws Exception if the test fails */ @Test @Alerts(FF = { "0", "exception" }, IE = { "0", "1" }) public void testAddWith1Arg() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "2", "Three", "value3" }) public void testRemoveOption() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "2", "Three", "value3" }) public void testRemoveOptionWithRemoveMethod() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("0") public void testClearOptions() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test that option array is filled with empty options when length is increased. * Test case for bug 1370484 * @throws Exception if the test fails */ @Test @Alerts({ "1", "2", "", "", "foo", "fooValue" }) public void testIncreaseOptionsSettingLength() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "One", "value1" }) public void testOptionArrayHasItemMethod() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "Two", "", "Two", "", "" }, IE = { "", "", "", "", "" }) public void getValue() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Changes made through JS should not trigger an onchange event. * @throws Exception if the test fails */ @Test public void testNoOnchangeFromJS() throws Exception { final String html = "Test infinite loop on js onchange\n" + "
\n" + "\n" + "\n" + "
\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlSelect selectA = page.getFormByName("myForm").getSelectByName("a"); final HtmlOption optionA2 = selectA.getOption(1); assertEquals("two", optionA2.asText()); final HtmlSelect selectB = page.getFormByName("myForm").getSelectByName("b"); assertEquals(1, selectB.getSelectedOptions().size()); assertEquals("red", selectB.getSelectedOptions().get(0).asText()); // changed selection in first select optionA2.setSelected(true); assertTrue(optionA2.isSelected()); assertEquals(1, selectB.getSelectedOptions().size()); assertEquals("green", selectB.getSelectedOptions().get(0).asText()); assertEquals(Collections.EMPTY_LIST, collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts({ "0", "1" }) public void testSetValue() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test for bug 1159709. * @throws Exception if the test fails */ @Test public void testRightPageAfterOnchange() throws Exception { final String html = "\n" + "\n" + "
\n" + " \n" + "
\n" + ""; final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(""); webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); final HtmlForm form = page.getFormByName("form1"); final HtmlSelect select = form.getSelectByName("select1"); final Page page2 = select.setSelectedAttribute("option2", true); assertEquals("http://first/", page2.getWebResponse().getRequestSettings().getUrl()); } /** * Test that options delegates to select (bug 1111597). * @throws Exception if the test fails */ @Test @Alerts({ "2-2", "1-1", "2-2", "0-0", "2-2", "1-1" }) @Browsers(Browser.IE) public void testOptionsDelegateToSelect() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Test that options delegates to select (bug 1111597). * @throws Exception if the test fails */ @Test @Alerts({ "2", "b", "3", "c" }) public void testOptionsArrayAdd() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Tests that select delegates submit to the containing form. * @throws Exception if the test fails */ @Test public void testOnChangeCallsFormSubmit() throws Exception { final String html = "\n" + "\n" + "\n" + "
\n" + "
\n" + ""; final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse("page 2"); webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); final HtmlPage page2 = page.getFormByName("test").getSelectByName("select1").getOption(0).click(); assertEquals("page 2", page2.getTitleText()); } /** * Test for bug 1684652. * @throws Exception if the test fails */ @Test public void testSelectedIndexReset() throws Exception { final String html = "first\n" + "\n" + "
\n" + "\n" + "\n" + "
\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final Page page2 = page.getHtmlElementById("testButton").click(); final URL url2 = page2.getWebResponse().getRequestSettings().getUrl(); assertTrue("Select in URL " + url2, url2.toExternalForm().contains("testSelect=testValue")); } /** * @throws Exception if the test fails */ @Test @Alerts("-1") public void testSelectedIndex() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void testDefaultSelectedValue_SizeNegativeOne() throws Exception { testDefaultSelectedValue("-1", false, new String[] {"0", "true", "false", "false", "0"}); testDefaultSelectedValue("-1", true, new String[] {"0", "false", "false", "false", "-1"}); } /** * @throws Exception if the test fails */ @Test public void testDefaultSelectedValue_SizeZero() throws Exception { testDefaultSelectedValue("0", false, new String[] {"0", "true", "false", "false", "0"}); testDefaultSelectedValue("0", true, new String[] {"0", "false", "false", "false", "-1"}); } /** * @throws Exception if the test fails */ @Test public void testDefaultSelectedValue_SizeOne() throws Exception { testDefaultSelectedValue("1", false, new String[] {"1", "true", "false", "false", "0"}); testDefaultSelectedValue("1", true, new String[] {"1", "false", "false", "false", "-1"}); } /** * @throws Exception if the test fails */ @Test public void testDefaultSelectedValue_SizeTwo() throws Exception { testDefaultSelectedValue("2", false, new String[] {"2", "false", "false", "false", "-1"}); testDefaultSelectedValue("2", true, new String[] {"2", "false", "false", "false", "-1"}); } /** * @throws Exception if the test fails */ @Test public void testDefaultSelectedValue_SizeInvalid() throws Exception { testDefaultSelectedValue("x", false, new String[] {"0", "true", "false", "false", "0"}); testDefaultSelectedValue("x", true, new String[] {"0", "false", "false", "false", "-1"}); } /** * Tests default selection status for options in a select of the specified size, optionally * allowing multiple selections. * @param size the select input's size attribute * @param multiple whether or not the select input should allow multiple selections * @param expected the expected alerts * @throws Exception if the test fails */ private void testDefaultSelectedValue(final String size, final boolean multiple, final String[] expected) throws Exception { final String m; if (multiple) { m = " multiple"; } else { m = ""; } final String html = "\n" + "
\n" + " \n" + "
\n" + ""; final List actual = new ArrayList(); loadPage(getBrowserVersion(), html, actual); assertEquals(expected, actual); } /** * @throws Exception if the test fails */ @Test @Alerts("5") public void testSize() throws Exception { final String html = "foo\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts() public void selectedIndex_onfocus() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "-1", "0", "-1" }) public void selectedIndex_appendChild() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "-1", "0", "-1" }) public void selectedIndex_insertBefore() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "-1", "0", "-1" }) public void selectedIndex_add() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000642511650253660034430 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLDivElement}. * * @version $Revision: 4503 $ * @author Daniel Gredler * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLDivElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = "no", IE = "yes") public void doScroll() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + "
abc
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"", "hello", "left", "hi", "right" }, IE = {"", "error", "", "left", "error", "left", "right" }) public void align() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + "
abc
\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000002571311650253660034431 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; /** * Tests for {@link HTMLCollection}. * * @version $Revision: 4684 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLCollectionTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts("true") public void testImplicitToStringConversion() throws Exception { final String html = "foo\n" + "link\n" + ""; loadPageWithAlerts(html); } /** * Test that toString is accessible. * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF) @Alerts(IE = "object", FF = "function") public void testToStringFunction() throws Exception { final String html = "foo\n" + "link\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "5", "6" }) @Browsers(Browser.IE) public void getElements() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "true", "1" }) public void testChildNodes() throws Exception { final String firstContent = "foo\n" + ""; final String secondContent = "Immortality"; final List collectedAlerts = new ArrayList(); final WebClient client = getWebClient(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, firstContent); conn.setResponse(URL_SECOND, secondContent, "text/xml"); client.setWebConnection(conn); client.getPage(URL_FIRST); assertEquals(getExpectedAlerts(), collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = {"string 0", "string length", "string item", "string namedItem" }, IE = {"string length", "string myForm" }) public void testFor_in() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = {"string 0", "string 1", "string 2", "string 3", "string 4", "string 5", "string length", "string item", "string namedItem" }, IE = {"string length", "string val1", "string 1", "string val2", "string first_submit", "string second_submit", "string action" }) public void testFor_in2() throws Exception { final String html = "foo\n" + "
\n" + " \n" + "
This is not a form element
\n" + " \n" + " \n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts(html); } /** * document.all.tags is different from document.forms.tags! * @throws Exception if the test fails */ @Test @Alerts(FF2 = {"true", "false" }, FF3 = {"false", "false" }, IE = {"true", "true" }) public void testTags() throws Exception { final String html = "foo\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Depending on the method used, out of bound access give different responses. * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF) @Alerts(IE = { "null", "null", "undefined", "null" }, FF = { "null", "null", "undefined", "exception" }) public void testOutOfBoundAccess() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "undefined", "undefined", "undefined" }) public void testInexistentProperties() throws Exception { final String html = "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "1", "DIV", "2" }, FF = { "3", "#text", "5" }) public void childNodes() throws Exception { final String html = "\n" + "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("object") public void typeof() throws Exception { final String html = "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Verifies that dollar signs don't cause exceptions in {@link HTMLCollection} (which uses Java * regex internally). Found via the MooTools unit tests. * * @throws Exception if the test fails */ @Test @Alerts(IE = { "[object]", "undefined" }, FF = { "[object HTMLHeadingElement]", "undefined" }) public void getElementWithDollarSign() throws Exception { final String html = "

h

"; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000005630611650253660034433 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link HTMLTableElement}. * * @version $Revision: 4900 $ * @author David D. Kilzer * @author Mike Bowler * @author Daniel Gredler * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLTableElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "caption1", "caption2", "null", "caption3" }) public void tableCaptions() throws Exception { final String html = "foo\n" + " \n" + " \n" + " \n" + "
caption1caption2
cell1cell2cell4
cell3
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "thead1", "thead2", "null", "thead3" }) public void tableHeaders() throws Exception { final String html = "foo\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
cell1cell2cell3
cell7cell8cell9
cell1cell2cell4
cell3
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "2", "true", "4 2 2", "6 3 3" }) public void tableBodies() throws Exception { final String html = "foo\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
cell1cell2
cell3cell4
cell1cell2
cell3cell4
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "2", "true", "3", "2", "3", "2" }) public void tableRows() throws Exception { final String html = "foo\n" + " \n" + " \n" + " \n" + "
cell1cell2cell4
cell3
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * Regression test for bug 1528024. * @see bug * @throws Exception if the test fails */ @Test @Alerts({ "1", "1" }) public void tableHeadRows() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
Some Heading
some desc
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "2", "true", "8 2 2 2 2", "9 2 2 2 3", "8 2 2 1 3", "9 2 3 1 3", "8 1 3 1 3" }) public void tableRowsWithManySections() throws Exception { final String html = "foo\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
cell1cell2
cell3cell4
cell1cell2
cell3cell4
cell1cell2
cell3cell4
cell1cell2
cell3cell4
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "tfoot1", "tfoot2", "null", "tfoot3" }) public void tableFooters() throws Exception { final String html = "foo\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
cell1cell2cell4
cell3
cell1cell2cell3
cell7cell8cell9
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "0", "1", "0", "1" }) public void cellIndex() throws Exception { final String html = "Test\n" + "\n" + "\n" + "\n" + "\n" + "
ab
cd
"; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "1", "2", "1", "0", "TD", "1", "2" }) public void insertRow() throws Exception { final String html = "foo\n" + " \n" + " \n" + "
foo
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * Regression test for bug 1244839. * @throws Exception if the test fails */ @Test @Alerts({ "mytable", "mytable" }) public void insertRowNested() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + "
\n" + "
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Tests that a tbody is automatically created. * @throws Exception if the test fails */ @Test @Alerts({ "TBODY", "TABLE" }) public void insertRowInEmptyTable() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Tests that a tbody is automatically created. * @throws Exception if the test fails */ @Test @Alerts({ "TBODY", "TBODY", "TBODY" }) public void insertRowInTableWithEmptyTbody() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Tests length, tBodies on nested rows. * @throws Exception if the test fails */ @Test @Alerts({ "1", "1" }) public void nestedTables() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + "
\n" + "
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Tests string default values. * See https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1538136&group_id=47038. * Currently not working for FF as HtmlUnit's object names don't map to FF ones. * @throws Exception if the test fails */ @Test @Alerts(IE = { "table: [object]", "row: [object]", "cell: [object]" }, FF = { "table: [object HTMLTableElement]", "row: [object HTMLTableRowElement]", "cell: [object HTMLTableCellElement]" }) public void stringValues() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
Foo
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void width() throws Exception { final String content = "\n" + "
\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), content, null); final String xml = page.asXml(); assertTrue(xml.contains("width=\"200\"")); } /** * @throws Exception if the test fails */ @Test @Alerts("21") public void cellSpacing() throws Exception { final String html = "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("21") public void cellPadding() throws Exception { final String html = "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void refresh() throws Exception { final String html = "\n" + "
\n" + ""; loadPage(getBrowserVersion(), html, null); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"", "hello", "left", "hi", "right" }, IE = {"", "error", "", "left", "error", "left", "right" }) public void align() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({"", "#0000aa", "#000000" }) public void bgColor() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
a
\n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMetaElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000417611650253660034431 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLMetaElement}. * * @version $Revision: 4503 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLMetaElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(IE = { "", "text/html; charset=utf-8", "Content-Type", "", "", "" }, FF = { "undefined", "text/html; charset=utf-8", "Content-Type", "", "", "undefined" }) public void name() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCanvasElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000377311650253660034433 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLCanvasElement}. * * @version $Revision: 4503 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLCanvasElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "300", "150", "[object CanvasRenderingContext2D]" }, IE = { "undefined", "undefined" }) public void test() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000004025311650253660034425 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import static org.junit.Assert.assertSame; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link HTMLAnchorElement}. * * @version $Revision: 4553 $ * @author Alexei Goussev * @author Marc Guillemot * @author Sudhan Moghe * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLAnchorElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "http://x/testsite1.html", "testsite1.html", "http://x/testsite2.html", "testsite2.html", "13", "testanchor", "mailto:" }) public void getAttribute_and_href() throws Exception { final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); final String html = "AnchorTest\n" + "\n" + "bla\n" + "mail\n" + ""; webConnection.setDefaultResponse(html); client.setWebConnection(webConnection); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final HtmlPage page = client.getPage("http://x"); final HtmlAnchor anchor = page.getAnchorByName("testanchor"); anchor.click(); assertEquals(getExpectedAlerts(), collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts({ "true", "not defined" }) public void onclickToString() throws Exception { final String html = "AnchorTest\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "", "http://www.gargoylesoftware.com/foo.html", "javascript:void(0)", "http://www.gargoylesoftware.com/#", "mailto:" }) public void defaultConversionToString() throws Exception { final String html = "AnchorTest\n" + "\n" + "\n" + "foo\n" + "void\n" + "#\n" + "mail\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void onClickAnchorHref() throws Exception { final String html = "\n" + "link 1\n" + "
\n" + "\n" + "
\n" + ""; final HtmlPage page1 = loadPage(getBrowserVersion(), html, null); final Page page2 = page1.getAnchorByHref("#").click(); assertEquals(URL_GARGOYLE + "foo.html", page2.getWebResponse().getRequestSettings().getUrl()); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) public void javaScriptAnchorClick() throws Exception { final String html = "First\n" + "link 1\n" + "
\n" + "\n" + "\n" + "
\n" + ""; final String secondHtml = "\n" + "Second\n" + ""; final WebClient client = getWebClient(); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html); conn.setResponse(URL_SECOND, secondHtml); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); final HtmlButtonInput button = page.getHtmlElementById("button1"); final HtmlPage page2 = button.click(); assertEquals("Second", page2.getTitleText()); } /** * Regression test for https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1689798&group_id=47038. * In href, "this" should be the window and not the link. * @throws Exception if the test fails */ @Test public void thisInJavascriptHref() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final List collectedAlerts = new ArrayList(); final String[] expectedAlerts = {"true"}; final HtmlPage page1 = loadPage(getBrowserVersion(), html, collectedAlerts); final Page page2 = page1.getAnchors().get(0).click(); assertEquals(expectedAlerts, collectedAlerts); assertSame(page1, page2); } /** * @throws Exception if the test fails */ @Test public void readWriteAnchorTarget() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final HtmlPage page1 = loadPage(getBrowserVersion(), html, null); final HtmlAnchor link = page1.getAnchors().get(0); assertEquals("OK", link.getTargetAttribute()); } /** * @throws Exception if the test fails */ @Test public void readWriteAnchorSearch() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final HtmlPage page1 = loadPage(getBrowserVersion(), html, null); final HtmlAnchor link = page1.getAnchors().get(0); assertEquals("http://www.gargoylesoftware.com/foo.html?p1=1&p2=2", link.getHrefAttribute()); } /** * @throws Exception if an error occurs */ @Test public void readAnchorHash() throws Exception { final String html = "foo" + ""; final List actual = new ArrayList(); loadPage(getBrowserVersion(), html, actual); final String[] expected = {"#arg"}; assertEquals(expected, actual); } /** * @throws Exception if the test fails */ @Test public void readWriteAnchorHash() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlAnchor link = page.getAnchors().get(0); assertEquals("http://www.gargoylesoftware.com/foo.html#OK", link.getHrefAttribute()); } /** * @throws Exception if the test fails */ @Test public void readWriteAnchorPort() throws Exception { final String html = "\n" + "\n" + "link 1\n" + "link 1\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); HtmlAnchor link = page.getAnchors().get(0); assertEquals("http://www.gargoylesoftware.com:80/foo.html#O", link.getHrefAttribute()); link = page.getAnchors().get(1); assertEquals("http://www.gargoylesoftware.com:8080/foo.html#O", link.getHrefAttribute()); } /** * @throws Exception if the test fails */ @Test public void readWritePathname() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlAnchor link = page.getAnchors().get(0); assertEquals("http://www.gargoylesoftware.com/bar/foo.html#B", link.getHrefAttribute()); } /** * @throws Exception if the test fails */ @Test public void readWriteProtocol() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlAnchor link = page.getAnchors().get(0); assertEquals("https://www.gargoylesoftware.com/foo.html#B", link.getHrefAttribute()); } /** * @throws Exception if the test fails */ @Test public void readWriteAnchorHost() throws Exception { final String html = "\n" + "\n" + "link 0\n" + "link 1\n" + "link 2\n" + "link 3\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); HtmlAnchor link = page.getAnchors().get(0); assertEquals("http://www.gargoylesoftware.commotion:8080/foo.html#O", link.getHrefAttribute()); link = page.getAnchors().get(1); assertEquals("http://www.gargoylesoftware.commotion/foo.html#O", link.getHrefAttribute()); link = page.getAnchors().get(2); assertEquals("http://www.gargoylesoftware.com:8080/foo.html#O", link.getHrefAttribute()); link = page.getAnchors().get(3); assertEquals("http://www.gargoylesoftware.com/foo.html#O", link.getHrefAttribute()); } /** * @throws Exception if the test fails */ @Test public void readWriteAnchorHostname() throws Exception { final String html = "\n" + "\n" + "link 1\n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlAnchor link = page.getAnchors().get(0); assertEquals("http://www.gargoylesoftware.commotion/foo.html#O", link.getHrefAttribute()); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "", "A", "a", "A", "a8", "8Afoo", "8", "@" }) public void readWriteAccessKey() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * Verifies that anchor href attributes are trimmed of whitespace (bug 1658064), * just like they are in IE and Firefox. * Verifies that href of anchor without href is empty string. * @throws Exception if an error occurs */ @Test @Alerts({ "9", "9", "true", "false" }) public void testHrefTrimmed() throws Exception { final String html = "AnchorTest\n" + "\n" + "a " + "b\n" + "c\n" + "d\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLabelElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000001156411650253660034430 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlLabel; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link HTMLLabelElement}. * * @version $Revision: 4772 $ * @author Ahmed Ashour * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLLabelElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void htmlFor() throws Exception { final String html = "First\n" + "\n" + "
\n" + ""; final HtmlPage page = loadPage(html); final HtmlLabel label = page.getHtmlElementById("label1"); final HtmlCheckBoxInput checkbox = page.getHtmlElementById("checkbox1"); assertFalse(checkbox.isChecked()); label.click(); assertTrue(checkbox.isChecked()); } /** * Tests that clicking the label by JavaScript does not change 'htmlFor' attribute in FF!! * * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF) public void htmlFor_click() throws Exception { final String html = "First\n" + "\n" + "
\n" + "\n" + ""; final HtmlPage page = loadPage(html); final HtmlCheckBoxInput checkbox = page.getHtmlElementById("checkbox1"); final HtmlButtonInput button = page.getHtmlElementById("button1"); assertFalse(checkbox.isChecked()); button.click(); final boolean changedByClick = getWebClient().getBrowserVersion().isIE(); assertTrue(checkbox.isChecked() == changedByClick); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "", "A", "a", "A", "a8", "8Afoo", "8", "@" }) public void accessKey() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLFormElement]") public void form() throws Exception { final String html = "
"; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000014756011650253660034436 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import static org.junit.Assert.assertSame; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlFileInput; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; /** * Tests for {@link HTMLFormElement}. * * @version $Revision: 4900 $ * @author Mike Bowler * @author David K. Taylor * @author Marc Guillemot * @author Chris Erskine * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLFormElementTest extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "16", "button1", "button2", "checkbox1", "fileupload1", "hidden1", "radio1", "radio1", "select1", "select2", "password1", "reset1", "reset2", "submit1", "submit2", "textInput1", "textarea1" }) public void testElementsAccessor() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "undefined", "undefined" }) public void testElementsAccessorOutOfBound() throws Exception { final String html = "foo\n" + "
\n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "3", "1", "2", "3" }) public void testRadioButtonArray() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts2(html); } /** * If there is only one radio button with a specified name then that radio * button will be returned for the name, not an array of radio buttons. Test * this. * @throws Exception if the test fails */ @Test @Alerts("1") public void testRadioButton_OnlyOne() throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test public void testActionProperty() throws Exception { final String jsProperty = "action"; final String htmlProperty = "action"; final String oldValue = "http://foo.com"; final String newValue = "mailto:me@bar.com"; final HtmlForm form = doTestProperty(jsProperty, htmlProperty, oldValue, newValue); assertEquals(newValue, form.getActionAttribute()); } /** * @throws Exception if the test fails */ @Test public void testNameProperty() throws Exception { final String jsProperty = "name"; final String htmlProperty = "name"; final String oldValue = "myForm"; final String newValue = "testForm"; final HtmlForm form = doTestProperty(jsProperty, htmlProperty, oldValue, newValue); assertEquals(newValue, form.getNameAttribute()); } /** * @throws Exception if the test fails */ @Test public void testEncodingProperty() throws Exception { final String jsProperty = "encoding"; final String htmlProperty = "enctype"; final String oldValue = "myEncoding"; final String newValue = "newEncoding"; final HtmlForm form = doTestProperty(jsProperty, htmlProperty, oldValue, newValue); assertEquals(newValue, form.getEnctypeAttribute()); } /** * @throws Exception if the test fails */ @Test public void testMethodProperty() throws Exception { final String jsProperty = "method"; final String htmlProperty = "method"; final String oldValue = "get"; final String newValue = "post"; final HtmlForm form = doTestProperty(jsProperty, htmlProperty, oldValue, newValue); assertEquals(newValue, form.getMethodAttribute()); } /** * @throws Exception if the test fails */ @Test public void testTargetProperty() throws Exception { final String jsProperty = "target"; final String htmlProperty = "target"; final String oldValue = "_top"; final String newValue = "_parent"; final HtmlForm form = doTestProperty(jsProperty, htmlProperty, oldValue, newValue); assertEquals(newValue, form.getTargetAttribute()); } private HtmlForm doTestProperty( final String jsProperty, final String htmlProperty, final String oldValue, final String newValue) throws Exception { final String html = "foo\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; setExpectedAlerts(oldValue, newValue); final HtmlPage page = loadPageWithAlerts(html); return page.getForms().get(0); } /** * Tests form reset and input default values while emulating IE. * @throws Exception if the test fails */ @Test public void testFormReset() throws Exception { // As tested with IE 6.0 on Win2k; note that refreshing the page will get you different results; // you need to open a new browser instance each time you test this. final String[] expectedIE = { "before setting default values", /* Before setting default values. */ "text: initial1 initial1 false false", "file: false false", "image: initial3 initial3 false false", "radio: initial4 initial4 true true", "reset: initial5 initial5 false false", "hidden: initial6 initial6 false false", "button: initial7 initial7 false false", "submit: initial8 initial8 false false", "password: initial9 initial9 false false", "checkbox: initial10 initial10 true true", "textarea: initial11 initial11 undefined undefined", "after setting default values", /* After setting default values. */ "text: initial1 default1 false false", "file: default2 false false", "image: default3 default3 false false", "radio: default4 default4 true false", "reset: initial5 default5 false false", "hidden: initial6 default6 false false", "button: initial7 default7 false false", "submit: initial8 default8 false false", "password: initial9 default9 false false", "checkbox: default10 default10 true false", "textarea: initial11 default11 undefined undefined", "after resetting the form", /* After resetting the form. */ "text: default1 default1 false false", "file: default2 false false", "image: default3 default3 false false", "radio: default4 default4 false false", "reset: initial5 default5 false false", "hidden: default6 default6 false false", "button: initial7 default7 false false", "submit: initial8 default8 false false", "password: default9 default9 false false", "checkbox: default10 default10 false false", "textarea: default11 default11 undefined undefined" }; // As tested with Firefox 2.0.20 and 3.0.13 on Linux. final String[] expectedFF = { "before setting default values", /* Before setting default values. */ "text: initial1 initial1 false false", "file: initial2 false false", // THIS LINE DIFFERS FROM IE; see HtmlFileInput constructor. "image: initial3 initial3 false false", "radio: initial4 initial4 true true", "reset: initial5 initial5 false false", "hidden: initial6 initial6 false false", "button: initial7 initial7 false false", "submit: initial8 initial8 false false", "password: initial9 initial9 false false", "checkbox: initial10 initial10 true true", "textarea: initial11 initial11 undefined undefined", "after setting default values", /* After setting default values. */ "text: default1 default1 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "file: default2 false false", "image: default3 default3 false false", "radio: default4 default4 false false", // DIFFERS FROM IE; see HtmlRadioButtonInput.setDefaultChecked() "reset: default5 default5 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "hidden: default6 default6 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "button: default7 default7 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "submit: default8 default8 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "password: default9 default9 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "checkbox: default10 default10 false false", // DIFFERS FROM IE; see HtmlCheckBoxInput.setDefaultChecked() "textarea: default11 default11 undefined undefined", "after resetting the form", /* After resetting the form. */ "text: default1 default1 false false", "file: default2 false false", "image: default3 default3 false false", "radio: default4 default4 false false", "reset: default5 default5 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "hidden: default6 default6 false false", "button: default7 default7 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "submit: default8 default8 false false", // DIFFERS FROM IE; see HtmlInput.setDefaultValue() "password: default9 default9 false false", "checkbox: default10 default10 false false", "textarea: default11 default11 undefined undefined" }; final String[] expectedAlerts = getBrowserVersion().isFirefox() ? expectedFF : expectedIE; setExpectedAlerts(expectedAlerts); final String html = "\n" + " \n" + " Reset Test\n" + " \n" + " \n" + " \n" + "
\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
\n" + " \n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test public void testFormSubmit() throws Exception { final String html = "first\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + "
\n" + ""; final String secondContent = "second\n" + "

hello world

\n" + ""; getMockWebConnection().setDefaultResponse(secondContent); final HtmlPage page = loadPageWithAlerts(html); final HtmlPage secondPage = (HtmlPage) page.executeJavaScript("document.form1.submit()").getNewPage(); assertEquals("second", secondPage.getTitleText()); } /** * @throws Exception if the test fails */ @Test public void testOnSubmitChangesAction() throws Exception { final String html = "\n" + "
\n" + " \n" + "
\n" + ""; getMockWebConnection().setDefaultResponse(""); final HtmlPage page = loadPageWithAlerts(html); final Page page2 = page.getHtmlElementById("button1").click(); assertEquals(URL_THIRD.toExternalForm(), page2.getWebResponse().getRequestSettings().getUrl()); } /** * @throws Exception if the test fails */ @Test public void testFormSubmit_target() throws Exception { final String html = "first\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; final String secondContent = "second\n" + "

hello world

\n" + ""; getMockWebConnection().setDefaultResponse(secondContent); final HtmlPage page = loadPageWithAlerts(html); final HtmlPage secondPage = (HtmlPage) page.executeJavaScript("document.form1.submit()").getNewPage(); assertEquals("second", secondPage.getTitleText()); assertEquals("MyNewWindow", secondPage.getEnclosingWindow().getName()); } /** * @throws Exception if the test fails */ @Test public void testFormSubmitDoesntCallOnSubmit() throws Exception { final String html = "first\n" + "
\n" + " \n" + "
\n" + "Click me\n" + ""; final String secondContent = "second\n" + "

hello world

\n" + ""; getMockWebConnection().setDefaultResponse(secondContent); final HtmlPage page = loadPageWithAlerts(html); final HtmlAnchor link = page.getHtmlElementById("link1"); final HtmlPage page2 = link.click(); assertEquals("second", page2.getTitleText()); } /** * @throws Exception if the test fails */ @Test @Alerts({ "id2", "foo" }) public void testInputNamedId() throws Exception { doTestInputWithName("id"); } /** * @throws Exception if the test fails */ @Test @Alerts({ "action2", "foo" }) public void testInputNamedAction() throws Exception { doTestInputWithName("action"); } private void doTestInputWithName(final String name) throws Exception { final String html = "foo\n" + "\n" + "

hello world

\n" + "
\n" + " \n" + "
\n" + ""; loadPageWithAlerts2(html); } /** * Regression test that used to blow up on page load. * @throws Exception if the test fails */ @Test @Alerts("value = 2") public void testAccessingRadioButtonArrayByName_Regression() throws Exception { final String html = "Button Test
\n" + "\n" + "\n" + "
"; loadPageWithAlerts2(html); } /** * Test for a bug that appeared when visiting mail.yahoo.com. Setting the value of one input * seems to blow away the other input. Also tests that the form input collection does not get * cached before the document is finished loading. * @throws Exception if the test fails */ @Test @Alerts("foo") public void testFindInputWithoutTypeDefined() throws Exception { final String html = "foo\n" + "\n" + "

hello world

\n" + "
\n" + " \n" + " \n" + " \n" + "
\n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test public void testFormSubmit_MultipleButtons() throws Exception { final String html = "first\n" + "

hello world

\n" + "
\n" + "
\n" + "\n" + "\n" + ""; final String frame1Html = "frame 1\n" + "\n" + "frame 1"; final String frame2Html = frame1Html.replaceAll("frame 1", "frame 2"); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setResponse(new URL(URL_FIRST, "frame1.html"), frame1Html); webConnection.setResponse(new URL(URL_FIRST, "frame2.html"), frame2Html); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); page.getHtmlElementById("btn1").click(); page.getHtmlElementById("btn2").click(); page.getHtmlElementById("btn3").click(); assertEquals(getExpectedAlerts(), collectedAlerts); } /** * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF) @Alerts(IE = "[object]", FF = "undefined") public void frames() throws Exception { final String mainHtml = "frames\n" + "\n" + "\n" + "\n" + ""; final String frame1 = "1\n" + "\n" + ""; final WebClient webClient = getWebClient(); final List collectedAlerts = new ArrayList(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection conn = new MockWebConnection(); webClient.setWebConnection(conn); conn.setResponse(URL_FIRST, mainHtml); conn.setResponse(new URL(URL_FIRST, "1.html"), frame1); webClient.getPage(URL_FIRST); assertEquals(getExpectedAlerts(), collectedAlerts); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLLinkElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000437511650253660034432 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Unit tests for {@link HTMLLinkElement}. * * @version $Revision: 4503 $ * @author Daniel Gredler */ public class HTMLLinkElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test public void basicLinkAttributes() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + ""; final List actual = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, html, actual); final String[] expected = new String[] { "", "", "", "http://www.gargoylesoftware.com/test.css", "text/css", "stylesheet"}; assertEquals(expected, actual); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBaseElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000375311650253660034431 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLBaseElement}. * @version $Revision: 4503 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLBaseElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts({ "http://www.foo.com/images/", "", "", "_blank" }) public void hrefAndTarget() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " foo\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLObjectElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000312311650253660034420 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLObjectElement}. * * @version $Revision: 4649 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLObjectElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "[object]", "null" }, FF = { "[object HTMLFormElement]", "null" }) public void form() throws Exception { final String html = "
"; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFrameSetElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000714111650253660034424 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLFrameSetElement}. * * @version $Revision: 4697 $ * @author Bruce Chapman * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLFrameSetElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts({ "20%,*", "*,*" }) public void testCols() throws Exception { final String html = "First\n" + "\n" + "\n" + " \n" + " \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "20%,*", "*,*" }) public void testRows() throws Exception { final String framesetContent = "First\n" + "\n" + " \n" + " \n" + "\n" + ""; final String frameContent = "TopFrame\n" + "\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final WebClient webClient = getWebClient(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, framesetContent); webConnection.setResponse(URL_SECOND, frameContent); webClient.setWebConnection(webConnection); webClient.getPage(URL_FIRST); assertEquals(getExpectedAlerts(), collectedAlerts); } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000033526311650253660034435 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlDivision; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; /** * Tests for {@link HTMLElement}. * * @version $Revision: 4900 $ * @author Brad Clarke * @author Chris Erskine * @author David D. Kilzer * @author Daniel Gredler * @author Marc Guillemot * @author Hans Donner * @author George Murnock * @author Bruce Faulkner * @author Ahmed Ashour * @author Sudhan Moghe * @author Ethan Glasser-Camp */ @RunWith(BrowserRunner.class) public class HTMLElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts(IE = { "all node for body: DIV A IMG DIV ", "all node for testDiv: A IMG ", "all node for testA: IMG ", "all node for testImg: ", "all node for testDiv2: " }) public void all_IndexByInt() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
foo
\n" + "
foo
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts({ "a", "a", "undefined", "null" }) public void getAttribute() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

\n" + "

\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertEquals("test", page.getTitleText()); } /** * Some libraries like MochiKit looks after the number of attributes of a freshly created node. * When this is fixed for IE, all {@link com.gargoylesoftware.htmlunit.libraries.MochiKitTest} * working for FF will work for IE too. * @throws Exception on test failure */ @Test @Alerts(FF = "0 attribute", IE = "at least 1 attribute") public void attributes() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "" // no \n here! + "test span\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Browsers(Browser.FF) @Alerts({ "", "bla" }) public void getSetAttributeNS() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

\n" + "

\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts({ "a", "b", "undefined", "foo" }) public void setAttribute() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

\n" + "

\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertEquals("test", page.getTitleText()); } /** * Caution: with IE if you get a node with some lowercase letters, the node will be retrieved * and will get as name the value passed as attribute to getAttributeNode. * The consequence for IE: x.getAttributeNode("Foo").nodeName != x.getAttributeNode("foo").nodeName * @throws Exception on test failure */ @Test @Alerts(IE = { "null", "expando=true", "firstChild=null", "lastChild=null", "name=custom_attribute", "nextSibling=null", "nodeName=custom_attribute", "nodeType=2", "nodeValue=bleh", "(ownerDocument==document)=true", "parentNode=null", "previousSibling=null", "specified=true", "value=bleh" }, FF = { "null", "expando=undefined", "firstChild=[object Text]", "lastChild=[object Text]", "name=custom_attribute", "nextSibling=null", "nodeName=custom_attribute", "nodeType=2", "nodeValue=bleh", "(ownerDocument==document)=true", "parentNode=null", "previousSibling=null", "specified=true", "value=bleh" }) public void getAttributeNode() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "
\n" + "
\n" + "
\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertEquals("test", page.getTitleText()); } /** * @throws Exception on test failure */ @Test @Alerts({ "left", "left", "right", "right" }) public void setAttributeNode() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "
\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertEquals("test", page.getTitleText()); } /** * Test for getElementsByTagName. * @throws Exception if the test fails */ @Test @Alerts({ "all = 4", "row = 2", "by wrong name: 0" }) public void getElementsByTagName() throws Exception { final String html = "First\n" + "\n" + "\n" + "\n" + "
12
34
\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "div1", "div2" }) public void getElementsByTagName2() throws Exception { final String html = "foo\n" + "
\n" + "
\n" + "
\n" + " \n" + ""; loadPageWithAlerts(html); } /** * Test that {@link HTMLElement#jsxFunction_getElementsByTagName} returns an associative array. * Test for bug 1369514. * @throws Exception if the test fails */ @Test @Alerts({ "first", "second", "third" }) public void getElementsByTagNameCollection() throws Exception { final String html = "\n" + "\n" + "\n" + "
\n" + "\n" + "\n" + "\n" + "
\n" + ""; loadPageWithAlerts(html); } /** * Tests that getElementsByTagName('*') returns all child elements, both * at the document level and at the element level. * @throws Exception if the test fails */ @Test @Alerts({ "8", "3" }) public void getElementsByTagNameAsterisk() throws Exception { final String html = "\n" + "

a

b

c

\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "true", "true", "true", "false", "false" }) public void getElementsByTagNameEquality() throws Exception { final String html = "
"; loadPageWithAlerts(html); } /** * Test getting the class for the element. * @throws Exception if the test fails */ @Test @Alerts("the class is x") public void getClassName() throws Exception { final String html = "\n" + "\n" + "

text

\n" + ""; loadPageWithAlerts(html); } /** * Test setting the class for the element. * @throws Exception if the test fails */ @Test @Alerts("the class is z") public void setClassName() throws Exception { final String html = "\n" + "\n" + "

text

\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("if (1 > 2 & 3 < 2) willNotHappen('yo');") public void getInnerHTML() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + " \n" + "\n" + "\n" + "
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(IE = "
", FF = "
") public void getInnerHTML_EmptyAttributes() throws Exception { final String html = "
"; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "Old = Old innerHTML", "New = New cell value" }, FF = { "Old = Old innerHTML", "New = New cell value" }) public void getSetInnerHTMLSimple_FF() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

Old innerHTML

\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Test the use of innerHTML to set new HTML code. * @throws Exception if the test fails */ @Test @Alerts(IE = { "Old = Old innerHTML", "New = New cell value", "I" }, FF = { "Old = Old innerHTML", "New = New cell value", "I" }) public void getSetInnerHTMLComplex_FF() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

Old innerHTML

\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlElement pElt = page.getHtmlElementById("myNode"); assertEquals("p", pElt.getNodeName()); final HtmlElement elt = page.getHtmlElementById("newElt"); assertEquals("New cell value", elt.asText()); assertEquals(1, page.getWebClient().getWebWindows().size()); } /** * Test the use of innerHTML to set a new input. * @throws Exception if the test fails */ @Test @Alerts("true") public void getSetInnerHTMLNewInput() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "
\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "Old = Old innerHTML", "New = New cell value & \u0110 \u0110" }, FF = { "Old = Old innerHTML", "New = New cell value & \u0110 \u0110" }) public void getSetInnerHTMLChar_FF() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

Old innerHTML

\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Verifies that empty tags are not abbreviated into their <tag/> form. * @throws Exception if the test fails */ @Test @Alerts(IE = { "
    ", "
      ", "" }, FF = { "undefined", "
        ", "undefined" }) public void getSetInnerHtmlEmptyTag_FF() throws Exception { final String html = "\n" + "
          " + ""; loadPageWithAlerts(html); } /** * Verifies that attributes containing whitespace are always quoted. * @throws Exception if the test fails */ @Test @Alerts(IE = { "
          ", "", "" }, FF = { "undefined", "", "undefined" }) public void getSetInnerHtmlAttributeWithWhitespace_FF() throws Exception { final String html = "\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * Test setting innerHTML to empty string. * @throws Exception if the test fails */ @Test @Alerts("Empty ChildrenLength: 0") public void setInnerHTMLEmpty() throws Exception { final String html = "\n" + "
          foo
          \n" + ""; loadPageWithAlerts(html); } /** * Test setting innerHTML to null. * @throws Exception if the test fails */ @Test @Alerts(IE = "Null ChildrenLength: 1", FF = "Null ChildrenLength: 0") public void setInnerHTMLNull() throws Exception { final String html = "\n" + "
          foo
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "Old = Old outerHTML", "New = New cell value" }, FF = { "Old = undefined", "New = Old outerHTML" }) public void getSetOuterHTMLSimple() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

          Old outerHTML

          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * Test the use of outerHTML to set new HTML code. * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts(IE = { "Old = Old outerHTML", "New = New cell value", "I" }) public void getSetOuterHTMLComplex() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "

          Old outerHTML

          \n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlElement pElt = page.getHtmlElementById("myNode"); assertEquals("p", pElt.getNodeName()); final HtmlElement elt = page.getHtmlElementById("newElt"); assertEquals("New cell value", elt.asText()); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "outside", "1", "middle", "2", "3", "4" }) public void insertAdjacentHTML() throws Exception { insertAdjacentHTML("beforeEnd", "afterEnd", "beforeBegin", "afterBegin"); insertAdjacentHTML("BeforeEnd", "AfterEnd", "BeFoReBeGiN", "afterbegin"); } /** * @param beforeEnd data to insert * @param afterEnd data to insert * @param beforeBegin data to insert * @param afterBegin data to insert * @throws Exception if the test fails */ private void insertAdjacentHTML(final String beforeEnd, final String afterEnd, final String beforeBegin, final String afterBegin) throws Exception { final String html = "First\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "inside\n" + "\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlElement elt = page.getHtmlElementById("outside"); assertEquals("before begin after begin inside before end after end", elt.asText()); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "outside", "1", "middle", "2", "3", "4" }) public void insertAdjacentElement() throws Exception { insertAdjacentElement("beforeEnd", "afterEnd", "beforeBegin", "afterBegin"); insertAdjacentElement("BeforeEnd", "AfterEnd", "BeFoReBeGiN", "afterbegin"); } private void insertAdjacentElement(final String beforeEnd, final String afterEnd, final String beforeBegin, final String afterBegin) throws Exception { final String html = "First\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "inside\n" + "\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlElement elt = page.getHtmlElementById("outside"); assertEquals("before begin after begin inside before end after end", elt.asText()); } /** * Test the #default#clientCaps default IE behavior. * * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts(IE = { "body.cpuClass = undefined", "body.cpuClass = x86", "body.cpuClass = undefined" }) public void addBehaviorDefaultClientCaps() throws Exception { final String html = "\n" + "\n" + " Test\n" + " \n" + "\n" + "Test\n" + ""; loadPageWithAlerts(html); } /** * Test the #default#homePage default IE behavior. * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts(IE = { "isHomePage = false", "isHomePage = true", "isHomePage = true", "isHomePage = false" }) public void addBehaviorDefaultHomePage() throws Exception { final URL url1 = URL_FIRST; final URL url2 = URL_SECOND; final String html1 = "\n" + " \n" + " Test\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final String html2 = ""; final WebClient client = getWebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(url1, html1); webConnection.setResponse(url2, html2); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(url1); assertEquals(getExpectedAlerts(), collectedAlerts); assertEquals(url2.toExternalForm(), page.getWebResponse().getRequestSettings().getUrl().toExternalForm()); } /** * Test the #default#download default IE behavior. * * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts(IE = { "Refused", "foo" }) public void addBehaviorDefaultDownload() throws Exception { final URL url1 = new URL("http://htmlunit.sourceforge.net/"); final URL url2 = new URL("http://htmlunit.sourceforge.net/test.txt"); // The download behavior doesn't accept downloads from a different domain ... final URL url3 = new URL("http://www.domain2.com/test.txt"); final String html1 = "\n" + " \n" + " Test\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final WebClient client = getWebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(url1, html1); webConnection.setResponse(url2, "foo"); webConnection.setResponse(url3, "foo2"); client.setWebConnection(webConnection); client.getPage(url1); final String[] expectedAlerts = getExpectedAlerts(); final int waitTime = 50; final int maxTime = 1000; for (int time = 0; time < maxTime; time += waitTime) { if (expectedAlerts.length <= collectedAlerts.size()) { assertEquals(expectedAlerts, collectedAlerts); return; } Thread.sleep(waitTime); } fail("Unable to collect expected alerts within " + maxTime + "ms; collected alerts: " + collectedAlerts); } /** * Test the removal of behaviors. * * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "body.isHomePage = undefined", "body.isHomePage = false", "body.isHomePage = undefined" }) public void removeBehavior() throws Exception { final String html = "\n" + "\n" + " Test\n" + " \n" + "\n" + "Test\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "BR", "DIV", "2", "3" }) public void children() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "

          test
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void setOnclick() throws Exception { eventHandlerSetterGetterTest("onclick"); } /** * @throws Exception if the test fails */ @Test public void setOndblclick() throws Exception { eventHandlerSetterGetterTest("ondblclick"); } /** * @throws Exception if the test fails */ @Test public void setOnblur() throws Exception { eventHandlerSetterGetterTest("onblur"); } /** * @throws Exception if the test fails */ @Test public void setOnfocus() throws Exception { eventHandlerSetterGetterTest("onfocus"); } /** * @throws Exception if the test fails */ @Test public void setOnkeydown() throws Exception { eventHandlerSetterGetterTest("onkeydown"); } /** * @throws Exception if the test fails */ @Test public void setOnkeypress() throws Exception { eventHandlerSetterGetterTest("onkeypress"); } /** * @throws Exception if the test fails */ @Test public void setOnkeyup() throws Exception { eventHandlerSetterGetterTest("onkeyup"); } /** * @throws Exception if the test fails */ @Test public void setOnmousedown() throws Exception { eventHandlerSetterGetterTest("onmousedown"); } /** * @throws Exception if the test fails */ @Test public void setOnmouseup() throws Exception { eventHandlerSetterGetterTest("onmouseup"); } /** * @throws Exception if the test fails */ @Test public void setOnmouseover() throws Exception { eventHandlerSetterGetterTest("onmouseover"); } /** * @throws Exception if the test fails */ @Test public void setOnmouseout() throws Exception { eventHandlerSetterGetterTest("onmouseout"); } /** * @throws Exception if the test fails */ @Test public void setOnmousemove() throws Exception { eventHandlerSetterGetterTest("onmousemove"); } /** * @throws Exception if the test fails */ @Test public void setOnresize() throws Exception { eventHandlerSetterGetterTest("onresize"); } /** * @param eventName the name of the event * @throws Exception if the test fails */ private void eventHandlerSetterGetterTest(final String eventName) throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "

          test
          \n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final String[] expectedAlerts = {"success"}; final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlElement div = page.getHtmlElementById("myDiv"); assertNotNull("Event handler was not set", div.getEventHandler(eventName)); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "Old = Old \r\ninnerText", "New = New cell value" }, FF = { "Old = undefined", "New = New cell value" }) public void getSetInnerTextSimple() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "
          Old

          innerText

          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void clickHashAnchor() throws Exception { final String html = "HashAnchor\n" + "\n" + " \n" + " Click\n" + "\n" + ""; final String[] expectedAlerts = {"test hash"}; // first use direct load final List loadCollectedAlerts = new ArrayList(); final HtmlPage loadPage = loadPage(getBrowserVersion(), html, loadCollectedAlerts); final HtmlAnchor loadHashAnchor = loadPage.getAnchorByName("hash"); loadHashAnchor.click(); assertEquals(expectedAlerts, loadCollectedAlerts); // finally try via the client final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); final CollectingAlertHandler clientCollectedAlertsHandler = new CollectingAlertHandler(); webClient.setAlertHandler(clientCollectedAlertsHandler); final HtmlPage clientPage = webClient.getPage(URL_FIRST); final HtmlAnchor clientHashAnchor = clientPage.getAnchorByName("hash"); clientHashAnchor.click(); assertEquals(expectedAlerts, clientCollectedAlertsHandler.getCollectedAlerts()); } /** * Test the removal of attributes from HTMLElements. * * @throws Exception if the test fails */ @Test @Alerts({ "removeMe", "null" }) public void removeAttribute() throws Exception { final String html = "\n" + "\n" + " Test\n" + " \n" + "\n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * IE doesn't really make a distinction between property and attribute... * * @throws Exception if the test fails */ @Test @Alerts(FF = { "hello", "null", "hello" }, IE = { "hello", "hello", "undefined" }) public void removeAttribute_property() throws Exception { final String html = "\n" + "\n" + " Test\n" + " \n" + "\n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * Test offsets (real values don't matter currently). * * @throws Exception if the test fails */ @Test @Alerts({ "number", "number", "number", "number", "number", "number", "number", "number" }) public void offsets() throws Exception { final String html = "\n" + "\n" + " Test\n" + "\n" + "\n" + "
          \n" + "
          foo
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "30px", "46", "55px", "71" }) public void offsetWidthAndHeight() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) @Alerts({ "30", "30", "30" }) public void offsetWidth_withEvent() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts("30") public void offsetWidth_parentWidthConstrainsChildWidth() throws Exception { final String html = "\n" + "
          foo
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "15", "15" }) public void offsetTopAndLeft_Padding() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          \n" + "
          d
          \n" + "
          \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "13", "28" }) public void offsetTopAndLeft_Margins() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          \n" + "
          d
          \n" + "
          \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "12", "12" }) public void offsetTopAndLeft_Borders() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          \n" + "
          d
          \n" + "
          \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "0", "0" }) public void offsetTopAndLeft_Nothing() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          \n" + "
          d
          \n" + "
          \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "50", "50" }) public void offsetTopAndLeft_AbsolutelyPositioned() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          \n" + "
          d
          \n" + "
          \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "40", "10" }) public void offsetTopAndLeft_parentAbsolute() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "
          " + "
          TEST
          \n" + ""; loadPageWithAlerts(html); } /** * Minimal flow/layouting test: verifies that the offsetTop property changes depending * on previous siblings. In the example below, the second div is below the first one, so its * offsetTop must be greater than zero. This sort of test is part of the Dojo unit tests, so * this needs to pass for the Dojo unit tests to pass. * * @throws Exception if an error occurs */ @Test @Alerts({ "false", "true" }) public void offsetTopWithPreviousSiblings() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          foo
          \n" + "
          bar
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * Test scrolls (real values don't matter currently). * * @throws Exception if the test fails */ @Test @Alerts({ "number", "number", "number", "number", "number", "number", "number", "number" }) public void scrolls() throws Exception { final String html = "\n" + "\n" + " Test\n" + "\n" + "\n" + "
          \n" + "
          foo
          \n" + ""; loadPageWithAlerts(html); } /** * Tests that JavaScript scrollIntoView() function doesn't fail. * @throws Exception if the test fails */ @Test @Alerts("ok") public void scrollIntoView() throws Exception { final String html = "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Tests the offsetParent property. * @throws Exception if the test fails */ @Test @Alerts({ "element: span3 offsetParent: td2", "element: td2 offsetParent: table2", "element: tr2 offsetParent: table2", "element: table2 offsetParent: td1", "element: td1 offsetParent: table1", "element: tr1 offsetParent: table1", "element: table1 offsetParent: body1", "element: span2 offsetParent: body1", "element: span1 offsetParent: body1", "element: div1 offsetParent: body1", "element: body1 offsetParent: null", "new element: undefined" }) public void offsetParent_Basic() throws Exception { final String html = "\n" + "\n" + "\n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " some text\n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * Tests the offsetParent property, including the effects of CSS "position" attributes. * Based on this work. * @throws Exception if an error occurs */ @Test @Alerts(IE = { "null", "body", "body", "body", "body", "body", "body", "body", "h1", "i1", "td", "td", "td", "body", "body" }, FF = { "null", "body", "body", "body", "body", "body", "f1", "body", "h1", "i1", "td", "body", "td", "body", "body" }) public void offsetParent_WithCSS() throws Exception { final String html = "\n" + " \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          x
          \n" + "
          \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } /** * Test for bug https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1960512&group_id=47038. * @throws Exception if the test fails */ @Test public void offsetParent_withSelectors() throws Exception { final String html = "\n" + "\n" + "
          \n" + "\n" + ""; loadPage(getBrowserVersion(), html, null); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "undefined", "undefined", "undefined", "undefined", "undefined", "123", "from myFunction", "123", "from myFunction" }) public void prototype() throws Exception { final String html = "Prototype test\n" + "\n" + "
          bla
          \n" + "bla\n" + ""; loadPageWithAlerts(html); } /** * 'Element' and 'HTMLElement' prototypes are synonyms. * * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts("in selectNodes") public void prototype_Element() throws Exception { final String html = "foo\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "true", "true" }) public void instanceOf() throws Exception { final String html = "instanceof test\n" + "\n" + "
          bla
          \n" + "bla\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "null", "[object]" }, FF = { "undefined", "undefined" }) public void parentElement() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
          \n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("rgb(0, 0, 0)") @Browsers(Browser.IE) public void currentStyle() throws Exception { style("currentStyle"); } /** * @throws Exception if the test fails */ @Test @Alerts("") @Browsers(Browser.IE) public void runtimeStyle() throws Exception { style("runtimeStyle"); } private void style(final String styleProperty) throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Alerts({ "402", "102" }) @Test @Browsers(Browser.IE) public void getBoundingClientRect() throws Exception { final String html = "foo\n" + "
          " + "
          " + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) public void getClientRects() throws Exception { final String html = "foo\n" + "
          \n" + ""; loadPage(getBrowserVersion(), html, null); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "null", "#document-fragment" }, FF = { "null", "null" }) public void innerHTML_parentNode() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "null", "#document-fragment" }, FF = { "null", "null" }) public void innerText_parentNode() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "true", "false" }, FF = { "true", "true" }) public void uniqueID() throws Exception { final String html = "foo\n" + "
          \n" + "
          \n" + ""; final WebClient client = getWebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_GARGOYLE, html); client.setWebConnection(webConnection); client.getPage(URL_GARGOYLE); if (!getBrowserVersion().isIE()) { assertEquals("undefined", collectedAlerts.get(0)); } else { assertFalse("undefined".equals(collectedAlerts.get(0))); } assertEquals(getExpectedAlerts(), collectedAlerts.subList(1, collectedAlerts.size())); } /** * Tests if element.uniqueID starts with 'ms__id', and is lazily created. * * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "true", "true" }) public void uniqueIDFormatIE() throws Exception { final String html = "foo\n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * Tests setAttribute() with name of event handler. * @throws Exception if the test fails */ @Test public void setAttribute_eventHandler() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          \n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlForm form = page.getForms().get(0); final HtmlTextInput inputLogin = form.getInputByName("login"); final HtmlPasswordInput inputPassword = form.getInputByName("password"); inputLogin.focus(); inputPassword.focus(); final int expectedAlertNumber; if (getBrowserVersion().isIE()) { expectedAlertNumber = 0; } else { expectedAlertNumber = 3; } assertEquals(expectedAlertNumber, collectedAlerts.size()); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void fireEvent_WithoutTemplate() throws Exception { final String html = "\n" + "
          foo
          \n" + "
          bar
          \n" + ""; final List actual = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, actual); page.getHtmlElementById("a").click(); page.getHtmlElementById("b").mouseOver(); final String[] expected = {"clicked", "clicked"}; assertEquals(expected, actual); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void fireEvent_WithTemplate() throws Exception { final String html = "\n" + "\n" + "\n" + "
          foo
          \n" + "
          bar
          \n" + "
          baz
          \n" + ""; final List actual = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, actual); page.getHtmlElementById("a").click(); page.getHtmlElementById("b").mouseOver(); page.getHtmlElementById("c").mouseOver(); final String[] expected = {"click", "click", "click"}; assertEquals(expected, actual); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void setExpression() throws Exception { final String html = "foo\n" + "
          \n" + ""; loadPage(getBrowserVersion(), html, null); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.IE) public void removeExpression() throws Exception { final String html = "foo\n" + "
          \n" + ""; loadPage(getBrowserVersion(), html, null); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) @Alerts("clicked") public void dispatchEvent() throws Exception { final String html = "\n" + "\n" + "
          foo
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) @Alerts({ "true", "true", "false" }) public void hasAttribute() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.NONE) public void dispatchEvent2() throws Exception { testHTMLFile("HTMLElementTest_dispatchEvent2.html"); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({ "undefined", "x86", "0", "undefined" }) public void getComponentVersion() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(IE = { "30", "40" }, FF = { "36", "46" }) public void clientWidthAndHeight() throws Exception { final String html = "foo\n" + "\n" + "\n" + "\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts({"[object]", "text1", "[object]", "onfocus text2", "text2", "onfocus text1", "onfocus text2" }) public void setActiveAndFocus() throws Exception { final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); final List collectedAlerts = new ArrayList(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final String firstHtml = "First\n" + "\n" + "
          \n" + "\n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({"false", "true" }) public void checkedAttribute_Checkbox() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + "
          \n" + " \n" + "
          \n" + "click me\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlCheckBoxInput checkBox = page.getHtmlElementById("checkbox1"); assertFalse(checkBox.isChecked()); page.getHtmlElementById("clickme").click(); assertTrue(checkBox.isChecked()); assertEquals(getExpectedAlerts(), collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void checkedAttribute_Radio() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + "
          \n" + " \n" + " \n" + " \n" + "
          \n" + "click me\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlRadioButtonInput radioA = page.getHtmlElementById("radioA"); final HtmlRadioButtonInput radioB = page.getHtmlElementById("radioB"); final HtmlRadioButtonInput radioC = page.getHtmlElementById("radioC"); assertTrue(radioA.isChecked()); assertFalse(radioB.isChecked()); assertFalse(radioC.isChecked()); page.getHtmlElementById("clickme").click(); assertFalse(radioA.isChecked()); assertTrue(radioB.isChecked()); assertFalse(radioC.isChecked()); final String[] expectedAlerts = {"true", "false", "false", "false", "true", "false"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void disabledAttribute() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + "
          \n" + " \n" + " \n" + " \n" + "
          \n" + "click me\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlForm form = page.getFormByName("form1"); final HtmlSubmitInput button1 = form.getInputByName("button1"); final HtmlSubmitInput button2 = form.getInputByName("button2"); final HtmlSubmitInput button3 = form.getInputByName("button3"); assertFalse(button1.isDisabled()); assertTrue(button2.isDisabled()); assertFalse(button3.isDisabled()); page.getHtmlElementById("clickme").click(); assertTrue(button1.isDisabled()); assertFalse(button2.isDisabled()); assertTrue(button3.isDisabled()); final String[] expectedAlerts = {"false", "true", "false", "true", "false", "true"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void inputValue() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + "
          \n" + " \n" + "
          \n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlForm form = page.getFormByName("form1"); form.submit(null); } /** * @throws Exception if the test fails */ @Test public void inputSelect_NotDefinedAsPropertyAndFunction() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + "
          \n" + " \n" + "
          \n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlForm form = page.getFormByName("form1"); form.submit(null); } /** * @throws Exception if the test fails */ @Test public void thisDotFormInOnClick() throws Exception { final String htmlContent = "\n" + "First\n" + "\n" + "
          \n" + "\n" + "
          \n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), htmlContent, null); assertEquals("First", page.getTitleText()); assertEquals("", page.getFormByName("form1").getTargetAttribute()); ((HtmlSubmitInput) page.getFormByName("form1").getInputByName("button1")).click(); assertEquals("_blank", page.getFormByName("form1").getTargetAttribute()); } /** * @throws Exception if the test fails */ @Test @Alerts({"true", "true", "true", "true", "true" }) public void fieldDotForm() throws Exception { final String html = "\n" + "foo\n" + "\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void inputNameChange() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + "
          \n" + " \n" + " \n" + "
          \n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final MockWebConnection connection = (MockWebConnection) page.getWebClient().getWebConnection(); final HtmlForm form = page.getFormByName("form1"); form.getInputByName("button1").click(); final String[] expectedAlerts = {"changed"}; assertEquals(expectedAlerts, collectedAlerts); final List expectedParameters = Arrays.asList(new NameValuePair[] { new NameValuePair("changed", "foo"), new NameValuePair("button1", "pushme") }); assertEquals(expectedParameters, connection.getLastParameters()); } /** * @throws Exception if the test fails */ @Test public void onChange() throws Exception { final String html = "foo\n" + "\n" + "

          hello world

          \n" + "
          \n" + " \n" + "\n" + "
          \n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlForm form = page.getFormByName("form1"); final HtmlTextInput textinput = form.getInputByName("text1"); textinput.setValueAttribute("foo"); final HtmlButtonInput button = form.getInputByName("myButton"); button.click(); assertEquals("from button", textinput.getValueAttribute()); final String[] expectedAlerts = {"foo"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void onChangeSetByJavaScript() throws Exception { final String html = "foo\n" + "\n" + "

          hello world

          \n" + "
          \n" + " \n" + "\n" + "
          \n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlForm form = page.getFormByName("form1"); final HtmlTextInput textinput = form.getInputByName("text1"); textinput.setValueAttribute("foo"); final HtmlButtonInput button = form.getInputByName("myButton"); button.click(); assertEquals("from button", textinput.getValueAttribute()); final String[] expectedAlerts = {"foo"}; assertEquals(expectedAlerts, collectedAlerts); createTestPageForRealBrowserIfNeeded(html, expectedAlerts); } /** * Test the default value of a radio and checkbox buttons. * @throws Exception if the test fails */ @Test @Alerts({"on", "on" }) public void defautValue() throws Exception { final String html = "First\n" + "\n" + "
          \n" + "\n" + "\n" + "
          "; loadPageWithAlerts(html); } /** * Test that changing type doesn't throw. * Test must be extended when setting type really does something. * @throws Exception if the test fails */ @Test @Alerts({"radio", "hidden", "image" }) public void changeType() throws Exception { final String html = "First\n" + "\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlImageInput.class.isInstance(page.getFormByName("myForm").getInputByName("myRadio"))); } /** * @throws Exception if the test fails */ @Test @Alerts({"radio", "hidden", "image" }) public void changeType2() throws Exception { final String html = "First\n" + "\n" + "
          " + "\n" + "
          "; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlImageInput.class.isInstance(page.getFormByName("myForm").getInputByName("myRadio"))); } /** * Inputs have properties not only from there own type. * Works with Mozilla, Firefox and IE... but not with HtmlUnit now. * @throws Exception if the test fails */ @Test public void defaultValues() throws Exception { final String html = "\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + "\n" + ""; final String[] expectedAlerts = { "button: false, false, function, function, , ", "submit: false, false, function, function, submit it!, submit it!", "file: false, false, function, function, , ", "checkbox: true, true, function, function, , on", "radio: true, true, function, function, , on", "text: false, false, function, function, , ", "password: false, false, function, function, , " }; createTestPageForRealBrowserIfNeeded(html, expectedAlerts); final List collectedAlerts = new ArrayList(); loadPage(getBrowserVersion(), html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts({"text", "hidden" }) public void createInputAndChangeType() throws Exception { final String html = "First\n" + "\n" + "
          \n" + "
          "; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void buttonOutsideForm() throws Exception { final String content = "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), content, collectedAlerts); final Page page2 = page.getHtmlElementById("clickMe").click(); assertSame(page, page2); final String[] expectedAlerts = {"123"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Test that field delegates submit to the containing form. * @throws Exception if the test fails */ @Test public void onChangeCallsFormSubmit() throws Exception { final String content = "\n" + "\n" + "\n" + "
          \n" + "\n" + "
          \n" + ""; final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse("page 2"); webConnection.setResponse(URL_FIRST, content); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); final HtmlPage page2 = (HtmlPage) page.getFormByName("test").getInputByName("field1").setValueAttribute("bla"); assertEquals("page 2", page2.getTitleText()); } /** * @throws Exception if the test fails */ @Test @Alerts({"undefined", "30", "undefined", "30", "30", "30", "40", "50", "string", "number" }) public void maxLength() throws Exception { final String html = "First\n" + "\n" + "
          \n" + "\n" + "
          "; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts("hello") public void selectionRange() throws Exception { final String html = "foo\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlTextInput input = page.getHtmlElementById("myInput"); assertEquals("me te", input.getSelectedText()); } /** * @throws Exception if the test fails */ @Test @Alerts({"text text", "password password", "hidden hidden", "checkbox checkbox", "radio radio", "file file", "checkbox checkbox" }) public void typeCase() throws Exception { final String html = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("true") public void readOnly() throws Exception { final String html = "foo\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"", "hello", "left", "hi", "right" }, IE = {"", "error", "", "", "error", "", "" }) public void align() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({ "", "A", "a", "A", "a8", "8Afoo", "8", "@" }) public void accessKey() throws Exception { final String html = ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDirectoryElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000655211650253660034431 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLDirectoryElement}. * * @version $Revision: 4774 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLDirectoryElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "false", "true", "true", "true", "null", "", "blah", "2", "true", "false", "true", "false", "", "null", "", "null" }, IE = { "false", "true", "true", "true", "false", "true", "true", "true", "true", "false", "true", "false", "true", "false", "true", "false" }) public void compact() throws Exception { final String html = "\n" + "
        • a
        • b
        • \n" + "
        • a
        • b
        • \n" + "
        • a
        • b
        • \n" + "
        • a
        • b
        • \n" + "\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableSectionElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000003016011650253660034421 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLTableSectionElement}. * * @version $Revision: 4698 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLTableSectionElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"left", "hello", "left", "hi", "right" }, IE = {"", "error", "", "left", "error", "left", "right" }) public void align_thead() throws Exception { align("th"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"left", "hello", "left", "hi", "right" }, IE = {"", "error", "", "left", "error", "left", "right" }) public void align_tbody() throws Exception { align("tb"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"left", "hello", "left", "hi", "right" }, IE = {"", "error", "", "left", "error", "left", "right" }) public void align_tfoot() throws Exception { align("tf"); } private void align(final String id) throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "top", "baseline", "3", "middle", "8", "bottom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) public void vAlign_thead() throws Exception { vAlign("th"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "top", "baseline", "3", "middle", "8", "bottom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) public void vAlign_tbody() throws Exception { vAlign("tb"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "top", "baseline", "3", "middle", "8", "bottom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) public void vAlign_tfoot() throws Exception { vAlign("tf"); } private void vAlign(final String id) throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "p", "po", ".", "u", "8", "U8" }, IE = { "", "", "", "u", "8", "U8" }) public void ch_thead() throws Exception { ch("th"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "p", "po", ".", "u", "8", "U8" }, IE = { "", "", "", "u", "8", "U8" }) public void ch_tbody() throws Exception { ch("tb"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "p", "po", ".", "u", "8", "U8" }, IE = { "", "", "", "u", "8", "U8" }) public void ch_tfoot() throws Exception { ch("tf"); } private void ch(final String id) throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "0", "4", "", "5", "0", "abc" }, IE = { "", "", "", "5.2", "-3", "abc" }) public void chOff_thead() throws Exception { chOff("th"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "0", "4", "", "5", "0", "abc" }, IE = { "", "", "", "5.2", "-3", "abc" }) public void chOff_tbody() throws Exception { chOff("tb"); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "0", "4", "", "5", "0", "abc" }, IE = { "", "", "", "5.2", "-3", "abc" }) public void chOff_tfoot() throws Exception { chOff("tf"); } private void chOff(final String id) throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = "world", IE = { "exception", "hello" }) public void TBODY_innerHTML() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + " \n" + "
          hello
          \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBodyElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000002353411650253660034430 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Unit tests for {@link HTMLBodyElement}. * * @version $Revision: 4559 $ * @author Daniel Gredler * @author Ahmed Ashour * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class HTMLBodyElementTest extends WebTestCase { /** * Tests the default body padding and margins. * @throws Exception if an error occurs */ @Test @Alerts(FF = {",0px,0px,0px,0px", ",,,,", ",8px,8px,8px,8px", ",,,," }, IE = {"0px,0px,0px,0px,0px", ",,,,", "15px 10px,10px,10px,15px,15px", ",,,," }) public void testDefaultPaddingAndMargins() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts("[object]") @Browsers(Browser.IE) public void attachEvent() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); page.getHtmlElementById("myInput").click(); assertEquals(getExpectedAlerts(), collectedAlerts); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = "no", IE = "yes") public void doScroll() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"#ee0000", "#0000aa", "#000000" }, IE = {"", "#0000aa", "#000000" }) public void aLink() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"", "http://www.foo.com/blah.gif", "http://www.gargoylesoftware.com/blah.gif" }, IE = {"", "http://www.foo.com/blah.gif", "blah.gif" }) public void background() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"#ffffff", "#0000aa", "#000000" }, IE = {"", "#0000aa", "#000000" }) public void bgColor() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"#0000ee", "#0000aa", "#000000" }, IE = {"", "#0000aa", "#000000" }) public void link() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"#000000", "#0000aa", "#000000" }, IE = {"", "#0000aa", "#000000" }) public void text() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"#000000", "#0000aa", "#000000" }, IE = {"", "#0000aa", "#000000" }) public void vLink() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000004146111650253660034427 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSelect; /** * Tests for {@link HTMLOptionElement}. * * @version $Revision: 4900 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLOptionElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "some text", "some value", "false", "some other text", "some other value", "true" }) public void readPropsBeforeAdding() throws Exception { final String html = "foo\n" + "

          hello world

          \n" + ""; loadPageWithAlerts(html); } /** * Regression test for bug 1323425. * See http://sourceforge.net/tracker/index.php?func=detail&aid=1323425&group_id=47038&atid=448266. * @throws Exception if the test fails */ @Test public void selectingOrphanedOptionCreatedByDocument() throws Exception { final String html = "\n" + "\n" + "
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * Regression test for 1592728. * @throws Exception if the test fails */ @Test @Alerts({ "2", "2" }) public void setSelected() throws Exception { final String html = "foo\n" + "\n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * Regression test for 1672048. * @throws Exception if the test fails */ @Test public void setAttribute() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "undefined", "caught exception for negative index" }) public void optionIndexOutOfBound() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "o2: text: Option 2, label: , value: 2, defaultSelected: false, selected: false", "o3: text: Option 3, label: , value: 3, defaultSelected: true, selected: false", "0", "1" }) public void constructor() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("0") public void insideBold() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "[object]", "[object]", "[object]", "[object]", "null", "[object]", "null", "[object]", "[object]", "null" }, FF = { "null", "[object Attr]", "null", "null", "null", "null", "null", "null", "null", "null" }) public void getAttributeNode() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @NotYetImplemented @Alerts("1") public void without_new() throws Exception { final String html = "foo\n" + " \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "value1", "text1", "label1", "value2", "text2", "" }) public void label() throws Exception { final String html = "foo\n" + " \n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlSelect select = page.getHtmlElementById("testSelect"); assertEquals("value1", select.getOption(0).getValueAttribute()); assertEquals("text1", select.getOption(0).getTextContent()); assertEquals("label1", select.getOption(0).getLabelAttribute()); assertEquals("value2", select.getOption(1).getValueAttribute()); assertEquals("text2", select.getOption(1).getTextContent()); assertEquals("", select.getOption(1).getLabelAttribute()); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "null", "[object]", "null" }, FF = { "[object Text]", "[object Text]", "[object Text]" }) public void text() throws Exception { final String html = "foo\n" + " \n" + "\n" + ""; loadPageWithAlerts(html); } /** * Visibility of elements should not impact the determination of the value of option * without value attribute or the text of options. This tests for one part a regression * introduced in rev. 4367 as well probably as a problem that exists since a long time. * @throws Exception if the test fails */ @Test @Alerts({ "text1", "text1b", "text2" }) public void text_when_not_displayed() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + "
          \n" + "
          \n" + " \n" + "
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * For IE nested nodes aren't used as default value attribute. * @throws Exception if the test fails */ @Test @Alerts(FF = { "text0", "text1", "text1b", "text2" }, IE = { "", "", "", "" }) public void defaultValueFromNestedNodes() throws Exception { final String html = "foo\n" + " \n" + "
          \n" + " \n" + "
          \n" + "
          \n" + " \n" + "
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLFormElement]") public void form() throws Exception { final String html = "
          "; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000006431511650253660034432 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import static org.junit.Assert.fail; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.ScriptException; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlTextArea; /** * Tests for {@link HTMLDocument}. * * @version $Revision: 4855 $ * @author Ahmed Ashour * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class HTMLDocumentTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({ "2", "DIV", "2" }) public void getElementsByTagName() throws Exception { final String html = "\n" + "\n" + " Test\n" + " \n" + "\n" + "" + "
          \n" + "
          \n" + "
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF3 = { "function", "div1", "span2", "span3", "2", "1", "1", "0", "0", "0" }, FF2 = { "undefined", "exception" }, IE = { "undefined", "exception" }) public void getElementsByClassName() throws Exception { final String html = "First\n" + "
          hello\n" + " World!
          \n" + "again\n" + "bye\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts("BackCompat") public void compatMode() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts("BackCompat") public void compatMode_no_url() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts("CSS1Compat") public void compatMode_strict() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts("CSS1Compat") public void compatMode_strict_40() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "CSS1Compat", FF = "BackCompat") public void compatMode_loose_40() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts("CSS1Compat") public void compatMode_loose() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts("CSS1Compat") public void compatMode_xhtml_traditional() throws Exception { compatMode(""); } /** * @throws Exception if the test fails */ @Test @Alerts("CSS1Compat") public void compatMode_xhtml_strict() throws Exception { compatMode(""); } private void compatMode(final String doctype) throws Exception { final String html = doctype + "\n" + "\n" + " Test\n" + " \n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "true", FF = "false") public void uniqueID() throws Exception { final String html = "\n" + "\n" + " Test\n" + " \n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "[object HTMLDivElement]", "[object HTMLUnknownElement]", "[object Element]" }) public void createDocumentNS() throws Exception { final String html = "\n" + "\n" + "Test\n" + "\n" + "\n" + "" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts("Hello") public void createDocumentNS_xul() throws Exception { final String html = "\n" + "\n" + "Test\n" + "\n" + "\n" + "" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "[object HTMLCollection]", "0" }, IE = { "[object]", "0" }) public void applets() throws Exception { final String html = "\n" + "\n" + "Test\n" + "\n" + "\n" + "" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = "imported: [object HTMLScriptElement]", IE = "exception") @NotYetImplemented(Browser.FF) public void importNode_script() throws Exception { final String html = "foo\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) @Alerts("clicked") public void dispatchEvent() throws Exception { final String html = "\n" + "\n" + "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "undefined", "exception" }, IE = { "[object]", "0", "1", "f", "f", "f", "f", "urn:f", "urn:f", "true" }) public void namespaces() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * Verifies that we can store document methods and use them from a variable (IE only). * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts(IE = { "d", "1" }) public void documentMethodsWithoutDocument() throws Exception { final String html = "
          d
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @NotYetImplemented @Alerts("Hello There") public void write() throws Exception { final String html = "\n" + "\n" + "Test\n" + "\n" + "\n" + "" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "null") public void getElementById_caseSensitivity() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "" + "
          \n" + "
          \n" + "
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.IE) public void readyState() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "" + "
          \n" + " \n" + "
          \n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final String expected = getBrowserVersion().isIE() ? "loading,null-complete,[object]-" : "undefined,[object HTMLBodyElement]-undefined,[object HTMLBodyElement]-"; page.getWebClient().waitForBackgroundJavaScript(500); assertEquals(expected, page.getHtmlElementById("myTextarea").getText()); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"#ffffff", "#ffffff", "#0000aa", "#0000aa", "#000000", "#000000" }, IE = {"#ffffff", "", "#0000aa", "#0000aa", "#000000", "#000000" }) public void bgColor() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " blah\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"[object HTMLSpanElement]", "undefined" }, IE = {"[object]", "4", "red" }) public void identicalIDs() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "www.gargoylesoftware.com", "gargoylesoftware.com" }) public void domain() throws Exception { final String html = "foo\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) public void domainMixedCaseNetscape() throws Exception { final URL urlGargoyleUpperCase = new URL("http://WWW.GARGOYLESOFTWARE.COM/"); final String html = "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); loadPage(getBrowserVersion(), html, collectedAlerts, urlGargoyleUpperCase); final String[] expectedAlerts = {"www.gargoylesoftware.com", "gargoylesoftware.com"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "www.gargoylesoftware.com", "gargoylesoftware.com" }, IE = { "www.gargoylesoftware.com", "GaRgOyLeSoFtWaRe.CoM" }) public void domainMixedCase() throws Exception { final String html = "foo\n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void domainLong() throws Exception { final String html = "foo\n" + "\n" + ""; final String[] expectedAlerts = {"d4.d3.d2.d1.gargoylesoftware.com", "d4.d3.d2.d1.gargoylesoftware.com", "d1.gargoylesoftware.com"}; final List collectedAlerts = new ArrayList(); loadPage(getWebClient(), html, collectedAlerts, new URL("http://d4.d3.d2.d1.gargoylesoftware.com")); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void domainSetSelf() throws Exception { final String html = "foo\n" + "\n" + ""; final String[] expectedAlerts = {"localhost", "localhost"}; final List collectedAlerts = new ArrayList(); loadPage(getWebClient(), html, collectedAlerts, new URL("http://localhost")); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void domainTooShort() throws Exception { final String html = "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); try { loadPage(getWebClient(), html, collectedAlerts); } catch (final ScriptException ex) { return; } fail(); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "www.gargoylesoftware.com", "www.gargoylesoftware.com" }, IE = { "www.gargoylesoftware.com", "www.gargoylesoftware.com", "exception" }) public void domain_set_for_about_blank() throws Exception { final String html = "foo\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Caused infinite loop at some point of 2.6 snapshot. * See Bug 2824922 * @throws Exception if the test fails */ @Test public void write2_html_endhtml_in_head() throws Exception { final String html = "\n" + "\n" + "\n" + "\n"; loadPageWithAlerts(html); } /** * We couldn't document.write() script elements that contained the '<' character... * @exception Exception if the test fails */ @Test @Alerts("true") public void writeScript() throws Exception { final String html = ""; loadPageWithAlerts(html); } /** * Test that document.forms.form_name should be evaluated to undefined if the form has a prefix. * @throws Exception if the test fails */ @Test @NotYetImplemented @Alerts("undefined") public void prefix() throws Exception { final String html = "foo\n" + "\n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAreaElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000407411650253660034426 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLAreaElement}. * * @version $Revision: 4503 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLAreaElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts({ "", "A", "a", "A", "a8", "8Afoo", "8", "@" }) public void readWriteAccessKey() throws Exception { final String html = ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLButtonElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000411511650253660034422 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLButtonElement}. * * @version $Revision: 4503 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLButtonElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts({ "", "A", "a", "A", "a8", "8Afoo", "8", "@" }) public void readWriteAccessKey() throws Exception { final String html = ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCellElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000003726211650253660034433 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; /** * Tests for {@link HTMLTableCellElement}. * * @version $Revision: 4661 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLTableCellElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "left", "right", "3", "center", "8", "foo" }, IE = { "left", "right", "", "error", "error", "center", "right", "" }) public void align() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          abc
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "p", "po", ".", "u", "8", "U8" }, IE = { "", "", "", "u", "8", "U8" }) public void ch() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          abc
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "0", "4", "", "5", "0", "abc" }, IE = { "", "", "", "5.2", "-3", "abc" }) public void chOff() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          abc
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "top", "baseline", "3", "middle", "8", "bottom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) public void vAlign() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          abc
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({"", "#0000aa", "#000000" }) public void bgColor() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          a
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = {"false", "null", "true", "", "true", "", "true", "blah", "false", "null" }, IE = {"false", "false", "true", "true", "true", "true", "true", "true", "false", "false" }) public void noWrap() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          a
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({"", "blah", "3", "" }) public void abbr() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          a
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "1", "3", "1", "2", "1", "5", "1", "2", "1" }, IE = { "1", "3", "1", "error", "2", "3", "5", "error", "error", "2", "2", "5" }) public void colSpan() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          abc
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "1", "3", "1", "2", "1", "5", "1", "2", "1" }, IE = { "1", "3", "1", "error", "2", "3", "5", "error", "error", "2", "2", "5" }) public void rowSpan() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          abc
          abc
          abc
          abc
          abc
          abc
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({"", "blah", "abc , xyz", "3", "" }) public void axis() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          a
          \n" + " \n" + ""; loadPageWithAlerts(html); } /** * Tests some obscure table cell CSS calculations required by the MochiKit tests. * @throws Exception if an error occurs */ @Test @Browsers(Browser.FF) @Alerts(FF = { "84,30", "84,30", "84,30", "82,30", "82,30", "82,30" }) public void cellWidthHeightWithBorderCollapse() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "
          aaa
          "; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableRowElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000002363111650253660034426 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLTableRowElement}. * * @version $Revision: 4608 $ * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class HTMLTableRowElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(FF = "[object HTMLTableRowElement]", IE = "[object]") public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts({ "4", "td1", "3", "td2", "td4", "2", "td3", "exception", "exception" }) public void deleteCell() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          1234
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "4", "exception", "4" }, IE = { "4", "3" }) public void deleteCell_noArg() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          1234
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "left", "right", "3", "center", "8", "foo" }, IE = { "left", "right", "", "error", "error", "center", "right", "" }) public void align() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + "
          a
          b
          c
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "p", "po", ".", "u", "8", "U8" }, IE = { "", "", "", "u", "8", "U8" }) public void ch() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + "
          a
          b
          c
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "0", "4", "", "5", "0", "abc" }, IE = { "", "", "", "5.2", "-3", "abc" }) public void chOff() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + "
          a
          b
          c
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts(FF = { "top", "baseline", "3", "middle", "8", "bottom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) public void vAlign() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + "
          a
          b
          c
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if an error occurs */ @Test @Alerts({"", "#0000aa", "#000000" }) public void bgColor() throws Exception { final String html = "\n" + " \n" + " \n" + " \n" + " \n" + "
          a
          \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000321211650253660034417 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLElement}. * * @version $Revision: 4895 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HTMLElement2Test extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "HTML", "" }, FF = { "undefined", "undefined" }) public void scopeName() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts2(html); } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBRElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000636111650253660034427 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HTMLBRElement}. * * @version $Revision: 4569 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class HTMLBRElementTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test @Alerts( IE = { "", "left", "all", "right", "none", "", "", "!", "!", "!", "left", "none", "right", "all", "none", "", "" }, FF = { "", "left", "all", "right", "none", "2", "foo", "left", "none", "right", "all", "2", "abc", "8" }) public void clear() throws Exception { final String html = "\n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTitleElementTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTML0000664000175000017500000000353111650253660034423 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link HTMLTitleElement}. * @version $Revision: 4503 $ * @author Sudhan Moghe */ @RunWith(BrowserRunner.class) public class HTMLTitleElementTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts({"Page Title", "New Title" }) public void text() throws Exception { final String html = "\n" + " \n" + " Page Title\n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MimeTypeTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MimeTypeT0000664000175000017500000000711211650253660034567 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.PluginConfiguration; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Unit tests for {@link MimeType}. * * @version $Revision: 4002 $ * @author Marc Guillemot */ public class MimeTypeTest extends WebTestCase { /** * Tests default configuration of Flash plugin for Firefox. * @throws Exception if the test fails */ @Test public void testFlashMimeType() throws Exception { final String html = "\n" + ""; final String[] expectedAlerts = {"[object MimeType]", "swf", "Shockwave Flash", "true", "true"}; createTestPageForRealBrowserIfNeeded(html, expectedAlerts); final List collectedAlerts = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Tests default configuration of Flash plugin for Firefox. * @throws Exception if the test fails */ @Test public void testRemoveFlashMimeType() throws Exception { final String html = "\n" + ""; final String[] expectedAlerts = {"undefined", "undefined", "null"}; createTestPageForRealBrowserIfNeeded(html, expectedAlerts); final List collectedAlerts = new ArrayList(); final Set plugins = new HashSet(BrowserVersion.FIREFOX_2.getPlugins()); BrowserVersion.FIREFOX_2.getPlugins().clear(); try { loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } finally { BrowserVersion.FIREFOX_2.getPlugins().addAll(plugins); } } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResultTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XPathResu0000664000175000017500000002003711650253660034576 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; /** * Tests for {@link XPathResult}. * * @version $Revision: 4617 $ * @author Ahmed Ashour * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class XPathResultTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "4", "1", "3" }) public void resultType() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "7", "id1", "id2" }) public void snapshotType() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "9", "id1" }) public void singleNodeValue() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts({ "id1", "id2" }) public void iterateNext() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts("7") public void notOr() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XSLTProcessorTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/XSLTProce0000664000175000017500000001277611650253660034511 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link XSLTProcessor}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ public class XSLTProcessorTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void test() throws Exception { final String[] expectedAlertsIE = {"97"}; test(BrowserVersion.INTERNET_EXPLORER_7, expectedAlertsIE); final String[] expectedAlertsFF = {"97", "null"}; test(BrowserVersion.FIREFOX_2, expectedAlertsFF); } private void test(final BrowserVersion browserVersion, final String[] expectedAlerts) throws Exception { final String html = "foo\n" + ""; final String xml = "\n" + "\n" + " \n" + " Empire Burlesque\n" + " Bob Dylan\n" + " USA\n" + " Columbia\n" + " 10.90\n" + " 1985\n" + " \n" + ""; final String xsl = "\n" + "\n" + " \n" + " \n" + " \n" + "

          My CD Collection

          \n" + "
            \n" + " \n" + "
          • ()
          • \n" + "
            \n" + "
          \n" + " \n" + " \n" + "
          \n" + "
          "; final List collectedAlerts = new ArrayList(); final WebClient client = new WebClient(browserVersion); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html); conn.setResponse(URL_SECOND, xml, "text/xml"); conn.setResponse(URL_THIRD, xsl, "text/xml"); client.setWebConnection(conn); client.getPage(URL_FIRST); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/BoxObjectTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/BoxObject0000664000175000017500000000751111650253660034574 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.host; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Unit tests for {@link BoxObject}. * * @version $Revision: 4741 $ * @author Daniel Gredler */ @RunWith(BrowserRunner.class) public class BoxObjectTest extends WebDriverTestCase { /** * Tests box object attributes relating to HTML elements: firstChild, lastChild, previousSibling, etc. * @throws Exception if an error occurs */ @Test @Alerts(FF = { "true", "true", "true", "true", "true" }, IE = "exception") public void testElementAttributes() throws Exception { final String html = "\n" + " \n" + " foo
          ab
          bar\n" + " \n" + " \n" + ""; loadPageWithAlerts2(html); } /** * Tests box object attributes relating to position and size: x, y, screenX, screenY, etc. * @throws Exception if an error occurs */ @Test @Alerts(FF = { "73-123", "73-244", "510-410" }, IE = "exception") public void testPositionAndSizeAttributes() throws Exception { final String html = "\n" + " \n" + " \n" + "
          daniel
          \n" + " \n" + " \n" + ""; loadPageWithAlerts2(html); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/0000775000175000017500000000000011650253660034660 5ustar jamespagejamespage././@LongLink0000000000000000000000000000020500000000000011562 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/0000664000175000017500000007511611650253660034674 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.configuration; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Assert; import org.junit.Test; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.javascript.StrictErrorHandler; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; /** * Tests for {@link JavaScriptConfiguration}. * * @version $Revision: 4792 $ * @author Chris Erskine * @author Ahmed Ashour */ public class JavaScriptConfigurationTest extends WebTestCase { private static final Log LOG = LogFactory.getLog(JavaScriptConfigurationTest.class); /** * Constructor. */ public JavaScriptConfigurationTest() { JavaScriptConfiguration.resetClassForTesting(); } /** * Resets the JavaScriptConfiguration file for each test to it's initial clean state. * @throws Exception if the test fails */ @After public void tearDown() throws Exception { JavaScriptConfiguration.resetClassForTesting(); } /** * Tests loading a configuration from the supplied stream. */ @Test public void loadLocalConfiguration() { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + ""; final Reader reader = new StringReader(configurationString); Assert.assertFalse("Document should not be loaded", JavaScriptConfiguration.isDocumentLoaded()); JavaScriptConfiguration.loadConfiguration(reader); assertTrue("Documnet should now be loaded", JavaScriptConfiguration.isDocumentLoaded()); } /** * Tests loading a configuration from the supplied stream. */ @Test public void loadSystemConfigurationFile() { Assert.assertFalse("Document should not be loaded", JavaScriptConfiguration.isDocumentLoaded()); JavaScriptConfiguration.loadConfiguration(); assertTrue("Documnet should now be loaded", JavaScriptConfiguration.isDocumentLoaded()); } /** * Tests getting the configuration for the full browser. * @throws Exception - Exception on error */ @Test public void getInstance() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration expectedConfig = new ClassConfiguration("HTMLDocument", HTMLDocument.class.getName(), null, null, null, true); expectedConfig.addProperty("readyState", true, false); assertTrue("Document property did not match", configuration.classConfigEquals("HTMLDocument", expectedConfig)); } /** * Test getting the configuration for the Netscape browser. The readyState property should not be available * in this case. * @throws Exception if an error occurs */ @Test public void getConditionalPropertyBrowser() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.FIREFOX_2; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration expectedConfig = new ClassConfiguration("Document", HTMLDocument.class.getName(), null, null, null, true); assertTrue("Document property did not match", configuration.classConfigEquals("Document", expectedConfig)); } /** * Test that the JSObject is being set correctly. * @throws Exception on error */ @Test public void forSettingJSObject() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration config = configuration.getClassConfiguration("Document"); assertTrue("JSObject is not set", config.isJsObject()); } /** * Test getting the configuration for the Netscape browser. The readyState property should not be * available in this case. * @throws Exception if an error occurs */ @Test public void instanceForTestVersion() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final JavaScriptConfiguration configuration = JavaScriptConfiguration.getAllEntries(); final ClassConfiguration expectedConfig = new ClassConfiguration("HTMLDocument", HTMLDocument.class.getName(), null, null, null, true); expectedConfig.addProperty("readyState", true, false); assertTrue("Document property did not match", configuration.classConfigEquals("HTMLDocument", expectedConfig)); } /** * Tests getting the configuration for the Netscape browser. The readyState property should not be * available in this case. * @throws Exception if an error occurs */ @Test public void propertyForNullBrowser() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); try { JavaScriptConfiguration.getInstance(null); assertTrue("Should have thrown an exception for no browser supplied", false); } catch (final IllegalStateException e) { // everything is fine } } /** * Test getting the configuration for the Netscape browser. The readyState property should not be * available in this case. * * @throws Exception - Exception on error */ @Test public void getConditionalPropertyMinBrowserVersion() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration expectedConfig = new ClassConfiguration("Document", HTMLDocument.class.getName(), null, null, null, true); assertTrue("Document should not property did not match", configuration.classConfigEquals("Document", expectedConfig)); } /** * Test getting the configuration for the browser max version. The readyState property should not be * available in this case. * * @throws Exception - Exception on error */ @Test public void getConditionalPropertyMaxBrowserVersion() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration expectedConfig = new ClassConfiguration("Document", HTMLDocument.class.getName(), null, null, null, true); assertTrue("Document should not property did not match", configuration.classConfigEquals("Document", expectedConfig)); } /** * Test parsing the configuration with a function in it. * * @throws Exception - Exception on error */ @Test public void parseFunction() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration expectedConfig = new ClassConfiguration("Document", HTMLDocument.class.getName(), null, null, null, true); expectedConfig.addFunction("createAttribute"); assertTrue("Document function did not match", configuration.classConfigEquals("Document", expectedConfig)); } /** * Test parsing the configuration for a browser that does not support the function. * * @throws Exception - Exception on error */ @Test public void parseFunctionForLimitedBrowser() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); final ClassConfiguration expectedConfig = new ClassConfiguration("Document", HTMLDocument.class.getName(), null, null, null, true); assertTrue("Document function did not match", configuration.classConfigEquals("Document", expectedConfig)); } /** * Test that the file JavaScriptConfiguration.xml is valid. * @throws Exception if the test fails */ @Test public void configurationFileAgainstSchema() throws Exception { final XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); final String directory = "src/main/resources/com/gargoylesoftware/htmlunit/javascript/configuration/"; parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(final String publicId, final String systemId) throws IOException { return createInputSourceForFile(directory + "JavaScriptConfiguration.xsd"); } }); parser.setErrorHandler(new ErrorHandler() { public void warning(final SAXParseException exception) throws SAXException { throw exception; } public void error(final SAXParseException exception) throws SAXException { throw exception; } public void fatalError(final SAXParseException exception) throws SAXException { throw exception; } }); parser.parse(createInputSourceForFile(directory + "JavaScriptConfiguration.xml")); } private InputSource createInputSourceForFile(final String fileName) throws FileNotFoundException { return new InputSource(getFileAsStream(fileName)); } /** * Test that the data in the JavaScriptConfiguration file matches the classes in listed * properties and functions. The first step is to get the configuration using a special method which * ignores the browser and JavaScript constraints. This checks that there is a method for each item in * the configuration file and fails by throwing an exception. * * The second step is to go through each class and determine if for each jsGet, jsSet, and jsFunction class, * there is an entry in the configuration. * * @throws Exception if an error occurs */ @Test public void configurationFile() throws Exception { final JavaScriptConfiguration configuration = JavaScriptConfiguration.getAllEntries(); for (final String classname : configuration.keySet()) { LOG.debug("Now testing for class " + classname); final Class< ? > clazz = configuration.getClassObject(classname); final Method[] methods = clazz.getMethods(); String elementName; Method theMethod; for (final Method method : methods) { final String name = method.getName(); if (checkForIgnore(name, classname)) { continue; } if (name.startsWith("jsxGet_")) { elementName = name.substring(7); theMethod = configuration.getPropertyReadMethod(classname, elementName); assertNotNull("No definition found for " + name + " defined in " + clazz.getName() + " for object " + classname, theMethod); } else if (name.startsWith("jsxSet_")) { elementName = name.substring(7); theMethod = configuration.getPropertyWriteMethod(classname, elementName); assertNotNull("No definition found for " + name + " defined in " + clazz.getName() + " for object " + classname, theMethod); } else if (name.startsWith("jsxFunction_")) { elementName = name.substring(12); theMethod = configuration.getFunctionMethod(classname, elementName); assertNotNull("No definition found for " + name + " defined in " + clazz.getName() + " for object " + classname, theMethod); } } } // Now test the config for each class and test for methods being defined in the config file // This is the place } private boolean checkForIgnore(final String methodName, final String classname) { final String[] ignoreList = {"Button|jsxGet_form", "FormField|jsxGet_form", "FileUpload|jsxGet_form", "Radio|jsxGet_form", "Reset|jsxGet_form", "Submit|jsxGet_form", "Checkbox|jsxGet_form", "Hidden|jsxGet_form", "Select|jsxGet_form", "Textarea|jsxGet_form", "Input|jsxGet_form", "Password|jsxGet_form", "HTMLSpanElement|jsxGet_cite", "HTMLSpanElement|jsxSet_cite", "HTMLSpanElement|jsxGet_dateTime", "HTMLSpanElement|jsxSet_dateTime", "CharacterDataImpl|jsxGet_tabindex"}; final String key = classname + "|" + methodName; for (final String value : ignoreList) { if (value.equals(key)) { return true; } } return false; } /** * Tests for if the property exists for the configuration. * @throws Exception if an error occurs */ @Test public void forPropertyExist() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); assertTrue("Requested property should have existed", configuration.propertyExists(HTMLDocument.class, "readyState")); } /** * Tests for if the property exists for the configuration. * @throws Exception if an error occurs */ @Test public void forPropertyNotExist() throws Exception { final String configurationString = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; final Reader reader = new StringReader(configurationString); JavaScriptConfiguration.loadConfiguration(reader); final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER_6; final JavaScriptConfiguration configuration = JavaScriptConfiguration.getInstance(browser); Assert.assertFalse("Requested property should not exist", configuration.propertyExists(HTMLDocument.class, "noreadyState")); } /** * Test if configuration map expands with each new instance of BrowserVersion used. * * @throws Exception if the test fails */ @Test public void configurationMapExpands() throws Exception { // get a reference to the leaky map final Field field = JavaScriptConfiguration.class.getDeclaredField("ConfigurationMap_"); field.setAccessible(true); final HashMap< ? , ? > leakyMap = (HashMap< ? , ? >) field.get(null); for (int i = 0; i < 3; i++) { final BrowserVersion browserVersion = new BrowserVersion("App", "Version", "User agent", 1); JavaScriptConfiguration.getInstance(browserVersion); } assertEquals(1, leakyMap.size()); } /** * Test if the class name entries are lexicographically sorted. * * @throws Exception if the test fails */ @Test public void lexicographicOrder() throws Exception { final String directory = "src/main/resources/com/gargoylesoftware/htmlunit/javascript/configuration/"; final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); final DocumentBuilder documentBuilder = factory.newDocumentBuilder(); documentBuilder.setErrorHandler(new StrictErrorHandler()); final org.w3c.dom.Document doc = documentBuilder.parse(createInputSourceForFile(directory + "JavaScriptConfiguration.xml")); String lastClassName = null; Node node = doc.getDocumentElement().getFirstChild(); while (node != null) { if (node instanceof Element) { final Element element = (Element) node; if (element.getTagName().equals("class")) { final String className = element.getAttribute("name"); if (lastClassName != null && className.compareToIgnoreCase(lastClassName) < 1) { fail("JavaScriptConfiguration.xml: \"" + className + "\" should be before \"" + lastClassName + '"'); } lastClassName = className; String lastChildName = null; int lastChildType = 0; Node child = element.getFirstChild(); while (child != null) { if (child instanceof Element) { final Element childE = (Element) child; final String name = childE.getAttribute("name"); final String tagName = childE.getTagName(); final int childType = getType(tagName); if (childType != -1 && childType != lastChildType) { lastChildType = childType; lastChildName = name; } else { if (childType > 0) { if (lastChildName != null && name.compareToIgnoreCase(lastChildName) < 1) { fail("JavaScriptConfiguration.xml: \"" + name + "\" should be before \"" + lastChildName + '"'); } lastChildName = name; } } } child = child.getNextSibling(); } } } node = node.getNextSibling(); } } private static int getType(final String tagName) { if (tagName.equals("constant")) { return 0; } if (tagName.equals("property")) { return 1; } if (tagName.equals("function")) { return 2; } return -1; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/package.htmljenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/0000664000175000017500000000012111650253660034654 0ustar jamespagejamespageTest Classes Test Classes ././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfigurationTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/0000664000175000017500000001714211650253660034667 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.configuration; import static org.junit.Assert.fail; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link JavaScriptConfiguration}. * * @version $Revision: 4002 $ * @author Chris Erskine * @author Ahmed Ashour */ public class ClassConfigurationTest extends WebTestCase { /** * Constructor. */ public ClassConfigurationTest() { JavaScriptConfiguration.resetClassForTesting(); } /** * Tests equality on a class configuration. * @throws Exception - Exception on error */ @Test public void testConfigurationSimplePropertyEquality() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); final ClassConfiguration config2 = new ClassConfiguration("c2", ConfigTestClass.class.getName(), null, null, null, true); config1.addProperty("test", true, true); Assert.assertFalse("Configs should not be equal", config1.equals(config2)); config2.addProperty("test", true, true); assertTrue("Configs should now be equal", config1.equals(config2)); } /** * Tests equality on a class configuration for function. * @throws Exception - Exception on error */ @Test public void testConfigurationSimpleFunctionEquality() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); final ClassConfiguration config2 = new ClassConfiguration("c2", ConfigTestClass.class.getName(), null, null, null, true); config1.addFunction("testFunction"); Assert.assertFalse("Configs should not be equal", config1.equals(config2)); config2.addFunction("testFunction"); assertTrue("Configs should now be equal", config1.equals(config2)); } /** * Tests equality on a class configuration. * @throws Exception - Exception on error */ @Test public void testConfigurationSimpleUnequalProperties() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); final ClassConfiguration config2 = new ClassConfiguration("c2", ConfigTestClass.class.getName(), null, null, null, true); config1.addProperty("test", true, true); Assert.assertFalse("Configs should not be equal", config1.equals(config2)); config2.addProperty("test", true, false); Assert.assertFalse("Configs should not be equal due to different property values", config1.equals(config2)); } /** * @throws Exception on error */ @Test public void testForJSFlagTrue() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); assertTrue("JSObject Flag should have been set", config1.isJsObject()); } /** * @throws Exception on error */ @Test public void testForJSFlagFalse() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, false); Assert.assertFalse("JSObject Flag should not have been set", config1.isJsObject()); } /** * Tests equality on a class configuration. * @throws Exception - Exception on error */ @Test public void testConfigurationPropertyEqualityWithBrowser() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); final ClassConfiguration config2 = new ClassConfiguration("c2", ConfigTestClass.class.getName(), null, null, null, true); config1.addProperty("test", true, true); config2.addProperty("test", true, true); config1.setBrowser("test", "Netscape"); Assert.assertFalse("Should not be equal with browser added", config1.equals(config2)); config2.setBrowser("test", "Netscape"); assertTrue("Should be equal with browser added", config1.equals(config2)); } /** * Tests equality on a class configuration mis-matched browsers. * @throws Exception - Exception on error */ @Test public void testConfigurationPropertyEqualityWithDifferentBrowsers() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); final ClassConfiguration config2 = new ClassConfiguration("c2", ConfigTestClass.class.getName(), null, null, null, true); config1.addProperty("test", true, true); config2.addProperty("test", true, true); config1.setBrowser("test", "Netscape"); Assert.assertFalse("Should not be equal with browser added", config1.equals(config2)); config2.setBrowser("test", "Microsoft Internet Explorer"); Assert.assertFalse("Should be equal with different browser added", config1.equals(config2)); } /** * Test for throwing exception when setter method is not defined. * @throws Exception - Exception on error */ @Test public void testNoSetterMethod() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); try { config1.addProperty("getterOnly", true, true); fail("Should produce an exception due to not finding the methods"); } catch (final IllegalStateException e) { assertTrue(true); } } /** * Test for throwing exception when setter method is not defined. * @throws Exception - Exception on error */ @Test public void testNoFunctionMethod() throws Exception { final ClassConfiguration config1 = new ClassConfiguration("c1", ConfigTestClass.class.getName(), null, null, null, true); try { config1.addFunction("noTestFunction"); fail("Should produce an exception due to not finding the methods"); } catch (final IllegalStateException e) { assertTrue(true); } } /** * Test class. */ protected class ConfigTestClass { private boolean test_ = false; /** * Dummy function. */ public void jsxFunction_testFunction() { } /** * @return boolean */ public boolean jsxGet_test() { return test_; } /** * @return boolean */ public boolean jsxGet_getterOnly() { return test_; } /** * @param testFlag - test value */ public void jsxSet_test(final boolean testFlag) { test_ = testFlag; } } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/DateTest.java0000664000175000017500000000370411650253660034375 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Date is a native JavaScript object and therefore provided by Rhino but behavior should be * different depending on the simulated browser. * * @version $Revision: 4181 $ * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class DateTest extends WebTestCase { /** * Test for bug 2615817. * @see this doc * @throws Exception if the test fails */ @Test @Alerts(FF = { "-13", "84", "109" }, IE = { "1887", "84", "2009" }) public void getYear() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts(html); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/0000775000175000017500000000000011650253660034130 5ustar jamespagejamespage././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/package.htmljenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/pac0000664000175000017500000000012111650253660034610 0ustar jamespagejamespageTest Classes Test Classes ././@LongLink0000000000000000000000000000020600000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerMinimalTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/Jav0000664000175000017500000001110111650253660034565 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.background; import junit.framework.Assert; import org.apache.commons.lang.mutable.MutableInt; import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebWindow; /** * Minimal tests for {@link JavaScriptJobManagerImpl}. Tests which use the full HtmlUnit stack * go in {@link JavaScriptJobManagerTest}. * * @version $Revision: 4343 $ * @author Daniel Gredler */ public class JavaScriptJobManagerMinimalTest { private WebWindow window_; private Page page_; private JavaScriptJobManagerImpl manager_; /** * Initializes variables required by the unit tests. */ @Before public void before() { window_ = EasyMock.createNiceMock(WebWindow.class); page_ = EasyMock.createNiceMock(Page.class); EasyMock.expect(window_.getEnclosedPage()).andReturn(page_).anyTimes(); EasyMock.replay(window_, page_); manager_ = new JavaScriptJobManagerImpl(window_); } /** * @throws Exception if an error occurs */ @Test public void addJob_singleExecution() throws Exception { final MutableInt count = new MutableInt(0); final JavaScriptJob job = new JavaScriptJob(50, null) { public void run() { count.increment(); } }; manager_.addJob(job, page_); manager_.waitForJobs(1000); Assert.assertEquals(1, count.intValue()); } /** * @throws Exception if an error occurs */ @Test public void addJob_multipleExecution_removeJob() throws Exception { final MutableInt id = new MutableInt(); final MutableInt count = new MutableInt(0); final JavaScriptJob job = new JavaScriptJob(50, 50) { public void run() { count.increment(); if (count.intValue() >= 5) { manager_.removeJob(id.intValue()); } } }; id.setValue(manager_.addJob(job, page_)); manager_.waitForJobs(1000); Assert.assertEquals(5, count.intValue()); } /** * @throws Exception if an error occurs */ @Test public void addJob_multipleExecution_removeAllJobs() throws Exception { final MutableInt count = new MutableInt(0); final JavaScriptJob job = new JavaScriptJob(50, 50) { public void run() { count.increment(); if (count.intValue() >= 5) { manager_.removeAllJobs(); } } }; manager_.addJob(job, page_); manager_.waitForJobs(1000); Assert.assertEquals(5, count.intValue()); } /** * @throws Exception if an error occurs */ @Test public void getJobCount() throws Exception { final MutableInt count = new MutableInt(); final JavaScriptJob job = new JavaScriptJob(50, null) { public void run() { count.setValue(manager_.getJobCount()); } }; Assert.assertEquals(0, manager_.getJobCount()); manager_.addJob(job, page_); manager_.waitForJobs(1000); Assert.assertEquals(1, count.intValue()); Assert.assertEquals(0, manager_.getJobCount()); } /** * @throws Exception if an error occurs */ @Test public void waitForJobsStartingBefore() throws Exception { final JavaScriptJob job1 = new JavaScriptJob(50, null) { public void run() { // Empty. } }; final JavaScriptJob job2 = new JavaScriptJob(1000, null) { public void run() { // Empty. } }; Assert.assertEquals(0, manager_.getJobCount()); manager_.addJob(job1, page_); manager_.addJob(job2, page_); manager_.waitForJobsStartingBefore(250); Assert.assertEquals(1, manager_.getJobCount()); } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/MemoryLeakTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/Mem0000664000175000017500000000700111650253660034567 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.background; import org.junit.Test; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.util.MemoryLeakDetector; /** *

          Tests for memory leaks. This test passes when run independently in Eclipse or via * Maven (mvn test -Dtest=MemoryLeakTest), but not when all tests are run via Maven * (mvn test). Note that this probably constitutes a false positive, meaning that the * window isn't leaked in this situation -- we just can't get the JVM to GC it because * there is no surefire way to force complete garbage collection.

          * *

          All suspected memory leaks should be verified with a profiler before a fix and/or * unit test is committed. In JProfiler, for example, you can run a unit test and tell * the profiler to keep the VM alive when it has finished running; once it has finished * running you can go to the Heap Walker, take a snapshot of the heap, sort the resultant * table by class name and find the class you're interested in, double-click on it, choose * to view References to instances of this class, then right-click on the class and choose * Show Paths to GC Root. This will give you a list of references which need to be * eliminated. Once you have a fix, repeat the above steps in order to verify that the * fix works.

          * * @version $Revision: 4023 $ * @author Daniel Gredler */ public class MemoryLeakTest extends WebTestCase { /** * Empty test which keeps Maven/JUnit from complaining about a test class with no tests. This test * class cannot be run automatically via Maven for the reasons outlined above. * @throws Exception if an error occurs */ @Test public void testLeaks() throws Exception { // windowLeaks(); } /** * Verifies that windows don't get leaked, especially when there are long-running background JS tasks * scheduled via setTimeout or setInterval. See the following bugs: * https://sourceforge.net/tracker/index.php?func=detail&aid=2003396&group_id=47038&atid=448266 * https://sourceforge.net/tracker/index.php?func=detail&aid=2014629&group_id=47038&atid=448266 * * @throws Exception if an error occurs */ protected void windowLeaks() throws Exception { final MemoryLeakDetector detector = new MemoryLeakDetector(); WebClient client = new WebClient(); detector.register("w", client.getCurrentWindow()); MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, ""); client.setWebConnection(conn); client.getPage(URL_FIRST); client = null; conn = null; assertTrue("Window can't be garbage collected.", detector.canBeGCed("w")); } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/Jav0000664000175000017500000002040711650253660034576 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.javascript.background; import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.TopLevelWindow; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link JavaScriptJobManagerImpl} using the full HtmlUnit stack. Minimal unit tests * which do not use the full HtmlUnit stack go in {@link JavaScriptJobManagerMinimalTest}. * * @version $Revision: 4343 $ * @author Brad Clarke * @author Ahmed Ashour */ public class JavaScriptJobManagerTest extends WebTestCase { private long startTime_; private void startTimedTest() { startTime_ = System.currentTimeMillis(); } private void assertMaxTestRunTime(final long maxRunTimeMilliseconds) { final long endTime = System.currentTimeMillis(); final long runTime = endTime - startTime_; assertTrue("\nTest took too long to run and results may not be accurate. Please try again. " + "\n Actual Run Time: " + runTime + "\n Max Run Time: " + maxRunTimeMilliseconds, runTime < maxRunTimeMilliseconds); } /** * @throws Exception if the test fails */ @Test public void setClearTimeoutUsesManager() throws Exception { final String content = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + "\n" + ""; final List collectedAlerts = Collections.synchronizedList(new ArrayList()); startTimedTest(); final HtmlPage page = loadPage(content, collectedAlerts); final JavaScriptJobManager jobManager = page.getEnclosingWindow().getJobManager(); assertNotNull(jobManager); assertEquals(1, jobManager.getJobCount()); final HtmlAnchor a = page.getHtmlElementById("clickme"); a.click(); jobManager.waitForJobs(7000); assertEquals(0, jobManager.getJobCount()); assertEquals(Collections.EMPTY_LIST, collectedAlerts); assertMaxTestRunTime(10000); } /** * @throws Exception if the test fails */ @Test public void setClearIntervalUsesManager() throws Exception { final String content = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + ""; final List collectedAlerts = Collections.synchronizedList(new ArrayList()); startTimedTest(); final HtmlPage page = loadPage(content, collectedAlerts); final JavaScriptJobManager jobManager = page.getEnclosingWindow().getJobManager(); assertNotNull(jobManager); assertEquals(1, jobManager.getJobCount()); jobManager.waitForJobs(1000); assertEquals(0, jobManager.getJobCount()); assertEquals(Collections.nCopies(3, "blah"), collectedAlerts); assertMaxTestRunTime(1000); } /** * @throws Exception if the test fails */ @Test public void navigationStopThreadsInChildWindows() throws Exception { final String firstContent = "First\n" + "\n" + "\n" + ""; final String nested = "\n" + "\n" + " nested\n" + " \n" + "\n" + "\n" + "\n" + ""; final WebClient client = new WebClient(BrowserVersion.FIREFOX_2); final List collectedAlerts = Collections.synchronizedList(new ArrayList()); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); webConnection.setDefaultResponse(nested); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); final JavaScriptJobManager jobManager = page.getEnclosingWindow().getJobManager(); assertNotNull(jobManager); assertEquals(0, jobManager.getJobCount()); startTimedTest(); assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(20000)); assertMaxTestRunTime(300); assertEquals(0, jobManager.getJobCount()); final String[] expectedAlerts = {"work1"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Test the case where a job is being executed at the time where waitForBackgroundJavaScriptStartingBefore * and where this jobs schedules a new job after call to waitForBackgroundJavaScriptStartingBefore, * . * @throws Exception if the test fails */ @Test public void newJobStartedAfterWait() throws Exception { final String html = "\n" + "\n" + " test\n" + " \n" + "\n" + "\n" + "\n" + ""; final ThreadSynchronizer threadSynchronizer = new ThreadSynchronizer(); final MockWebConnection webConnection = new MockWebConnection() { @Override public WebResponse getResponse(final WebRequestSettings settings) throws IOException { if (settings.getUrl().toExternalForm().endsWith("/wait")) { threadSynchronizer.waitForState("just before waitForBackgroundJavaScriptStartingBefore"); threadSynchronizer.sleep(400); // main thread need to be able to process next instruction } return super.getResponse(settings); } }; webConnection.setResponse(URL_FIRST, html); webConnection.setDefaultResponse(""); final WebClient client = new WebClient(BrowserVersion.FIREFOX_3); // just to simplify test code using XHR client.setWebConnection(webConnection); final List collectedAlerts = Collections.synchronizedList(new ArrayList()); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final HtmlPage page = client.getPage(URL_FIRST); final JavaScriptJobManager jobManager = page.getEnclosingWindow().getJobManager(); assertNotNull(jobManager); assertEquals(1, jobManager.getJobCount()); startTimedTest(); threadSynchronizer.setState("just before waitForBackgroundJavaScriptStartingBefore"); assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(20000)); assertMaxTestRunTime(1000); assertEquals(0, jobManager.getJobCount()); final String[] expectedAlerts = {"xhr onchange", "work1"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Tests that waitForBackgroundJavaScriptStartingBefore waits for jobs that should have been started earlier * but that are "late" due to processing of previous job. * This test needs to start many setTimeout to expect to reach the state, where a check for future * jobs occurs when one of this job is not active. * @throws Exception if the test fails */ @Test public void waitForJobThatIsAlreadyLate() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "\n" + "\n" + ""; final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); webConnection.setDefaultResponse(""); final WebClient client = new WebClient(BrowserVersion.FIREFOX_3); // just to simplify test code using XHR client.setWebConnection(webConnection); final List collectedAlerts = Collections.synchronizedList(new ArrayList()); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); client.getPage(URL_FIRST); startTimedTest(); assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(1000)); assertMaxTestRunTime(1000); assertEquals(51, collectedAlerts.size()); } /** * {@link WebClient#waitForBackgroundJavaScript(long)} should have an overview of all windows. * @throws Exception if the test fails */ @Test public void jobSchedulesJobInOtherWindow1() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "\n" + "\n" + ""; final List collectedAlerts = Collections.synchronizedList(new ArrayList()); final HtmlPage page = loadPage(html, collectedAlerts); startTimedTest(); assertEquals(0, page.getWebClient().waitForBackgroundJavaScript(1000)); assertMaxTestRunTime(1000); final String[] expectedAlerts = {"work1", "work2"}; assertEquals(expectedAlerts, collectedAlerts); } /** * {@link WebClient#waitForBackgroundJavaScriptStartingBefore(long)} should have an overview of all windows. * @throws Exception if the test fails */ @Test public void jobSchedulesJobInOtherWindow2() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "\n" + "\n" + ""; final List collectedAlerts = Collections.synchronizedList(new ArrayList()); final HtmlPage page = loadPage(html, collectedAlerts); startTimedTest(); assertEquals(0, page.getWebClient().waitForBackgroundJavaScriptStartingBefore(1000)); assertMaxTestRunTime(1000); final String[] expectedAlerts = {"work1", "work2"}; assertEquals(expectedAlerts, collectedAlerts); } } /** * Helper to ensure some synchronization state between threads to reproduce a particular situation in the tests. * @author Marc Guillemot */ class ThreadSynchronizer { private String state_ = "initial"; private static final Log LOG = LogFactory.getLog(ThreadSynchronizer.class); synchronized void setState(final String newState) { state_ = newState; notifyAll(); } /** * Just like {@link Thread#sleep(long)} but throws a {@link RuntimeException}. * @param millis the time to sleep in milliseconds */ public void sleep(final long millis) { try { LOG.debug("Sleeping for " + millis + "ms"); Thread.sleep(millis); } catch (final InterruptedException e) { throw new RuntimeException(e); } } synchronized void waitForState(final String expectedState) { try { while (!state_.equals(expectedState)) { wait(); } } catch (final InterruptedException e) { throw new RuntimeException(e); } } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/NicelyResynchronizingAjaxControllerTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/NicelyResynchronizingAjax0000664000175000017500000000237211650253660034735 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import org.junit.Test; /** * Tests for {@link NicelyResynchronizingAjaxController}. * * @version $Revision: 4802 $ * @author Nick Kralevich */ public class NicelyResynchronizingAjaxControllerTest extends WebServerTestCase { /** * @throws Exception if an error occurs */ @Test public void serialization() throws Exception { final NicelyResynchronizingAjaxController controller = new NicelyResynchronizingAjaxController(); final NicelyResynchronizingAjaxController copy = clone(controller); assertTrue(copy.isInOriginalThread()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java0000664000175000017500000002754111650253660032362 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.util.DateUtil; import org.apache.commons.lang.time.DateUtils; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link Cache}. * * @version $Revision: 4872 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class CacheTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.NONE) public void isDynamicContent() throws Exception { final Cache cache = new Cache(); final Map headers = new HashMap(); final WebResponse response = new DummyWebResponse() { @Override public String getResponseHeaderValue(final String headerName) { return headers.get(headerName); } }; assertTrue(cache.isDynamicContent(response)); headers.put("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT"); assertFalse(cache.isDynamicContent(response)); headers.put("Last-Modified", DateUtil.formatDate(DateUtils.addMinutes(new Date(), -5))); assertTrue(cache.isDynamicContent(response)); headers.put("Expires", DateUtil.formatDate(DateUtils.addMinutes(new Date(), 5))); assertTrue(cache.isDynamicContent(response)); headers.put("Expires", DateUtil.formatDate(DateUtils.addHours(new Date(), 1))); assertFalse(cache.isDynamicContent(response)); headers.remove("Last-Modified"); assertFalse(cache.isDynamicContent(response)); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.NONE) public void isJavascript() throws Exception { final Cache cache = new Cache(); final String[] contentType = {""}; final URL[] url = {URL_FIRST}; final WebResponse response = new DummyWebResponse() { @Override public String getContentType() { return contentType[0]; } @Override public WebRequestSettings getRequestSettings() { return new WebRequestSettings(url[0]); } }; assertFalse(cache.isJavaScript(response)); contentType[0] = "text/javascript"; assertTrue(cache.isJavaScript(response)); contentType[0] = "application/x-javascript"; assertTrue(cache.isJavaScript(response)); contentType[0] = "text/plain"; assertFalse(cache.isJavaScript(response)); url[0] = new URL(URL_FIRST, "foo.js"); assertTrue(cache.isJavaScript(response)); url[0] = new URL(URL_FIRST, "foo.js?1_1_40C"); assertTrue(cache.isJavaScript(response)); } /** *@throws Exception if the test fails */ @Test public void usage() throws Exception { final String content = "page 1\n" + "\n" + "\n" + "\n" + "to page 2\n" + ""; final String content2 = "page 2\n" + "\n" + "\n" + "to page 1\n" + ""; final String script1 = "alert('in foo1');"; final String script2 = "alert('in foo2');"; final WebClient webClient = getWebClient(); final MockWebConnection connection = new MockWebConnection(); webClient.setWebConnection(connection); final URL urlPage1 = new URL(URL_FIRST, "page1.html"); connection.setResponse(urlPage1, content); final URL urlPage2 = new URL(URL_FIRST, "page2.html"); connection.setResponse(urlPage2, content2); final List
          headers = new ArrayList
          (); headers.add(new Header("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT")); connection.setResponse(new URL(URL_FIRST, "foo1.js"), script1, 200, "ok", "text/javascript", headers); connection.setResponse(new URL(URL_FIRST, "foo2.js"), script2, 200, "ok", "text/javascript", headers); final List collectedAlerts = new ArrayList(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final HtmlPage page1 = webClient.getPage(urlPage1); final String[] expectedAlerts = {"in foo1", "in foo2"}; assertEquals(expectedAlerts, collectedAlerts); collectedAlerts.clear(); page1.getAnchors().get(0).click(); assertEquals(new String[] {"in foo2"}, collectedAlerts); assertEquals("no request for scripts should have been performed", urlPage2, connection.getLastWebRequestSettings().getUrl()); } /** *@throws Exception if the test fails */ @Test public void maxSizeMaintained() throws Exception { final String html = "page 1\n" + "\n" + "\n" + "x\n" + ""; final MockWebConnection connection = getMockWebConnection(); final List
          headers = Collections.singletonList(new Header("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT")); connection.setResponse(new URL(getDefaultUrl(), "foo.txt"), "hello", 200, "OK", "text/plain", headers); loadPageWithAlerts(html); assertEquals(2, connection.getRequestCount()); } } class DummyWebResponse implements WebResponse { private static final long serialVersionUID = 631259170130126480L; public InputStream getContentAsStream() throws IOException { throw new RuntimeException("not implemented"); } public String getContentAsString() { throw new RuntimeException("not implemented"); } public String getContentAsString(final String encoding) { throw new RuntimeException("not implemented"); } public byte[] getContentAsBytes() { throw new RuntimeException("not implemented"); } public String getContentCharSet() { throw new RuntimeException("not implemented"); } public String getContentCharset() { throw new RuntimeException("not implemented"); } public String getContentCharsetOrNull() { throw new RuntimeException("not implemented"); } public String getContentType() { throw new RuntimeException("not implemented"); } public long getLoadTimeInMilliSeconds() { throw new RuntimeException("not implemented"); } public long getLoadTime() { throw new RuntimeException("not implemented"); } /** * {@inheritDoc} * @deprecated As of 2.6, please use {@link #getRequestSettings()}.getHttpMethod() */ @Deprecated public HttpMethod getRequestMethod() { throw new RuntimeException("not implemented"); } public List getResponseHeaders() { throw new RuntimeException("not implemented"); } public String getResponseHeaderValue(final String headerName) { throw new RuntimeException("not implemented"); } public int getStatusCode() { throw new RuntimeException("not implemented"); } public String getStatusMessage() { throw new RuntimeException("not implemented"); } /** * {@inheritDoc} * @deprecated As of 2.6, please use {@link #getRequestSettings()}.getUrl() */ @Deprecated public URL getRequestUrl() { throw new RuntimeException("not implemented"); } public URL getUrl() { throw new RuntimeException("not implemented"); } public WebRequestSettings getRequestSettings() { throw new RuntimeException("not implemented"); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/xml/0000775000175000017500000000000011650253660030443 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/xml/package.html0000664000175000017500000000012111650253660032716 0ustar jamespagejamespageTest Classes Test Classes jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/xml/XmlPage2Test.java0000664000175000017500000001103111650253660033561 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.xml; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link XmlPage}. * * @version $Revision: 4815 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class XmlPage2Test extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test @Alerts("8") public void load_XMLComment() throws Exception { final String html = "foo\n" + ""; final String xml = ""; final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html); conn.setResponse(URL_SECOND, xml, "text/xml"); loadPageWithAlerts2(conn); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "true", "16" }, FF = { "true", "14" }) public void createElement() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test @Alerts(FF = "[object Element]", IE = "exception") public void createElementNS() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts2(html); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/xml/XmlPageTest.java0000664000175000017500000001710211650253660033504 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.xml; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.httpclient.HttpStatus; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.w3c.dom.Node; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebServerTestCase; /** * Tests for {@link XmlPage}. * * @version $Revision: 4815 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class XmlPageTest extends WebServerTestCase { /** * Tests namespace. * @throws Exception if the test fails */ @Test public void namespace() throws Exception { final String content = "\n" + "" + "" + "My Plugin" + "\n" + ""; final XmlPage xmlPage = testXmlDocument(content, "text/xml"); final Node node = xmlPage.getXmlDocument().getFirstChild().getFirstChild().getFirstChild(); assertEquals("em:name", node.getNodeName()); assertEquals("name", node.getLocalName()); assertEquals("http://www.mozilla.org/2004/em-rdf#", node.getNamespaceURI()); } /** * Tests a simple valid XML document. * @throws Exception if the test fails */ @Test public void validDocument() throws Exception { final String content = "\n" + "\n" + " something\n" + " something else\n" + ""; final XmlPage xmlPage = testXmlDocument(content, "text/xml"); assertEquals("foo", xmlPage.getXmlDocument().getFirstChild().getNodeName()); } /** * Utility method to test XML page of different MIME types. * @param content the XML content * @param mimeType the MIME type * @return the page returned by the WebClient * @throws Exception if a problem occurs */ private XmlPage testXmlDocument(final String content, final String mimeType) throws Exception { final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(content, 200, "OK", mimeType); client.setWebConnection(webConnection); final Page page = client.getPage(URL_FIRST); assertEquals(URL_FIRST, page.getWebResponse().getRequestSettings().getUrl()); assertEquals("OK", page.getWebResponse().getStatusMessage()); assertEquals(HttpStatus.SC_OK, page.getWebResponse().getStatusCode()); assertEquals(mimeType, page.getWebResponse().getContentType()); assertTrue(XmlPage.class.isInstance(page)); final XmlPage xmlPage = (XmlPage) page; assertEquals(content, xmlPage.getContent()); Assert.assertNotNull(xmlPage.getXmlDocument()); return xmlPage; } /** * Tests a simple invalid (badly formed) XML document. * @throws Exception if the test fails */ @Test public void invalidDocument() throws Exception { final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); final String content = "\n" + "\n" + " something\n" + " something else\n" + ""; webConnection.setDefaultResponse(content, 200, "OK", "text/xml"); client.setWebConnection(webConnection); final Page page = client.getPage(URL_FIRST); assertEquals(URL_FIRST, page.getWebResponse().getRequestSettings().getUrl()); assertEquals("OK", page.getWebResponse().getStatusMessage()); assertEquals(HttpStatus.SC_OK, page.getWebResponse().getStatusCode()); assertEquals("text/xml", page.getWebResponse().getContentType()); assertTrue(Page.class.isInstance(page)); final XmlPage xmlPage = (XmlPage) page; assertEquals(content, xmlPage.getContent()); assertNull(xmlPage.getXmlDocument()); } /** * @throws Exception if the test fails */ @Test public void voiceXML() throws Exception { final String content = "\n" + "\n" + "
          \n" + " Hello World!\n" + "
          \n" + "
          "; final XmlPage xmlPage = testXmlDocument(content, "application/voicexml+xml"); assertEquals("vxml", xmlPage.getXmlDocument().getFirstChild().getNodeName()); } /** * @throws Exception if the test fails */ @Test public void xpath() throws Exception { final String html = "\n" + "\n" + " something\n" + " something else\n" + ""; final XmlPage xmlPage = testXmlDocument(html, "text/xml"); assertEquals(1, xmlPage.getByXPath("//foofoo[@name='first']").size()); } /** * @throws Exception if the test fails */ @Test public void noResponse() throws Exception { final Map> servlets = new HashMap>(); servlets.put("/test", NoResponseServlet.class); startWebServer("./", null, servlets); final WebClient client = getWebClient(); client.getPage("http://localhost:" + PORT + "/test"); } /** * Servlet for {@link #noResponse()}. */ public static class NoResponseServlet extends HttpServlet { private static final long serialVersionUID = 714328190645334742L; /** * {@inheritDoc} */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { response.setContentType("text/xml"); response.setStatus(HttpServletResponse.SC_NO_CONTENT); } } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/ScriptExceptionTest.java0000664000175000017500000001151211650253660034471 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.net.URL; import java.util.Locale; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link ScriptException}. * * @version $Revision: 4731 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public final class ScriptExceptionTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void constructor() throws Exception { final String message = "bla bla"; final Throwable t = new RuntimeException(message); final HtmlPage page = loadPage(getBrowserVersion(), "", null); final ScriptException exception = new ScriptException(page, t); assertEquals(t, exception.getCause()); assertEquals(message, exception.getMessage()); } /** * Tests access to the page where the exception occurred from the exception. * @throws Exception if the test fails */ @Test public void getPage() throws Exception { final String html = ""; try { loadPage(getBrowserVersion(), html, null); } catch (final ScriptException e) { assertEquals(getDefaultUrl(), e.getPage().getWebResponse().getRequestSettings().getUrl()); } } /** * Test the JavaScript stacktrace. * Note: this test will fail when the information (line, col, source name) provided to execute * scripts is improved. In this case this unit test should be adapted IF the provided information * in the script stack trace gets better and provides more useful information to understand the * cause of a problem. * @throws Exception if the test fails */ @Test public void scriptStackTrace() throws Exception { testScriptStackTrace("ScriptExceptionTest1"); testScriptStackTrace("ScriptExceptionTest2"); } private void testScriptStackTrace(final String baseFileName) throws Exception { try { final Locale locale = Locale.getDefault(); // Set the default locale to US because Rhino messages are localized Locale.setDefault(Locale.US); loadPage(getBrowserVersion(), getFileContent(baseFileName + ".html"), null); Locale.setDefault(locale); } catch (final ScriptException e) { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); e.printScriptStackTrace(printWriter); final String expectedTrace = getFileContent(baseFileName + ".txt"); assertEquals(expectedTrace, stringWriter.toString()); return; } fail("Exception not thrown"); } private String getFileContent(final String fileName) throws IOException { final InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName); assertNotNull(fileName, stream); return IOUtils.toString(stream); } /** * @throws Exception if the test fails */ @Test public void errorLineNumber() throws Exception { testErrorLineNumber("testJsError1.html", 6); testErrorLineNumber("testJsError2.html", 7); testErrorLineNumber("testJsError3.html", 6); testErrorLineNumber("testJsError4.html", 8); } private void testErrorLineNumber(final String fileName, final int errorLine) throws Exception { final WebClient webClient = getWebClient(); final URL url = getClass().getClassLoader().getResource(fileName); assertNotNull(url); try { final HtmlPage page = webClient.getPage(url); page.getHtmlElementById("clickMe").click(); fail(); } catch (final ScriptException e) { assertEquals(errorLine, e.getFailingLineNumber()); } } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/SimpleWebDriverTest.java0000664000175000017500000003323711650253660034421 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; /** * Proof of concept for using WebDriver to run (some) HtmlUnit tests and have the possibility * to check in "real" browsers if our expectations are correct. * * @version $Revision: 4741 $ * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class SimpleWebDriverTest extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test public void arrayProperties() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + " \n" + ""; final WebDriver driver = loadPageWithAlerts2(html); final String expected; if (getBrowserVersion().isFirefox()) { expected = "concat: function,every: function,filter: function,forEach: function,indexOf: function," + "join: function,lastIndexOf: function,map: function,pop: function,push: function,reverse: function," + "shift: function,slice: function,some: function,sort: function,splice: function," + "toLocaleString: function,toSource: function,toString: function,unshift: function,"; } else { expected = "concat: function,every: undefined,filter: undefined,forEach: undefined,indexOf: undefined," + "join: function,lastIndexOf: undefined,map: undefined,pop: function,push: function," + "reverse: function,shift: function,slice: function,some: undefined,sort: function,splice: function," + "toLocaleString: function,toSource: undefined,toString: function,unshift: function,"; } assertEquals(expected, driver.findElement(By.id("myTextarea")).getValue()); } /** * @throws Exception if the test fails */ @Test public void objectProperties() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + " \n" + ""; final WebDriver driver = loadPageWithAlerts2(html); final String expected; if (getBrowserVersion().isFirefox()) { expected = "__defineGetter__: function,__defineSetter__: function,__lookupGetter__: function," + "__lookupSetter__: function,hasOwnProperty: function,isPrototypeOf: function," + "propertyIsEnumerable: function,toLocaleString: function,toSource: function,toString: function," + "valueOf: function,"; } else { expected = "__defineGetter__: undefined,__defineSetter__: undefined,__lookupGetter__: undefined," + "__lookupSetter__: undefined,hasOwnProperty: function,isPrototypeOf: function," + "propertyIsEnumerable: function,toLocaleString: function,toSource: undefined,toString: function," + "valueOf: function,"; } assertEquals(expected, driver.findElement(By.id("myTextarea")).getValue()); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "test span", FF = "test span") public void innerHTMLwithQuotes() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "
          test span
          \n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "true", "[object]", "true" }, FF = { "true", "undefined", "false" }) public void document_xxx_formAccess() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "
          the div 1
          \n" + "
          \n" + " \n" + "
          \n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test @Browsers(Browser.IE) @Alerts("hello") public void fireEvent_initFromTemplate() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + " a span\n" + ""; loadPageWithAlerts2(html); } /** * @throws Exception if the test fails */ @Test public void clickEvents() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + " test span\n" + "
          \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + ""; final WebDriver driver = loadPageWithAlerts2(html); driver.findElement(By.id("testSpan")).click(); driver.findElement(By.id("testInput")).click(); driver.findElement(By.id("testImage")).click(); driver.findElement(By.id("testTextarea")).click(); final String expected = "mousedown span,mouseup span,click span,mousedown text,focus text,mouseup text," + "click text,mousedown image,focus image,mouseup image,click image,mousedown textarea,focus textarea," + "mouseup textarea,click textarea,"; assertEquals(expected, driver.findElement(By.id("myTextarea")).getValue()); } /** * @throws Exception if the test fails */ @Test @NotYetImplemented(Browser.FF) public void scriptEventFor() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + " \n" + "
          the div 1
          \n" + "
          the div 2
          \n" + " \n" + " \n" + " \n" + ""; final WebDriver webDriver = loadPageWithAlerts2(html); webDriver.findElement(By.id("div1")).click(); webDriver.findElement(By.id("div2")).click(); final String expected; if (getBrowserVersion().isIE()) { expected = "onload for window,onclick for div1,"; } else { expected = ""; } assertEquals(expected, webDriver.findElement(By.id("myTextarea")).getValue()); } /** * Test event order. * @throws Exception if the test fails */ @Test //Fails with InternetExplorerDriver, but works in independent IE :( public void eventOrder() throws Exception { final String html = "\n" + "\n" + " \n" + "\n" + "
          \n" + " \n" + " \n" + "
          \n" + " \n" + ""; final WebDriver webDriver = loadPageWithAlerts2(html); final WebElement textField = webDriver.findElement(By.id("foo")); textField.click(); // to give focus textField.sendKeys("a"); webDriver.findElement(By.id("other")).click(); final String expected; if (getBrowserVersion().isFirefox() && getBrowserVersion().getBrowserVersionNumeric() == 2) { expected = "focus,keydown,keypress,keyup,blur,change,"; } else { expected = "focus,keydown,keypress,keyup,change,blur,"; } assertEquals(expected, webDriver.findElement(By.id("myTextarea")).getValue()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/WebAssertTest.java0000664000175000017500000003702111650253660033250 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import org.junit.Test; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link WebAssert}. * * @version $Revision: 4002 $ * @author Daniel Gredler */ public class WebAssertTest extends WebTestCase { /** * @throws Exception if an error occurs */ @Test public void testAssertTitleEquals() throws Exception { final String html = "foobar"; final HtmlPage page = loadPage(html); WebAssert.assertTitleEquals(page, "foo"); boolean caught = false; try { WebAssert.assertTitleEquals(page, "bar"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertTitleContains() throws Exception { final String html = "foobar"; final HtmlPage page = loadPage(html); WebAssert.assertTitleContains(page, "o"); boolean caught = false; try { WebAssert.assertTitleContains(page, "a"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertTitleMatches() throws Exception { final String html = "foobar"; final HtmlPage page = loadPage(html); WebAssert.assertTitleMatches(page, "f.."); boolean caught = false; try { WebAssert.assertTitleMatches(page, "b.."); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertElementPresent() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertElementPresent(page, "a"); boolean caught = false; try { WebAssert.assertElementPresent(page, "b"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertElementPresentByXPath() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertElementPresentByXPath(page, "html/body/div"); boolean caught = false; try { WebAssert.assertElementPresentByXPath(page, "ul"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertElementNotPresent() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertElementNotPresent(page, "b"); boolean caught = false; try { WebAssert.assertElementNotPresent(page, "a"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertElementNotPresentByXPath() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertElementNotPresentByXPath(page, "ul"); boolean caught = false; try { WebAssert.assertElementNotPresentByXPath(page, "html/body/div"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertTextPresent() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertTextPresent(page, "bar"); boolean caught = false; try { WebAssert.assertTextPresent(page, "baz"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertTextPresentInElement() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertTextPresentInElement(page, "bar", "a"); boolean caught = false; try { WebAssert.assertTextPresentInElement(page, "baz", "a"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); caught = false; try { WebAssert.assertTextPresentInElement(page, "bar", "b"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertTextNotPresent() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertTextNotPresent(page, "baz"); boolean caught = false; try { WebAssert.assertTextNotPresent(page, "bar"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertTextNotPresentInElement() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertTextNotPresentInElement(page, "baz", "a"); boolean caught = false; try { WebAssert.assertTextNotPresentInElement(page, "bar", "a"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); caught = false; try { WebAssert.assertTextNotPresentInElement(page, "bar", "b"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertLinkPresent() throws Exception { final String html = "bar"; final HtmlPage page = loadPage(html); WebAssert.assertLinkPresent(page, "x"); boolean caught = false; try { WebAssert.assertLinkPresent(page, "z"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertLinkNotPresent() throws Exception { final String html = "bar"; final HtmlPage page = loadPage(html); WebAssert.assertLinkNotPresent(page, "z"); boolean caught = false; try { WebAssert.assertLinkNotPresent(page, "x"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertLinkPresentWithText() throws Exception { final String html = "bar"; final HtmlPage page = loadPage(html); WebAssert.assertLinkPresentWithText(page, "r"); boolean caught = false; try { WebAssert.assertLinkPresentWithText(page, "x"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertLinkNotPresentWithText() throws Exception { final String html = "bar"; final HtmlPage page = loadPage(html); WebAssert.assertLinkNotPresentWithText(page, "x"); boolean caught = false; try { WebAssert.assertLinkNotPresentWithText(page, "r"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertFormPresent() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertFormPresent(page, "f"); boolean caught = false; try { WebAssert.assertFormPresent(page, "x"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertFormNotPresent() throws Exception { final String html = "
          bar
          "; final HtmlPage page = loadPage(html); WebAssert.assertFormNotPresent(page, "x"); boolean caught = false; try { WebAssert.assertFormNotPresent(page, "f"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertInputPresent() throws Exception { final String html = "
          "; final HtmlPage page = loadPage(html); WebAssert.assertInputPresent(page, "i"); boolean caught = false; try { WebAssert.assertInputPresent(page, "q"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertInputNotPresent() throws Exception { final String html = "
          "; final HtmlPage page = loadPage(html); WebAssert.assertInputNotPresent(page, "q"); boolean caught = false; try { WebAssert.assertInputNotPresent(page, "i"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertInputContainsValue() throws Exception { final String html = "
          "; final HtmlPage page = loadPage(html); WebAssert.assertInputContainsValue(page, "i", "x"); boolean caught = false; try { WebAssert.assertInputContainsValue(page, "i", "z"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); caught = false; try { WebAssert.assertInputContainsValue(page, "q", "x"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertInputDoesNotContainValue() throws Exception { final String html = "
          "; final HtmlPage page = loadPage(html); WebAssert.assertInputDoesNotContainValue(page, "i", "z"); boolean caught = false; try { WebAssert.assertInputDoesNotContainValue(page, "i", "x"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); caught = false; try { WebAssert.assertInputDoesNotContainValue(page, "q", "x"); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertAllTabIndexAttributesSet() throws Exception { final String html1 = "foo"; final HtmlPage page1 = loadPage(html1); WebAssert.assertAllTabIndexAttributesSet(page1); final String html2 = "foo"; final HtmlPage page2 = loadPage(html2); boolean caught = false; try { WebAssert.assertAllTabIndexAttributesSet(page2); } catch (final AssertionError e) { caught = true; } assertTrue(caught); final String html3 = "foo"; final HtmlPage page3 = loadPage(html3); caught = false; try { WebAssert.assertAllTabIndexAttributesSet(page3); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertAllAccessKeyAttributesUnique() throws Exception { final String html1 = "foo"; final HtmlPage page1 = loadPage(html1); WebAssert.assertAllAccessKeyAttributesUnique(page1); final String html2 = "foobar"; final HtmlPage page2 = loadPage(html2); boolean caught = false; try { WebAssert.assertAllAccessKeyAttributesUnique(page2); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } /** * @throws Exception if an error occurs */ @Test public void testAssertAllIdAttributesUnique() throws Exception { final String html1 = "foo"; final HtmlPage page1 = loadPage(html1); WebAssert.assertAllIdAttributesUnique(page1); final String html2 = "foobar"; final HtmlPage page2 = loadPage(html2); boolean caught = false; try { WebAssert.assertAllIdAttributesUnique(page2); } catch (final AssertionError e) { caught = true; } assertTrue(caught); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/WebTestCase.java0000664000175000017500000007764411650253660032701 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.ConnectException; import java.net.MalformedURLException; import java.net.SocketException; import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.SerializationUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Common superclass for HtmlUnit tests. * * @version $Revision: 4859 $ * @author Mike Bowler * @author David D. Kilzer * @author Marc Guillemot * @author Chris Erskine * @author Michael Ottati * @author Daniel Gredler * @author Ahmed Ashour */ public abstract class WebTestCase { /** Logging support. */ private static final Log LOG = LogFactory.getLog(WebTestCase.class); /** The listener port for the web server. */ public static final int PORT = Integer.valueOf(System.getProperty("htmlunit.test.port", "12345")); /** Constant for the URL which is used in the tests. */ public static final URL URL_FIRST; /** Constant for the URL which is used in the tests. */ public static final URL URL_SECOND; /** Constant for the URL which is used in the tests. */ public static final URL URL_THIRD; /** Constant for the URL http://www.gargoylesoftware.com which is used in the tests. */ public static final URL URL_GARGOYLE; /** * The name of the system property used to determine if files should be generated * or not in {@link #createTestPageForRealBrowserIfNeeded(String,List)}. */ public static final String PROPERTY_GENERATE_TESTPAGES = "com.gargoylesoftware.htmlunit.WebTestCase.GenerateTestpages"; /** System-specific line separator. */ protected static final String LINE_SEPARATOR = System.getProperty("line.separator"); private BrowserVersion browserVersion_; private WebClient webClient_; private MockWebConnection mockWebConnection_; private String[] expectedAlerts_; private static final BrowserVersion FLAG_ALL_BROWSERS = new BrowserVersion("", "", "", 0); private static final ThreadLocal generateTest_browserVersion_ = new ThreadLocal(); private String generateTest_content_; private List generateTest_expectedAlerts_; private boolean generateTest_notYetImplemented_; private String generateTest_testName_; static { try { URL_FIRST = new URL("http://localhost:" + PORT + "/"); URL_SECOND = new URL("http://localhost:" + PORT + "/second/"); URL_THIRD = new URL("http://localhost:" + PORT + "/third/"); URL_GARGOYLE = new URL("http://www.gargoylesoftware.com/"); } catch (final MalformedURLException e) { // This is theoretically impossible. throw new IllegalStateException("Unable to create URL constants"); } } /** * Constructor. */ protected WebTestCase() { generateTest_browserVersion_.remove(); } /** * Load a page with the specified HTML using the default browser version. * @param html the HTML to use * @return the new page * @throws Exception if something goes wrong */ public static final HtmlPage loadPage(final String html) throws Exception { return loadPage(html, null); } /** * Load a page with the specified HTML and collect alerts into the list. * @param browserVersion the browser version to use * @param html the HTML to use * @param collectedAlerts the list to hold the alerts * @return the new page * @throws Exception if something goes wrong */ public static final HtmlPage loadPage(final BrowserVersion browserVersion, final String html, final List collectedAlerts) throws Exception { if (generateTest_browserVersion_.get() == null) { generateTest_browserVersion_.set(browserVersion); } return loadPage(browserVersion, html, collectedAlerts, URL_GARGOYLE); } /** * User the default browser version to load a page with the specified HTML * and collect alerts into the list. * @param html the HTML to use * @param collectedAlerts the list to hold the alerts * @return the new page * @throws Exception if something goes wrong */ public static final HtmlPage loadPage(final String html, final List collectedAlerts) throws Exception { generateTest_browserVersion_.set(FLAG_ALL_BROWSERS); return loadPage(BrowserVersion.getDefault(), html, collectedAlerts, URL_GARGOYLE); } /** * Loads an external URL, accounting for the fact that the remote server may be down or the * machine running the tests may not be connected to the internet. * @param url the URL to load * @return the loaded page, or null if there were connectivity issues * @throws Exception if an error occurs */ protected static final HtmlPage loadUrl(final String url) throws Exception { try { final WebClient client = new WebClient(); client.setUseInsecureSSL(true); return client.getPage(url); } catch (final ConnectException e) { // The remote server is probably down. System.out.println("Connection could not be made to " + url); return null; } catch (final SocketException e) { // The local machine may not be online. System.out.println("Connection could not be made to " + url); return null; } catch (final UnknownHostException e) { // The local machine may not be online. System.out.println("Connection could not be made to " + url); return null; } } /** * Loads a page with the specified HTML and collect alerts into the list. * @param html the HTML to use * @param collectedAlerts the list to hold the alerts * @param url the URL that will use as the document host for this page * @return the new page * @throws Exception if something goes wrong */ protected static final HtmlPage loadPage(final String html, final List collectedAlerts, final URL url) throws Exception { return loadPage(BrowserVersion.getDefault(), html, collectedAlerts, url); } /** * Load a page with the specified HTML and collect alerts into the list. * @param browserVersion the browser version to use * @param html the HTML to use * @param collectedAlerts the list to hold the alerts * @param url the URL that will use as the document host for this page * @return the new page * @throws Exception if something goes wrong */ protected static final HtmlPage loadPage(final BrowserVersion browserVersion, final String html, final List collectedAlerts, final URL url) throws Exception { final WebClient client = new WebClient(browserVersion); return loadPage(client, html, collectedAlerts, url); } /** * Load a page with the specified HTML and collect alerts into the list. * @param client the WebClient to use (webConnection and alertHandler will be configured on it) * @param html the HTML to use * @param collectedAlerts the list to hold the alerts * @param url the URL that will use as the document host for this page * @return the new page * @throws Exception if something goes wrong */ protected static final HtmlPage loadPage(final WebClient client, final String html, final List collectedAlerts, final URL url) throws Exception { if (collectedAlerts != null) { client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); } final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(html); client.setWebConnection(webConnection); return client.getPage(url); } /** * Load a page with the specified HTML and collect alerts into the list. * @param client the WebClient to use (webConnection and alertHandler will be configured on it) * @param html the HTML to use * @param collectedAlerts the list to hold the alerts * @return the new page * @throws Exception if something goes wrong */ protected static final HtmlPage loadPage(final WebClient client, final String html, final List collectedAlerts) throws Exception { return loadPage(client, html, collectedAlerts, URL_GARGOYLE); } /** * Assert that the specified object is null. * @param object the object to check */ public static void assertNull(final Object object) { Assert.assertNull("Expected null but found [" + object + "]", object); } /** * Facility to test external form of urls. Comparing external form of URLs is * really faster than URL.equals() as the host doesn't need to be resolved. * @param expectedUrl the expected URL * @param actualUrl the URL to test */ protected void assertEquals(final URL expectedUrl, final URL actualUrl) { Assert.assertEquals(expectedUrl.toExternalForm(), actualUrl.toExternalForm()); } /** * Asserts the two objects are equal. * @param expected the expected object * @param actual the object to test */ protected void assertEquals(final Object expected, final Object actual) { Assert.assertEquals(expected, actual); } /** * Facility to test external form of urls. Comparing external form of URLs is * really faster than URL.equals() as the host doesn't need to be resolved. * @param message the message to display if assertion fails * @param expectedUrl the string representation of the expected URL * @param actualUrl the URL to test */ protected void assertEquals(final String message, final URL expectedUrl, final URL actualUrl) { Assert.assertEquals(message, expectedUrl.toExternalForm(), actualUrl.toExternalForm()); } /** * Facility to test external form of an URL. * @param expectedUrl the string representation of the expected URL * @param actualUrl the URL to test */ protected void assertEquals(final String expectedUrl, final URL actualUrl) { Assert.assertEquals(expectedUrl, actualUrl.toExternalForm()); } /** * Facility method to avoid having to create explicitly a list from * a String[] (for example when testing received alerts). * Transforms the String[] to a List before calling * {@link junit.framework.Assert#assertEquals(java.lang.Object, java.lang.Object)}. * @param expected the expected strings * @param actual the collection of strings to test */ protected void assertEquals(final String[] expected, final List actual) { assertEquals(null, expected, actual); } /** * Facility method to avoid having to create explicitly a list from * a String[] (for example when testing received alerts). * Transforms the String[] to a List before calling * {@link junit.framework.Assert#assertEquals(java.lang.String, java.lang.Object, java.lang.Object)}. * @param message the message to display if assertion fails * @param expected the expected strings * @param actual the collection of strings to test */ protected void assertEquals(final String message, final String[] expected, final List actual) { Assert.assertEquals(message, Arrays.asList(expected).toString(), actual.toString()); } /** * Facility to test external form of an URL. * @param message the message to display if assertion fails * @param expectedUrl the string representation of the expected URL * @param actualUrl the URL to test */ protected void assertEquals(final String message, final String expectedUrl, final URL actualUrl) { Assert.assertEquals(message, expectedUrl, actualUrl.toExternalForm()); } /** * Assert the specified condition is true. * @param condition condition to test */ protected void assertTrue(final boolean condition) { Assert.assertTrue(condition); } /** * Assert the specified condition is true. * @param message message to show * @param condition condition to test */ protected void assertTrue(final String message, final boolean condition) { Assert.assertTrue(message, condition); } /** * Assert the specified condition is false. * @param condition condition to test */ protected void assertFalse(final boolean condition) { Assert.assertFalse(condition); } /** * Returns an input stream for the specified file name. Refer to {@link #getFileObject(String)} * for details on how the file is located. * @param fileName the base file name * @return the input stream * @throws FileNotFoundException if the file cannot be found */ public static InputStream getFileAsStream(final String fileName) throws FileNotFoundException { return new BufferedInputStream(new FileInputStream(getFileObject(fileName))); } /** * Returns a File object for the specified file name. This is different from just * new File(fileName) because it will adjust the location of the file * depending on how the code is being executed. * * @param fileName the base filename * @return the new File object * @throws FileNotFoundException if the file doesn't exist */ public static File getFileObject(final String fileName) throws FileNotFoundException { final String localizedName = fileName.replace('/', File.separatorChar); File file = new File(localizedName); if (!file.exists()) { file = new File("../../" + localizedName); } if (!file.exists()) { try { System.out.println("currentDir=" + new File(".").getCanonicalPath()); } catch (final IOException e) { e.printStackTrace(); } throw new FileNotFoundException(localizedName); } return file; } /** * Facility method transforming expectedAlerts to a list and calling * {@link #createTestPageForRealBrowserIfNeeded(String, List)}. * @param content the content of the HTML page * @param expectedAlerts the expected alerts * @throws IOException if writing file fails */ protected void createTestPageForRealBrowserIfNeeded(final String content, final String[] expectedAlerts) throws IOException { createTestPageForRealBrowserIfNeeded(content, Arrays.asList(expectedAlerts)); } /** * Generates an instrumented HTML file in the temporary dir to easily make a manual test in a real browser. * The file is generated only if the system property {@link #PROPERTY_GENERATE_TESTPAGES} is set. * @param content the content of the HTML page * @param expectedAlerts the expected alerts * @throws IOException if writing file fails */ protected void createTestPageForRealBrowserIfNeeded(final String content, final List expectedAlerts) throws IOException { // save the information to create a test for WebDriver generateTest_content_ = content; generateTest_expectedAlerts_ = expectedAlerts; final Method testMethod = findRunningJUnitTestMethod(); generateTest_testName_ = testMethod.getDeclaringClass().getSimpleName() + "_" + testMethod.getName() + ".html"; if (System.getProperty(PROPERTY_GENERATE_TESTPAGES) != null) { // should be optimized.... // calls to alert() should be replaced by call to custom function String newContent = StringUtils.replace(content, "alert(", "htmlunitReserved_caughtAlert("); final String instrumentationJS = createInstrumentationScript(expectedAlerts); // first version, we assume that there is a and a or a if (newContent.indexOf("") > -1) { newContent = StringUtils.replaceOnce(newContent, "", "" + instrumentationJS); } else { newContent = StringUtils.replaceOnce(newContent, "", "\n\n" + instrumentationJS + "\n\n"); } final String endScript = "\n\n"; if (newContent.contains("")) { newContent = StringUtils.replaceOnce(newContent, "", endScript + ""); } else { LOG.info("No test generated: currently only content with a and a is supported"); } final File f = File.createTempFile("TEST" + '_', ".html"); FileUtils.writeStringToFile(f, newContent, "ISO-8859-1"); LOG.info("Test file written: " + f.getAbsolutePath()); } else { LOG.debug("System property \"" + PROPERTY_GENERATE_TESTPAGES + "\" not set, don't generate test HTML page for real browser"); } } /** * @param expectedAlerts the list of the expected alerts * @return the script to be included at the beginning of the generated HTML file * @throws IOException in case of problem */ private String createInstrumentationScript(final List expectedAlerts) throws IOException { // generate the js code final InputStream is = getClass().getClassLoader().getResourceAsStream("alertVerifier.js"); final String baseJS = IOUtils.toString(is); IOUtils.closeQuietly(is); final StringBuilder sb = new StringBuilder(); sb.append("\n\n"); return sb.toString(); } /** * Convenience method to pull the MockWebConnection out of an HtmlPage created with * the loadPage method. * @param page HtmlPage to get the connection from * @return the MockWebConnection that served this page */ protected static final MockWebConnection getMockConnection(final HtmlPage page) { return (MockWebConnection) page.getWebClient().getWebConnection(); } /** * Runs the calling JUnit test again and fails only if it already runs.
          * This is helpful for tests that don't currently work but should work one day, * when the tested functionality has been implemented.
          * The right way to use it is: *
               * public void testXXX() {
               *   if (notYetImplemented()) {
               *       return;
               *   }
               *
               *   ... the real (now failing) unit test
               * }
               * 
          * @return false when not itself already in the call stack */ protected boolean notYetImplemented() { generateTest_notYetImplemented_ = true; if (notYetImplementedFlag.get() != null) { return false; } notYetImplementedFlag.set(Boolean.TRUE); final Method testMethod = findRunningJUnitTestMethod(); try { LOG.info("Running " + testMethod.getName() + " as not yet implemented"); testMethod.invoke(this, (Object[]) new Class[] {}); Assert.fail(testMethod.getName() + " is marked as not implemented but already works"); } catch (final Exception e) { LOG.info(testMethod.getName() + " fails which is normal as it is not yet implemented"); // method execution failed, it is really "not yet implemented" } finally { notYetImplementedFlag.set(null); } return true; } /** * Finds from the call stack the active running JUnit test case * @return the test case method * @throws RuntimeException if no method could be found */ private Method findRunningJUnitTestMethod() { final Class< ? > cl = getClass(); final Class< ? >[] args = new Class[] {}; // search the initial junit test final Throwable t = new Exception(); for (int i = t.getStackTrace().length - 1; i >= 0; i--) { final StackTraceElement element = t.getStackTrace()[i]; if (element.getClassName().equals(cl.getName())) { try { final Method m = cl.getMethod(element.getMethodName(), args); if (isPublicTestMethod(m)) { return m; } } catch (final Exception e) { // can't access, ignore it } } } throw new RuntimeException("No JUnit test case method found in call stack"); } /** * From Junit. Test if the method is a junit test. * @param method the method * @return true if this is a junit test */ private boolean isPublicTestMethod(final Method method) { return method.getParameterTypes().length == 0 && (method.getName().startsWith("test") || method.getAnnotation(Test.class) != null) && method.getReturnType() == Void.TYPE && Modifier.isPublic(method.getModifiers()); } private static final ThreadLocal notYetImplementedFlag = new ThreadLocal(); /** * Load the specified resource for the supported browsers and tests * that the generated log corresponds to the expected one for this browser. * * @param fileName the resource name which resides in /resources folder and * belongs to the same package as the test class. * * @throws Exception if the test fails */ protected void testHTMLFile(final String fileName) throws Exception { final String resourcePath = getClass().getPackage().getName().replace('.', '/') + '/' + fileName; final URL url = getClass().getClassLoader().getResource(resourcePath); final Map testedBrowser = new HashMap(); testedBrowser.put("FIREFOX_2", BrowserVersion.FIREFOX_2); testedBrowser.put("INTERNET_EXPLORER_6_0", BrowserVersion.INTERNET_EXPLORER_6); for (final Map.Entry entry : testedBrowser.entrySet()) { final String browserKey = entry.getKey(); final BrowserVersion browserVersion = entry.getValue(); final WebClient client = new WebClient(browserVersion); final HtmlPage page = client.getPage(url); final HtmlElement want = page.getHtmlElementById(browserKey); final HtmlElement got = page.getHtmlElementById("log"); final List expected = readChildElementsText(want); final List actual = readChildElementsText(got); Assert.assertEquals(expected, actual); } } private List readChildElementsText(final HtmlElement elt) { final List list = new ArrayList(); for (final HtmlElement child : elt.getChildElements()) { list.add(child.asText()); } return list; } void setBrowserVersion(final BrowserVersion browserVersion) { browserVersion_ = browserVersion; } /** * Returns the WebClient instance for the current test with the current {@link BrowserVersion}. * @return a WebClient with the current {@link BrowserVersion} */ protected final WebClient createNewWebClient() { return new WebClient(getBrowserVersion()); } /** * Returns the WebClient instance for the current test with the current {@link BrowserVersion}. * @return a WebClient with the current {@link BrowserVersion} */ protected final WebClient getWebClient() { if (webClient_ == null) { webClient_ = createNewWebClient(); } return webClient_; } /** * Returns the WebClient instance for the current test with the current {@link BrowserVersion}. * @return a WebClient with the current {@link BrowserVersion} */ protected final WebClient getWebClientWithMockWebConnection() { if (webClient_ == null) { webClient_ = createNewWebClient(); webClient_.setWebConnection(getMockWebConnection()); } return webClient_; } /** * Returns the mock WebConnection instance for the current test. * @return the mock WebConnection instance for the current test */ protected MockWebConnection getMockWebConnection() { if (mockWebConnection_ == null) { mockWebConnection_ = new MockWebConnection(); } return mockWebConnection_; } /** * Sets the mock WebConnection instance for the current test. * @param connection the connection to use */ protected void setMockWebConnection(final MockWebConnection connection) { mockWebConnection_ = connection; } /** * Returns the current {@link BrowserVersion}. * @return current {@link BrowserVersion} */ protected final BrowserVersion getBrowserVersion() { if (browserVersion_ == null) { throw new IllegalStateException("You must annotate the test class with '@RunWith(BrowserRunner.class)'"); } return browserVersion_; } /** * Sets the expected alerts. * @param expectedAlerts the expected alerts */ protected void setExpectedAlerts(final String... expectedAlerts) { expectedAlerts_ = expectedAlerts; } /** * Returns the expected alerts. * @return the expected alerts */ protected String[] getExpectedAlerts() { return expectedAlerts_; } /** * Defines the provided HTML as the response of the MockWebConnection for {@link #getDefaultUrl()} * and loads the page with this URL using the current browser version. * Finally asserts the alerts equal the expected alerts. * @param html the HTML to use * @return the new page * @throws Exception if something goes wrong */ protected final HtmlPage loadPageWithAlerts(final String html) throws Exception { return loadPageWithAlerts(html, getDefaultUrl(), -1); } /** * Defines the provided HTML as the response of the MockWebConnection for {@link #getDefaultUrl()} * and loads the page with this URL using the current browser version. * Finally asserts the alerts equal the expected alerts. * @param html the HTML to use * @param url the URL from which the provided HTML code should be delivered * @param waitForJS the milliseconds to wait for background JS tasks to complete. Ignored if -1. * @return the new page * @throws Exception if something goes wrong */ protected final HtmlPage loadPageWithAlerts(final String html, final URL url, final int waitForJS) throws Exception { if (expectedAlerts_ == null) { throw new IllegalStateException("You must annotate the test class with '@RunWith(BrowserRunner.class)'"); } createTestPageForRealBrowserIfNeeded(html, expectedAlerts_); final WebClient client = getWebClientWithMockWebConnection(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = getMockWebConnection(); webConnection.setResponse(url, html); final HtmlPage page = client.getPage(url); if (waitForJS > 0) { assertEquals(0, client.waitForBackgroundJavaScriptStartingBefore(waitForJS)); } assertEquals(expectedAlerts_, collectedAlerts); return page; } /** * A generics-friendly version of {@link SerializationUtils#clone(Serializable)}. * @param the type of the object being cloned * @param object the object being cloned * @return a clone of the specified object */ @SuppressWarnings("unchecked") protected T clone(final T object) { return (T) SerializationUtils.clone(object); } /** * Gets the default URL used for the tests. * @return the url */ protected URL getDefaultUrl() { return URL_GARGOYLE; } /** * Generates an HTML file that can be loaded and understood as a test. * @throws IOException in case of problem */ @After public void generateTestForWebDriver() throws IOException { if (generateTest_content_ != null && !generateTest_notYetImplemented_) { final File targetDir = new File("target/generated_tests"); targetDir.mkdirs(); final File outFile = new File(targetDir, generateTest_testName_); // replace alert(x) by a storage in window's scope // Convert to string here due to: http://code.google.com/p/webdriver/issues/detail?id=209 final String newContent = StringUtils.replace(generateTest_content_, "alert(", "(function(t){var x = window.__huCatchedAlerts; x = x ? x : []; " + "window.__huCatchedAlerts = x; x.push(String(t))})("); FileUtils.writeStringToFile(outFile, newContent); // write the expected alerts final String suffix; BrowserVersion browser = generateTest_browserVersion_.get(); if (browser == null) { browser = getBrowserVersion(); } if (browser == FLAG_ALL_BROWSERS) { suffix = ".expected"; } else { suffix = "." + browser.getNickname() + ".expected"; } final File expectedLog = new File(outFile.getParentFile(), outFile.getName() + suffix); final FileOutputStream fos = new FileOutputStream(expectedLog); final ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(generateTest_expectedAlerts_); oos.close(); } } /** * Cleanup after a test. */ @After public void releaseResources() { if (webClient_ != null) { webClient_.closeAllWindows(); } webClient_ = null; mockWebConnection_ = null; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnectionTest.jav0000664000175000017500000002406511650253660034611 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.StatusLine; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests methods in {@link HttpWebConnection}. * * @version $Revision: 4848 $ * @author David D. Kilzer * @author Marc Guillemot * @author Ahmed Ashour */ public class HttpWebConnectionTest extends WebServerTestCase { /** * Assert that the two byte arrays are equal. * @param expected the expected value * @param actual the actual value */ public static void assertEquals(final byte[] expected, final byte[] actual) { assertEquals(null, expected, actual); } /** * Assert that the two byte arrays are equal. * @param message the message to display on failure * @param expected the expected value * @param actual the actual value */ public static void assertEquals(final String message, final byte[] expected, final byte[] actual) { assertEquals(message, expected, actual, expected.length); } /** * Assert that the two byte arrays are equal. * @param message the message to display on failure * @param expected the expected value * @param actual the actual value * @param length How many characters at the beginning of each byte array will be compared */ public static void assertEquals( final String message, final byte[] expected, final byte[] actual, final int length) { if (expected == null && actual == null) { return; } if (expected == null || actual == null) { Assert.fail(message); } if (expected.length < length || actual.length < length) { Assert.fail(message); } for (int i = 0; i < length; i++) { Assert.assertEquals(message, expected[i], actual[i]); } } /** * Assert that the two input streams are the same. * @param expected the expected value * @param actual the actual value * @throws IOException if an IO problem occurs during comparison */ public static void assertEquals(final InputStream expected, final InputStream actual) throws IOException { assertEquals(null, expected, actual); } /** * Assert that the two input streams are the same. * @param message the message to display on failure * @param expected the expected value * @param actual the actual value * @throws IOException if an IO problem occurs during comparison */ public static void assertEquals(final String message, final InputStream expected, final InputStream actual) throws IOException { if (expected == null && actual == null) { return; } if (expected == null || actual == null) { try { Assert.fail(message); } finally { try { if (expected != null) { expected.close(); } } finally { if (actual != null) { actual.close(); } } } } InputStream expectedBuf = null; InputStream actualBuf = null; try { expectedBuf = new BufferedInputStream(expected); actualBuf = new BufferedInputStream(actual); final byte[] expectedArray = new byte[2048]; final byte[] actualArray = new byte[2048]; int expectedLength = expectedBuf.read(expectedArray); while (true) { final int actualLength = actualBuf.read(actualArray); Assert.assertEquals(message, expectedLength, actualLength); if (expectedLength == -1) { break; } assertEquals(message, expectedArray, actualArray, expectedLength); expectedLength = expectedBuf.read(expectedArray); } } finally { try { if (expectedBuf != null) { expectedBuf.close(); } } finally { if (actualBuf != null) { actualBuf.close(); } } } } /** * Tests creation of a web response. * @throws Exception if the test fails */ @Test public void testMakeWebResponse() throws Exception { final URL url = new URL("http://htmlunit.sourceforge.net/"); final String content = ""; final int httpStatus = HttpStatus.SC_OK; final long loadTime = 500L; final HttpMethodBase httpMethod = new GetMethod(url.toString()); final Field responseBodyField = HttpMethodBase.class.getDeclaredField("responseBody"); responseBodyField.setAccessible(true); responseBodyField.set(httpMethod, content.getBytes()); final StatusLine statusLine = new StatusLine("HTTP/1.0 200 OK"); final Field statusLineField = HttpMethodBase.class.getDeclaredField("statusLine"); statusLineField.setAccessible(true); statusLineField.set(httpMethod, statusLine); final HttpWebConnection connection = new HttpWebConnection(new WebClient()); final Method method = connection.getClass().getDeclaredMethod("makeWebResponse", new Class[]{ int.class, HttpMethodBase.class, WebRequestSettings.class, long.class}); method.setAccessible(true); final WebResponse response = (WebResponse) method.invoke(connection, new Object[]{ new Integer(httpStatus), httpMethod, new WebRequestSettings(url), new Long(loadTime)}); Assert.assertEquals(httpStatus, response.getStatusCode()); Assert.assertEquals(url, response.getRequestSettings().getUrl()); Assert.assertEquals(loadTime, response.getLoadTime()); Assert.assertEquals(content, response.getContentAsString()); assertEquals(content.getBytes(), response.getContentAsBytes()); assertEquals(new ByteArrayInputStream(content.getBytes()), response.getContentAsStream()); } /** * Tests Jetty. * @throws Exception on failure */ @Test public void testJettyProofOfConcept() throws Exception { startWebServer("./"); final WebClient client = new WebClient(); final Page page = client.getPage("http://localhost:" + PORT + "/src/test/resources/event_coordinates.html"); final WebConnection defaultConnection = client.getWebConnection(); Assert.assertTrue( "HttpWebConnection should be the default", HttpWebConnection.class.isInstance(defaultConnection)); Assert.assertTrue("Response should be valid HTML", HtmlPage.class.isInstance(page)); } /** * Test for feature request 1438216: HttpWebConnection should allow extension to create the HttpClient. * @throws Exception if the test fails */ @Test public void testDesignedForExtension() throws Exception { startWebServer("./"); final WebClient webClient = new WebClient(); final boolean[] tabCalled = {false}; final WebConnection myWebConnection = new HttpWebConnection(webClient) { @Override protected HttpClient createHttpClient() { tabCalled[0] = true; return new HttpClient(); } }; webClient.setWebConnection(myWebConnection); webClient.getPage("http://localhost:" + PORT + "/LICENSE.txt"); Assert.assertTrue("createHttpClient has not been called", tabCalled[0]); } /** * Test that the right file part is built for a file that doesn't exist. * @throws Exception if the test fails */ @Test public void testBuildFilePart() throws Exception { final String encoding = "ISO8859-1"; final KeyDataPair pair = new KeyDataPair("myFile", new File("this/doesnt_exist.txt"), "text/plain", encoding); final FilePart part = new HttpWebConnection(new WebClient()).buildFilePart(pair, encoding); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); part.send(baos); final String expected = "------------------314159265358979323846\r\n" + "Content-Disposition: form-data; name=\"myFile\"; filename=\"doesnt_exist.txt\"\r\n" + "Content-Type: text/plain\r\n" + "Content-Transfer-Encoding: binary\r\n" + "\r\n" + "\r\n"; Assert.assertEquals(expected, baos.toString(encoding)); } /** * @throws Exception on failure */ @Test public void unicode() throws Exception { startWebServer("./"); final WebClient client = new WebClient(); client.getPage("http://localhost:" + PORT + "/src/test/resources/event_coordinates.html?param=\u00F6"); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java0000664000175000017500000002735711650253660034051 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sourceforge.htmlunit.corejs.javascript.NativeArray; import net.sourceforge.htmlunit.corejs.javascript.Undefined; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.json.JSONArray; import org.junit.AfterClass; import org.mortbay.jetty.Server; import org.mortbay.jetty.webapp.WebAppContext; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.htmlunit.HtmlUnitWebElement; import org.openqa.selenium.ie.InternetExplorerDriver; import com.gargoylesoftware.htmlunit.html.HtmlElement; /** * Base class for tests using WebDriver. *

          * This test runs with HtmlUnit unless the system property "htmlunit.webdriver" is set to "ff2" * in which case the test will run in the "real" firefox browser. *

          *

          * You can set the property in maven by modifying the POM value of the system properties in maven-surefire-plugin. * In eclipse you can change the "Run configurations" -> "Arguments" tab -> "VM arguments" * -> "-Dhtmlunit.webdriver=ff2" *

          *

          To change the firefox binary, you can also setup the system property "webdriver.firefox.bin".

          * @version $Revision: 4888 $ * @author Marc Guillemot * @author Ahmed Ashour */ public abstract class WebDriverTestCase extends WebTestCase { static final String PROPERTY = "htmlunit.webdriver"; private static WebDriver WEB_DRIVER_; private static Server STATIC_SERVER_; private static String JSON_; /** * Configure the driver only once. * @return the driver */ protected WebDriver getWebDriver() { if (WEB_DRIVER_ == null) { WEB_DRIVER_ = buildWebDriver(); } return WEB_DRIVER_; } /** * Closes the drivers. * @throws Exception If an error occurs */ @AfterClass public static void shutDownAll() throws Exception { if (WEB_DRIVER_ != null) { WEB_DRIVER_.close(); } WEB_DRIVER_ = null; if (STATIC_SERVER_ != null) { STATIC_SERVER_.stop(); } STATIC_SERVER_ = null; } private WebDriver buildWebDriver() { final String property = System.getProperty(PROPERTY, "").toLowerCase(); if (property.contains("ff2") || property.contains("ff3")) { return new FirefoxDriver(); } if (property.contains("ie6") || property.contains("ie7")) { return new InternetExplorerDriver(); } final WebClient webClient = getWebClient(); final HtmlUnitDriver driver = new HtmlUnitDriver(true) { @Override protected WebClient newWebClient(final BrowserVersion browserVersion) { return webClient; } @Override protected WebElement newHtmlUnitWebElement(final HtmlElement element) { return new FixedWebDriverHtmlUnitWebElement(this, element); } }; return driver; } /** * Starts the web server delivering response from the provided connection. * @param mockConnection the sources for responses * @throws Exception if a problem occurs */ private void startWebServer(final MockWebConnection mockConnection) throws Exception { if (STATIC_SERVER_ == null) { STATIC_SERVER_ = new Server(PORT); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setResourceBase("./"); context.addServlet(MockWebConnectionServlet.class, "/*"); STATIC_SERVER_.setHandler(context); STATIC_SERVER_.start(); } MockWebConnectionServlet.MockConnection_ = mockConnection; } /** * Servlet delivering content from a MockWebConnection. * @author Marc Guillemot */ public static class MockWebConnectionServlet extends HttpServlet { private static final long serialVersionUID = -3417522859381706421L; private static MockWebConnection MockConnection_; /** * {@inheritDoc} */ @Override protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { try { doService(request, response); } catch (final ServletException e) { throw e; } catch (final IOException e) { throw e; } catch (final Exception e) { throw new ServletException(e); } } @SuppressWarnings("unchecked") private void doService(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final URL requestedUrl = new URL(request.getRequestURL().toString()); final WebRequestSettings settings = new WebRequestSettings(requestedUrl); settings.setHttpMethod(HttpMethod.valueOf(request.getMethod())); for (final Enumeration en = request.getHeaderNames(); en.hasMoreElements();) { final String headerName = en.nextElement(); final String headerValue = request.getHeader(headerName); settings.setAdditionalHeader(headerName, headerValue); } final WebResponse resp = MockConnection_.getResponse(settings); // write WebResponse to HttpServletResponse for (final NameValuePair responseHeader : resp.getResponseHeaders()) { response.addHeader(responseHeader.getName(), responseHeader.getValue()); } final String newContent = StringUtils.replace(resp.getContentAsString(), "alert(", "(function(t){var x = top.__huCatchedAlerts; x = x ? x : []; " + "top.__huCatchedAlerts = x; x.push(String(t))})("); response.getWriter().print(newContent); response.flushBuffer(); } } /** * Same as {@link #loadPageWithAlerts(String)}, but using WebDriver instead. * @param html the HTML to use * @return the web driver * @throws Exception if something goes wrong */ protected final WebDriver loadPageWithAlerts2(final String html) throws Exception { final String[] expectedAlerts = getExpectedAlerts(); final MockWebConnection mockWebConnection = getMockWebConnection(); mockWebConnection.setResponse(URL_FIRST, html); startWebServer(mockWebConnection); final WebDriver driver = getWebDriver(); driver.get(URL_FIRST.toExternalForm()); assertEquals(expectedAlerts, getCollectedAlerts(driver)); return driver; } private List getCollectedAlerts(final WebDriver driver) throws Exception { final List collectedAlerts = new ArrayList(); if (driver instanceof HtmlUnitDriver) { final Object result = ((JavascriptExecutor) driver) .executeScript("return window.__huCatchedAlerts"); if (result != Undefined.instance) { final NativeArray resp = (NativeArray) result; for (int i = 0; i < resp.getLength(); ++i) { collectedAlerts.add( net.sourceforge.htmlunit.corejs.javascript.Context.toString(resp.get(i, resp))); } } } else if (driver instanceof InternetExplorerDriver) { final String jsonResult = (String) ((JavascriptExecutor) driver) .executeScript(getJSON() + ";return JSON.stringify(window.__huCatchedAlerts)"); if (jsonResult != null) { final JSONArray array = new JSONArray(jsonResult); for (int i = 0; i < array.length(); i++) { collectedAlerts.add(net.sourceforge.htmlunit.corejs.javascript.Context.toString(array.get(i))); } } } else { final JSONArray array = (JSONArray) ((JavascriptExecutor) driver) .executeScript("return window.__huCatchedAlerts"); if (array != null) { for (int i = 0; i < array.length(); i++) { collectedAlerts.add(net.sourceforge.htmlunit.corejs.javascript.Context.toString(array.get(i))); } } } return collectedAlerts; } /** * Same as {@link #loadPageWithAlerts2(String)}, but using a MockConnection instead. * @param conn the connection to use * @return the web driver * @throws Exception if something goes wrong */ protected final WebDriver loadPageWithAlerts2(final MockWebConnection conn) throws Exception { final String[] expectedAlerts = getExpectedAlerts(); startWebServer(conn); final WebDriver driver = getWebDriver(); driver.get(URL_FIRST.toExternalForm()); assertEquals(expectedAlerts, getCollectedAlerts(driver)); return driver; } private String getJSON() { if (JSON_ == null) { try { final StringBuilder builder = new StringBuilder(); final File file = new File(getClass().getClassLoader().getResource("json2.js").toURI()); for (final Object line : FileUtils.readLines(file)) { builder.append(line).append('\n'); } JSON_ = builder.toString(); } catch (final Exception e) { throw new RuntimeException(e); } } return JSON_; } /** * Returns the HtmlElement of the specified WebElement. * @param webElement the webElement * @return the HtmlElement */ protected HtmlElement toHtmlElement(final WebElement webElement) { try { final Field field = HtmlUnitWebElement.class.getDeclaredField("element"); field.setAccessible(true); return (HtmlElement) field.get(webElement); } catch (final Exception e) { throw new RuntimeException(e); } } } /** * As HtmlUnit didn't generate the right events, WebDriver did it for us, but now that we do it correctly, * WebDriver shouldn't do it anymore * http://code.google.com/p/webdriver/issues/detail?id=93 */ class FixedWebDriverHtmlUnitWebElement extends HtmlUnitWebElement { public FixedWebDriverHtmlUnitWebElement(final HtmlUnitDriver parent, final HtmlElement element) { super(parent, element); } @Override public void click() { try { getElement().click(); } catch (final IOException e) { throw new RuntimeException(e); } } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/WebResponseImplTest.java0000664000175000017500000001745611650253660034441 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.lang.ArrayUtils; import org.junit.Test; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for {@link WebResponseImpl}. * * @version $Revision: 4574 $ * @author Marc Guillemot * @author Ahmed Ashour */ public class WebResponseImplTest extends WebServerTestCase { /** * Verifies that when no encoding header is provided, encoding may be recognized with its Byte Order Mark. * @throws Exception if the test fails */ @Test public void recognizeBOM() throws Exception { recognizeBOM("UTF-8", new byte[] {(byte) 0xef, (byte) 0xbb, (byte) 0xbf}); recognizeBOM("UTF-16BE", new byte[] {(byte) 0xfe, (byte) 0xff}); recognizeBOM("UTF-16LE", new byte[] {(byte) 0xff, (byte) 0xfe}); } private void recognizeBOM(final String encoding, final byte[] markerBytes) throws Exception { final WebClient webClient = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); final String html = ""; // see http://en.wikipedia.org/wiki/Byte_Order_Mark final String[] expectedAlerts = {"\u6211\u662F\u6211\u7684 " + "\u064A\u0627 \u0623\u0647\u0644\u0627\u064B"}; final byte[] script = ("alert('" + expectedAlerts[0] + "');").getBytes(encoding); webConnection.setDefaultResponse(ArrayUtils.addAll(markerBytes, script), 200, "OK", "text/javascript"); webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); final List collectedAlerts = new ArrayList(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); webClient.getPage(URL_FIRST); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void encoding() throws Exception { final String title = "\u6211\u662F\u6211\u7684FOCUS"; final String content = "\n" + "" + title + "\n" + "\n" + "\n" + ""; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); final List< ? extends NameValuePair> emptyList = Collections.emptyList(); webConnection.setResponse(URL_FIRST, content.getBytes("UTF-8"), 200, "OK", "text/html", emptyList); client.setWebConnection(webConnection); final WebRequestSettings settings = new WebRequestSettings(URL_FIRST); settings.setCharset("UTF-8"); final HtmlPage page = client.getPage(settings); assertEquals(title, page.getTitleText()); } /** * @throws Exception if the test fails */ @Test public void quotedCharset() throws Exception { final String xml = "\n" + " \n" + " Immortality\n" + " John Smith\n" + " \n" + ""; final List collectedAlerts = new ArrayList(); final WebClient client = new WebClient(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection conn = new MockWebConnection(); final List< ? extends NameValuePair> emptyList = Collections.emptyList(); conn.setResponse(URL_FIRST, xml, HttpStatus.SC_OK, "OK", "text/xml; charset=\"ISO-8859-1\"", emptyList); client.setWebConnection(conn); client.getPage(URL_FIRST); } /** * @throws Exception if the test fails */ @Test public void charsetInMetaTag() throws Exception { final String html = "\n" + "\n" + "foo\n" + ""; final WebClient client = new WebClient(); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("utf-8", page.getWebResponse().getContentCharsetOrNull()); } /** * Test that extracting charset from Content-Type header is forgiving. * @throws Exception if the test fails */ @Test public void illegalCharset() throws Exception { illegalCharset("text/html; text/html; charset=ISO-8859-1;", "ISO-8859-1"); illegalCharset("text/html; charset=UTF-8; charset=UTF-8", "UTF-8"); illegalCharset("text/html; charset=#sda+s", TextUtil.DEFAULT_CHARSET); illegalCharset("text/html; charset=UnknownCharset", TextUtil.DEFAULT_CHARSET); } private void illegalCharset(final String cntTypeHeader, final String expectedCharset) throws Exception { final MockWebConnection conn = new MockWebConnection(); final List headers = new ArrayList(); headers.add(new NameValuePair("Content-Type", cntTypeHeader)); conn.setDefaultResponse("", 200, "OK", "text/html", headers); final WebClient webClient = new WebClient(); webClient.setWebConnection(conn); final Page page = webClient.getPage(URL_FIRST); assertEquals(expectedCharset, page.getWebResponse().getContentCharset()); assertEquals(cntTypeHeader, page.getWebResponse().getResponseHeaderValue("Content-Type")); } /** * @throws Exception if the test fails */ @Test public void responseHeaders() throws Exception { final Map> servlets = new HashMap>(); servlets.put("/test", ResponseHeadersServlet.class); startWebServer("./", null, servlets); final WebClient client = new WebClient(); final HtmlPage page = client.getPage("http://localhost:" + PORT + "/test"); assertEquals("some_value", page.getWebResponse().getResponseHeaderValue("some_header")); } /** * Servlet for {@link #responseHeaders()}. */ public static class ResponseHeadersServlet extends HttpServlet { private static final long serialVersionUID = -8815307540281233182L; /** * {@inheritDoc} */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { response.setContentType("text/html"); response.setHeader("some_header", "some_value"); final Writer writer = response.getWriter(); writer.write(""); writer.close(); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/NotYetImplementedTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/NotYetImplementedTest.jav0000664000175000017500000001425011650253660034615 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Set; import java.util.TreeSet; import org.apache.commons.io.FileUtils; import org.junit.Test; import com.gargoylesoftware.htmlunit.javascript.host.PropertiesTest; /** * Generates HTML file with all NotYetImplemented methods. * * @version $Revision: 4687 $ * @author Ahmed Ashour */ public class NotYetImplementedTest { private Set entries_ = new TreeSet(); /** * @throws Exception if the test fails */ @Test public void test() throws Exception { process(new File("src/test/java")); save(); } private void process(final File dir) throws IOException { for (final File file : dir.listFiles()) { if (file.isDirectory() && !file.getName().equals(".svn")) { process(file); } else { if (file.getName().endsWith(".java") && !file.getName().equals("WebTestCase.java") && !file.getName().equals("NotYetImplementedTest.java") && !file.getName().equals("CodeStyleTest.java")) { final List lines = CodeStyleTest.getLines(file); final String relativePath = file.getAbsolutePath().substring( new File(".").getAbsolutePath().length() - 1).replace('\\', '/'); process(lines, relativePath); } } } } private void process(final List lines, final String path) { int index = 1; for (final String line : lines) { if (line.contains("notYetImplemented()")) { String methodName = null; int lineNumber = -1; for (int i = index; i >= 0; i--) { final String l = lines.get(i); if (l.startsWith(" public ")) { methodName = l.split(" ")[6]; break; } } for (int i = index; i >= 0; i--) { final String l = lines.get(i); if (l.startsWith(" /**")) { lineNumber = i; break; } } entries_.add(path + ';' + methodName + ';' + lineNumber); } else if (line.contains("@NotYetImplemented")) { final String browser; if (line.contains("(")) { browser = line.replaceAll(".*\\((.*)\\).*", "$1").replaceAll("Browser\\.", "") .replaceAll("[{}]", "").trim(); } else { browser = ""; } String methodName = null; int lineNumber = -1; for (int i = index; i < lines.size(); i++) { final String l = lines.get(i); if (l.startsWith(" public ")) { methodName = l.split(" ")[6]; break; } } for (int i = index; i >= 0; i--) { final String l = lines.get(i); if (l.startsWith(" /**")) { lineNumber = i; break; } } entries_.add(path + ';' + methodName + ';' + lineNumber + ";" + browser); } index++; } } private void save() throws Exception { final StringBuilder builder = new StringBuilder(); builder.append("\n"); builder.append("NotYetImplemented is a condition in which a test is known to fail with HtmlUnit."); builder.append("\n"); builder.append(" \n"); String lastFile = null; for (final String entry : entries_) { final String[] values = entry.split(";"); final String file = values[0]; final String fileName = file.substring(file.lastIndexOf('/') + 1, file.length() - 5); final String method = values[1]; final String line = values[2]; final String browser = values.length > 3 ? values[3] : ""; builder.append(" \n"); if (!file.equals(lastFile)) { int totalCount = 0; for (final String e : entries_) { if (e.startsWith(file)) { totalCount++; } } if (totalCount != 1) { builder.append(" \n"); lastFile = file; } builder.append(" \n"); builder.append(" \n"); builder.append(" \n"); } builder.append("
          FileMethodLine
          "); } else { builder.append(" "); } builder.append(fileName); builder.append("").append(method).append(" ") .append(browser).append("").append(line).append("
          \n").append(""); FileUtils.writeStringToFile(new File(PropertiesTest.getArtifactsDirectory(), "notYetImplemented.html"), builder.toString()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/WebServerTestCase.java0000664000175000017500000001242511650253660034052 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.util.Map; import javax.servlet.Servlet; import org.junit.After; import org.mortbay.jetty.Handler; import org.mortbay.jetty.Server; import org.mortbay.jetty.handler.HandlerList; import org.mortbay.jetty.handler.ResourceHandler; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.webapp.WebAppClassLoader; import org.mortbay.jetty.webapp.WebAppContext; /** * Base class for cases that need real web server. * * @version $Revision: 4738 $ * @author Ahmed Ashour * @author Marc Guillemot */ public abstract class WebServerTestCase extends WebTestCase { private Server server_; /** * Starts the web server on the default {@link #PORT}. * The given resourceBase is used to be the ROOT directory that serves the default context. *

          Don't forget to stop the returned HttpServer after the test * * @param resourceBase the base of resources for the default context * @throws Exception if the test fails */ protected void startWebServer(final String resourceBase) throws Exception { if (server_ != null) { throw new IllegalStateException("startWebServer() can not be called twice"); } server_ = new Server(PORT); final Context context = new Context(); context.setContextPath("/"); context.setResourceBase(resourceBase); final ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase(resourceBase); final HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{resourceHandler, context}); server_.setHandler(handlers); server_.setHandler(resourceHandler); server_.start(); } /** * Starts the web server on the default {@link #PORT}. * The given resourceBase is used to be the ROOT directory that serves the default context. *

          Don't forget to stop the returned HttpServer after the test * * @param resourceBase the base of resources for the default context * @param classpath additional classpath entries to add (may be null) * @throws Exception if the test fails */ protected void startWebServer(final String resourceBase, final String[] classpath) throws Exception { if (server_ != null) { throw new IllegalStateException("startWebServer() can not be called twice"); } server_ = new Server(PORT); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setResourceBase(resourceBase); final WebAppClassLoader loader = new WebAppClassLoader(context); if (classpath != null) { for (final String path : classpath) { loader.addClassPath(path); } } context.setClassLoader(loader); server_.setHandler(context); server_.start(); } /** * Starts the web server on the default {@link #PORT}. * The given resourceBase is used to be the ROOT directory that serves the default context. *

          Don't forget to stop the returned HttpServer after the test * * @param resourceBase the base of resources for the default context * @param classpath additional classpath entries to add (may be null) * @param servlets map of {String, Class} pairs: String is the path spec, while class is the class * @throws Exception if the test fails */ protected void startWebServer(final String resourceBase, final String[] classpath, final Map> servlets) throws Exception { if (server_ != null) { throw new IllegalStateException("startWebServer() can not be called twice"); } server_ = new Server(PORT); final WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setResourceBase(resourceBase); for (final String pathSpec : servlets.keySet()) { final Class< ? extends Servlet> servlet = servlets.get(pathSpec); context.addServlet(servlet, pathSpec); } final WebAppClassLoader loader = new WebAppClassLoader(context); if (classpath != null) { for (final String path : classpath) { loader.addClassPath(path); } } context.setClassLoader(loader); server_.setHandler(context); server_.start(); } /** * Performs post-test deconstruction. * @throws Exception if an error occurs */ @After public void tearDown() throws Exception { if (server_ != null) { server_.stop(); } server_ = null; } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/BrowserStatement.java0000664000175000017500000000542111650253660034020 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit; import java.lang.reflect.Method; import org.junit.runners.model.Statement; /** * The Browser Statement. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ class BrowserStatement extends Statement { private Statement next_; private final boolean shouldFail_; private final boolean notYetImplemented_; private final Method method_; private final String browserVersionString_; BrowserStatement(final Statement next, final Method method, final boolean shouldFail, final boolean notYetImplemented, final String browserVersionString) { next_ = next; method_ = method; shouldFail_ = shouldFail; notYetImplemented_ = notYetImplemented; browserVersionString_ = browserVersionString; } @Override public void evaluate() throws Throwable { Exception toBeThrown = null; try { next_.evaluate(); if (shouldFail_) { final String errorMessage; if (browserVersionString_ == null) { errorMessage = method_.getName() + " is marked to fail with " + browserVersionString_ + ", but succeeds"; } else { errorMessage = method_.getName() + " is marked to fail, but succeeds"; } toBeThrown = new Exception(errorMessage); } else if (notYetImplemented_) { final String errorMessage; if (browserVersionString_ == null) { errorMessage = method_.getName() + " is marked as not implemented but already works"; } else { errorMessage = method_.getName() + " is marked as not implemented with " + browserVersionString_ + " but already works"; } toBeThrown = new Exception(errorMessage); } } catch (final Throwable e) { if (!shouldFail_ && !notYetImplemented_) { throw e; } } if (toBeThrown != null) { throw toBeThrown; } } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/0000775000175000017500000000000011650253660030607 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript2Test.java0000664000175000017500000003223611650253660034473 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.apache.commons.httpclient.HttpStatus.SC_NO_CONTENT; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.httpclient.NameValuePair; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlScript}, but with BrowserRunner. * * @version $Revision: 4772 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlScript2Test extends WebTestCase { /** * @throws Exception on test failure */ @Test @Alerts("myValue") public void insertBefore() throws Exception { final String html = "Page A" + "\n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Tests the 'Referer' HTTP header. * @throws Exception on test failure */ @Test public void refererHeader() throws Exception { final String firstContent = "Page A\n" + ""; final String js = "alert('loaded')"; final WebClient client = getWebClient(); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html); conn.setResponse(URL_SECOND, js, "text/javascript"); client.setWebConnection(conn); final List actual = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(actual)); final HtmlPage page = client.getPage(URL_FIRST); assertEquals(2, conn.getRequestCount()); page.cloneNode(true); assertEquals(2, conn.getRequestCount()); final String[] expected = {"loaded"}; assertEquals(expected, actual); } /** * Verifies that we're lenient about whitespace before and after URLs in the "src" attribute. * @throws Exception if an error occurs */ @Test public void testWhitespaceInSrc() throws Exception { final String html = "abc"; final String js = "alert('ok')"; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); webConnection.setResponse(URL_SECOND, js); client.setWebConnection(webConnection); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); client.getPage(URL_FIRST); final String[] expectedAlerts = {"ok"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Verifies that we're lenient about empty "src" attributes. * @throws Exception if an error occurs */ @Test public void testEmptySrc() throws Exception { final String html1 = "abc"; final String html2 = "abc"; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html1); webConnection.setResponse(URL_SECOND, html2); client.setWebConnection(webConnection); client.getPage(URL_FIRST); assertEquals(1, webConnection.getRequestCount()); client.getPage(URL_SECOND); assertEquals(2, webConnection.getRequestCount()); } /** * @throws Exception if an error occurs */ @Test public void testAsXml() throws Exception { final String html = "foo\n" + ""; final String[] expectedAlerts = {"hello"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); // asXml() should be reusable final String xml = page.asXml(); collectedAlerts.clear(); loadPage(xml, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Verifies that setting a script's src attribute behaves correctly. * @throws Exception if an error occurs */ @Test @Alerts(FF = { "1", "2", "3" }, IE = { "1", "2", "3", "4", "5" }) public void testSettingSrcAttribute() throws Exception { final String html = "\n" + " \n" + " Test\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " test\n" + " \n" + ""; final List actual = new ArrayList(); final WebClient client = getWebClient(); client.setAlertHandler(new CollectingAlertHandler(actual)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(html); webConnection.setResponse(new URL("http://abc/script2.js"), "alert(2);"); webConnection.setResponse(new URL("http://abc/script3.js"), "alert(3);"); webConnection.setResponse(new URL("http://abc/script4.js"), "alert(4);"); webConnection.setResponse(new URL("http://abc/script5.js"), "alert(5);"); client.setWebConnection(webConnection); client.getPage("http://abc/"); assertEquals(getExpectedAlerts(), actual); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLScriptElement]") public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlScript.class.isInstance(page.getHtmlElementById("myId"))); } /** * Verifies that 204 (No Content) responses for script resources are handled gracefully. * @throws Exception on test failure * @see 2815903 */ @Test public void noContent() throws Exception { final String html = "\n" + "\n" + "\n" + ""; final WebClient client = getWebClient(); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html); conn.setResponse(URL_SECOND, "", "text/javascript"); client.setWebConnection(conn); final List actual = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(actual)); client.getPage(URL_FIRST); assertEquals(getExpectedAlerts(), actual); } /** * @exception Exception If the test fails */ @Test @Alerts("Hello") public void type_case_sensitivity() throws Exception { final String html = "\n" + "\n" + " \n" + ""; loadPageWithAlerts(html); } /** * @exception Exception If the test fails */ @Test @Alerts({ "1", "5", "7" }) public void type_language() throws Exception { final String html = "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; loadPageWithAlerts(html); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageDownloadTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageDownloadTes0000664000175000017500000000776611650253660034565 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.io.IOException; import java.net.URL; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebServerTestCase; /** * Tests for {@link HtmlImage}. * * @version $Revision: 4713 $ * @author Knut Johannes Dahle * @author Ahmed Ashour * @author Marc Guillemot */ public class HtmlImageDownloadTest extends WebServerTestCase { private static final String base_file_path_ = "src/test/resources/com/gargoylesoftware/htmlunit/html"; /** * Constructor. * @throws Exception if an exception occurs */ public HtmlImageDownloadTest() throws Exception { startWebServer(base_file_path_); } /** * @throws Exception if the test fails */ @Test public void testImageHeight() throws Exception { final HtmlImage htmlimage = getHtmlElementToTest("image1"); Assert.assertEquals("Image height", 612, htmlimage.getHeight()); } /** * @throws Exception if the test fails */ @Test public void testImageWidth() throws Exception { final HtmlImage htmlimage = getHtmlElementToTest("image1"); Assert.assertEquals("Image width", 879, htmlimage.getWidth()); } /** * @throws Exception if the test fails */ @Test public void testImageFileSize() throws Exception { final HtmlImage htmlimage = getHtmlElementToTest("image1"); Assert.assertEquals("Image filesize", 140144, htmlimage.getWebResponse(true).getContentAsBytes().length); } /** * @throws Exception if the test fails */ @Test public void testGetImageReader() throws Exception { final HtmlImage htmlimage = getHtmlElementToTest("image1"); Assert.assertNotNull("ImageReader should not be null", htmlimage.getImageReader()); } /** * @throws Exception if the test fails */ @Test public void testGetImageReaderNoneSupportedImage() throws Exception { final HtmlImage htmlimage = getHtmlElementToTest("image1"); final String url = "/HtmlImageDownloadTest.html"; htmlimage.setAttribute("src", url); try { htmlimage.getImageReader(); Assert.fail("it was not an image!"); } catch (final IOException ioe) { // Correct behaviour } } /** * @throws Exception if the test fails */ @Test public void testGetWebResponse() throws Exception { final HtmlImage htmlimage = getHtmlElementToTest("image1"); final URL url = htmlimage.getPage().getWebResponse().getRequestSettings().getUrl(); Assert.assertNull(htmlimage.getWebResponse(false)); final WebResponse resp = htmlimage.getWebResponse(true); Assert.assertNotNull(resp); assertEquals(url.toExternalForm(), resp.getRequestSettings().getAdditionalHeaders().get("Referer")); } /** * Common code for the tests to load the testpage and fetch the HtmlImage object. * @param id value of image id attribute * @return the found HtmlImage * @throws Exception if an error occurs */ private HtmlImage getHtmlElementToTest(final String id) throws Exception { final String url = "http://localhost:" + PORT + "/HtmlImageDownloadTest.html"; final HtmlPage page = loadUrl(url); return (HtmlImage) page.getElementById(id); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrameTest.java0000664000175000017500000002050711650253660034175 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.fail; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlFrame}. * * @version $Revision: 4820 $ * @author Mike Bowler * @author Ahmed Ashour */ public class HtmlFrameTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void srcOfBlankAndEmpty() throws Exception { final String html = "first\n" + "\n" + " \n" + " \n" + ""; final HtmlPage page = loadPage(html); final HtmlFrame frame1 = page.getHtmlElementById("frame1"); Assert.assertEquals("frame1", "", ((HtmlPage) frame1.getEnclosedPage()).getTitleText()); final HtmlFrame frame2 = page.getHtmlElementById("frame2"); Assert.assertEquals("frame2", "", ((HtmlPage) frame2.getEnclosedPage()).getTitleText()); } /** * @throws Exception if the test fails */ @Test public void onLoadHandler() throws Exception { final WebClient webClient = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); final List collectedAlerts = new ArrayList(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final String html = "first\n" + "\n" + " \n" + " \n" + ""; final String[] expectedAlerts = {"FRAME"}; webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); assertEquals("first", page.getTitleText()); final HtmlFrame frame1 = page.getHtmlElementById("frame1"); Assert.assertEquals("frame1", "", ((HtmlPage) frame1.getEnclosedPage()).getTitleText()); final HtmlFrame frame2 = page.getHtmlElementById("frame2"); Assert.assertEquals("frame2", "", ((HtmlPage) frame2.getEnclosedPage()).getTitleText()); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void documentWrite() throws Exception { final String html = "first\n" + "\n" + " \n" + " generatedgenerated');" + "frame1.document.close()\" id='frame2'>\n" + ""; final HtmlPage page = loadPage(html); assertEquals("first", page.getTitleText()); final HtmlFrame frame1 = page.getHtmlElementById("frame1"); Assert.assertEquals("frame1", "generated", ((HtmlPage) frame1.getEnclosedPage()).getTitleText()); final HtmlFrame frame2 = page.getHtmlElementById("frame2"); Assert.assertEquals("frame2", "", ((HtmlPage) frame2.getEnclosedPage()).getTitleText()); } /** * Tests that frames are correctly deregistered even if not HTML. * @throws Exception if the test fails */ @Test public void deregisterNonHtmlFrame() throws Exception { final WebClient webClient = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); final String html = "first\n" + "\n" + " \n" + ""; webConnection.setDefaultResponse("foo", 200, "OK", "text/plain"); webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); assertEquals("first", page.getTitleText()); // loads something else to trigger frame de-registration webClient.getPage(URL_SECOND); } /** * @throws Exception if the test fails */ @Test public void failingHttpStatusCodeException() throws Exception { final String failingHtml = "Not found"; final String firstHtml = "First\n" + "\n" + " \n" + " \n" + " \n" + " <body>Frames not supported</body>\n" + " \n" + "\n" + ""; final String secondHtml = "Second"; final String thirdHtml = "Third"; final WebClient webClient = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(failingHtml, 404, "No Found", "text/html"); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setResponse(URL_SECOND, secondHtml); webConnection.setResponse(URL_THIRD, thirdHtml); webClient.setWebConnection(webConnection); try { webClient.getPage(URL_FIRST); fail("Expected FailingHttpStatusCodeException"); } catch (final FailingHttpStatusCodeException e) { assertEquals(404, e.getStatusCode()); } } /** * Regression test for bug 1518195. * See http://sourceforge.net/tracker/index.php?func=detail&aid=1518195&group_id=47038&atid=448266. * @throws Exception if the test fails */ @Test public void frameScriptReplaceOtherFrame() throws Exception { final String html = "frames\n" + "\n" + "\n" + "\n" + "\n" + ""; final String frame1 = "1\n" + "1" + "\n" + ""; final String frame3 = "page 3"; final WebClient webClient = new WebClient(); final MockWebConnection conn = new MockWebConnection(); webClient.setWebConnection(conn); conn.setDefaultResponse("default"); conn.setResponse(URL_FIRST, html); conn.setResponse(new URL(URL_FIRST, "1.html"), frame1); conn.setResponse(new URL(URL_FIRST, "3.html"), frame3); final HtmlPage page = webClient.getPage(URL_FIRST); assertEquals("page 3", ((HtmlPage) page.getFrameByName("f2").getEnclosedPage()).getTitleText()); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableSectionTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableSectionTest0000664000175000017500000000470411650253660034600 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlTableBody}, {@link HtmlTableHeader}, and {@link HtmlTableFooter}. * * @version $Revision: 4002 $ * @author Mike Bowler * @author Ahmed Ashour */ public class HtmlTableSectionTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + ""; final String[] expectedAlerts = {"[object HTMLTableSectionElement]", "[object HTMLTableSectionElement]", "[object HTMLTableSectionElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlTableHeader.class.isInstance(page.getHtmlElementById("myId1"))); assertTrue(HtmlTableBody.class.isInstance(page.getHtmlElementById("myId2"))); assertTrue(HtmlTableFooter.class.isInstance(page.getHtmlElementById("myId3"))); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlListItemTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlListItemTest.jav0000664000175000017500000000340011650253660034525 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlListItem}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlListItemTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLLIElement]") public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + "

            \n" + "
          • Item1>
          • \n" + "
          \n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlListItem.class.isInstance(page.getHtmlElementById("myId"))); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHtmlTest.java0000664000175000017500000000476311650253660034055 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlHtml}. * * @version $Revision: 4002 $ * @author Marc Guillemot * @author Ahmed Ashour */ public class HtmlHtmlTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testAttributes() throws Exception { final String htmlContent = "\n" + "\n" + "\n" + "test\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlHtml root = (HtmlHtml) page.getDocumentElement(); assertEquals("en", root.getLangAttribute()); assertEquals("en", root.getXmlLangAttribute()); } /** * @throws Exception if the test fails */ @Test public void testSimpleScriptable() throws Exception { final String content = "foo\n" + ""; final String[] expectedAlerts = {"[object HTMLHtmlElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, content, collectedAlerts); assertTrue(HtmlHtml.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.jav0000664000175000017500000002314311650253660034516 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlTextArea}. * * @version $Revision: 4463 $ * @author Mike Bowler * @author Marc Guillemot * @author Ahmed Ashour * @author Sudhan Moghe */ public class HtmlTextAreaTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void formSubmission() throws Exception { formSubmission("foo", "foo"); formSubmission("\r\nfoo\r\n", "foo%0D%0A"); formSubmission("\nfoo\n", "foo%0D%0A"); formSubmission("\r\n\r\nfoo\r\n", "%0D%0Afoo%0D%0A"); } private void formSubmission(final String textAreaText, final String expectedValue) throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextArea textArea = form.getTextAreaByName("textArea1"); assertNotNull(textArea); final Page secondPage = form.submit((SubmittableElement) null); assertEquals("url", URL_GARGOYLE + "?textArea1=" + expectedValue, secondPage.getWebResponse().getRequestSettings().getUrl()); assertSame("method", HttpMethod.GET, webConnection.getLastMethod()); } /** * @throws Exception if the test fails */ @Test public void testFormSubmission_NewValue() throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextArea textArea = form.getTextAreaByName("textArea1"); textArea.setText("Flintstone"); final Page secondPage = form.submit((SubmittableElement) null); assertEquals("url", URL_GARGOYLE + "?textArea1=Flintstone", secondPage.getWebResponse().getRequestSettings().getUrl()); assertSame("method", HttpMethod.GET, webConnection.getLastMethod()); } /** * @throws Exception if the test fails */ @Test public void testGetText() throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextArea textArea = form.getTextAreaByName("textArea1"); assertNotNull(textArea); Assert.assertEquals("White space must be preserved!", " foo \n bar ", textArea.getText()); Assert.assertEquals(" foo \n bar ", textArea.getDefaultValue()); } /** * @throws Exception if the test fails */ @Test public void testAsXml() throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextArea textArea1 = form.getTextAreaByName("textArea1"); assertEquals("", textArea1.asXml()); final HtmlTextArea textArea2 = form.getTextAreaByName("textArea2"); assertEquals("", textArea2.asXml()); } /** * @throws Exception if an error occurs */ @Test public void testPreventDefault() throws Exception { testPreventDefault(BrowserVersion.FIREFOX_2); testPreventDefault(BrowserVersion.INTERNET_EXPLORER_7); } private void testPreventDefault(final BrowserVersion browserVersion) throws Exception { final String html = "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(browserVersion, html, null); final HtmlTextArea text1 = page.getHtmlElementById("text1"); text1.type("abcd"); assertEquals("abc", text1.getText()); } /** * @throws Exception if the test fails */ @Test public void type() throws Exception { final String html = ""; final HtmlPage page = loadPage(html, null); final HtmlTextArea t = page.getHtmlElementById("t"); t.type("abc"); assertEquals("abc", t.getText()); t.type('\b'); assertEquals("ab", t.getText()); t.type('\b'); assertEquals("a", t.getText()); t.type('\b'); assertEquals("", t.getText()); t.type('\b'); assertEquals("", t.getText()); t.type("ab\ncd"); assertEquals("ab\ncd", t.getText()); t.type("\r\nef"); assertEquals("ab\ncd\r\nef", t.getText()); } /** * @throws Exception if the test fails */ @Test public void typeWhileDisabled() throws Exception { final String html = ""; final HtmlPage page = loadPage(html); final HtmlTextArea t = page.getHtmlElementById("t"); t.type("abc"); assertEquals("", t.getText()); } /** * @throws Exception if the test fails */ @Test public void asText() throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextArea textArea = form.getTextAreaByName("textArea1"); assertNotNull(textArea); Assert.assertEquals("White space must be preserved!", " foo " + LINE_SEPARATOR + " bar

          html snippet

          " + LINE_SEPARATOR, textArea.asText()); } /** * @throws Exception if the test fails */ @Test public void testParentAsText() throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final HtmlForm form = page.getHtmlElementById("form1"); Assert.assertEquals(" foo " + LINE_SEPARATOR + " bar

          html snippet

          " + LINE_SEPARATOR, form.asText()); } /** * Style=visibility:hidden should not affect getText(). * @throws Exception if the test fails */ @Test public void getTextAndVisibility() throws Exception { final String content = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextArea textArea = form.getTextAreaByName("textArea1"); assertNotNull(textArea); assertEquals(" foo \n bar ", textArea.getText()); assertEquals("", textArea.asText()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlBodyTest.java0000664000175000017500000000342611650253660034041 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; /** * Tests for {@link HtmlBody}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlBodyTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Browsers(Browser.FF) @Alerts("[object HTMLBodyElement]") public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlBody.class.isInstance(page.getHtmlElementById("myId"))); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/package.html0000664000175000017500000000012111650253660033062 0ustar jamespagejamespageTest Classes Test Classes ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/DomDocumentFragmentTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/DomDocumentFragmentT0000664000175000017500000000443711650253660034570 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link DomDocumentFragment}. * * @version $Revision: 4753 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class DomDocumentFragmentTest extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "
          ", "undefined" }, FF = { "undefined", "undefined" }) public void xml() throws Exception { final String html = "foo\n" + ""; loadPageWithAlerts2(html); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java0000664000175000017500000022605611650253660034026 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Writer; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.NameValuePair; import org.junit.Assert; import org.junit.Test; import org.w3c.dom.NodeList; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.ImmediateRefreshHandler; import com.gargoylesoftware.htmlunit.IncorrectnessListener; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.OnbeforeunloadHandler; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.StringWebResponse; import com.gargoylesoftware.htmlunit.TextUtil; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebServerTestCase; import com.gargoylesoftware.htmlunit.html.HtmlElementTest.HtmlAttributeChangeListenerTestImpl; /** * Tests for {@link HtmlPage}. * * @version $Revision: 4810 $ * @author Mike Bowler * @author Noboru Sinohara * @author David K. Taylor * @author Andreas Hangler * @author Christian Sell * @author Marc Guillemot * @author Ahmed Ashour */ public class HtmlPageTest extends WebServerTestCase { /** * @throws Exception if the test fails */ @Test public void testFormSubmit() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "

          hello world

          \n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + ""; final HtmlPage page = loadPage(htmlContent); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlInput textInput = form.getInputByName("textInput1"); textInput.setValueAttribute("foo"); final HtmlSubmitInput button = form.getInputByName("submitInput1"); final HtmlPage secondPage = (HtmlPage) button.click(); final List expectedParameters = new ArrayList(); expectedParameters.add(new NameValuePair("textInput1", "foo")); expectedParameters.add(new NameValuePair("textInput2", "textInput2")); expectedParameters.add(new NameValuePair("hidden1", "hidden1")); expectedParameters.add(new NameValuePair("submitInput1", "push me")); final URL expectedUrl = new URL(URL_GARGOYLE + "formSubmit"); final URL actualUrl = secondPage.getWebResponse().getRequestSettings().getUrl(); assertEquals("url", expectedUrl, actualUrl); Assert.assertSame("method", HttpMethod.POST, webConnection.getLastMethod()); Assert.assertEquals("parameters", expectedParameters, webConnection.getLastParameters()); assertNotNull(secondPage); } /** * Tests getHtmlElement() for all elements that can be loaded. * @throws Exception if the test fails */ @Test public void testGetHtmlElement() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "

          hello world

          \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " foo.com\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          HeaderData
          \n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); assertSame("form1", form, page.getHtmlElementById("form1")); //huh?? final HtmlInput input = form.getInputByName("textInput1"); assertSame("input1", input, form.getInputByName("textInput1")); //?? final HtmlButton button = form.getButtonByName("button1"); assertSame("button1", button, form.getButtonByName("button1")); final HtmlSelect select = form.getSelectsByName("select1").get(0); assertSame("select1", select, form.getSelectsByName("select1").get(0)); final HtmlOption option = select.getOptionByValue("option1"); assertSame("option1", option, select.getOptionByValue("option1")); final HtmlTable table = page.getHtmlElementById("table1"); assertSame("table1", table, page.getHtmlElementById("table1")); final HtmlAnchor anchor = page.getAnchorByName("anchor1"); assertSame("anchor1", anchor, page.getAnchorByName("anchor1")); assertSame("anchor3", anchor, page.getAnchorByHref("http://www.foo.com")); assertSame("anchor4", anchor, page.getAnchorByText("foo.com")); final HtmlTableRow tableRow = table.getRow(0); assertSame("tableRow1", tableRow, table.getRow(0)); final HtmlTableHeaderCell tableHeaderCell = (HtmlTableHeaderCell) tableRow.getCell(0); assertSame("tableHeaderCell1", tableHeaderCell, tableRow.getCell(0)); assertSame("tableHeaderCell2", tableHeaderCell, page.getHtmlElementById("header1")); final HtmlTableDataCell tableDataCell = (HtmlTableDataCell) tableRow.getCell(1); assertSame("tableDataCell1", tableDataCell, tableRow.getCell(1)); assertSame("tableDataCell2", tableDataCell, page.getHtmlElementById("data1")); final HtmlTextArea textArea = form.getTextAreaByName("textArea1"); assertSame("textArea1", textArea, form.getTextAreaByName("textArea1")); } /** * @throws Exception if the test fails */ @Test public void testGetTabbableElements_None() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "

          hello world

          \n" + "
          foo
          \n" + ""; final HtmlPage page = loadPage(htmlContent); assertEquals(Collections.EMPTY_LIST, page.getTabbableElements()); } /** * @throws Exception if the test fails */ @Test public void testGetTabbableElements_OneEnabled_OneDisabled() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "

          hello world

          \n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final List expectedElements = new ArrayList(); expectedElements.add(page.getHtmlElementById("bar")); assertEquals(expectedElements, page.getTabbableElements()); } /** * @throws Exception if the test fails */ @Test public void testGetTabbableElements() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "foo\n" + "foo\n" + "
          \n" + "foo\n" + "foo\n" + "foo\n" + "
          \n" + "foo\n" + "foo\n" + "foo\n" + "

          hello world

          \n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final List expectedElements = Arrays.asList(new HtmlElement[] {page.getHtmlElementById("a"), page.getHtmlElementById("g"), page.getHtmlElementById("d"), page.getHtmlElementById("c"), page.getHtmlElementById("f"), page.getHtmlElementById("e"), page.getHtmlElementById("b"), page.getHtmlElementById("bar")}); assertEquals(expectedElements, page.getTabbableElements()); final String[] expectedIds = {"a", "g", "d", "c", "f", "e", "b", "bar"}; assertEquals(expectedIds, page.getTabbableElementIds()); } /** * @throws Exception if the test fails */ @Test public void testGetHtmlElementByAccessKey() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "foo\n" + "foo\n" + "
          \n" + "foo\n" + "
          \n" + "

          hello world

          \n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); assertEquals(page.getHtmlElementById("a"), page.getElementByAccessKey('A')); assertEquals(page.getHtmlElementById("c"), page.getElementByAccessKey('c')); assertNull(page.getElementByAccessKey('z')); } /** * @throws Exception if the test fails */ @Test public void testGetHtmlElementsByAccessKey() throws Exception { final String htmlContent = "\n" + "foo\n" + "foo\n" + "foo\n" + "
          \n" + "foo\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final List expectedElements = Arrays.asList(new HtmlElement[] {page.getHtmlElementById("a"), page.getHtmlElementById("b")}); final List collectedElements = page.getElementsByAccessKey('a'); assertEquals(expectedElements, collectedElements); } /** * @throws Exception if the test fails */ @Test public void testGetFullQualifiedUrl_NoBaseSpecified() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "
          \n" + "
          "; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(htmlContent); client.setWebConnection(webConnection); final String urlString = URL_GARGOYLE.toExternalForm(); final HtmlPage page = client.getPage(URL_GARGOYLE); assertEquals(urlString, page.getFullyQualifiedUrl("")); assertEquals(urlString + "foo", page.getFullyQualifiedUrl("foo")); assertEquals("http://foo.com/bar", page.getFullyQualifiedUrl("http://foo.com/bar")); assertEquals("mailto:me@foo.com", page.getFullyQualifiedUrl("mailto:me@foo.com")); assertEquals(urlString + "foo", page.getFullyQualifiedUrl("foo")); assertEquals(urlString + "bbb", page.getFullyQualifiedUrl("aaa/../bbb")); assertEquals(urlString + "c/d", page.getFullyQualifiedUrl("c/./d")); final HtmlPage secondPage = client.getPage(urlString + "foo/bar?a=b&c=d"); assertEquals(urlString + "foo/bar?a=b&c=d", secondPage.getFullyQualifiedUrl("")); assertEquals(urlString + "foo/one", secondPage.getFullyQualifiedUrl("one")); assertEquals(urlString + "two", secondPage.getFullyQualifiedUrl("/two")); assertEquals(urlString + "foo/two?a=b", secondPage.getFullyQualifiedUrl("two?a=b")); final HtmlPage thirdPage = client.getPage("http://foo.com/dog/cat/one.html"); assertEquals("http://foo.com/dog/cat/one.html", thirdPage.getFullyQualifiedUrl("")); assertEquals("http://foo.com/dog/cat/two.html", thirdPage.getFullyQualifiedUrl("two.html")); } /** * @throws Exception if the test fails */ @Test public void testGetFullQualifiedUrl_WithBase() throws Exception { testGetFullQualifiedUrl_WithBase("http", ""); testGetFullQualifiedUrl_WithBase("http", ":8080"); testGetFullQualifiedUrl_WithBase("https", ""); testGetFullQualifiedUrl_WithBase("https", ":2005"); } /** * @throws Exception if the test fails */ private void testGetFullQualifiedUrl_WithBase(final String baseProtocol, final String basePortPart) throws Exception { final String baseUrl = baseProtocol + "://second" + basePortPart; final String htmlContent = "foo\n" + "\n" + "\n" + "
          \n" + "
          \n" + "
          "; final HtmlPage page = loadPage(htmlContent); assertEquals(baseUrl, page.getFullyQualifiedUrl("")); assertEquals(baseUrl + "/foo", page.getFullyQualifiedUrl("foo")); assertEquals(baseUrl + "/foo.js", page.getFullyQualifiedUrl("/foo.js")); assertEquals("http://foo.com/bar", page.getFullyQualifiedUrl("http://foo.com/bar")); assertEquals("mailto:me@foo.com", page.getFullyQualifiedUrl("mailto:me@foo.com")); assertEquals(baseUrl + "/bbb", page.getFullyQualifiedUrl("aaa/../bbb")); assertEquals(baseUrl + "/c/d", page.getFullyQualifiedUrl("c/./d")); } /** * @throws Exception if the test fails */ @Test public void testGetFullQualifiedUrl_WithInvalidBase() throws Exception { final String htmlContent = ""; final HtmlPage page = loadPage(htmlContent); // invalid base URL should be ignored assertEquals("http://somewhere.com/", page.getFullyQualifiedUrl("http://somewhere.com/")); assertEquals(page.getWebResponse().getRequestSettings().getUrl() + "foo.html", page.getFullyQualifiedUrl("foo.html")); } /** * @throws Exception if an error occurs */ @Test public void testBase_Multiple() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + " \n" + ""; final WebClient webClient = new WebClient(); final List collectedIncorrectness = new ArrayList(); final IncorrectnessListener listener = new IncorrectnessListener() { public void notify(final String message, final Object origin) { collectedIncorrectness.add(message); } }; webClient.setIncorrectnessListener(listener); final MockWebConnection webConnection = new MockWebConnection(); webClient.setWebConnection(webConnection); webConnection.setDefaultResponse(html); final HtmlPage page = webClient.getPage(URL_FIRST); page.getAnchors().get(0).click(); final String[] expectedIncorrectness = {"Multiple 'base' detected, only the first is used.", "Multiple 'base' detected, only the first is used."}; assertEquals(expectedIncorrectness, collectedIncorrectness); } /** * @throws Exception if an error occurs */ @Test public void testBase_InsideBody() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + " \n" + " \n" + ""; final WebClient webClient = new WebClient(); final List collectedIncorrectness = new ArrayList(); final IncorrectnessListener listener = new IncorrectnessListener() { public void notify(final String message, final Object origin) { collectedIncorrectness.add(message); } }; webClient.setIncorrectnessListener(listener); final MockWebConnection webConnection = new MockWebConnection(); webClient.setWebConnection(webConnection); webConnection.setDefaultResponse(html); final HtmlPage page = webClient.getPage(URL_FIRST); final HtmlAnchor anchor = page.getAnchors().get(0); final HtmlPage secondPage = (HtmlPage) anchor.click(); final String[] expectedIncorrectness = { "Element 'base' must appear in , it is ignored." }; assertEquals(expectedIncorrectness, collectedIncorrectness); assertEquals(URL_FIRST + "somepage.html", secondPage.getWebResponse().getRequestSettings().getUrl()); } /** * @throws Exception if the test fails */ @Test public void testOnLoadHandler_BodyStatement() throws Exception { final String htmlContent = "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); final String[] expectedAlerts = {"foo"}; assertEquals(expectedAlerts, collectedAlerts); } /** * If the onload handler contains two statements then only the first would execute. * @throws Exception if the test fails */ @Test public void testOnLoadHandler_TwoBodyStatements() throws Exception { final String htmlContent = "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); final String[] expectedAlerts = {"foo", "bar"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Regression test for bug 713646. * @throws Exception if the test fails */ @Test public void testOnLoadHandler_BodyName() throws Exception { final String htmlContent = "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); final String[] expectedAlerts = {"foo"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Regression test for bug 713646. * @throws Exception if the test fails */ @Test public void testOnLoadHandler_BodyName_NotAFunction() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); page.getAnchorByName("alert").click(); final String[] expectedAlerts = {"4711"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Regression test for window.onload property. * @throws Exception if the test fails */ @Test public void testOnLoadHandler_ScriptName() throws Exception { final String htmlContent = "foo\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); final String[] expectedAlerts = {"foo"}; assertEquals(expectedAlerts, collectedAlerts); } /** * Regression test for window.onload property. * @throws Exception if the test fails */ @Test public void testOnLoadHandler_ScriptNameRead() throws Exception { final String htmlContent = "foo\n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); final String[] expectedAlerts = {"\nfunction () {\n}\n"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testEmbeddedMetaTag_Regression() throws Exception { final String htmlContent = "foo\n" + "\n" + "
          \n" + "\n" + "
          \n" + " \n" + " \n" + "
          \n" + "
          \n" + ""; final List collectedAlerts = new ArrayList(); // This used to blow up on page load final HtmlPage page = loadPage(htmlContent, collectedAlerts); assertEquals("foo", page.getTitleText()); final List< ? > expectedAlerts = Collections.EMPTY_LIST; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testGetPageEncoding() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "\n" + "
          \n" + "\n" + "
          \n" + " \n" + " \n" + "
          \n" + "
          \n" + ""; final HtmlPage page = loadPage(htmlContent); assertEquals("Shift_JIS", page.getPageEncoding()); } /** * Verifies that an empty charset in a content-type meta tag is ignored. See bug 2484753. * @throws Exception if an error occurs */ @Test public void testGetPageEncoding_EmptyCharset() throws Exception { final String html = "\n" + "\n" + "abc"; final HtmlPage page = loadPage(html); assertEquals(TextUtil.DEFAULT_CHARSET, page.getPageEncoding()); } /** * @throws Exception if the test fails */ @Test public void testGetForms() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "
          \n" + "foo\n" + "
          \n" + "
          \n" + "foo\n" + "
          \n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final List expectedForms = Arrays.asList(new HtmlForm[] {page.getFormByName("one"), page.getFormByName("two")}); assertEquals(expectedForms, page.getForms()); } /** * Test auto-refresh from a meta tag. * @throws Exception if the test fails */ @Test public void testRefresh_MetaTag_DefaultRefreshHandler() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * @throws Exception if the test fails */ @Test public void testRefresh_MetaTag_caseSensitivity() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test auto-refresh from a meta tag with no URL. * @throws Exception if the test fails */ @Test public void testRefresh_MetaTag_NoUrl() throws Exception { final String firstContent = "first\n" + "\n" + ""; final WebClient client = new WebClient(); final List collectedItems = new ArrayList(); client.setRefreshHandler(new LoggingRefreshHandler(collectedItems)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); client.setWebConnection(webConnection); client.getPage(URL_FIRST); // avoid using equals() on URL because it takes to much time (due to ip resolution) assertEquals("first", collectedItems.get(0)); assertEquals(URL_FIRST, (URL) collectedItems.get(1)); assertEquals(new Integer(1), collectedItems.get(2)); } /** * Ensures that if a page is supposed to refresh itself every certain amount of * time, and the ImmediateRefreshHandler is being used, an OOME is avoided by * not performing the refresh. * @throws Exception if the test fails */ @Test public void testRefresh_ImmediateRefresh_AvoidOOME() throws Exception { final String firstContent = "first\n" + "\n" + ""; final WebClient client = new WebClient(); assertTrue(ImmediateRefreshHandler.class.isInstance(client.getRefreshHandler())); try { loadPage(firstContent); fail("should have thrown"); } catch (final RuntimeException e) { assertTrue(e.getMessage().indexOf("could have caused an OutOfMemoryError") > -1); } Thread.sleep(1000); } /** * Test auto-refresh from a meta tag with URL quoted. * @throws Exception if the test fails */ @Test public void testRefresh_MetaTagQuoted() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test auto-refresh from a meta tag with URL partly quoted. * @throws Exception if the test fails */ @Test public void testRefresh_MetaTagPartlyQuoted() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test auto-refresh from a meta tag inside noscript. * @throws Exception if the test fails */ @Test public void testRefresh_MetaTagNoScript() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); HtmlPage page = client.getPage(URL_FIRST); assertEquals("first", page.getTitleText()); client.setJavaScriptEnabled(false); page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test auto-refresh from a meta tag with a refresh handler that doesn't refresh. * @throws Exception if the test fails */ @Test public void testRefresh_MetaTag_CustomRefreshHandler() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final List collectedItems = new ArrayList(); client.setRefreshHandler(new LoggingRefreshHandler(collectedItems)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("first", page.getTitleText()); // avoid using equals() on URL because it takes to much time (due to ip resolution) assertEquals("first", collectedItems.get(0)); assertEquals(URL_SECOND, ((URL) collectedItems.get(1))); assertEquals(new Integer(3), collectedItems.get(2)); } /** * Test that whitespace before and after ';' is permitted. * * @throws Exception if the test fails */ @Test public void testRefresh_MetaTag_Whitespace() throws Exception { final String firstContent = "first\n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test that the refresh time can be a double ("3.4", for example), not just an integer. * * @throws Exception if an error occurs */ @Test public void testRefresh_MetaTag_Double() throws Exception { final String html1 = "first\n" + "\n" + ""; final String html2 = "secondabc"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html1); webConnection.setResponse(URL_SECOND, html2); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test auto-refresh from a response header. * @throws Exception if the test fails */ @Test public void testRefresh_HttpResponseHeader() throws Exception { final String firstContent = "first\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent, 200, "OK", "text/html", Collections .singletonList(new NameValuePair("Refresh", "3;URL=" + URL_SECOND + ""))); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); assertEquals("second", page.getTitleText()); } /** * Test that the parent of the DOM Document (HtmlPage) is null. * @throws Exception if the test fails */ @Test public void testDocumentParentIsNull() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); assertNotNull(page); assertNull(page.getParentNode()); } /** * @throws Exception if the test fails */ @Test public void testDocumentElement() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlElement root = page.getDocumentElement(); assertNotNull(root); assertEquals("html", root.getTagName()); assertSame(page, root.getParentNode()); } /** * @throws Exception if the test fails */ @Test public void testDocumentNodeType() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlElement root = page.getDocumentElement(); assertEquals(org.w3c.dom.Node.DOCUMENT_NODE, page.getNodeType()); assertEquals(org.w3c.dom.Node.ELEMENT_NODE, root.getNodeType()); assertEquals("#document", page.getNodeName()); } /** * @throws Exception if the test fails */ @Test public void testDeregisterFrameWithoutSrc() throws Exception { final String htmlContent = "\n" + "foo\n" + "\n" + "" + ""; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(html); webConnection.setResponse(new URL(URL_FIRST, "script.js"), "", "text/javascript"); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); String xml = page.asXml(); final String prefix = ""; assertTrue(xml.startsWith(prefix)); xml = xml.substring(prefix.length()); assertEquals(html, xml .replaceAll("[\\n\\r]", "") .replaceAll("\\s\\s+", "") .replaceAll("\"", "'")); } /** * @exception Exception If the test fails */ @Test public void testAsXml2() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "

          helloworld &amp; helloall

          \n" + ""; final HtmlPage page = loadPage(htmlContent); assertNotNull("xml document could not be parsed", page.asXml()); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); builder.parse(TextUtil.toInputStream(page.asXml())); } /** * @throws Exception if the test fails */ @Test public void testAsXml_unicode() throws Exception { final String unicodeString = "\u064A\u0627 \u0644\u064A\u064A\u0644"; final String html = "\n" + "\n" + "" + unicodeString + ""; final WebClient client = new WebClient(BrowserVersion.getDefault()); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(TextUtil.stringToByteArray(html, "UTF-8"), 200, "OK", "text/html"); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_GARGOYLE); final String xml = page.asXml(); assertTrue(xml.contains("
          foo
          "; final HtmlPage page = loadPage(html); assertEquals(1, page.getElementsByName("a").size()); assertEquals(2, page.getElementsByName("b").size()); assertEquals(0, page.getElementsByName("c").size()); final HtmlElement a = page.getElementsByName("a").get(0); a.remove(); assertEquals(0, page.getElementsByName("a").size()); final HtmlElement b1 = page.getElementsByName("b").get(0); b1.appendChild(a); assertEquals(1, page.getElementsByName("a").size()); } /** * @exception Exception if the test fails */ @Test public void testGetElementByName() throws Exception { final String html = "\n" + "
          foo
          \n" + "
          bar
          \n" + "
          baz
          "; final HtmlPage page = loadPage(html); assertEquals(page.getElementById("a"), page.getElementByName("a")); assertEquals(page.getElementById("b1"), page.getElementByName("b")); page.getElementByName("b").remove(); assertEquals(page.getElementById("b2"), page.getElementByName("b")); boolean thrown = false; try { page.getElementByName("c"); } catch (final ElementNotFoundException e) { thrown = true; } assertTrue(thrown); } /** * @exception Exception if the test fails */ @Test public void testGetHtmlElementsByIdAndOrName() throws Exception { final String html = "
          foo
          bar
          " + "
          bar
          "; final HtmlPage page = loadPage(html); assertEquals(1, page.getElementsByIdAndOrName("a").size()); assertEquals(2, page.getElementsByIdAndOrName("b").size()); assertEquals(1, page.getElementsByIdAndOrName("c").size()); assertEquals(1, page.getElementsByIdAndOrName("d").size()); final HtmlElement a = page.getElementsByIdAndOrName("a").get(0); a.remove(); assertEquals(0, page.getElementsByIdAndOrName("a").size()); final HtmlElement b1 = page.getElementsByIdAndOrName("b").get(0); b1.appendChild(a); assertEquals(1, page.getElementsByIdAndOrName("a").size()); } /** * Regression test for bug 1233519. * @exception Exception If the test fails */ @Test public void testGetHtmlElementByIdAfterRemove() throws Exception { final String htmlContent = "foo\n" + "\n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlElement div1 = page.getHtmlElementById("div1"); page.getHtmlElementById("div2"); // would throw if not found div1.remove(); try { page.getHtmlElementById("div1"); // throws if not found fail("div1 should have been removed"); } catch (final ElementNotFoundException e) { // nothing } try { page.getHtmlElementById("div2"); // throws if not found fail("div2 should have been removed"); } catch (final ElementNotFoundException e) { // nothing } } /** * Test getHtmlElementById() when 2 elements have the same id and the first one * is removed. * @exception Exception If the test fails */ @Test public void testGetHtmlElementById_idTwice() throws Exception { final String htmlContent = "foo\n" + "\n" + "
          foo
          \n" + "bla\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlElement elt1 = page.getHtmlElementById("id1"); assertEquals("div", elt1.getNodeName()); elt1.remove(); assertEquals("span", page.getHtmlElementById("id1").getNodeName()); } /** * Test the "set-cookie" meta tag. * @throws Exception if the test fails */ @Test public void testSetCookieMetaTag() throws Exception { final String content = "first\n" + "\n" + "\n" + "\n" + ""; final String[] expectedAlerts = {"webm=none"}; createTestPageForRealBrowserIfNeeded(content, expectedAlerts); final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); final Set cookies = page.getWebClient().getCookieManager().getCookies(); assertEquals(1, cookies.size()); final Cookie cookie = cookies.iterator().next(); assertEquals(page.getWebResponse().getRequestSettings().getUrl().getHost(), cookie.getDomain()); assertEquals("webm", cookie.getName()); assertEquals("none", cookie.getValue()); assertEquals("/", cookie.getPath()); } /** * Regression test for bug 1658273. * @throws Exception if the test fails */ @Test public void testOnLoadHandler_idChange() throws Exception { final String content = "foo\n" + "
          '" + "\n" + ""; final String[] expectedAlerts = {"cl2", "cl1"}; createTestPageForRealBrowserIfNeeded(content, expectedAlerts); final List collectedAlerts = new ArrayList(); loadPage(content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Test for bug 1714767. * @throws Exception if the test fails */ @Test public void testNoSlashURL() throws Exception { testNoSlashURL("http:/second"); testNoSlashURL("http:second"); } private void testNoSlashURL(final String url) throws Exception { final String firstContent = "\n" + "\n" + ""; final String secondContent = ""; final WebClient client = new WebClient(BrowserVersion.FIREFOX_2); final URL secondURL = new URL("http://second/"); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(secondURL, secondContent); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlInlineFrame iframe = firstPage.getHtmlElementById("myIFrame"); assertEquals(secondURL, iframe.getEnclosedPage().getWebResponse().getRequestSettings().getUrl()); } /** * @throws Exception failure */ @Test public void testMetaTagWithEmptyURL() throws Exception { final WebClient client = new WebClient(); client.setRefreshHandler(new ImmediateRefreshHandler()); // connection will return a page with for the first call // and the same page without it for the other calls final MockWebConnection webConnection = new MockWebConnection() { private int nbCalls_ = 0; @Override public WebResponse getResponse(final WebRequestSettings settings) throws IOException { String content = "\n"; if (nbCalls_ == 0) { content += "\n"; } content += ""; nbCalls_++; final StringWebResponse response = new StringWebResponse(content, settings.getUrl()); response.getRequestSettings().setHttpMethod(settings.getHttpMethod()); return response; } }; client.setWebConnection(webConnection); final WebRequestSettings settings = new WebRequestSettings(URL_GARGOYLE); settings.setHttpMethod(HttpMethod.POST); client.getPage(settings); } /** * @throws Exception if the test fails */ @Test public void testSerialization() throws Exception { // The document.all and form.elements calls are important because they trigger the creation // of HTMLCollections, which have caused serialization problems in the past (see bug 1951047). final String content = "\n" + "
          Hello there!
          \n" + "\n" + "
          \n" + "\n" + ""; final HtmlPage page1 = loadPage(content); final ByteArrayOutputStream byteOS = new ByteArrayOutputStream(); final ObjectOutputStream objectOS = new ObjectOutputStream(byteOS); objectOS.writeObject(page1); final ByteArrayInputStream byteIS = new ByteArrayInputStream(byteOS.toByteArray()); final ObjectInputStream objectIS = new ObjectInputStream(byteIS); final HtmlPage page2 = (HtmlPage) objectIS.readObject(); final Iterator iterator1 = page1.getAllHtmlChildElements().iterator(); final Iterator iterator2 = page2.getAllHtmlChildElements().iterator(); while (iterator1.hasNext()) { assertTrue(iterator2.hasNext()); final HtmlElement element1 = iterator1.next(); final HtmlElement element2 = iterator2.next(); assertEquals(element1.getNodeName(), element2.getNodeName()); } assertFalse(iterator2.hasNext()); assertEquals("Hello there!", page2.getHtmlElementById("myId").getFirstChild().getNodeValue()); } /** * Verifies that a cloned HtmlPage has its own "idMap_". * @throws Exception if the test fails */ @Test public void testClonedPageHasOwnIdMap() throws Exception { final String content = "foo" + "" + "
          " + ""; final HtmlPage page = loadPage(content); final HtmlElement id1 = (HtmlElement) page.getDocumentElement().getLastChild().getLastChild(); assertEquals("id1", id1.getId()); assertSame(id1, page.getHtmlElementById("id1")); final HtmlPage clone = page.cloneNode(true); assertSame(id1, page.getHtmlElementById("id1")); final HtmlElement id1clone = (HtmlElement) clone.getDocumentElement().getLastChild().getLastChild(); assertNotSame(id1, id1clone); assertEquals("id1", id1clone.getId()); assertSame(id1clone, clone.getHtmlElementById("id1")); assertNotSame(id1clone, page.getHtmlElementById("id1")); assertNotSame(id1, clone.getHtmlElementById("id1")); page.getHtmlElementById("id2").remove(); try { page.getHtmlElementById("id2"); fail("should have thrown ElementNotFoundException"); } catch (final ElementNotFoundException enfe) { // expected } assertNotNull(clone.getHtmlElementById("id2")); } /** * Verifies that a cloned HtmlPage has its own "documentElement". * @throws Exception if the test fails */ @Test public void testClonedPageHasOwnDocumentElement() throws Exception { final String content = "foo\n" + "\n" + "
          \n" + ""; final HtmlPage page = loadPage(content); final HtmlPage clone = page.cloneNode(true); assertTrue(page != clone); final HtmlElement doc = page.getDocumentElement(); final HtmlElement docclone = clone.getDocumentElement(); assertTrue(doc != docclone); } /** * @throws Exception if the test fails */ @Test public void testHtmlAttributeChangeListener_AddAttribute() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "

          \n" + "\n" + ""; final String[] expectedValues = {"attributeAdded: p,title,myTitle"}; final HtmlPage page = loadPage(htmlContent); final HtmlAttributeChangeListenerTestImpl listenerImpl = new HtmlAttributeChangeListenerTestImpl(); page.addHtmlAttributeChangeListener(listenerImpl); final HtmlButtonInput myButton = page.getHtmlElementById("myButton"); myButton.click(); assertEquals(expectedValues, listenerImpl.getCollectedValues()); } /** * @throws Exception if the test fails */ @Test public void testHtmlAttributeChangeListener_ReplaceAttribute() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "

          \n" + "\n" + ""; final String[] expectedValues = {"attributeReplaced: p,title,myTitle"}; final HtmlPage page = loadPage(htmlContent); final HtmlAttributeChangeListenerTestImpl listenerImpl = new HtmlAttributeChangeListenerTestImpl(); page.addHtmlAttributeChangeListener(listenerImpl); final HtmlButtonInput myButton = page.getHtmlElementById("myButton"); myButton.click(); assertEquals(expectedValues, listenerImpl.getCollectedValues()); } /** * @throws Exception if the test fails */ @Test public void testHtmlAttributeChangeListener_RemoveAttribute() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "

          \n" + "\n" + ""; final String[] expectedValues = {"attributeRemoved: p,title,myTitle"}; final HtmlPage page = loadPage(htmlContent); final HtmlAttributeChangeListenerTestImpl listenerImpl = new HtmlAttributeChangeListenerTestImpl(); page.addHtmlAttributeChangeListener(listenerImpl); final HtmlButtonInput myButton = page.getHtmlElementById("myButton"); myButton.click(); assertEquals(expectedValues, listenerImpl.getCollectedValues()); } /** * @throws Exception if the test fails */ @Test public void testHtmlAttributeChangeListener_RemoveListener() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "

          \n" + "\n" + ""; final String[] expectedValues = {"attributeReplaced: p,title,myTitle"}; final HtmlPage page = loadPage(htmlContent); final HtmlAttributeChangeListenerTestImpl listenerImpl = new HtmlAttributeChangeListenerTestImpl(); page.addHtmlAttributeChangeListener(listenerImpl); final HtmlButtonInput myButton = page.getHtmlElementById("myButton"); myButton.click(); page.removeHtmlAttributeChangeListener(listenerImpl); myButton.click(); assertEquals(expectedValues, listenerImpl.getCollectedValues()); } /** * @throws Exception if the test fails */ @Test public void testHtmlAttributeChangeListener_ListenerRegistersNewListener() throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "

          \n" + ""; final HtmlPage page = loadPage(htmlContent); final List collector = new ArrayList(); final HtmlAttributeChangeListener listener2 = new HtmlAttributeChangeListenerTestImpl() { private static final long serialVersionUID = 3234623604670201391L; @Override public void attributeReplaced(final HtmlAttributeChangeEvent event) { collector.add("in listener 2"); } }; final HtmlAttributeChangeListener listener1 = new HtmlAttributeChangeListenerTestImpl() { private static final long serialVersionUID = 1955007276078013337L; @Override public void attributeReplaced(final HtmlAttributeChangeEvent event) { collector.add("in listener 1"); page.addHtmlAttributeChangeListener(listener2); } }; page.addHtmlAttributeChangeListener(listener1); final HtmlElement p = page.getHtmlElementById("p1"); p.setAttribute("title", "new title"); final String[] expectedValues = {"in listener 1"}; assertEquals(expectedValues, collector); collector.clear(); p.setAttribute("title", "new new title"); final String[] expectedValues2 = {"in listener 1", "in listener 2"}; assertEquals(expectedValues2, collector); } /** * @throws Exception if the test fails */ @Test public void testCaseInsensitiveRegexReplacement() throws Exception { final String html = ""; final String[] expectedAlerts = {"0"}; final List actualAlerts = new ArrayList(); loadPage(html, actualAlerts); assertEquals(expectedAlerts, actualAlerts); } /** * @throws Exception if the test fails */ @Test public void testRegexReplacementWithFunction() throws Exception { final String html = ""; final String[] expectedAlerts = {"fontSize"}; final List collectedAlerts = new ArrayList(); loadPage(html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testTitle_EmptyXmlTagExpanded() throws Exception { final String content = "</head>\n" + "<body>Hello World!</body></html>"; final HtmlPage page = loadPage(content); assertTrue(page.asXml().indexOf("") != -1); } /** * Tests getElementById() of child element after appendChild(), removeChild(), then appendChild() * of the parent element. * * @throws Exception if the test fails */ @Test public void testGetElementById_AfterAppendRemoveAppendChild() throws Exception { final String content = "foo\n" + ""; final List collectedAlerts = new ArrayList(); loadPage(content, collectedAlerts); assertFalse(collectedAlerts.get(0).equals("null")); } /** * @throws Exception if the test fails */ @Test public void testGetElementById_AfterAppendingToNewlyCreatedElement() throws Exception { final String content = "foo\n" + ""; final List collectedAlerts = new ArrayList(); loadPage(content, collectedAlerts); assertTrue(collectedAlerts.get(0).equals("null")); } /** * @throws Exception if the test fails */ @Test public void testOnunLoadHandler() throws Exception { final String htmlContent = "foo\n" + "\n" + ""; final String[] expectedAlerts = {"foo", "bar"}; final List collectedAlerts = new ArrayList(); final WebClient client = new WebClient(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, htmlContent); client.setWebConnection(conn); client.getPage(URL_FIRST); client.getPage(URL_FIRST); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testOnbeforeunloadHandler() throws Exception { testOnbeforeunloadHandler(BrowserVersion.INTERNET_EXPLORER_7, false, "first"); testOnbeforeunloadHandler(BrowserVersion.INTERNET_EXPLORER_7, true, "second"); testOnbeforeunloadHandler(BrowserVersion.FIREFOX_2, false, "first"); testOnbeforeunloadHandler(BrowserVersion.FIREFOX_2, true, "second"); } /** * @param browserVersion the browser version to use * @param handlerOk whether OnbeforeunloadHandler.handleEvent will return true of false * @param expectedPageTitle the expected title of the page after clicking */ private void testOnbeforeunloadHandler(final BrowserVersion browserVersion, final boolean handlerOk, final String expectedPageTitle) throws Exception { final WebClient webClient = new WebClient(browserVersion); final MockWebConnection webConnection = new MockWebConnection(); final List collectedConfirms = new ArrayList(); webClient.setOnbeforeunloadHandler(new OnbeforeunloadHandler() { public boolean handleEvent(final Page page, final String message) { collectedConfirms.add(message); return handlerOk; } }); final String expectedMessage = "Any string value here forces a dialog box to appear before closing the window."; final String firstContent = "first\n" + "\n" + "\n" + " Second page\n" + ""; final String secondContent = "second\n" + "\n" + ""; webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); final HtmlAnchor anchor = page.getAnchors().get(0); final HtmlPage secondPage = anchor.click(); assertEquals(new String[] {expectedMessage}, collectedConfirms); assertEquals(expectedPageTitle, secondPage.getTitleText()); } /** * @throws Exception if an error occurs */ @Test public void testSrcJavaScript() throws Exception { final String htmlContent = "foo\n" + "\n" + ""; loadPage(htmlContent); } /** * Regression test for asText() which would blow up. * * @exception Exception If the test fails */ @Test public void testAsText() throws Exception { final String htmlContent = "test\n" + "\n" + "\n" + "
          a
          "; final HtmlPage page = loadPage(htmlContent); page.asText(); } /** * @throws Exception if the test fails */ @Test public void getElementsByTagName() throws Exception { final String firstContent = "First\n" + "\n" + "
          \n" + "
          a
          b
          c
          \n" + ""; final HtmlPage page = loadPage(firstContent); final NodeList inputs = page.getElementsByTagName("input"); assertEquals(1, inputs.getLength()); assertEquals("button", inputs.item(0).getAttributes().getNamedItem("type").getNodeValue()); final NodeList divs = page.getElementsByTagName("div"); assertEquals(3, divs.getLength()); final HtmlDivision newDiv = new HtmlDivision(null, HtmlDivision.TAG_NAME, page, null); page.getBody().appendChild(newDiv); assertEquals(4, divs.getLength()); } /** * HtmlPage.getReadyState() should give the same information than the document element. * @see 1592733 * @exception Exception If the test fails */ @Test public void testReadyState() throws Exception { final String htmlContent = "test\n" + "\n" + "\n" + "
          a
          "; final HtmlPage page = loadPage(htmlContent); assertEquals(DomNode.READY_STATE_COMPLETE, page.getReadyState()); } /** * @exception Exception If the test fails */ @Test public void cloneNode() throws Exception { final String html = "\n" + "foo\n" + "\n" + "

          hello world

          \n" + ""; final HtmlPage page = loadPage(html); page.getByXPath("//p"); final HtmlPage clonedPage = page.cloneNode(true); clonedPage.getByXPath("//p"); } /** * @exception Exception If the test fails */ @Test public void refresh() throws Exception { final Map> map = new HashMap>(); map.put("/one.html", RefreshServlet.class); map.put("/two.html", RefreshServlet.class); startWebServer(".", null, map); final WebClient client = new WebClient(); final HtmlPage page = client.getPage("http://localhost:" + PORT + "/one.html"); final HtmlSubmitInput submit = page.getHtmlElementById("myButton"); final HtmlPage secondPage = submit.click(); assertEquals("0\nPOST\nsome_name some_value\n", secondPage.getWebResponse().getContentAsString()); final HtmlPage secondPage2 = (HtmlPage) secondPage.refresh(); assertEquals("1\nPOST\nsome_name some_value\n", secondPage2.getWebResponse().getContentAsString()); } /** * Refresh servlet. */ public static class RefreshServlet extends HttpServlet { private int counter_; private static final long serialVersionUID = 4970162835902592484L; /** * {@inheritDoc} */ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { final Writer writer = resp.getWriter(); resp.setContentType("text/html"); final String response = "\n" + "\n" + "
          " + counter_++ + "
          \n" + "
          \n" + " \n" + " \n" + "
          \n" + "\n" + ""; writer.write(response); writer.close(); } /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { resp.setContentType("text/html"); final StringBuilder builder = new StringBuilder(); builder.append(counter_++).append("\n"); builder.append(req.getMethod()).append("\n"); for (final Enumeration en = req.getParameterNames(); en.hasMoreElements();) { final String name = (String) en.nextElement(); final String value = req.getParameter(name); builder.append(name).append(' ').append(value).append('\n'); } resp.getWriter().write(builder.toString()); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlBaseFontTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlBaseFontTest.jav0000664000175000017500000000345211650253660034503 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlBaseFont}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ public class HtmlBaseFontTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final String[] expectedAlerts = {"[object HTMLBaseFontElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlBaseFont.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageInputTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageInputTest.j0000664000175000017500000001605411650253660034517 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.commons.httpclient.NameValuePair; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlImageInput}. * * @version $Revision: 4782 $ * @author Mike Bowler * @author Marc Guillemot * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlImageInputTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testClick_NoPosition() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPageWithAlerts(htmlContent); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlImageInput imageInput = form.getInputByName("button"); final HtmlPage secondPage = (HtmlPage) imageInput.click(); assertNotNull(secondPage); final List expectedPairs = new ArrayList(); expectedPairs.add(new NameValuePair("button.x", "0")); expectedPairs.add(new NameValuePair("button.y", "0")); if (getBrowserVersion().isFirefox()) { expectedPairs.add(new NameValuePair("button", "foo")); } assertEquals( expectedPairs, webConnection.getLastParameters()); } /** * @throws Exception if the test fails */ @Test public void testClick_WithPosition() throws Exception { final String html = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPageWithAlerts(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlImageInput imageInput = form.getInputByName("button"); final HtmlPage secondPage = (HtmlPage) imageInput.click(100, 200); assertNotNull(secondPage); final List expectedPairs = new ArrayList(); expectedPairs.add(new NameValuePair("button.x", "100")); expectedPairs.add(new NameValuePair("button.y", "200")); if (getBrowserVersion().isFirefox()) { expectedPairs.add(new NameValuePair("button", "foo")); } assertEquals( expectedPairs, webConnection.getLastParameters()); } /** * If an image button without name is clicked, it should send only "x" and "y" parameters. * Regression test for bug 1118877. * @throws Exception if the test fails */ @Test public void testNoNameClick_WithPosition() throws Exception { final String html = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPageWithAlerts(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlImageInput imageInput = form.getInputByValue("foo"); final HtmlPage secondPage = (HtmlPage) imageInput.click(100, 200); assertNotNull(secondPage); final List expectedPairs = Arrays.asList(new NameValuePair[]{ new NameValuePair("x", "100"), new NameValuePair("y", "200") }); assertEquals( expectedPairs, webConnection.getLastParameters()); } /** * @throws Exception if the test fails */ @Test public void testOutsideForm() throws Exception { final String html = "\n" + "\n" + "\n" + ""; final String[] expectedAlerts = {"1"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlImageInput input = page.getHtmlElementById("myInput"); input.click(); assertEquals(expectedAlerts, collectedAlerts); } /** * Test for bug: http://sourceforge.net/tracker/index.php?func=detail&aid=2013891&group_id=47038&atid=448266. * @throws Exception if an error occurs */ @Test public void testClickFiresOnMouseDown() throws Exception { final String s = ""; final String[] expectedAlerts = {"1"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), s, collectedAlerts); page.getHtmlElementById("i").click(); assertEquals(expectedAlerts, collectedAlerts); } /** * Test for bug: http://sourceforge.net/tracker/index.php?func=detail&aid=2013891&group_id=47038&atid=448266. * @throws Exception if an error occurs */ @Test public void testClickFiresOnMouseUp() throws Exception { final String s = ""; final String[] expectedAlerts = {"1"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(getBrowserVersion(), s, collectedAlerts); page.getHtmlElementById("i").click(); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableCellTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableCellTest.ja0000664000175000017500000000417211650253660034443 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlTableCell}. * * @version $Revision: 4551 $ * @author Mike Bowler * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlTableCellTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(FF = { "[object HTMLTableCellElement]", "[object HTMLTableCellElement]" }, IE = { "[object]", "[object]" }) public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + "
          \n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlTableCell.class.isInstance(page.getHtmlElementById("myId1"))); assertTrue(HtmlTableCell.class.isInstance(page.getHtmlElementById("myId2"))); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageTest.java0000664000175000017500000001264511650253660034171 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlImage}. * * @version $Revision: 4463 $ * @author Marc Guillemot * @author Ahmed Ashour */ public class HtmlImageTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testIsMapClick() throws Exception { testIsMapClick("img1", false, "?0,0", "?25,30"); testIsMapClick("img2", false, "", ""); testIsMapClick("img3", true, "", ""); testIsMapClick("img3", true, "", ""); } private void testIsMapClick(final String imgId, final boolean samePage, final String urlSuffixClick, final String urlSuffixClickXY) throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlImage img = page.getHtmlElementById(imgId); final Page page2 = img.click(); Assert.assertEquals("same page after click", samePage, (page == page2)); if (!samePage) { assertEquals("http://server/foo" + urlSuffixClick, page2.getWebResponse().getRequestSettings().getUrl()); } final Page page3 = img.click(25, 30); Assert.assertEquals("same page after click(25, 30)", samePage, (page == page3)); if (!samePage) { assertEquals("http://server/foo" + urlSuffixClickXY, page3.getWebResponse().getRequestSettings().getUrl()); } } /** * @throws Exception if the test fails */ @Test public void testUseMapClick() throws Exception { testUseMapClick(0, 0, "/"); testUseMapClick(10, 10, "a.html"); testUseMapClick(20, 10, "a.html"); testUseMapClick(29, 10, "b.html"); testUseMapClick(50, 50, "/"); } /** * @throws Exception if the test fails */ private void testUseMapClick(final int x, final int y, final String urlSuffix) throws Exception { final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlImage img = page.getHtmlElementById("myImg"); final Page page2 = img.click(x, y); final URL url = page2.getWebResponse().getRequestSettings().getUrl(); assertTrue(url.toExternalForm(), url.toExternalForm().endsWith(urlSuffix)); } /** * Tests circle radius of percentage value. * @throws Exception if the test fails */ @Test public void testUseMapClick_CircleRadiusPercentage() throws Exception { if (notYetImplemented()) { return; } final String htmlContent = "foo\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlImage img = page.getHtmlElementById("myImg"); img.click(0, 0); } /** * @throws Exception if the test fails */ @Test public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final String[] expectedAlerts = {"[object HTMLImageElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlImage.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParserListenerTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParserListenerTe0000664000175000017500000001334311650253660034456 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.junit.Test; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Test class for {@link HTMLParserListener}.
          * We probably don't need to check the details of the messages generated by the * parser but just that we catch and "transmit" them. * * @version $Revision: 4719 $ * @author Marc Guillemot */ public class HTMLParserListenerTest extends WebTestCase { static class MessageInfo { private boolean error_; // versus warning private String message_; private URL url_; private int line_; private int column_; /** * Utility class to hold data. * @param error the error * @param message the message * @param url the URL * @param line the line number * @param column the column number * @param key Ignored value */ MessageInfo(final boolean error, final String message, final URL url, final int line, final int column, final String key) { error_ = error; message_ = message; url_ = url; line_ = line; column_ = column; // ignore key } /** @see Object#toString() */ @Override public String toString() { return message_ + " (" + url_ + " " + line_ + ":" + column_ + ")"; } /** * Compares according to error, message, URL and line. * @see Object#equals(Object) */ @Override public boolean equals(final Object obj) { if (!(obj instanceof MessageInfo)) { return false; } final MessageInfo other = (MessageInfo) obj; final EqualsBuilder builder = new EqualsBuilder(); builder.append(error_, other.error_); builder.append(message_, other.message_); builder.append(url_.toExternalForm(), other.url_.toExternalForm()); builder.append(line_, other.line_); return builder.isEquals(); } /** * @see Object#hashCode() */ @Override public int hashCode() { final HashCodeBuilder builder = new HashCodeBuilder(); builder.append(error_); builder.append(message_); builder.append(url_); builder.append(line_); return builder.hashCode(); } } /** * This is the right test as we had before HtmlUnit-2.6 but due * to an (accepted - at least in a first time -) regression in * NekoHTML, it doesn't work anymore. * testSimple_withWrongLineCol ensures that no other regression occurs here. * @exception Exception If the test fails */ @Test public void testSimple() throws Exception { if (notYetImplemented()) { return; } testSimple(4, -1); } /** * Currently, NekoHtml doesn't deliver right information about the line * for the warning. Let this test run with wrong expectation * on line and col to avoid that other regression occur. * @exception Exception If the test fails */ @Test public void testSimple_withWrongLineCol() throws Exception { testSimple(5, 7); } private void testSimple(final int line, final int col) throws Exception { final String htmlContent = "\n" + "\nfoo\n</head>\n" + "<body>\nfoo\n</body>\n</html>"; final WebClient webClient = new WebClient(); assertNull(webClient.getHTMLParserListener()); final List<MessageInfo> messages = new ArrayList<MessageInfo>(); final HTMLParserListener collecter = new HTMLParserListener() { public void error(final String message, final URL url, final int line, final int column, final String key) { messages.add(new MessageInfo(true, message, url, line, column, key)); } public void warning(final String message, final URL url, final int line, final int column, final String key) { messages.add(new MessageInfo(false, message, url, line, column, key)); } }; webClient.setHTMLParserListener(collecter); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(htmlContent); webClient.setWebConnection(webConnection); final HtmlPage page = webClient.getPage(URL_FIRST); assertEquals("foo", page.getTitleText()); // ignore column and key final MessageInfo expectedError = new MessageInfo(false, "End element <head> automatically closes element <title>.", URL_FIRST, line, col, null); assertEquals(Collections.singletonList(expectedError), messages); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelect2Test.java0000664�0001750�0001750�00000005312�11650253660�034441� 0����������������������������������������������������������������������������������������������������ustar �jamespage�����������������������jamespage��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlSelect}, but with BrowserRunner. * * @version $Revision: 4549 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlSelect2Test extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "two", "" }, FF = { "two", "two" }) public void value() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " var select = document.getElementById('mySelect');\n" + " alert(select.value);\n" + " select.value = 'three';\n" + " alert(select.value);\n" + " }\n" + "</script>\n" + "<body onload='test()'>\n" + " <select id='mySelect'>\n" + " <option value='one'>One</option>\n" + " <option selected value='two'>Two</option>\n" + " </select>\n" + "</body></html>"; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = { "two", "" }, FF = { "two", "One" }) public void value2() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " var select = document.getElementById('mySelect');\n" + " alert(select.value);\n" + " select.value = 'One';\n" + " alert(select.value);\n" + " }\n" + "</script>\n" + "<body onload='test()'>\n" + " <select id='mySelect'>\n" + " <option>One</option>\n" + " <option selected value='two'>Two</option>\n" + " </select>\n" + "</body></html>"; loadPageWithAlerts(html); } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@LongLink���������������������������������������������������������������������������������������0000000�0000000�0000000�00000000146�00000000000�011566� L����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlDivisionTest.java���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlDivisionTest.jav0000664�0001750�0001750�00000007061�11650253660�034566� 0����������������������������������������������������������������������������������������������������ustar �jamespage�����������������������jamespage��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlDivision}. * * @version $Revision: 4002 $ * @author Ahmed Ashour * @author Marc Guillemot */ public class HtmlDivisionTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void simpleScriptable() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " alert(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <div id='myId'/>\n" + "</body></html>"; final String[] expectedAlerts = {"[object HTMLDivElement]"}; final List<String> collectedAlerts = new ArrayList<String>(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlDivision.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void asText() throws Exception { String expected = "hello" + LINE_SEPARATOR + "world"; testAsText(expected, "<div>hello</div>world"); testAsText(expected, "<div>hello<br/></div>world"); expected = "hello" + LINE_SEPARATOR + LINE_SEPARATOR + "world"; testAsText(expected, "<div>hello<br/><br/></div>world"); } /** * @throws Exception if the test fails */ @Test public void asText_contiguousBlocks() throws Exception { final String expected = "hello" + LINE_SEPARATOR + "world"; testAsText(expected, "<div><table><tr><td>hello</td></tr><tr><td>world<br/></td></tr></table></div>"); testAsText(expected, "<div>hello</div><div>world</div>"); testAsText(expected, "<div>hello</div><div><div>world</div></div>"); testAsText(expected, "<div><table><tr><td>hello</td></tr><tr><td>world<br/></td></tr></table></div>"); } private void testAsText(final String expected, final String htmlSnippet) throws Exception { final String html = "<html><head></head><body>\n" + htmlSnippet + "</body></html>"; final HtmlPage page = loadPage(html); assertEquals(expected, page.asText()); } /** * @throws Exception if the test fails */ @Test public void asTextDiv() throws Exception { final String html = "<html><head></head><body>\n" + "<div id='foo'>\n \n hello </div>" + "</body></html>"; final HtmlPage page = loadPage(html); assertEquals("hello", page.asText()); final HtmlDivision div = page.getHtmlElementById("foo"); assertEquals("hello", div.asText()); } } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@LongLink���������������������������������������������������������������������������������������0000000�0000000�0000000�00000000151�00000000000�011562� L����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableColumnTest.java������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableColumnTest.0000664�0001750�0001750�00000003410�11650253660�034500� 0����������������������������������������������������������������������������������������������������ustar �jamespage�����������������������jamespage��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlTableColumn}. * * @version $Revision: 4551 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlTableColumnTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(FF = "[object HTMLTableColElement]", IE = "[object]") public void simpleScriptable() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " alert(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <table>\n" + " <col id='myId'/>\n" + " </table>\n" + "</body></html>"; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlTableColumn.class.isInstance(page.getHtmlElementById("myId"))); } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@LongLink���������������������������������������������������������������������������������������0000000�0000000�0000000�00000000156�00000000000�011567� L����������������������������������������������������������������������������������������������������ustar �root����������������������������root�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInputTest.java�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput0000664�0001750�0001750�00000023054�11650253660�034635� 0����������������������������������������������������������������������������������������������������ustar �jamespage�����������������������jamespage��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlRadioButtonInput}. * * @version $Revision: 4002 $ * @author Mike Bresnahan * @author Marc Guillemot * @author Bruce Faulkner * @author Ahmed Ashour */ public class HtmlRadioButtonInputTest extends WebTestCase { /** * Verifies that a asText() returns "checked" or "unchecked" according to the state of the radio. * @throws Exception if the test fails */ @Test public void test_asTextWhenNotChecked() throws Exception { final String htmlContent = "<html><head><title>foo\n" + "
          \n" + " Check me\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlRadioButtonInput radio = page.getHtmlElementById("radio"); assertEquals("unchecked", radio.asText()); radio.setChecked(true); assertEquals("checked", radio.asText()); } /** * @throws Exception if the test fails */ @Test public void testOnchangeHandlerInvoked() throws Exception { final String htmlContent = "foo\n" + "
          \n" + " Check me\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlRadioButtonInput radio = page.getHtmlElementById("radio"); assertFalse(radio.isChecked()); radio.setChecked(true); assertTrue(radio.isChecked()); assertEquals("newtrue", radio.getValueAttribute()); } /** * @throws Exception if the test fails */ @Test public void testOnchangeHandlerNotInvokedIfNotChanged() throws Exception { final String htmlContent = "foo\n" + "
          \n" + " Check me\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlRadioButtonInput radio = page.getHtmlElementById("radio"); assertFalse(radio.isChecked()); radio.setChecked(false); assertFalse(radio.isChecked()); assertEquals("on", radio.getValueAttribute()); } /** * @throws Exception if the test fails */ @Test public void testUpdateStateFirstForOnclickHandler() throws Exception { final String htmlContent = "foo\n" + "\n" + "
          \n" + "Number of items:" + "\n" + "\n" + "\n" + "\n" + "
          "; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); final HtmlRadioButtonInput oneItem = page.getHtmlElementById("oneItem"); final HtmlRadioButtonInput twoItems = page.getHtmlElementById("twoItems"); assertTrue(oneItem.isChecked()); assertFalse(twoItems.isChecked()); twoItems.click(); assertTrue(twoItems.isChecked()); assertFalse(oneItem.isChecked()); oneItem.click(); assertTrue(oneItem.isChecked()); assertFalse(twoItems.isChecked()); final String[] expectedAlerts = { "oneItem.checked: false twoItems.checked: true", "oneItem.checked: true twoItems.checked: false"}; assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testSetChecked() throws Exception { final String firstContent = "First\n" + "
          \n" + "\n" + "
          \n" + ""; final String secondContent = "Second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage page = client.getPage(URL_FIRST); final HtmlRadioButtonInput radio = page.getHtmlElementById("myRadio"); final HtmlPage secondPage = (HtmlPage) radio.setChecked(true); assertEquals("Second", secondPage.getTitleText()); } /** * Test input.checked if the radio <input> do not have distinct 'value'. * @throws Exception if the test fails */ @Test public void testRadioInputChecked() throws Exception { final String content = "\n" + "\n" + "\n" + "
          \n" + " \n" + " \n" + "
          \n" + "\n" + ""; final String[] expectedAlerts = {"false,false", "true,false", "false,true"}; final List collectedAlerts = new ArrayList(); loadPage(content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testSetCheckedOutsideForm() throws Exception { final String content = "\n" + "\n" + "\n" + "\n" + "\n" + "
          \n" + " \n" + " \n" + "
          \n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(content, collectedAlerts); final HtmlRadioButtonInput radio1 = page.getHtmlElementById("radio1"); final HtmlRadioButtonInput radio2 = page.getHtmlElementById("radio2"); final HtmlRadioButtonInput radio3 = page.getHtmlElementById("radio3"); final HtmlRadioButtonInput radio4 = page.getHtmlElementById("radio4"); assertFalse(radio1.isChecked()); assertFalse(radio2.isChecked()); assertFalse(radio3.isChecked()); assertFalse(radio4.isChecked()); radio1.setChecked(true); assertTrue(radio1.isChecked()); assertFalse(radio2.isChecked()); assertFalse(radio3.isChecked()); assertFalse(radio4.isChecked()); radio2.setChecked(true); assertFalse(radio1.isChecked()); assertTrue(radio2.isChecked()); assertFalse(radio3.isChecked()); assertFalse(radio4.isChecked()); radio3.setChecked(true); assertFalse(radio1.isChecked()); assertTrue(radio2.isChecked()); assertTrue(radio3.isChecked()); assertFalse(radio4.isChecked()); radio4.setChecked(true); assertFalse(radio1.isChecked()); assertTrue(radio2.isChecked()); assertFalse(radio3.isChecked()); assertTrue(radio4.isChecked()); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOptionGroupTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOptionGroupTest.0000664000175000017500000001050011650253660034556 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlOptionGroup}. * * @version $Revision: 4002 $ * @author Ahmed Ashour * @author Daniel Gredler */ public class HtmlOptionGroupTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final String[] expectedAlerts = {"[object HTMLOptGroupElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlOptionGroup.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if an error occurs */ @Test public void testDisabled() throws Exception { testDisabled(BrowserVersion.FIREFOX_2, true, false); testDisabled(BrowserVersion.INTERNET_EXPLORER_6, false, false); testDisabled(BrowserVersion.INTERNET_EXPLORER_7, false, false); } private void testDisabled(final BrowserVersion version, final boolean d1, final boolean d2) throws Exception { final String html = "
          \n" + " \n" + " \n" + "
          "; final String[] expected = {"false", "false", "true", "false", "true", "false", "false", "false"}; final List actual = new ArrayList(); final HtmlPage page = loadPage(version, html, actual); assertEquals(expected, actual); assertEquals(d1, ((HtmlOptionGroup) page.getElementById("g1")).isDisabled()); assertEquals(d2, ((HtmlOptionGroup) page.getElementById("g2")).isDisabled()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCaptionTest.java0000664000175000017500000000354511650253660034543 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlCaption}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ public class HtmlCaptionTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + "
          \n" + "
          \n" + ""; final String[] expectedAlerts = {"[object HTMLTableCaptionElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlCaption.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlBreakTest.java0000664000175000017500000000423311650253660034165 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlBreak}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ public class HtmlBreakTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + "
          \n" + ""; final String[] expectedAlerts = {"[object HTMLBRElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlBreak.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void asText() throws Exception { final String html = "\n" + "" + "Hello
          world\n" + ""; final HtmlPage page = loadPage(html); assertEquals("Hello" + LINE_SEPARATOR + "world", page.getBody().asText()); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.ja0000664000175000017500000003476311650253660034524 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.IOException; import java.io.Writer; import java.net.URI; import java.net.URL; import java.net.URLDecoder; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadBase; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.KeyDataPair; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebServerTestCase; import com.gargoylesoftware.htmlunit.util.ServletContentWrapper; /** * Tests for {@link HtmlFileInput}. * * @version $Revision: 4002 $ * @author Marc Guillemot * @author Ahmed Ashour */ public class HtmlFileInputTest extends WebServerTestCase { /** * @throws Exception if the test fails */ @Test public void testFileInput() throws Exception { String path = getClass().getClassLoader().getResource("testfiles/" + "tiny-png.img").toExternalForm(); testFileInput(path); final File file = new File(new URI(path)); testFileInput(file.getCanonicalPath()); if (path.startsWith("file:")) { path = path.substring("file:".length()); } while (path.startsWith("/")) { path = path.substring(1); } if (System.getProperty("os.name").toLowerCase().contains("windows")) { testFileInput(URLDecoder.decode(path.replace('/', '\\'), "UTF-8")); } testFileInput("file:/" + path); testFileInput("file://" + path); testFileInput("file:///" + path); } /** * Tests setData method. * @throws Exception if the test fails */ @Test public void testSetData() throws Exception { final String firstContent = "\n" + "
          \n" + " \n" + "
          \n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlForm f = firstPage.getForms().get(0); final HtmlFileInput fileInput = f.getInputByName("image"); fileInput.setValueAttribute("dummy.txt"); fileInput.setContentType("text/csv"); fileInput.setData("My file data".getBytes()); f.submit((SubmittableElement) null); final KeyDataPair pair = (KeyDataPair) webConnection.getLastParameters().get(0); assertNotNull(pair.getData()); assertTrue(pair.getData().length != 0); } private void testFileInput(final String fileURL) throws Exception { final String firstContent = "\n" + "
          \n" + " \n" + "
          \n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlForm f = firstPage.getForms().get(0); final HtmlFileInput fileInput = f.getInputByName("image"); fileInput.setValueAttribute(fileURL); f.submit((SubmittableElement) null); final KeyDataPair pair = (KeyDataPair) webConnection.getLastParameters().get(0); assertNotNull(pair.getFile()); assertTrue(pair.getFile().length() != 0); } /** * Verifies that content is provided for a not filled file input. * @throws Exception if the test fails */ @Test public void testEmptyField() throws Exception { final String firstContent = "\n" + "
          \n" + " \n" + "
          \n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlForm f = firstPage.getForms().get(0); f.submit(null); final KeyDataPair pair = (KeyDataPair) webConnection.getLastParameters().get(0); assertEquals("image", pair.getName()); assertNull(pair.getFile()); } /** * @throws Exception if the test fails */ @Test public void testContentType() throws Exception { final String firstContent = "\n" + "
          \n" + " \n" + "
          \n" + "\n" + ""; final String secondContent = "second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlForm f = firstPage.getForms().get(0); final HtmlFileInput fileInput = f.getInputByName("image"); final URL fileURL = getClass().getClassLoader().getResource("testfiles/empty.png"); fileInput.setValueAttribute(fileURL.toExternalForm()); f.submit((SubmittableElement) null); final KeyDataPair pair = (KeyDataPair) webConnection.getLastParameters().get(0); assertNotNull(pair.getFile()); Assert.assertFalse("Content type: " + pair.getContentType(), "text/webtest".equals(pair.getContentType())); fileInput.setContentType("text/webtest"); f.submit((SubmittableElement) null); final KeyDataPair pair2 = (KeyDataPair) webConnection.getLastParameters().get(0); assertNotNull(pair2.getFile()); assertEquals("text/webtest", pair2.getContentType()); } /** * Test HttpClient for uploading a file with non-ASCII name, if it works it means HttpClient has fixed its bug. * * Test for http://issues.apache.org/jira/browse/HTTPCLIENT-293, * which is related to http://sourceforge.net/tracker/index.php?func=detail&aid=1818569&group_id=47038&atid=448266 * * @throws Exception if the test fails */ @Test public void testUploadFileWithNonASCIIName_HttpClient() throws Exception { if (notYetImplemented()) { return; } final String filename = "\u6A94\u6848\uD30C\uC77C\u30D5\u30A1\u30A4\u30EB\u0645\u0644\u0641.txt"; final String path = getClass().getClassLoader().getResource(filename).toExternalForm(); final File file = new File(new URI(path)); assertTrue(file.exists()); final Map> servlets = new HashMap>(); servlets.put("/upload2", Upload2Servlet.class); startWebServer("./", null, servlets); final PostMethod filePost = new PostMethod("http://localhost:" + PORT + "/upload2"); final FilePart part = new FilePart("myInput", file); part.setCharSet("UTF-8"); filePost.setRequestEntity(new MultipartRequestEntity(new Part[] {part}, filePost.getParams())); final HttpClient client = new HttpClient(); client.executeMethod(filePost); final String response = filePost.getResponseBodyAsString(); //this is the value with ASCII encoding assertFalse("3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 2E 74 78 74
          myInput".equals(response)); } /** * Test uploading a file with non-ASCII name. * * Test for http://sourceforge.net/tracker/index.php?func=detail&aid=1818569&group_id=47038&atid=448266 * * @throws Exception if the test fails */ @Test public void testUploadFileWithNonASCIIName() throws Exception { final Map> servlets = new HashMap>(); servlets.put("/upload1", Upload1Servlet.class); servlets.put("/upload2", Upload2Servlet.class); startWebServer("./", null, servlets); testUploadFileWithNonASCIIName(BrowserVersion.FIREFOX_2); testUploadFileWithNonASCIIName(BrowserVersion.INTERNET_EXPLORER_7); } private void testUploadFileWithNonASCIIName(final BrowserVersion browserVersion) throws Exception { final String filename = "\u6A94\u6848\uD30C\uC77C\u30D5\u30A1\u30A4\u30EB\u0645\u0644\u0641.txt"; final String path = getClass().getClassLoader().getResource(filename).toExternalForm(); final File file = new File(new URI(path)); assertTrue(file.exists()); final WebClient client = new WebClient(browserVersion); final HtmlPage firstPage = client.getPage("http://localhost:" + PORT + "/upload1"); final HtmlForm form = firstPage.getForms().get(0); final HtmlFileInput fileInput = form.getInputByName("myInput"); fileInput.setValueAttribute(path); final HtmlSubmitInput submitInput = form.getInputByValue("Upload"); final HtmlPage secondPage = submitInput.click(); final String response = secondPage.getWebResponse().getContentAsString(); //this is the value with UTF-8 encoding final String expectedResponse = "6A94 6848 D30C C77C 30D5 30A1 30A4 30EB 645 644 641 2E 74 78 74
          myInput"; assertTrue("Invalid Response: " + response, response.contains(expectedResponse)); if (browserVersion.isIE()) { assertTrue(expectedResponse.length() < response.length()); } else { assertEquals(expectedResponse.length(), response.length()); } } /** * Servlet for '/upload1'. */ public static class Upload1Servlet extends ServletContentWrapper { private static final long serialVersionUID = 6693252829875297263L; /** * Creates an instance. */ public Upload1Servlet() { super("\n" + "
          \n" + "Name:
          \n" + "Name 2 (should stay empty):
          \n" + "\n" + "
          \n"); } } /** * Servlet for '/upload2'. */ public static class Upload2Servlet extends HttpServlet { private static final long serialVersionUID = -1350878755076138012L; /** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); final Writer writer = response.getWriter(); if (ServletFileUpload.isMultipartContent(request)) { try { final ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); for (final FileItem item : (List) upload.parseRequest(request)) { if ("myInput".equals(item.getFieldName())) { final String path = item.getName(); for (final char ch : path.toCharArray()) { writer.write(Integer.toHexString(ch).toUpperCase() + " "); } writer.write("
          "); writer.write(item.getFieldName()); } } } catch (final FileUploadBase.SizeLimitExceededException e) { writer.write("SizeLimitExceeded"); } catch (final Exception e) { writer.write("error"); } } writer.close(); } } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlObjectTest.java0000664000175000017500000000625211650253660034352 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectTest; /** * Tests for {@link HtmlObject}. * * @version $Revision: 4540 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlObjectTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(IE = "[object]", FF = "[object HTMLObjectElement]") public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertTrue(HtmlObject.class.isInstance(page.getHtmlElementById("myId"))); } /** * @throws Exception if the test fails */ @Test @Alerts(IE = "false", FF = "undefined") public void classid() throws Exception { if (getBrowserVersion().isIE() && !ActiveXObjectTest.isJacobInstalled()) { return; } final String html = "\n" // Window Media Player CLASSID + "\n" + "\n" + "\n" + ""; final WebClient client = getWebClient(); client.setActiveXNative(true); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_GARGOYLE, html); client.setWebConnection(webConnection); client.getPage(URL_GARGOYLE); assertEquals(getExpectedAlerts(), collectedAlerts); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParserTest.java0000664000175000017500000007127211650253660034244 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.StringWebResponse; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebServerTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; /** * Test class for {@link HTMLParser}. * * @version $Revision: 4868 $ * @author Christian Sell * @author Marc Guillemot * @author Ahmed Ashour * @author Sudhan Moghe */ @RunWith(BrowserRunner.class) public class HTMLParserTest extends WebServerTestCase { /** * Tests the new HTMLParser on a simple HTML string. * @throws Exception failure */ @Test public void simpleHTMLString() throws Exception { final WebClient webClient = getWebClient(); final WebResponse webResponse = new StringWebResponse( "TITLE", URL_GARGOYLE); final HtmlPage page = HTMLParser.parseHtml(webResponse, webClient.getCurrentWindow()); final String stringVal = page.getFirstByXPath("//noscript").getFirstChild().getNodeValue(); assertEquals("TEST", stringVal); final HtmlElement node = (HtmlElement) page.getFirstByXPath("//*[./text() = 'TEST']"); assertEquals(node.getTagName(), HtmlNoScript.TAG_NAME); } /** * Tests that inserted TBODY and TFOOT don't conflict. * @throws Exception failure */ @Test @Alerts("TABLE") public void table_tfoot() throws Exception { final String html = "" + "\n" + "" + "
          hello
          foot
          \n" + "\n" + ""; loadPageWithAlerts(html); } /** * Test for the condition when there is a <form> inside of a <table> and before * a <tr>. * @throws Exception failure */ @Test @Alerts("myForm") public void badlyFormedHTML() throws Exception { final String html = "first\n" + " \n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * Test when an illegal tag is found in head as some websites do. * @throws Exception failure */ @Test @Alerts("first") public void unknownTagInHead() throws Exception { // Note: the tag in this test is quite important because // I could adapt the TagBalancer to make it work except with this \n" + " first\n" + " \n" + "\n" + "\n" + ""; loadPageWithAlerts(html); } /** * Works since NekoHtml 0.9.5. * @exception Exception If the test fails */ @Test public void badTagInHead() throws Exception { final String htmlContent = "\n" + "\nfoo\n</head>\n" + "<body>\nfoo\n</body>\n</html>"; final HtmlPage page = loadPageWithAlerts(htmlContent); assertEquals("foo", page.getTitleText()); } /** * @throws Exception failure */ @Test @Alerts({"false", "true" }) public void duplicatedAttribute() throws Exception { final String html = "<html><head>\n" + "</head>\n" + " <script>\n" + " function test() {\n" + " alert(document.getElementById('foo') == null);\n" + " alert(document.getElementById('bla') == null);\n" + " }\n" + " </script>\n" + "</head>\n" + "<body onload='test()'>\n" + " <span id='foo' id='bla'></span>" + "</body></html>"; loadPageWithAlerts(html); } /** * @throws Exception failure */ @Test @Alerts(IE = {"1", "3", "[object]", "[object]", "[object]", "[object]" }, FF = {"1", "3", "[object HTMLScriptElement]", "[object HTMLUnknownElement]", "[object HTMLUnknownElement]", "[object HTMLFormElement]" }) public void namespace() throws Exception { final String html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" + "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:app='http://www.appcelerator.org'>\n" + "<head>\n" + "<script>\n" + " function test() {\n" + " alert(document.getElementById('script1'));\n" + " alert(document.getElementById('script2'));\n" + " alert(document.getElementById('message1'));\n" + " alert(document.getElementById('form1'));\n" + " }\n" + "</script>\n" + "</head>\n" + "<body onload='test()'>\n" + "<script id='script1'>alert(1)</script>\n" + "<app:script id='script2'>alert(2)</app:script>\n" + "<script>alert(3)</script>\n" + "<app:message name='r:tasks.request' id='message1'>hello</app:message>\n" + "<form id='form1' xmlns='http://org.pentaho'/>\n" + "</body></html>"; loadPageWithAlerts(html); } /** * @throws Exception failure */ @Test @Alerts(IE = {"1", "createElementNS() is not defined", "[object]", "SCRIPT,SCRIPT,undefined,undefined,undefined", "[object]", "script,script,undefined,undefined,undefined" }, FF = {"1", "[object Element]", "app:script,app:script,http://www.appcelerator.org,app,script", "[object HTMLScriptElement]", "SCRIPT,SCRIPT,null,null,SCRIPT", "[object HTMLUnknownElement]", "APP:SCRIPT,APP:SCRIPT,null,null,APP:SCRIPT" }) public void namespace2() throws Exception { final String html = "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:app='http://www.appcelerator.org'>\n" + "<head>\n" + "<script>\n" + " function test() {\n" + " try {\n" + " div = document.createElementNS('http://www.appcelerator.org', 'app:script');\n" + " debug(div);\n" + " } catch (e) {alert('createElementNS() is not defined')}\n" + " debug(document.getElementById('script1'));\n" + " debug(document.getElementById('script2'));\n" + " }\n" + " function debug(e) {\n" + " alert(e);\n" + " alert(e.nodeName + ',' + e.tagName + ',' + e.namespaceURI + ',' + e.prefix + ',' + e.localName);\n" + " }\n" + "</script>\n" + "</head>\n" + "<body onload='test()'>\n" + "<script id='script1'>alert(1)</script>\n" + "<app:script id='script2'>alert(2)</app:script>\n" + "</body></html>"; loadPageWithAlerts(html); } /** * Test for a case where complete HTML page is present inside DIV tag. * IE ignores the HTML tag, BODY tag and complete HEAD along with content inside HEAD * FF ignores only HTML, HEAD and BODY tags. Contents of HEAD are added to head of the page * and content of BODY are added to the current node (DIV tag in test case). * * @throws Exception failure */ @Test @NotYetImplemented(Browser.IE) @Alerts(IE = {"HEAD", "Outer Html", "outerDiv" }, FF = {"HEAD", "Outer Html", "HEAD", "Inner Html", "outerDiv" }) public void completeHtmlInsideDiv() throws Exception { final String html = "<html><head>\n" + " <title>Outer Html\n" + " \n" + "\n" + "\n" + "
          \n" + " Outer DIV\n" + " \n" + " Inner Html\n" + " \n" + "
          Inner DIV
          \n" + " \n" + " \n" + "
          \n" + "\n" + "\n"; loadPageWithAlerts(html); } /** * Test for a case where complete HTML page is added using document.write() inside DIV tag. * IE ignores the HTML tag, BODY tag and complete HEAD along with content inside HEAD * FF ignores only HTML, HEAD and BODY tags. Contents of HEAD are added to head of the page * and content of BODY are added to the current node (DIV tag in test case). * * @throws Exception failure */ @Test @NotYetImplemented(Browser.IE) @Alerts(IE = {"HEAD", "Outer Html", "outerDiv" }, FF = {"HEAD", "Outer Html", "HEAD", "Inner Html", "outerDiv" }) public void writeCompleteHtmlInsideDIV() throws Exception { final String html = "\n" + " Outer Html\n" + " \n" + "\n" + "\n" + "
          \n" + " Outer DIV\n" + " \n" + "
          \n" + "\n" + "\n"; loadPageWithAlerts(html); } /** * Test for a case where complete HTML page is set in innerHTML of DIV tag. * Behavior is same for any TAG inside body including BODY tag. * IE ignores the HTML tag, BODY tag and complete HEAD along with content inside HEAD * FF ignores only HTML, HEAD and BODY tags. Contents of HEAD and BODY are added to * the current node (DIV tag in test case). * * @throws Exception failure */ @Test @Alerts(IE = {"HEAD", "Outer Html", "outerDiv" }, FF = {"HEAD", "Outer Html", "DIV", "Inner Html", "DIV", "Inner Html", "outerDiv" }) public void setCompleteHtmlToDIV_innerHTML() throws Exception { final String html = "\n" + " Outer Html\n" + " \n" + "\n" + "\n" + "
          \n" + " Outer DIV\n" + "
          \n" + " \n" + "\n" + "\n"; loadPageWithAlerts(html); } /** * Test for a case where complete HTML page is set in innerHTML of HTML tag. * IE throws JavaScript error as innerHTML of HTML is read only * FF ignores HTML, HEAD and BODY tags. Contents of HEAD and BODY are added to HTML node. * Resulting DOM has only TITLE and DIV tag under HTML. There is no HEAD or BODY node. * * @throws Exception failure */ @Test @Alerts(IE = {"HEAD", "Outer Html", "true" }, FF = {"HTML", "Inner Html", "false", "HTML" }) public void setComplteHtmlToHTML_innerHTML() throws Exception { final String html = "\n" + " Outer Html\n" + " \n" + "\n" + "\n" + "
          \n" + " Outer DIV\n" + "
          \n" + " \n" + "\n" + "\n"; createTestPageForRealBrowserIfNeeded(html, getExpectedAlerts()); final WebClient client = getWebClient(); client.setThrowExceptionOnScriptError(false); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_GARGOYLE, html); client.setWebConnection(webConnection); client.getPage(URL_GARGOYLE); assertEquals(getExpectedAlerts(), collectedAlerts); } /** * @throws Exception on test failure */ @Test @Alerts(IE = { "2", "1", "2", "1", "1", "1", "2", "2", "1", "1", "1", "1" }, FF = { "2", "2", "3", "3", "2", "2", "3", "2", "2", "3", "2", "2" }) public void childNodes_p() throws Exception { final String html = "test_getChildNodes\n" + "\n" + "\n" + "

          \n" + "

          \n" + "

          \n" + "

          \n" + "

          \n" + "

          \n" + "

          there

          \n" + "

          there

          \n" + "

          there

          \n" + "

          \n" + "

          \n" + "

          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts(IE = { "2", "1", "2", "1", "1", "1", "2", "2", "1", "1", "1", "1", "1" }, FF = { "2", "2", "3", "3", "2", "2", "3", "2", "2", "3", "2", "2", "3" }) public void childNodes_f() throws Exception { final String html = "test_getChildNodes\n" + "\n" + "\n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          there
          \n" + "
          there
          \n" + "
          there
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts(IE = { "1", "1", "1", "2", "2", "1" }, FF = { "3", "2", "2", "3", "2", "2" }) public void childNodes_span() throws Exception { final String html = "test_getChildNodes\n" + "\n" + "\n" + "

          \n" + "

          \n" + "

          \n" + "

          something

          \n" + "

          something

          \n" + "

          something

          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception on test failure */ @Test @Alerts(IE = { "1", "1", "1", "2", "2", "1" }, FF = { "3", "2", "2", "3", "2", "2" }) public void childNodes_font() throws Exception { final String html = "test_getChildNodes\n" + "\n" + "\n" + "

          \n" + "

          \n" + "

          \n" + "

          something

          \n" + "

          something

          \n" + "

          something

          \n" + ""; loadPageWithAlerts(html); } /** * @throws Exception if the test fails */ @Test public void headerVsMetaTagContentType_both() throws Exception { HeaderVsMetaTagContentTypeServlet.setEncoding("UTF-8", "ISO-8859-1"); headerVsMetaTagContentType(true); } /** * @throws Exception if the test fails */ @Test public void headerVsMetaTagContentType_bothReversed() throws Exception { HeaderVsMetaTagContentTypeServlet.setEncoding("ISO-8859-1", "UTF-8"); headerVsMetaTagContentType(false); } /** * @throws Exception if the test fails */ @Test public void headerVsMetaTagContentType4_headerOnly() throws Exception { HeaderVsMetaTagContentTypeServlet.setEncoding("UTF-8", null); headerVsMetaTagContentType(true); } /** * @throws Exception if the test fails */ @Test public void headerVsMetaTagContentType_metaOnly() throws Exception { HeaderVsMetaTagContentTypeServlet.setEncoding(null, "UTF-8"); headerVsMetaTagContentType(true); } private void headerVsMetaTagContentType(final boolean utf8Encoded) throws Exception { final Map> servlets = new HashMap>(); servlets.put("/test", HeaderVsMetaTagContentTypeServlet.class); startWebServer("./", null, servlets); final WebClient client = getWebClient(); final HtmlPage page = client.getPage("http://localhost:" + PORT + "/test"); assertEquals(utf8Encoded, HeaderVsMetaTagContentTypeServlet.utf8String.equals(page.asText())); } /** * Servlet for {@link #headerVsMetaTagContentType(boolean)}. */ public static class HeaderVsMetaTagContentTypeServlet extends HttpServlet { private static final long serialVersionUID = -2575819782522464907L; private static final String utf8String = "\u064A\u0627 \u0644\u064A\u064A\u064A\u064A\u0644"; private static String HEADER_ENCODING_; private static String META_TAG_ENCODING_; private static void setEncoding(final String headerEncoding, final String metaTagEncoding) { HEADER_ENCODING_ = headerEncoding; META_TAG_ENCODING_ = metaTagEncoding; } /** * {@inheritDoc} */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { response.setContentType("text/html"); if (HEADER_ENCODING_ != null) { response.setCharacterEncoding(HEADER_ENCODING_); } final Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); String html = ""; if (META_TAG_ENCODING_ != null) { html += ""; } html += "" + utf8String + ""; writer.write(html); writer.close(); } } @Test public void bodyInInnerHTML() throws Exception { final String content = "
          " + "" + ""; loadPage(content); } /** * Regression test for bug 2523870: parse failure when parsing page with UTF-8 BOM (byte order mark). * The HTML file used is from NekoHTML's bug number 2560899. * @throws Exception if an error occurs */ @Test public void bomUtf8() throws Exception { final String resource = "bom-utf8.html"; final URL url = getClass().getClassLoader().getResource(resource); assertNotNull(url); final WebClient client = getWebClient(); final HtmlPage page = client.getPage(url); assertEquals("Welcome to Suffolk Coastal District Council online", page.getTitleText()); } /** * This HTML was causing an EmptyStackException to be thrown. * @throws Exception if an error occurs */ @Test public void emptyStack() throws Exception { final String html = "\n" + " \n" + "
          \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
          \n" + "
          \n" + "
          \n" + "

          \n" + " blah\n" + "

          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + "
          \n" + " \n" + ""; final HtmlPage page = loadPageWithAlerts(html); assertNotNull(page); } } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/IEConditionalCommentExpressionEvaluatorTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/IEConditionalComment0000664000175000017500000001145211650253660034541 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static com.gargoylesoftware.htmlunit.BrowserVersion.INTERNET_EXPLORER_6; import static com.gargoylesoftware.htmlunit.BrowserVersion.INTERNET_EXPLORER_7; import static com.gargoylesoftware.htmlunit.html.IEConditionalCommentExpressionEvaluator.evaluate; import static org.junit.Assert.assertEquals; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; /** * Tests for {@link IEConditionalCommentExpressionEvaluator}. * Due to current implementation, conditional comment expressions get evaluated only when the simulated browser is IE. * @version $Revision: 4079 $ * @author Marc Guillemot */ public class IEConditionalCommentExpressionEvaluatorTest { /** * Test for expression [if IE]. */ @Test public void IE() { doTest("IE", true, true); } /** * Test for expressions like [if IE 7]. */ @Test public void IE_X() { doTest("IE 5", false, false); doTest("IE 6", true, false); doTest("IE 7", false, true); doTest("IE 8", false, false); } /** * Test for expression [if !IE]. */ @Test public void notIE() { doTest("!IE", false, false); } /** * Test for expressions like [if lt IE 5.5]. */ @Test public void lt_IE_X() { doTest("lt IE 5.5", false, false); doTest("lt IE 6", false, false); doTest("lt IE 7", true, false); doTest("lt IE 8", true, true); } /** * Test for expressions like [if lte IE 6]. */ @Test public void lte_IE_X() { doTest("lte IE 5.5", false, false); doTest("lte IE 6", true, false); doTest("lte IE 7", true, true); doTest("lte IE 8", true, true); } /** * Test for expressions like [if gt IE 5]. */ @Test public void gt_IE_X() { doTest("gt IE 5.5", true, true); doTest("gt IE 6", false, true); doTest("gt IE 7", false, false); doTest("gt IE 8", false, false); } /** * Test for expressions like [if gte IE 7]. */ @Test public void gte_IE_X() { doTest("gte IE 5.5", true, true); doTest("gte IE 6", true, true); doTest("gte IE 7", false, true); doTest("gte IE 8", false, false); } /** * Test for expressions like [if !(IE 7)]. */ @Test public void parenthese() { doTest("!(IE 5)", true, true); doTest("!(IE 6)", false, true); doTest("!(IE 7)", true, false); doTest("!(IE 8)", true, true); } /** * Test for expressions like if [(gt IE 5)&(lt IE 7)]. */ @Test public void and() { doTest("(gt IE 5)&(lt IE 7)", true, false); doTest("(gt IE 6)&(lt IE 8)", false, true); } /** * Test for expressions like if [if (IE 6)|(IE 7)]. */ @Test public void or() { doTest("(IE 6)|(IE 7)", true, true); doTest("(IE 5)|(IE 7)", false, true); } /** * Test for expressions like if [if true]. */ @Test public void true_false() { doTest("true", true, true); doTest("false", false, false); } /** * Test for expressions with "mso" (HTML code generated by MS Office). */ @Test public void mso() { doTest("mso 9", false, false); doTest("gte mso 9", false, false); doTest("gt mso 9", false, false); doTest("lt mso 9", true, true); doTest("lt mso 1", true, true); } /** * Test for expressions with unexpected identifier. */ @Test public void unknown() { doTest("foo 1", false, false); doTest("gte foo 1", false, false); doTest("gt foo 1", false, false); doTest("lt foo 1", true, true); } private void doTest(final String expression, final boolean expectedIE6, final boolean expectedIE7) { doTest(expectedIE6, expression, INTERNET_EXPLORER_6); doTest(expectedIE7, expression, INTERNET_EXPLORER_7); } private void doTest(final boolean b, final String expression, final BrowserVersion browserVersion) { assertEquals(expression + " for " + browserVersion.getNickname(), b, evaluate(expression, browserVersion)); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSpanTest.java0000664000175000017500000000764211650253660034051 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlSpan}. * * @version $Revision: 4032 $ * @author Ahmed Ashour * @author Sudhan Moghe */ public class HtmlSpanTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " My Span\n" + ""; final String[] expectedAlerts = {"[object HTMLSpanElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlSpan.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } /** * Test that HTMLSpanElement is the default for other elements like 'address', 'code', 'strike', etc. * @throws Exception if the test fails */ @Test public void simpleScriptable_others() throws Exception { final String html = "\n" + "\n" + "\n" + "
          My Address
          \n" + ""; final String[] expectedAlerts = {"[object HTMLSpanElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlAddress.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void emptyTag() throws Exception { final String html = "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(html); final HtmlSpan htmlSpan = page.getHtmlElementById("myId"); assertTrue(htmlSpan.asXml().contains("")); } /** * @throws Exception if the test fails */ @Test public void asText() throws Exception { final String html = "\n" + "" + "\n" + "before\n" + "\n" + "\n" + "inside\n" + "\n" + "\n" + "after\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(html); final HtmlElement elt = page.getHtmlElementById("outside"); assertEquals("before inside after", elt.asText()); assertEquals("before inside after", page.asText()); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInputTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInputTest.0000664000175000017500000000276611650253660034523 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlHiddenInput}. * * @version $Revision: 4002 $ * @author Marc Guillemot */ public class HtmlHiddenInputTest extends WebTestCase { /** * Verifies that a asText() returns "checked" or "unchecked" according to the state of the checkbox. * @throws Exception if the test fails */ @Test public void testAsText() throws Exception { final String htmlContent = "foo\n" + "
          \n" + " \n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlInput input = page.getHtmlElementById("foo"); assertEquals("", input.asText()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlStyleTest.java0000664000175000017500000000665311650253660034251 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlStyle}. * * @version $Revision: 4681 $ * @author Marc Guillemot * @author Ahmed Ashour */ public class HtmlStyleTest extends WebTestCase { /** * Verifies that a asText() returns "checked" or "unchecked" according to the state of the checkbox. * @throws Exception if the test fails */ @Test public void testAsText() throws Exception { final String html = "foo\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(html); final DomNode node = page.getHtmlElementById("testStyle"); assertEquals("style", node.getNodeName()); assertEquals("", node.asText()); } /** * @throws Exception if the test fails */ @Test public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + "\n" + ""; final String[] expectedAlerts = {"[object HTMLStyleElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlStyle.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } /** * See Bug 2802096. * @throws Exception if the test fails */ @Test public void testAsXml() throws Exception { final String html = "foo\n" + "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(html); final String xml = page.asXml(); assertTrue("Style node not expanded in: " + xml, xml.contains("")); final String xmlWithoutSpace = xml.replaceAll("\\s", ""); assertTrue(xml, xmlWithoutSpace.contains("")); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/xpath/0000775000175000017500000000000011650253660031733 5ustar jamespagejamespagejenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/xpath/package.html0000664000175000017500000000012111650253660034206 0ustar jamespagejamespageTest Classes Test Classes ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/xpath/HtmlUnitXPathTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/xpath/HtmlUnitXPathT0000664000175000017500000002535511650253660034525 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html.xpath; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import junit.framework.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.DomText; import com.gargoylesoftware.htmlunit.html.HtmlBody; import com.gargoylesoftware.htmlunit.html.HtmlDivision; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * Tests for XPath evaluation on HtmlUnit DOM. * * @version $Revision: 4002 $ * @author Marc Guillemot * @author Ahmed Ashour */ public class HtmlUnitXPathTest extends WebTestCase { /** * Test evaluation of some simple paths. * @throws Exception if test fails */ @Test public void simplePath() throws Exception { final String content = "Test page\n" + "foo\n" + ""; final HtmlPage page = loadPage(content); assertEquals(page.getDocumentElement(), page.getFirstByXPath("/html")); assertEquals(page.getDocumentElement().getFirstChild(), page.getFirstByXPath("/html/head")); assertEquals(page.getHtmlElementById("myLink"), page.getFirstByXPath("/html/body/a")); assertEquals("Test page", ((DomText) page.getFirstByXPath("/html/head/title/text()")).getNodeValue()); } /** * Test evaluation relative from elements other than the whole page. * @throws Exception if test fails */ @Test public void xpathFromElement() throws Exception { final String content = "Test page\n" + "foo\n" + ""; final HtmlPage page = loadPage(content); final HtmlBody body = page.getFirstByXPath("/html/body"); assertEquals(page.getHtmlElementById("myLink"), body.getFirstByXPath("./a")); } /** * Test that the elements are in the right order. * @throws Exception if test fails */ @Test @SuppressWarnings("unchecked") public void elementOrder() throws Exception { final String content = "First\n" + ""; final HtmlPage page = loadPage(content); final List< ? > list = page.getByXPath("//*"); final String[] expected = {"html", "head", "title", "script", "body"}; final List actualNames = new ArrayList(); for (final DomNode node : (List) list) { actualNames.add(node.getNodeName()); } assertEquals(expected, actualNames); } /** * Test evaluation of paths after they're changed through JavaScript. * @throws Exception if test fails */ @Test public void whenJSChangesPage() throws Exception { final String content = "foo\n" + "\n" + "\n" + "

          hello world

          \n" + "
          \n" + " \n" + "
          \n" + "add option\n" + ""; final HtmlPage page = loadPage(content); assertEquals("foo", page.getTitleText()); assertEquals(3, page.getFirstByXPath("count(//select[@name='select1']/option)").intValue()); page.getAnchors().get(0).click(); assertEquals(4, page.getFirstByXPath("count(//select[@name='select1']/option)").intValue()); } /** * Tests XPath where results are attributes. * @throws Exception if test fails */ @Test @SuppressWarnings("unchecked") public void listAttributesResult() throws Exception { final String content = "\n" + "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPage(content); final List< ? > nameList = page.getByXPath("//img/@src"); final List< ? > valueList = new ArrayList(nameList); final String[] expectedNames = {"src", "src", "src"}; final List collectedNames = new ArrayList(); for (final DomNode node : (List) nameList) { collectedNames.add(node.getNodeName()); } assertEquals(expectedNames, collectedNames); final String[] expectedValues = {"1.png", "2.png", "3.png"}; final List collectedValues = new ArrayList(); for (final DomNode node : (List) valueList) { collectedValues.add(node.getNodeValue()); } assertEquals(expectedValues, collectedValues); } /** * @throws Exception if the test fails */ @Test public void optionText() throws Exception { final String content = "foo\n" + " \n" + ""; final String[] expectedAlerts = {"102", "111", "111", "160", "97", "110", "100", "160", "102", "111", "111"}; final List collectedAlerts = new ArrayList(); loadPage(BrowserVersion.FIREFOX_2, content, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Test if option/text() is cleaned like other text(). * @throws Exception if test fails */ @Test public void optionText_getFirstByXPath() throws Exception { final String content = "Test page\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(content); final String value = page.getFirstByXPath("string(//option)"); final int[] expectedValues = {102, 111, 111, 160, 97, 110, 100, 160, 102, 111, 111}; int index = 0; for (final int v : expectedValues) { if (value.codePointAt(index++) != v) { fail(); } } } /** * Regression test for https://sf.net/tracker/index.php?func=detail&aid=1527799&group_id=47038&atid=448266. * @throws Exception if test fails */ @Test public void followingAxis() throws Exception { final String content = "XPath tests\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
          a3c
          a4c
          \n" + ""; final HtmlPage page = loadPage(content); final HtmlElement td12 = page.getHtmlElementById("td12"); final HtmlElement tr2 = page.getHtmlElementById("tr2"); final HtmlElement td21 = page.getHtmlElementById("td21"); final HtmlElement td22 = page.getHtmlElementById("td22"); xpath(page, "//*[contains(.,'a4')]/following::td[.='c']", new Object[] {td22}); xpath(page, "//body/following::*", new Object[] {}); xpath(page, "//html/following::*", new Object[] {}); xpath(page, "//table/following::*", new Object[] {}); xpath(page, "//td[@id='td11']/following::*", new Object[] {td12, tr2, td21, td22}); } private void xpath(final HtmlPage page, final String xpathExpr, final Object[] expectedNodes) throws Exception { assertEquals(Arrays.asList(expectedNodes), page.getByXPath(xpathExpr)); } /** * @throws Exception if test fails */ @Test public void id() throws Exception { final String content = "foo\n" + "\n" + "
          \n" + ""; final HtmlPage page = loadPage(content); assertNull(page.getFirstByXPath("//div[@id='doesNotExist']")); assertNull(page.getFirstByXPath("id('doesNotExist')")); } /** * @throws Exception if test fails */ @Test public void changingAttributes() throws Exception { final String content = "foo\n" + "\n" + "
          \n" + ""; final HtmlPage page = loadPage(content); final HtmlDivision div = page.getHtmlElementById("testDiv"); Assert.assertSame(div, page.getFirstByXPath("//*[@title = 'foo']")); assertNull(page.getFirstByXPath("//*[@class = 'design']")); div.setAttribute("class", "design"); Assert.assertSame(div, page.getFirstByXPath("//*[@class = 'design']")); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlMapTest.java0000664000175000017500000000342511650253660033660 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import java.util.ArrayList; import java.util.List; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlMap}. * * @version $Revision: 4002 $ * @author Ahmed Ashour */ public class HtmlMapTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void testSimpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final String[] expectedAlerts = {"[object HTMLMapElement]"}; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(BrowserVersion.FIREFOX_2, html, collectedAlerts); assertTrue(HtmlMap.class.isInstance(page.getHtmlElementById("myId"))); assertEquals(expectedAlerts, collectedAlerts); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInputTest.java0000664000175000017500000002542311650253660034244 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlInput}. * * @version $Revision: 4463 $ * @author
          Mike Bowler * @author Marc Guillemot * @author Ahmed Ashour */ public final class HtmlInputTest extends WebTestCase { /** * Tests that selecting one radio button will deselect all the others. * @exception Exception If the test fails */ @Test public void testRadioButtonsAreMutuallyExclusive() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlRadioButtonInput radioButton = form.getFirstByXPath( "//input[@type='radio' and @name='foo' and @value='2']"); final HtmlSubmitInput pushButton = form.getInputByName("button"); radioButton.setChecked(true); // Test that only one value for the radio button is being passed back to the server final HtmlPage secondPage = (HtmlPage) pushButton.click(); assertEquals("url", URL_GARGOYLE + "?foo=2&button=foo", secondPage.getWebResponse().getRequestSettings().getUrl()); assertSame("method", HttpMethod.GET, webConnection.getLastMethod()); assertNotNull(secondPage); } /** * @throws Exception if the test fails */ @Test public void testSetChecked_CheckBox() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlCheckBoxInput checkbox = form.getInputByName("foo"); Assert.assertFalse("Initial state", checkbox.isChecked()); checkbox.setChecked(true); assertTrue("After setSelected(true)", checkbox.isChecked()); checkbox.setChecked(false); Assert.assertFalse("After setSelected(false)", checkbox.isChecked()); } /** * @throws Exception if the test fails */ @Test public void testGetChecked_RadioButton() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); final List radioButtons = form.getRadioButtonsByName("radio1"); assertEquals(2, radioButtons.size()); assertFalse(radioButtons.get(0).isChecked()); assertTrue(radioButtons.get(1).isChecked()); } /** * @throws Exception if the test fails */ @Test public void testOnChangeHandler() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "
          "; final List collectedAlerts = new ArrayList(); final HtmlPage page = loadPage(htmlContent, collectedAlerts); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlTextInput input = form.getInputByName("text1"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); input.setValueAttribute("foo"); assertEquals(new String[] {"changed"}, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testCheckboxDefaultValue() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlCheckBoxInput input = form.getInputByName("checkbox1"); assertEquals("on", input.getValueAttribute()); } /** * Tests that clicking a radio button will select it. * @exception Exception If the test fails */ @Test public void testClickRadioButton() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlRadioButtonInput radioButton = form.getFirstByXPath( "//input[@type='radio' and @name='foo' and @value='2']"); Assert.assertFalse("Should not be checked before click", radioButton.isChecked()); radioButton.click(); assertTrue("Should be checked after click", radioButton.isChecked()); } /** * Tests that default type of input is text. * @exception Exception If the test fails */ @Test public void testInputNoType() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); assertEquals("text", form.getInputByName("foo").getTypeAttribute()); } /** * @throws Exception if the test fails */ @Test public void testOnChangeHandlerNotFiredOnLoad() throws Exception { final String htmlContent = "foo\n" + "
          \n" + "\n" + "
          "; final List collectedAlerts = new ArrayList(); loadPage(htmlContent, collectedAlerts); assertEquals(Collections.EMPTY_LIST, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testBadInputType() throws Exception { final String htmlContent = "foo\n" + "\n" + "
          \n" + "\n" + "
          "; final String[] expectedAlerts = {"text"}; createTestPageForRealBrowserIfNeeded(htmlContent, expectedAlerts); final List collectedAlerts = new ArrayList(); loadPage(htmlContent, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testOnchangeNull() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final String[] expectedAlerts = {"\nfunction handler() {\n}\n", "null"}; final List collectedAlerts = new ArrayList(); loadPage(html, collectedAlerts); assertEquals(expectedAlerts, collectedAlerts); } /** * Tests that clicking a radio button will select it. * @exception Exception If the test fails */ @Test public void testSelect() throws Exception { final String content = "foo\n" + "\n" + "\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
          "; createTestPageForRealBrowserIfNeeded(content, new String[] {}); loadPage(content); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmbedTest.java0000664000175000017500000000370311650253660034156 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlEmbed}. * * @version $Revision: 4817 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlEmbedTest extends WebDriverTestCase { /** * @throws Exception if the test fails */ @Test @Alerts(FF = "[object HTMLEmbedElement]", IE = "[object]") public void simpleScriptable() throws Exception { final String html = "\n" + "\n" + "\n" + " \n" + ""; final WebDriver driver = loadPageWithAlerts2(html); if (driver instanceof HtmlUnitDriver) { final HtmlElement element = toHtmlElement(driver.findElement(By.id("myId"))); assertTrue(HtmlEmbed.class.isInstance(element)); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableRowTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTableRowTest.jav0000664000175000017500000002402311650253660034516 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import org.junit.Test; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; /** * Tests for {@link HtmlTableRow}. * * @version $Revision: 4503 $ * @author Mike Gallaher * @author Mike Bowler * @author Ahmed Ashour * @author Marc Guillemot */ public class HtmlTableRowTest extends WebTestCase { private static final String htmlContent = "foo\n" + "\n" + "\n" + "
          \n" + ""; private HtmlPage page_; private HtmlTable table_; private HtmlTableBody tbody_; private HtmlTableRow row_; private HtmlTableCell cell_; private HtmlTableRow rowClone_; private HtmlTableCell cellClone_; /** * Constructor. * @throws Exception if an exception occurs */ public HtmlTableRowTest() throws Exception { page_ = loadPage(htmlContent); table_ = page_.getHtmlElementById("table"); tbody_ = (HtmlTableBody) table_.getFirstChild(); row_ = table_.getRow(0); cell_ = row_.getCell(0); rowClone_ = (HtmlTableRow) row_.cloneNode(true); cellClone_ = rowClone_.getCell(0); } /** * Ensure that cloneNode leaves the original node unchanged. */ @Test public void testClonePreservesOriginal() { assertSame(tbody_, row_.getParentNode()); assertSame(row_, cell_.getParentNode()); assertSame(cell_, row_.getCell(0)); assertEquals("row", row_.getId()); assertEquals("cell", cell_.getId()); } /** * Ensure that the clones are not the originals. * @throws Exception if the test fails */ @Test public void testClonesAreDistinct() throws Exception { assertNotSame(row_, rowClone_); assertNotSame(cell_, cellClone_); } /** * Ensure that the clones have the same page as the originals. */ @Test public void testCloneHasSamePage() { assertSame(cell_.getPage(), cellClone_.getPage()); assertSame(row_.getPage(), rowClone_.getPage()); } /** * Ensure that the cloned row has no parent. * @throws Exception if the test fails */ @Test public void testClonedRowHasNullParent() throws Exception { assertNull(rowClone_.getParentNode()); } /** * Ensure that the cloned row's children are not those of the original. * @throws Exception if the test fails */ @Test public void testClonedRowHasDifferentChildren() throws Exception { assertEquals(row_.getCells().size(), rowClone_.getCells().size()); assertNotSame(row_.getFirstChild(), rowClone_.getFirstChild()); } /** * Ensure that the cloned cell's children are not those of the original. */ @Test public void testClonedCellHasDifferentChildren() { assertNotSame(cell_.getParentNode(), cellClone_.getParentNode()); assertNotNull(cell_.getFirstChild()); assertNotSame(cell_.getFirstChild(), cellClone_.getFirstChild()); } /** * Ensure that the cloned cell has the cloned row as its parent. * @throws Exception if the test fails */ @Test public void testClonedCellHasClonedRowAsParent() throws Exception { assertSame(rowClone_, cellClone_.getParentNode()); } /** * Ensure the cloned cell's attribute value is the same as the original. */ @Test public void testCloneAttributesCopiedFromOriginal() { assertEquals("20", cell_.getAttribute("width")); assertEquals("20", cellClone_.getAttribute("width")); } /** * Ensure that changing the clone's attribute leaves the original's * attribute unchanged. */ @Test public void testCloneAttributeIsIndependentOfOriginal() { cellClone_.setAttribute("a", "one"); assertFalse("one".equals(cell_.getAttribute("a"))); } /** * Ensure that changing the original's attribute leaves the clone's * attribute unchanged. */ @Test public void testOriginalAttributeIsIndependentOfClone() { cell_.setAttribute("a", "one"); assertFalse("one".equals(cellClone_.getAttribute("a"))); } /** * Ensure that changing the clone's nodeValue leaves the original's * unchanged. */ @Test public void testCloneValueIsIndependentOfOriginal() { cellClone_.setNodeValue("one"); assertFalse("one".equals(cell_.getNodeValue())); } /** * Ensure that changing the clone's id leaves the original's unchanged. */ @Test public void testCloneIdIsIndependentOfOriginal() { cellClone_.setNodeValue("one"); assertFalse("one".equals(cell_.getNodeValue())); } // these next few test our assumptions about how scripts affect the DOM /** * Ensure that the JavaScript object returned by the script fragment really * refers to the same DOM node we think it should. */ @Test public void testScriptCanGetOriginalCell() { final String cmd = "document.getElementById('cell')"; final Object object = page_.executeJavaScript(cmd).getJavaScriptResult(); final HtmlElement cellElement = ((HTMLElement) object).getDomNodeOrDie(); assertSame(cell_, cellElement); } /** * Ensure that the JavaScript object returned by the script fragment is the * same one the DOM node thinks it's wrapped by. */ @Test public void testCellScriptObjectIsReturnedByScript() { final String cmd = "document.getElementById('cell')"; final HTMLElement jselement = (HTMLElement) page_.executeJavaScript(cmd).getJavaScriptResult(); assertSame(jselement, cell_.getScriptObject()); } /** * Ensure that setting a property via script sets the property on the * ScriptableObject that we think it should. */ @Test public void testScriptCanSetJsPropertyOnCell() { final String cmd = "document.getElementById('cell').a='original';document.getElementById('cell')"; final Object object = page_.executeJavaScript(cmd).getJavaScriptResult(); final HTMLElement jselement = ((HTMLElement) object); assertEquals("original", ScriptableObject.getProperty(jselement, "a")); assertSame(jselement, cell_.getScriptObject()); } /** * Ensure that a script can set the disabled property on a DOM node. */ @Test public void testCloneScriptCanSetDisabledOnCell() { final String cmd = "document.getElementById('cell').disabled='true'"; page_.executeJavaScript(cmd); assertEquals("disabled", cell_.getAttribute("disabled")); } /** * Ensure that a script can set an attribute on the DOM node. */ @Test public void testCloneScriptCanSetAttributeOnCell() { final String cmd = "document.getElementById('cell').setAttribute('a','original')"; page_.executeJavaScript(cmd); assertEquals("original", cell_.getAttribute("a")); } // these next few check that scripts manipulate the clone independently /** * Ensure that a script setting an attribute on the original does not affect * that same attribute on the clone. */ @Test public void testCloneScriptSetAttributeIndependentOfOriginal() { final String cmd = "document.getElementById('cell').setAttribute('a','original')"; page_.executeJavaScript(cmd); assertEquals("original", cell_.getAttribute("a")); assertFalse("original".equals(cellClone_.getAttribute("a"))); } /** * Ensure that a script setting disabled on the original does not affect * that same attribute on the clone. */ @Test public void testCloneScriptSetDisabledIndependentOfOriginal() { final String cmd = "document.getElementById('cell').disabled = 'true'"; page_.executeJavaScript(cmd); assertEquals("disabled", cell_.getAttribute("disabled")); assertFalse("disabled".equals(cellClone_.getAttribute("disabled"))); } /** * Ensure that a script referencing an element causes only that DOM element * to get a ScriptObject assigned, and does not cause one to be assigned to * the clone. */ @Test public void testCloneHasDifferentScriptableObject() { final String cmd = "document.getElementById('cell')"; // force it to have a // scriptable object page_.executeJavaScript(cmd); assertNotSame(cell_.getScriptObject(), cellClone_.getScriptObject()); } /** * Ensure that setting the value on a child of a table cell doesn't affect * the cloned child. */ @Test public void testScriptDomOperations() { final String cmd = "document.getElementById('foo').value = 'Input!';document.getElementById('foo')"; page_.executeJavaScript(cmd); final HtmlElement input = (HtmlElement) cell_.getFirstChild(); assertEquals("Input!", input.getAttribute("value")); final HtmlElement inputClone = (HtmlElement) cellClone_.getFirstChild(); assertFalse("Input!".equals(inputClone.getAttribute("value"))); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootjenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTest.javajenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInputTes0000664000175000017500000001116511650253660034661 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link HtmlPasswordInput}. * * @version $Revision: 4808 $ * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class HtmlPasswordInputTest extends WebTestCase { /** * @throws Exception if the test fails */ @Test public void type() throws Exception { final String html = ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlPasswordInput p = page.getHtmlElementById("p"); p.type("abc"); assertEquals("abc", p.getValueAttribute()); p.type('\b'); assertEquals("ab", p.getValueAttribute()); p.type('\b'); assertEquals("a", p.getValueAttribute()); p.type('\b'); assertEquals("", p.getValueAttribute()); p.type('\b'); assertEquals("", p.getValueAttribute()); } /** * @throws Exception if the test fails */ @Test public void typeWhileDisabled() throws Exception { final String html = ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlPasswordInput p = page.getHtmlElementById("p"); p.type("abc"); assertEquals("", p.getValueAttribute()); } /** * @throws Exception if an error occurs */ @Test public void typeWhileSelected() throws Exception { final String html = "\n" + "
          \n" + ""; final HtmlPage page = loadPage(getBrowserVersion(), html, null); final HtmlPasswordInput input = page.getHtmlElementById("myInput"); input.select(); input.type("Bye World"); assertEquals("Bye World", input.getValueAttribute()); } /** * @throws Exception if an error occurs */ @Test public void preventDefault_OnKeyDown() throws Exception { final String html = "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlPasswordInput input = page.getHtmlElementById("x"); input.type("abcd"); assertEquals("abc", input.getValueAttribute()); } /** * @throws Exception if an error occurs */ @Test public void preventDefault_OnKeyPress() throws Exception { final String html = "\n" + "\n" + "\n" + ""; final HtmlPage page = loadPageWithAlerts(html); final HtmlPasswordInput input = page.getHtmlElementById("x"); input.type("abcd"); assertEquals("abc", input.getValueAttribute()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/DomCommentTest.java0000664000175000017500000000435011650253660034356 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import org.junit.Test; import com.gargoylesoftware.htmlunit.WebTestCase; /** * Tests for {@link DomComment}. * * @version $Revision: 4002 $ * @author Karel Kolman * @author Ahmed Ashour */ public class DomCommentTest extends WebTestCase { /** * Test the comment not visible when viewed by user. * @throws Exception if the test fails */ @Test public void testAsText() throws Exception { final String content = ""; final HtmlPage page = loadPage(content); assertEquals("", page.asText()); } /** * Test the comment correctness. * @throws Exception if the test fails */ @Test public void testAsXml() throws Exception { final String comment = ""; final String content = "" + comment + ""; final HtmlPage page = loadPage(content); final HtmlElement elt = page.getHtmlElementById("foo"); final DomNode node = elt.getFirstChild(); assertEquals(comment, node.asXml()); } /** * Test comment and character data sibling correctness. * @throws Exception if the test fails */ @Test public void testTextSibling() throws Exception { final String content = "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getHtmlElementById("body").getFirstChild(); assertEquals(DomText.NODE_NAME, node.getNextSibling().getNodeName()); } } jenkins-htmlunit-2.6-jenkins-6/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java0000664000175000017500000016123511650253660034052 0ustar jamespagejamespage/* * Copyright (c) 2002-2009 Gargoyle Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.lang.StringUtils; import org.junit.Assert; import org.junit.Test; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.WebTestCase; import com.gargoylesoftware.htmlunit.WebWindow; /** * Tests for {@link HtmlForm}. * * @version $Revision: 4900 $ * @author Mike Bowler * @author Jun Chen * @author George Murnock * @author Marc Guillemot * @author Ahmed Ashour * @author Philip Graf */ public class HtmlFormTest extends WebTestCase { /** * Tests the good case for setCheckedRatdioButton(). * @exception Exception If the test fails */ @Test public void testSetSelectedRadioButton_ValueExists() throws Exception { final String html = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlSubmitInput pushButton = form.getInputByName("button"); form.getFirstByXPath( "//input[@type='radio' and @name='foo' and @value='2']").setChecked(true); assertFalse(page.getHtmlElementById("input1").isChecked()); assertTrue(page.getHtmlElementById("input2").isChecked()); // Test that only one value for the radio button is being passed back to the server final HtmlPage secondPage = (HtmlPage) pushButton.click(); assertEquals("url", URL_GARGOYLE + "?foo=2&button=foo", secondPage.getWebResponse().getRequestSettings().getUrl()); Assert.assertSame("method", HttpMethod.GET, webConnection.getLastMethod()); } /** * Tests setCheckedRadioButton() with a value that doesn't exist. * @exception Exception If the test fails */ @Test public void testSetSelectedRadioButton_ValueDoesNotExist_DoNotForceSelection() throws Exception { final String html = "foo\n" + "
          \n" + "\n" + "\n" + "\n" + "\n" + "
          "; final HtmlPage page = loadPage(html); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlInput pushButton = form.getInputByName("button"); assertNotNull(pushButton); assertNull(form.getFirstByXPath("//input[@type='radio' and @name='foo' and @value='4']")); } /** * @throws Exception if the test fails */ @Test public void testSubmit_String() throws Exception { final String html = "foo\n" + "
          \n" + "\n" + "
          "; final HtmlPage page = loadPage(html); final HtmlForm form = page.getHtmlElementById("form1"); // Regression test: this used to blow up form.submit((HtmlSubmitInput) page.getHtmlElementById("submitButton")); } /** * @throws Exception if the test fails */ @Test public void testSubmit_ExtraParameters() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlSubmitInput button = form.getInputByName("button"); button.click(); final List expectedParameters = Arrays.asList(new NameValuePair[]{ new NameValuePair("textfield", "*"), new NameValuePair("button", "foo") }); final List collectedParameters = webConnection.getLastParameters(); assertEquals(expectedParameters, collectedParameters); } /** * @throws Exception if the test fails */ @Test public void testSubmit_BadSubmitMethod() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); page.getHtmlElementById("button").click(); assertSame(HttpMethod.GET, webConnection.getLastMethod()); } /** * @throws Exception if the test fails */ @Test public void testSubmit_onSubmitHandler() throws Exception { final String firstHtml = "First\n" + "
          \n" + "
          \n" + ""; final String secondHtml = "Second"; final WebClient client = new WebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setDefaultResponse(secondHtml); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlSubmitInput button = firstPage.getHtmlElementById("button"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = button.click(); assertEquals("Second", secondPage.getTitleText()); assertEquals(new String[] {"clicked"}, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testSubmit_onSubmitHandler_returnFalse() throws Exception { final String firstHtml = "First\n" + "
          \n" + "
          \n" + ""; final String secondHtml = "Second"; final WebClient client = new WebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setResponse(URL_SECOND, secondHtml); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlSubmitInput button = firstPage.getHtmlElementById("button"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = button.click(); assertEquals(firstPage.getTitleText(), secondPage.getTitleText()); assertEquals(new String[] {"clicked"}, collectedAlerts); } /** * Regression test for bug 1628521 (NullPointerException when submitting forms). * @throws Exception if the test fails */ @Test public void testSubmit_onSubmitHandler_fails() throws Exception { final String firstHtml = "First\n" + "
          \n" + "
          \n" + ""; final String secondHtml = "Second"; final WebClient client = new WebClient(); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setDefaultResponse(secondHtml); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlSubmitInput button = firstPage.getHtmlElementById("button"); final HtmlPage secondPage = button.click(); assertEquals("Second", secondPage.getTitleText()); } /** * @throws Exception if the test fails */ @Test public void testSubmit_onSubmitHandler_javascriptDisabled() throws Exception { final String firstHtml = "First\n" + "
          \n" + "
          \n" + ""; final String secondHtml = "Second"; final WebClient client = new WebClient(); client.setJavaScriptEnabled(false); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setDefaultResponse(secondHtml); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlSubmitInput button = firstPage.getHtmlElementById("button"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = (HtmlPage) button.click(); assertEquals("First", firstPage.getTitleText()); assertEquals("Second", secondPage.getTitleText()); assertEquals(Collections.EMPTY_LIST, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testSubmit_javascriptAction() throws Exception { final String firstHtml = "First\n" + "
          \n" + "
          \n" + ""; final String secondHtml = "Second"; final WebClient client = new WebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setResponse(URL_SECOND, secondHtml); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlSubmitInput button = firstPage.getHtmlElementById("button"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = button.click(); assertEquals(firstPage.getTitleText(), secondPage.getTitleText()); assertEquals(new String[] {"clicked"}, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testSubmit_javascriptAction_javascriptDisabled() throws Exception { final String html = "First\n" + "
          \n" + "
          \n" + ""; final WebClient client = new WebClient(); client.setJavaScriptEnabled(false); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlSubmitInput button = firstPage.getHtmlElementById("button"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = (HtmlPage) button.click(); assertSame(firstPage, secondPage); } /** * Regression test for a bug that caused a NullPointer exception to be thrown during submit. * @throws Exception if the test fails */ @Test public void testSubmitRadioButton() throws Exception { final String html = "
          \n" + "\n" + "\n" + "\n" + "
          " + "Option 1
          \n" + "Option 2
          Option 3
          \n" + ""; final HtmlPage page = loadPage(html); final HtmlSubmitInput loginButton = page.getDocumentElement().getOneHtmlElementByAttribute("input", "value", "Login"); loginButton.click(); } /** * @throws Exception if the test fails */ @Test public void testReset_onResetHandler() throws Exception { final String html = "First\n" + "
          \n" + "
          \n" + ""; final List collectedAlerts = new ArrayList(); final HtmlPage firstPage = loadPage(html, collectedAlerts); final HtmlResetInput button = (HtmlResetInput) firstPage.getHtmlElementById("button"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = (HtmlPage) button.click(); assertSame(firstPage, secondPage); final String[] expectedAlerts = {"clicked", "reset"}; assertEquals(expectedAlerts, collectedAlerts); } /** *

          Simulate a bug report where an anchor contained JavaScript that caused a form submit. * According to the bug report, the form would be submitted even though the onsubmit * handler would return false. This wasn't reproducible but I added a test for it anyway.

          * *

          UPDATE: If the form submit is triggered by JavaScript then the onsubmit handler is not * supposed to be called so it doesn't matter what value it returns.

          * @throws Exception if the test fails */ @Test public void testSubmit_AnchorCausesSubmit_onSubmitHandler_returnFalse() throws Exception { final String firstHtml = "First\n" + "\n" + "
          \n" + "
          \n" + "Click me\n" + ""; final String secondHtml = "Second"; final WebClient client = new WebClient(); final List collectedAlerts = new ArrayList(); client.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, firstHtml); webConnection.setDefaultResponse(secondHtml); client.setWebConnection(webConnection); final HtmlPage firstPage = client.getPage(URL_FIRST); final HtmlAnchor anchor = (HtmlAnchor) firstPage.getHtmlElementById("link1"); assertEquals(Collections.EMPTY_LIST, collectedAlerts); final HtmlPage secondPage = (HtmlPage) anchor.click(); assertEquals("Second", secondPage.getTitleText()); assertEquals(Collections.EMPTY_LIST, collectedAlerts); } /** * @throws Exception if the test fails */ @Test public void testSubmit_NoDefaultValue() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlSubmitInput button = form.getInputByName("button"); button.click(); final List expectedParameters = Arrays.asList(new NameValuePair[]{ new NameValuePair("textfield", ""), new NameValuePair("button", "foo") }); final List collectedParameters = webConnection.getLastParameters(); assertEquals(expectedParameters, collectedParameters); } /** * @throws Exception if the test fails */ @Test public void testSubmit_NoNameOnControl() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlSubmitInput button = form.getInputByName("button"); button.click(); final List expectedParameters = Arrays.asList(new NameValuePair[]{new NameValuePair("button", "foo")}); final List collectedParameters = webConnection.getLastParameters(); assertEquals(expectedParameters, collectedParameters); } /** * @throws Exception if the test fails */ @Test public void testSubmit_NoNameOnButton() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlButton button = page.getHtmlElementById("button"); button.click(); final List expectedParameters = Arrays.asList(new NameValuePair[]{new NameValuePair("textfield", "blah")}); final List collectedParameters = webConnection.getLastParameters(); assertEquals(expectedParameters, collectedParameters); } /** * @throws Exception if the test fails */ @Test public void testSubmit_NestedInput() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + "
          \n" + " \n" + " \n" + " \n" + "
          \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlSubmitInput button = form.getInputByName("button"); button.click(); final List expectedParameters = Arrays.asList(new NameValuePair[]{ new NameValuePair("textfield", "blah"), new NameValuePair("button", "foo") }); final List collectedParameters = webConnection.getLastParameters(); assertEquals(expectedParameters, collectedParameters); } /** * @throws Exception if the test fails */ @Test public void testSubmit_IgnoresDisabledControls() throws Exception { final String html = "foo\n" + "
          \n" + " \n" + " \n" + "
          "; final HtmlPage page = loadPage(html); final MockWebConnection webConnection = getMockConnection(page); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlSubmitInput button = form.getInputByName("button"); button.click(); final List expectedParameters = Arrays.asList(new NameValuePair[]{new NameValuePair("button", "foo")}); final List collectedParameters = webConnection.getLastParameters(); assertEquals(expectedParameters, collectedParameters); } /** * Reset buttons should not be successful controls. * @see Spec * @throws Exception if the test fails */ @Test public void testSubmit_IgnoresResetControls() throws Exception { final String html = "foo\n" + "
          \n" + "