Search in sources :

Example 46 with HtmlUnitNYI

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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 47 with HtmlUnitNYI

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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 48 with HtmlUnitNYI

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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 49 with HtmlUnitNYI

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;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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 50 with HtmlUnitNYI

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);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) URL(java.net.URL) Date(java.util.Date) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Aggregations

Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)72 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)72 Test (org.junit.Test)68 WebDriver (org.openqa.selenium.WebDriver)54 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)14 URL (java.net.URL)14 WebElement (org.openqa.selenium.WebElement)14 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)11 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)9 ArrayList (java.util.ArrayList)7 InputStream (java.io.InputStream)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 Servlet (javax.servlet.Servlet)2 HttpServlet (javax.servlet.http.HttpServlet)2 Page (com.gargoylesoftware.htmlunit.Page)1 UnexpectedPage (com.gargoylesoftware.htmlunit.UnexpectedPage)1 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1