use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method loadJavascript.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(CHROME = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "User-Agent: §§USER_AGENT§§", "sec-ch-ua-platform: \"Windows\"", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "User-Agent: §§USER_AGENT§§", "sec-ch-ua-platform: \"Windows\"", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin" }, FF_ESR = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin" }, IE = { "GET /script.js HTTP/1.1", "Accept: §§ACCEPT§§", "Referer: http://localhost:§§PORT§§/", "Accept-Language: en-US,en;q=0.9", "User-Agent: §§USER_AGENT§§", "Accept-Encoding: gzip, deflate", "Host: localhost:§§PORT§§", "Connection: Keep-Alive" })
@HtmlUnitNYI(CHROME = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", // wrong
"Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", // wrong
"Sec-Fetch-User: ?1", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", // wrong
"Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", // wrong
"Sec-Fetch-User: ?1", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", // wrong
"Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" /* wrong */
}, FF_ESR = { "GET /script.js HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", // wrong
"Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" /* wrong */
})
public void loadJavascript() throws Exception {
String html = "<html><head> <script src=\"script.js\"></script> </head><body></body></html>";
html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" + "\r\n" + html;
final String hi = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/javascript\r\n" + "\r\n" + ";;";
shutDownAll();
try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, html, hi)) {
final WebDriver driver = getWebDriver();
driver.get("http://localhost:" + primitiveWebServer.getPort());
final String[] expectedHeaders = getExpectedAlerts();
for (int i = 0; i < expectedHeaders.length; i++) {
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§PORT§§", "" + primitiveWebServer.getPort());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§USER_AGENT§§", getBrowserVersion().getUserAgent());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§SEC_USER_AGENT§§", getBrowserVersion().getSecClientHintUserAgentHeader());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§ACCEPT§§", getBrowserVersion().getScriptAcceptHeader());
}
final String request = primitiveWebServer.getRequests().get(1);
final String[] headers = request.split("\\r\\n");
assertEquals(Arrays.asList(expectedHeaders).toString(), Arrays.asList(headers).toString());
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method locationSetHref.
/**
* Tests a location href change.
* @throws Exception if the test fails
*/
@Test
@Alerts(CHROME = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin" }, FF_ESR = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin" }, IE = { "GET /foo HTTP/1.1", "Accept: §§ACCEPT§§", "Referer: http://localhost:§§PORT§§/", "Accept-Language: en-US,en;q=0.9", "User-Agent: §§USER_AGENT§§", "Accept-Encoding: gzip, deflate", "Host: localhost:§§PORT§§", "Connection: Keep-Alive" })
@HtmlUnitNYI(CHROME = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-User: ?1", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-User: ?1", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" }, FF_ESR = { "GET /foo HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" })
public void locationSetHref() throws Exception {
final String url = "http://localhost:" + WebTestCase.PORT_PRIMITIVE_SERVER;
String html = "<html><body><script>location.href='" + url + "/foo';</script></body></html>";
html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" + "\r\n" + html;
final String hi = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Hi";
shutDownAll();
try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, html, hi)) {
final WebDriver driver = getWebDriver();
driver.get("http://localhost:" + primitiveWebServer.getPort());
final String[] expectedHeaders = getExpectedAlerts();
for (int i = 0; i < expectedHeaders.length; i++) {
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§PORT§§", "" + primitiveWebServer.getPort());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§USER_AGENT§§", getBrowserVersion().getUserAgent());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§SEC_USER_AGENT§§", getBrowserVersion().getSecClientHintUserAgentHeader());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§ACCEPT§§", getBrowserVersion().getHtmlAcceptHeader());
}
final String request = primitiveWebServer.getRequests().get(1);
final String[] headers = request.split("\\r\\n");
assertEquals(Arrays.asList(expectedHeaders).toString(), Arrays.asList(headers).toString());
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method loadJavascriptCharset.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(CHROME = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "User-Agent: §§USER_AGENT§§", "sec-ch-ua-platform: \"Windows\"", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "User-Agent: §§USER_AGENT§§", "sec-ch-ua-platform: \"Windows\"", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin" }, FF_ESR = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin" }, IE = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Accept: §§ACCEPT§§", "Referer: http://localhost:§§PORT§§/", "Accept-Language: en-US,en;q=0.9", "User-Agent: §§USER_AGENT§§", "Accept-Encoding: gzip, deflate", "Host: localhost:§§PORT§§", "Connection: Keep-Alive" })
@HtmlUnitNYI(CHROME = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", // wrong
"Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", // wrong
"Sec-Fetch-User: ?1", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", // wrong
"Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: no-cors", // wrong
"Sec-Fetch-User: ?1", "Sec-Fetch-Dest: script", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", // wrong
"Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" /* wrong */
}, FF_ESR = { "GET /script.js?x=%CE%D2%CA%C7%CE%D2%B5%C4%20?%20Abc HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", // wrong
"Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: script", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" /* wrong */
})
// PrimitiveWebServer
@NotYetImplemented(value = {}, os = OS.Linux)
public void loadJavascriptCharset() throws Exception {
String html = "<html><head>" + "<meta http-equiv='Content-Type' content='text/html; charset=GB2312'>" + "<script src=\"script.js?x=\u6211\u662F\u6211\u7684 \u4eb8 Abc\"></script>" + "</head><body></body></html>";
html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" + "\r\n" + html;
final String hi = "HTTP/1.1 200 OK\r\n" + "Content-Length: 0\r\n" + "Content-Type: text/javascript\r\n" + "\r\n" + "";
shutDownAll();
try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(Charset.forName("GB2312"), html, hi)) {
final WebDriver driver = getWebDriver();
driver.get("http://localhost:" + primitiveWebServer.getPort());
final String[] expectedHeaders = getExpectedAlerts();
for (int i = 0; i < expectedHeaders.length; i++) {
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§PORT§§", "" + primitiveWebServer.getPort());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§USER_AGENT§§", getBrowserVersion().getUserAgent());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§SEC_USER_AGENT§§", getBrowserVersion().getSecClientHintUserAgentHeader());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§ACCEPT§§", getBrowserVersion().getScriptAcceptHeader());
}
final String request = primitiveWebServer.getRequests().get(1);
final String[] headers = request.split("\\r\\n");
assertEquals(Arrays.asList(expectedHeaders).toString(), Arrays.asList(headers).toString());
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method formGet.
/**
* Tests a form get request.
* @throws Exception if the test fails
*/
@Test
@Alerts(CHROME = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-User: ?1", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-User: ?1", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" }, FF_ESR = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" }, IE = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Accept: §§ACCEPT§§", "Referer: http://localhost:§§PORT§§/", "Accept-Language: en-US,en;q=0.9", "User-Agent: §§USER_AGENT§§", "Accept-Encoding: gzip, deflate", "Host: localhost:§§PORT§§", "Connection: Keep-Alive" })
@HtmlUnitNYI(CHROME = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-User: ?1", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, EDGE = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: Keep-Alive", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Sec-Fetch-Site: same-origin", "Sec-Fetch-Mode: navigate", "Sec-Fetch-User: ?1", "Sec-Fetch-Dest: document", "Referer: http://localhost:§§PORT§§/", "Accept-Encoding: gzip, deflate, br", "Accept-Language: en-US,en;q=0.9" }, FF = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" }, FF_ESR = { "GET /foo?text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21 HTTP/1.1", "Host: localhost:§§PORT§§", "User-Agent: §§USER_AGENT§§", "Accept: §§ACCEPT§§", "Accept-Language: en-US,en;q=0.5", "Accept-Encoding: gzip, deflate", "Connection: Keep-Alive", "Referer: http://localhost:§§PORT§§/", "Upgrade-Insecure-Requests: 1", "Sec-Fetch-Dest: document", "Sec-Fetch-Mode: navigate", "Sec-Fetch-Site: same-origin", "Sec-Fetch-User: ?1" })
public void formGet() throws Exception {
String html = "<html><body><form action='foo' method='get' accept-charset='iso-8859-1'>\n" + "<input name='text1' value='me &amp; you'>\n" + "<textarea name='text2'>Hello\nworld!</textarea>\n" + "<input type='submit' id='submit'>\n" + "</form></body></html>";
html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" + "\r\n" + html;
final String hi = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Hi";
shutDownAll();
try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, html, hi)) {
final WebDriver driver = getWebDriver();
driver.get("http://localhost:" + primitiveWebServer.getPort());
driver.findElement(By.id("submit")).click();
final String[] expectedHeaders = getExpectedAlerts();
for (int i = 0; i < expectedHeaders.length; i++) {
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§PORT§§", "" + primitiveWebServer.getPort());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§USER_AGENT§§", getBrowserVersion().getUserAgent());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§SEC_USER_AGENT§§", getBrowserVersion().getSecClientHintUserAgentHeader());
expectedHeaders[i] = expectedHeaders[i].replaceAll("§§ACCEPT§§", getBrowserVersion().getHtmlAcceptHeader());
}
final String request = primitiveWebServer.getRequests().get(1);
final String[] headers = request.split("\\r\\n");
assertEquals(Arrays.asList(expectedHeaders).toString(), Arrays.asList(headers).toString());
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class CookieManagerTest method setCookieDuring302.
/**
* Test for document.cookie for cookies expired after the page was loaded.
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "cookies: first=1", "cookies: " }, IE = {})
@HtmlUnitNYI(IE = { "cookies: first=1", "cookies: " })
public void setCookieDuring302() throws Exception {
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" + " function alertCookies() {\n" + " alert('cookies: ' + document.cookie);\n" + " }\n" + " function test() {\n" + " alertCookies();\n" + " window.setTimeout(alertCookies, 2500);\n" + " }\n" + "</script></head><body onload='test()'>\n" + "</body></html>";
getMockWebConnection().setDefaultResponse(html);
final URL firstUrl = new URL(URL_FIRST, "/foo/test.html");
final List<NameValuePair> responseHeader1 = new ArrayList<>();
final String expires = DateUtils.formatDate(new Date(System.currentTimeMillis() + 2_000));
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; expires=" + expires + "; path=/foo"));
responseHeader1.add(new NameValuePair("Location", "/foo/content.html"));
getMockWebConnection().setResponse(firstUrl, "", 302, "Moved", MimeType.TEXT_HTML, responseHeader1);
loadPageWithAlerts2(firstUrl, 4_000);
}
Aggregations