Search in sources :

Example 1 with Alerts

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

the class CookieManagerTest method cookieSetFromJSWithoutPathUsesCurrentLocation2.

/**
 * A cookie set with document.cookie without path applies only for the current path.
 * @throws Exception if the test fails
 */
@Test
@Alerts("first=1")
public void cookieSetFromJSWithoutPathUsesCurrentLocation2() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c"));
    final String html = "<html>\n" + "<head></head>\n" + "<body><script>\n" + "  document.cookie = 'first=new';\n" + "  location.replace('/c/test.html');\n" + "</script></body>\n" + "</html>";
    getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE);
    final URL firstUrl = new URL(URL_FIRST, "/a/b");
    getMockWebConnection().setResponse(firstUrl, html, 200, "Ok", 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)

Example 2 with Alerts

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

the class CookieManagerTest method cookieExpires_GMT.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "cookie1=1", IE = "cookie1=1; cookie2=2")
@NotYetImplemented(IE)
public void cookieExpires_GMT() throws Exception {
    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "cookie1=1;expires=Sun Jan 20 2042 17:45:00 GMT+0800 (CST)"));
    responseHeader.add(new NameValuePair("Set-Cookie", "cookie2=2;expires=Sun Jan 20 2004 17:45:00 GMT+0800 (CST)"));
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
    loadPageWithAlerts2(URL_FIRST);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 3 with Alerts

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

the class CookieManagerTest method issue270.

/**
 * Test for issue #270.
 * @throws Exception in case of error
 *
 * This requires an entry in your hosts file
 * 127.0.0.1       host1.htmlunit.org
 */
@Test
@Alerts("JDSessionID=1234567890")
public void issue270() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c"));
    final String html = "<html>\n" + "<head></head>\n" + "<body><script>\n" + "function setCookie(name, value, expires, path, domain, secure) {\n" + "  var curCookie = name + '=' + escape(value) +\n" + "    ((expires) ? '; expires=' + expires.toGMTString() : '') +\n" + "    ((path) ? '; path=' + path : '') +\n" + "    ((domain) ? '; domain=' + domain : '') +\n" + "    ((secure) ? '; secure' : '');\n" + "  document.cookie = curCookie;\n" + "}\n" + "var now = new Date();\n" + "now.setTime(now.getTime() + 60 * 60 * 1000);\n" + "setCookie('JDSessionID', '1234567890', now, '/', 'htmlunit.org');\n" + "</script></body>\n" + "</html>";
    // [IE] real IE waits for the page to load until infinity
    if (useRealBrowser() && getBrowserVersion().isIE()) {
        Assert.fail("Blocks real IE");
    }
    final URL firstUrl = new URL("http://host1.htmlunit.org:" + PORT + "/");
    getMockWebConnection().setResponse(firstUrl, html);
    loadPage2(html, firstUrl);
    loadPageWithAlerts2(HTML_ALERT_COOKIE, 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)

Example 4 with Alerts

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

the class CookieManagerTest method setCookieExpires_twoDigits.

/**
 * Two digits years should be interpreted as 20xx if before 1970 and as 19xx otherwise.
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "cookie1=1; cookie2=2; cookie3=3", IE = "cookie1=1; cookie2=2; cookie3=3; cookie4=4; cookie5=5; cookie6=6")
public void setCookieExpires_twoDigits() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie1=1;expires=Sun 01-Dec-68 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie2=2;expires=Thu 01-Dec-69 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie3=3;expires=Mon 31-Dec-69 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie4=4;expires=Thu 01-Jan-70 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie5=5;expires=Tue 01-Dec-70 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie6=6;expires=Wed 01-Dec-71 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 5 with Alerts

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

the class CookieManagerTest method orderFromServer.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("a_key=helloA; b_key=helloB; c_key=helloC")
public void orderFromServer() throws Exception {
    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "c_key=helloC"));
    responseHeader.add(new NameValuePair("Set-Cookie", "a_key=helloA"));
    responseHeader.add(new NameValuePair("Set-Cookie", "b_key=helloB"));
    getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
    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)

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