Skip to content

Commit

Permalink
refactor for better timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 10, 2025
1 parent 0ef820d commit 53e9727
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
41 changes: 41 additions & 0 deletions src/test/java/org/htmlunit/CookieManager4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,47 @@ public void sameSiteIFrameFromSubDomain() throws Exception {
}
}

/**
* Test for issue #270.
* @throws Exception in case of error
*/
@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"

// + "alert('cookies: ' + document.cookie);\n"

+ "</script></body>\n"
+ "</html>";

final URL firstUrl = new URL(URL_HOST1);
getMockWebConnection().setResponse(firstUrl, html);
loadPage2(html, firstUrl);

loadPage2(HTML_ALERT_COOKIE, firstUrl);
verifyTitle2(getWebDriver(), getExpectedAlerts());
}

@Override
protected final WebDriver getWebDriver() {
final WebDriver driver = super.getWebDriver();
Expand Down
44 changes: 0 additions & 44 deletions src/test/java/org/htmlunit/CookieManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -808,48 +808,4 @@ public void cookieSetFromJSWithoutPathUsesCurrentLocation2() throws Exception {
loadPage2(firstUrl, StandardCharsets.ISO_8859_1);
verifyTitle2(getWebDriver(), getExpectedAlerts());
}

/**
* 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"

// + "alert('cookies: ' + document.cookie);\n"

+ "</script></body>\n"
+ "</html>";

final URL firstUrl = new URL("http://host1.htmlunit.org:" + PORT + "/");
getMockWebConnection().setResponse(firstUrl, html);
loadPage2(html, firstUrl);

loadPage2(HTML_ALERT_COOKIE, firstUrl);
verifyTitle2(getWebDriver(), getExpectedAlerts());
}
}

0 comments on commit 53e9727

Please sign in to comment.