Search in sources :

Example 16 with Alerts

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

the class CookieManagerTest method cookieExpires_badDateFormat.

/**
 * Test some formating errors.
 * @throws Exception if the test fails
 */
@Test
@Alerts("fifth=5; first=1; fourth=4; second=2; sixth=6; third=3")
public void cookieExpires_badDateFormat() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Thu 01-Dec-42 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;expires=Thu 01 Dec 42 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "third=3;expires=Thu, 01-Dec-42 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "fourth=4;expires=Thu, 01 Dec 42 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "fifth=5;expires=Thu,01-Dec-42 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "sixth=6;expires=Thu,01 Dec 42 16:00:00 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) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 17 with Alerts

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

the class CookieManagerTest method setCookieSubPath.

/**
 * Response to / sets cookie to /foo/blah.
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "first=1; second=2", IE = "first=1")
public void setCookieSubPath() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;path=/foo/blah"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;path=/foo/blah/test"));
    responseHeader1.add(new NameValuePair("Location", "/foo/blah/test"));
    getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE);
    getMockWebConnection().setResponse(URL_FIRST, "", 302, "Moved", 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 18 with Alerts

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

the class CookieManagerTest method trailing_slash.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts({ "", "dog=dalmation" })
public void trailing_slash() throws Exception {
    final String[] expectedAlerts = getExpectedAlerts();
    final WebDriver driver = getWebDriver();
    setExpectedAlerts(expectedAlerts[0]);
    loadPageWithAlerts2(HTML_ALERT_COOKIE, URL_SECOND);
    setExpectedAlerts(expectedAlerts[1]);
    driver.manage().addCookie(new org.openqa.selenium.Cookie("dog", "dalmation", "/second/"));
    loadPageWithAlerts2(HTML_ALERT_COOKIE, URL_SECOND);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 19 with Alerts

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

the class DefaultCredentialsProvider2Test method basicAuthenticationUserFromUrlOverwrite.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("SecRet")
public void basicAuthenticationUserFromUrlOverwrite() throws Exception {
    final String html = "<html><body onload='alert(\"SecRet\")'></body></html>";
    getMockWebConnection().setDefaultResponse(html);
    getWebClient().getCredentialsProvider().clear();
    try {
        // no credentials
        loadPage(html, URL_FIRST);
        fail("Should not be authorized");
    } catch (final FailingHttpStatusCodeException e) {
    // success
    }
    final boolean urlWithCredentials = !getBrowserVersion().isIE();
    try {
        // now a url with credentials
        final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
        loadPageWithAlerts(url);
        if (!urlWithCredentials) {
            fail("Should not be authorized");
        }
    } catch (final FailingHttpStatusCodeException e) {
        if (urlWithCredentials) {
            throw e;
        }
    }
    try {
        // next step without credentials but the credentials are still known
        loadPageWithAlerts(URL_FIRST);
        if (!urlWithCredentials) {
            fail("Should not be authorized");
        }
    } catch (final FailingHttpStatusCodeException e) {
        if (urlWithCredentials) {
            throw e;
        }
    }
    try {
        final URL url = new URL("http://jetty:wrong@localhost:" + PORT + "/");
        loadPage(html, url);
        fail("Should not be authorized");
    } catch (final FailingHttpStatusCodeException e) {
    // success
    }
}
Also used : URL(java.net.URL) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 20 with Alerts

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

the class DefaultCredentialsProvider2Test method basicAuthenticationUserFromUrlOverwriteWrongDefaultCredentials.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("SecRet")
public void basicAuthenticationUserFromUrlOverwriteWrongDefaultCredentials() throws Exception {
    final String html = "<html><body onload='alert(\"SecRet\")'></body></html>";
    getMockWebConnection().setDefaultResponse(html);
    getWebClient().getCredentialsProvider().clear();
    ((DefaultCredentialsProvider) getWebClient().getCredentialsProvider()).addCredentials("joe", "hack");
    // use default wrong credentials
    try {
        loadPage(html, URL_FIRST);
        fail("Should not be authorized");
    } catch (final FailingHttpStatusCodeException e) {
    // success
    }
    final boolean urlWithCredentials = !getBrowserVersion().isIE();
    try {
        // now a url with correct credentials
        final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
        loadPageWithAlerts(url);
        if (!urlWithCredentials) {
            fail("Should not be authorized");
        }
    } catch (final FailingHttpStatusCodeException e) {
        if (urlWithCredentials) {
            throw e;
        }
    }
}
Also used : URL(java.net.URL) 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