/* * Copyright (c) 2002-2008 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.After; import org.junit.Assert; import org.junit.Test; import org.mortbay.jetty.Server; 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.HttpWebConnectionTest; 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.WebTestCase; import com.gargoylesoftware.htmlunit.html.HtmlElementTest.HtmlAttributeChangeListenerTestImpl; /** * Tests for {@link HtmlPage}. * * @version $Revision$ * @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 WebTestCase { private Server server_; /** * @exception Exception If the test fails */ @Test public void testConstructor() throws Exception { final String htmlContent = "\n" + "
hello world
\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); assertEquals("foo", page.getTitleText()); } /** * @throws Exception if the test fails */ @Test public void testGetInputByName() throws Exception { final String htmlContent = "\n" + "hello world
\n" + "\n" + ""; final HtmlPage page = loadPage(htmlContent); final HtmlForm form = page.getHtmlElementById("form1"); final HtmlInput input = form.getInputByName("textInput1"); Assert.assertEquals("name", "textInput1", input.getNameAttribute()); Assert.assertEquals("value", "textInput1", input.getValueAttribute()); Assert.assertEquals("type", "text", input.getTypeAttribute()); } /** * @throws Exception if the test fails */ @Test public void testFormSubmit() throws Exception { final String htmlContent = "\n" + "hello world
\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 Listhello world
\n" + " \n" + " foo.com\n" + "| Header | \n" + "Data | \n" + "
|---|
hello world
\n" + "| foo |
| \n" + "\n" + "\n" + " |
| \n" + "\n" + "\n" + " |