Skip to content

Commit 53e9727

Browse files
committed
refactor for better timeout handling
1 parent 0ef820d commit 53e9727

File tree

2 files changed

+41
-44
lines changed

2 files changed

+41
-44
lines changed

src/test/java/org/htmlunit/CookieManager4Test.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,47 @@ public void sameSiteIFrameFromSubDomain() throws Exception {
11521152
}
11531153
}
11541154

1155+
/**
1156+
* Test for issue #270.
1157+
* @throws Exception in case of error
1158+
*/
1159+
@Test
1160+
@Alerts("JDSessionID=1234567890")
1161+
public void issue270() throws Exception {
1162+
final List<NameValuePair> responseHeader1 = new ArrayList<>();
1163+
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c"));
1164+
1165+
final String html = "<html>\n"
1166+
+ "<head></head>\n"
1167+
+ "<body><script>\n"
1168+
1169+
+ "function setCookie(name, value, expires, path, domain, secure) {\n"
1170+
+ " var curCookie = name + '=' + escape(value) +\n"
1171+
+ " ((expires) ? '; expires=' + expires.toGMTString() : '') +\n"
1172+
+ " ((path) ? '; path=' + path : '') +\n"
1173+
+ " ((domain) ? '; domain=' + domain : '') +\n"
1174+
+ " ((secure) ? '; secure' : '');\n"
1175+
1176+
+ " document.cookie = curCookie;\n"
1177+
+ "}\n"
1178+
1179+
+ "var now = new Date();\n"
1180+
+ "now.setTime(now.getTime() + 60 * 60 * 1000);\n"
1181+
+ "setCookie('JDSessionID', '1234567890', now, '/', 'htmlunit.org');\n"
1182+
1183+
// + "alert('cookies: ' + document.cookie);\n"
1184+
1185+
+ "</script></body>\n"
1186+
+ "</html>";
1187+
1188+
final URL firstUrl = new URL(URL_HOST1);
1189+
getMockWebConnection().setResponse(firstUrl, html);
1190+
loadPage2(html, firstUrl);
1191+
1192+
loadPage2(HTML_ALERT_COOKIE, firstUrl);
1193+
verifyTitle2(getWebDriver(), getExpectedAlerts());
1194+
}
1195+
11551196
@Override
11561197
protected final WebDriver getWebDriver() {
11571198
final WebDriver driver = super.getWebDriver();

src/test/java/org/htmlunit/CookieManagerTest.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -808,48 +808,4 @@ public void cookieSetFromJSWithoutPathUsesCurrentLocation2() throws Exception {
808808
loadPage2(firstUrl, StandardCharsets.ISO_8859_1);
809809
verifyTitle2(getWebDriver(), getExpectedAlerts());
810810
}
811-
812-
/**
813-
* Test for issue #270.
814-
* @throws Exception in case of error
815-
*
816-
* This requires an entry in your hosts file
817-
* 127.0.0.1 host1.htmlunit.org
818-
*/
819-
@Test
820-
@Alerts("JDSessionID=1234567890")
821-
public void issue270() throws Exception {
822-
final List<NameValuePair> responseHeader1 = new ArrayList<>();
823-
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c"));
824-
825-
final String html = "<html>\n"
826-
+ "<head></head>\n"
827-
+ "<body><script>\n"
828-
829-
+ "function setCookie(name, value, expires, path, domain, secure) {\n"
830-
+ " var curCookie = name + '=' + escape(value) +\n"
831-
+ " ((expires) ? '; expires=' + expires.toGMTString() : '') +\n"
832-
+ " ((path) ? '; path=' + path : '') +\n"
833-
+ " ((domain) ? '; domain=' + domain : '') +\n"
834-
+ " ((secure) ? '; secure' : '');\n"
835-
836-
+ " document.cookie = curCookie;\n"
837-
+ "}\n"
838-
839-
+ "var now = new Date();\n"
840-
+ "now.setTime(now.getTime() + 60 * 60 * 1000);\n"
841-
+ "setCookie('JDSessionID', '1234567890', now, '/', 'htmlunit.org');\n"
842-
843-
// + "alert('cookies: ' + document.cookie);\n"
844-
845-
+ "</script></body>\n"
846-
+ "</html>";
847-
848-
final URL firstUrl = new URL("http://host1.htmlunit.org:" + PORT + "/");
849-
getMockWebConnection().setResponse(firstUrl, html);
850-
loadPage2(html, firstUrl);
851-
852-
loadPage2(HTML_ALERT_COOKIE, firstUrl);
853-
verifyTitle2(getWebDriver(), getExpectedAlerts());
854-
}
855811
}

0 commit comments

Comments
 (0)