Search in sources :

Example 6 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method cookie2.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("first=1")
public void cookie2() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1"));
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader1);
    loadPageWithAlerts2(URL_FIRST);
    final List<NameValuePair> responseHeader2 = new ArrayList<>();
    responseHeader2.add(new NameValuePair("Set-Cookie", "second=2"));
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader2);
    setExpectedAlerts("first=1; second=2");
    loadPageWithAlerts2(URL_FIRST);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 7 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method setCookieExpired_badDateFormat.

/**
 * Regression test for bug 3081652: it seems that expiration date should be ignored if format is incorrect.
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "fourth=4; third=3", FF = "first=1; second=2; third=3", FF_ESR = "first=1; second=2; third=3", IE = "first=1; fourth=4; second=2; third=3")
public void setCookieExpired_badDateFormat() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Dec-1-94 16:00:00"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;expires=Dec-1-1994 16:00:00"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "third=3;expires=Dec-1-2094 16:00:00"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "fourth=4;expires=1/1/2000; path=/"));
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader1);
    loadPageWithAlerts2(URL_FIRST);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 8 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method httpOnly.

/**
 * HttpOnly cookies should not be available from JS.
 * @throws Exception if the test fails
 */
@Test
@Alerts("second=2")
public void httpOnly() throws Exception {
    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "first=1; path=/; HttpOnly"));
    responseHeader.add(new NameValuePair("Set-Cookie", "second=2; path=/;"));
    getMockWebConnection().setDefaultResponse("");
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
    final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
    driver.get(URL_FIRST + "foo");
    final Map<String, String> lastHeaders = getMockWebConnection().getLastAdditionalHeaders();
    // strange check, but there is no order
    final String lastCookies = lastHeaders.get(HttpHeader.COOKIE);
    assertEquals(17, lastCookies.length());
    assertTrue("lastCookies: " + lastCookies, lastCookies.contains("first=1") && lastCookies.contains("second=2") && lastCookies.contains("; "));
    if (driver instanceof HtmlUnitDriver) {
        final CookieManager mgr = getWebWindowOf((HtmlUnitDriver) driver).getWebClient().getCookieManager();
        assertEquals(2, mgr.getCookies().size());
        assertTrue(mgr.getCookie("first").isHttpOnly());
        assertFalse(mgr.getCookie("second").isHttpOnly());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 9 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method setCookieExpired.

/**
 * Tests for expiration date.
 * Tests as well for bug 3421201 (with expiration date enclosed with quotes).
 * @throws Exception if the test fails
 */
@Test
@Alerts("second=2; visitor=f2")
public void setCookieExpired() throws Exception {
    // one hour later
    final Date aBitLater = new Date(new Date().getTime() + 60 * 60 * 1000);
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Fri, 02-Jan-1970 00:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;expires=" + DateUtils.formatDate(aBitLater)));
    responseHeader1.add(new NameValuePair("Set-Cookie", "visit=fo; expires=\"Sat, 07-Apr-2002 13:11:33 GMT\";"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "visitor=f2; expires=\"Sat, 07-Apr-2092 13:11:33 GMT\";"));
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader1);
    loadPageWithAlerts2(URL_FIRST);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) Date(java.util.Date) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 10 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method setCookieDifferentPathSlashAtEnd.

/**
 * Response to /a/b sets cookie to /foo/blah.
 * @throws Exception if the test fails
 */
@Test
@Alerts("first=1; second=2")
public void setCookieDifferentPathSlashAtEnd() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/foo"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "second=2; path=/foo/"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "third=3; path=/foo/other"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "fourth=4; path=/other/path"));
    responseHeader1.add(new NameValuePair("Location", "/foo/"));
    getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE);
    final URL firstUrl = new URL(URL_FIRST, "/a/b");
    getMockWebConnection().setResponse(firstUrl, "", 302, "Moved", MimeType.TEXT_HTML, responseHeader1);
    loadPageWithAlerts2(firstUrl);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) URL(java.net.URL) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)1266 Test (org.junit.Test)1261 WebDriver (org.openqa.selenium.WebDriver)894 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)398 URL (java.net.URL)238 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)206 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)159 WebElement (org.openqa.selenium.WebElement)146 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)128 MSXMLTestHelper.callLoadXMLDOMDocumentFromString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callLoadXMLDOMDocumentFromString)101 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)97 ArrayList (java.util.ArrayList)90 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)72 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)54 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)48 XMLDocumentTest.callLoadXMLDocumentFromString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromString)47 XMLDocumentTest.callSerializeXMLDocumentToString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callSerializeXMLDocumentToString)44 File (java.io.File)30 WebClient (com.gargoylesoftware.htmlunit.WebClient)29 InputStream (java.io.InputStream)29