use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class XMLSerializerTest method nameSpaces.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "<?xml32version=\"1.0\"32encoding=\"UTF-8\"?>1310<xsl:stylesheet32version=\"1.0\"32" + "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">103232<xsl:template32match=\"/\">103232<html>" + "1032323232<body>1032323232</body>103232</html>103232</xsl:template>10</xsl:stylesheet>", CHROME = "<?xml32version=\"1.0\"32encoding=\"ISO-8859-1\"?><xsl:stylesheet32xmlns:xsl=" + "\"http://www.w3.org/1999/XSL/Transform\"32version=\"1.0\">103232<xsl:template32" + "match=\"/\">103232<html>1032323232<body>1032323232</body>103232</html>103232" + "</xsl:template>10</xsl:stylesheet>", EDGE = "<?xml32version=\"1.0\"32encoding=\"ISO-8859-1\"?><xsl:stylesheet32xmlns:xsl=" + "\"http://www.w3.org/1999/XSL/Transform\"32version=\"1.0\">103232<xsl:template32" + "match=\"/\">103232<html>1032323232<body>1032323232</body>103232</html>103232" + "</xsl:template>10</xsl:stylesheet>", IE = "<xsl:stylesheet32xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"32version=\"1.0\">103232" + "<xsl:template32match=\"/\">103232<html>1032323232<body>1032323232</body>103232</html>103232" + "</xsl:template>10</xsl:stylesheet>")
@HtmlUnitNYI(CHROME = "<xsl:stylesheet32version=\"1.0\"32xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "103232<xsl:template32match=\"/\">103232<html>1032323232<body>1032323232</body>103232</html>" + "103232</xsl:template>10</xsl:stylesheet>", EDGE = "<xsl:stylesheet32version=\"1.0\"32xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "103232<xsl:template32match=\"/\">103232<html>1032323232<body>1032323232</body>103232</html>" + "103232</xsl:template>10</xsl:stylesheet>", FF_ESR = "<xsl:stylesheet32version=\"1.0\"32" + "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">103232<xsl:template32match=\"/\">103232<html>" + "1032323232<body>1032323232</body>103232</html>103232</xsl:template>10</xsl:stylesheet>", FF = "<xsl:stylesheet32version=\"1.0\"32" + "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">103232<xsl:template32match=\"/\">103232<html>" + "1032323232<body>1032323232</body>103232</html>103232</xsl:template>10</xsl:stylesheet>", IE = "<xsl:stylesheet32version=\"1.0\"32" + "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">103232<xsl:template32match=\"/\">103232<html>" + "1032323232<body>1032323232</body>103232</html>103232</xsl:template>10</xsl:stylesheet>")
public void nameSpaces() throws Exception {
final String expectedString = getExpectedAlerts()[0];
setExpectedAlerts();
final String serializationText = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\\n" + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\\n" + " <xsl:template match=\"/\">\\n" + " <html>\\n" + " <body>\\n" + " </body>\\n" + " </html>\\n" + " </xsl:template>\\n" + "</xsl:stylesheet>";
final WebDriver driver = loadPageVerifyTitle2(constructPageContent(serializationText));
final WebElement textArea = driver.findElement(By.id("myTextArea"));
assertEquals(expectedString, textArea.getAttribute("value"));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class XMLHttpRequest5Test method sendBlob307.
@Test
@Alerts({ "text/plain", "HtmlUnit" })
@HtmlUnitNYI(IE = { "application/x-www-form-urlencoded", "null" })
public void sendBlob307() throws Exception {
final URL redirectUrl = new URL(URL_FIRST, "/redirect.html");
final URL responseUrl = new URL(URL_FIRST, "/response.html");
final List<NameValuePair> headers = new ArrayList<>();
headers.add(new NameValuePair("Location", responseUrl.toExternalForm()));
getMockWebConnection().setResponse(redirectUrl, "", 307, "Redirected", null, headers);
getMockWebConnection().setResponse(responseUrl, "Result");
startWebServer(getMockWebConnection(), Charset.defaultCharset());
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title>" + "<script>\n" + " function test() {\n" + " try {\n" + " var xhr = new XMLHttpRequest();\n" + " xhr.open('POST', '/redirect.html', false);\n" + " var body = ['HtmlUnit'];\n" + " var blob = new Blob(body, {type:'text/plain'});\n" + " xhr.send(blob);\n" + " } catch (exception) { \n" + " alert(exception);\n" + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" + "</body></html>";
loadPage2(html);
Assert.assertEquals("Never received a call to '" + responseUrl + "'", responseUrl, getMockWebConnection().getLastWebRequest().getUrl());
Assert.assertEquals(3, getMockWebConnection().getRequestCount());
final String contentType = getMockWebConnection().getLastWebRequest().getAdditionalHeader(HttpHeader.CONTENT_TYPE);
final String requestBody = getMockWebConnection().getLastWebRequest().getRequestBody();
Assert.assertEquals("Unexpected Content-Type header", getExpectedAlerts()[0], contentType == null ? "null" : contentType);
Assert.assertEquals(getExpectedAlerts()[1], requestBody == null ? "null" : requestBody);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class XMLDocumentTest method html.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "[object HTMLDocument]", IE = "[object Document]")
@HtmlUnitNYI(IE = "[object HTMLDocument]")
public void html() throws Exception {
final String svg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<svg xmlns=\"http://www.w3.org/2000/svg\">\n" + " <rect id=\"rect\" width=\"50\" height=\"50\" fill=\"green\" onclick=\"alert(document)\"/>\n" + "</svg>";
final WebDriver driver = loadPage2(svg);
driver.findElement(By.id("rect")).click();
verifyAlerts(driver, getExpectedAlerts());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HttpWebConnection3Test method formPost.
/**
* Tests a form post request.
* @throws Exception if the test fails
*/
@Test
@Alerts(CHROME = { "POST /foo HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "Content-Length: 48", "Cache-Control: max-age=0", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "Origin: http://localhost:§§PORT§§", "Content-Type: application/x-www-form-urlencoded", "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", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, EDGE = { "POST /foo HTTP/1.1", "Host: localhost:§§PORT§§", "Connection: keep-alive", "Content-Length: 48", "Cache-Control: max-age=0", "sec-ch-ua: §§SEC_USER_AGENT§§", "sec-ch-ua-mobile: ?0", "sec-ch-ua-platform: \"Windows\"", "Upgrade-Insecure-Requests: 1", "Origin: http://localhost:§§PORT§§", "Content-Type: application/x-www-form-urlencoded", "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", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, FF = { "POST /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", "Content-Type: application/x-www-form-urlencoded", "Content-Length: 48", "Origin: http://localhost:§§PORT§§", "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", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, FF_ESR = { "POST /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", "Content-Type: application/x-www-form-urlencoded", "Content-Length: 48", "Origin: http://localhost:§§PORT§§", "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", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, IE = { "POST /foo HTTP/1.1", "Accept: §§ACCEPT§§", "Referer: http://localhost:§§PORT§§/", "Accept-Language: en-US,en;q=0.9", "User-Agent: §§USER_AGENT§§", "Content-Type: application/x-www-form-urlencoded", "Accept-Encoding: gzip, deflate", "Host: localhost:§§PORT§§", "Content-Length: 48", "Connection: Keep-Alive", "Cache-Control: no-cache", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" })
@HtmlUnitNYI(CHROME = { "POST /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", "Origin: http://localhost:§§PORT§§", "Cache-Control: max-age=0", "Content-Length: 48", "Content-Type: application/x-www-form-urlencoded", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, EDGE = { "POST /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", "Origin: http://localhost:§§PORT§§", "Cache-Control: max-age=0", "Content-Length: 48", "Content-Type: application/x-www-form-urlencoded", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, FF = { "POST /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", "Origin: http://localhost:§§PORT§§", "Content-Length: 48", "Content-Type: application/x-www-form-urlencoded", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, FF_ESR = { "POST /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", "Origin: http://localhost:§§PORT§§", "Content-Length: 48", "Content-Type: application/x-www-form-urlencoded", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" }, IE = { "POST /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", "Cache-Control: no-cache", "Content-Length: 48", "Content-Type: application/x-www-form-urlencoded", "", "text1=me+%26amp%3B+you&text2=Hello%0D%0Aworld%21" })
public void formPost() throws Exception {
String html = "<html><body><form action='foo' method='post' 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());
Thread.sleep(4_000);
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 HttpWebConnection3Test method locationSetSearch.
/**
* Tests a location href change.
* @throws Exception if the test fails
*/
@Test
@Alerts(CHROME = { "GET /?newSearch 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 /?newSearch 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 /?newSearch 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 /?newSearch 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 /?newSearch 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 /?newSearch 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 /?newSearch 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 /?newSearch 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 /?newSearch 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 locationSetSearch() throws Exception {
String html = "<html><body><script>location.search='newSearch';</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());
}
}
Aggregations