Search in sources :

Example 31 with HtmlUnitNYI

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.

the class XMLHttpRequestCORSTest method preflight_many_header_values.

/**
 * @throws Exception if the test fails.
 */
@Test
@Alerts(DEFAULT = { "4", "200", "options_headers", "x-ping,x-pong" }, IE = { "4", "200", "options_headers", "x-ping, x-pong" })
@HtmlUnitNYI(IE = { "4", "200", "options_headers", "x-ping,x-pong" })
public void preflight_many_header_values() throws Exception {
    expandExpectedAlertsVariables(new URL("http://localhost:" + PORT));
    final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "var xhr = new XMLHttpRequest();\n" + "function test() {\n" + "  try {\n" + "    var url = 'http://' + window.location.hostname + ':" + PORT2 + "/preflight2';\n" + "    xhr.open('GET', url, false);\n" + "    xhr.setRequestHeader('X-PING', 'ping');\n" + "    xhr.setRequestHeader('X-PONG', 'pong');\n" + "    xhr.send();\n" + "  } catch(e) { log('exception') }\n" + "  log(xhr.readyState);\n" + "  log(xhr.status);\n" + "  log(xhr.responseXML.firstChild.childNodes[3].tagName);\n" + "  log(xhr.responseXML.firstChild.childNodes[3].firstChild.nodeValue);\n" + "}\n" + "</script>\n" + "</head>\n" + "<body onload='test()'></body></html>";
    PreflightServerServlet.ACCESS_CONTROL_ALLOW_ORIGIN_ = "http://localhost:" + PORT;
    PreflightServerServlet.ACCESS_CONTROL_ALLOW_METHODS_ = "POST, GET, OPTIONS";
    PreflightServerServlet.ACCESS_CONTROL_ALLOW_HEADERS_ = "X-PING, X-PONG";
    final Map<String, Class<? extends Servlet>> servlets2 = new HashMap<>();
    servlets2.put("/preflight2", PreflightServerServlet.class);
    startWebServer2(".", null, servlets2);
    loadPage2(html, new URL(URL_FIRST, "/preflight1"));
    verifyTitle2(getWebDriver(), getExpectedAlerts());
}
Also used : HashMap(java.util.HashMap) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) URL(java.net.URL) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 32 with HtmlUnitNYI

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.

the class XMLHttpRequestTest method enctypeBlob.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "application/json", IE = "null")
@HtmlUnitNYI(IE = "application/x-www-form-urlencoded")
public void enctypeBlob() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + "function doTest() {\n" + "  try {\n" + "    var debug = {hello: 'world'};\n" + "    var blob = new Blob([JSON.stringify(debug, null, 2)], {type : 'application/json'});\n" + "    var xhr = new XMLHttpRequest();\n" + "    xhr.open('post', '/test2', false);\n" + "    xhr.send(blob);\n" + "    log('done');\n" + "  } catch (e) {\n" + "    log('error: ' + e.message);\n" + "  }\n" + "}\n" + "</script>\n" + "</head>\n" + "<body onload='doTest()'>\n" + "</body>\n" + "</html>";
    getMockWebConnection().setDefaultResponse("<html><title>Response</title></html>");
    final WebDriver driver = loadPage2(html);
    verifyTitle2(driver, new String[] { "done" });
    String headerValue = getMockWebConnection().getLastWebRequest().getAdditionalHeaders().get(HttpHeader.CONTENT_TYPE);
    // Can't test equality for multipart/form-data as it will have the form:
    // multipart/form-data; boundary=---------------------------42937861433140731107235900
    headerValue = StringUtils.substringBefore(headerValue, ";");
    assertEquals(getExpectedAlerts()[0], "" + headerValue);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 33 with HtmlUnitNYI

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.

the class XMLSerializerTest method htmlAttributes.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "<?xml32version=\"1.0\"32encoding=\"UTF-8\"?>1310<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", CHROME = "<?xml32version=\"1.0\"32encoding=\"ISO-8859-1\"?><html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", EDGE = "<?xml32version=\"1.0\"32encoding=\"ISO-8859-1\"?><html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", IE = "<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body>" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>")
// IE omits the body's ID attribute
@HtmlUnitNYI(CHROME = "<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", EDGE = "<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", FF_ESR = "<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", FF = "<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>", IE = "<html32xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body32id=\"bodyId\">" + "<span32class=\"spanClass\">foo</span>" + "</body>" + "</html>")
public void htmlAttributes() throws Exception {
    final String expectedString = getExpectedAlerts()[0];
    setExpectedAlerts();
    final String serializationText = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>html</title></head>" + "<body id=\"bodyId\">" + "<span class=\"spanClass\">foo</span>" + "</body>" + "</html>";
    final WebDriver driver = loadPageVerifyTitle2(constructPageContent(serializationText));
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(expectedString, textArea.getAttribute("value"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 34 with HtmlUnitNYI

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.

the class Window3Test method scrollByEvents.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "document", "body" }, IE = "document")
@HtmlUnitNYI(IE = { "document", "body" })
public void scrollByEvents() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head>\n" + "<script>\n" + "  function log(msg) {\n" + "    var ta = document.getElementById('myTextArea');\n" + "    ta.value += msg + '; ';\n" + "  }\n" + "  function test() {\n" + "    document.addEventListener('scroll', function(e) { log(\"document\") });\n" + "    window.scrollBy(10, 20);\n" + "  }\n" + "</script>\n" + "</head>\n" + "<body onload='test()' onscroll='log(\"body\")'>\n" + "  <div onscroll='log(\"div\")' style='height: 1000px;'></div>\n" + "  <textarea id='myTextArea' cols='80' rows='30'></textarea>\n" + "</body>\n" + "</html>";
    final WebDriver driver = loadPage2(html);
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 35 with HtmlUnitNYI

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.

the class Window3Test method scrollToEvents.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = { "document", "body" }, IE = "document")
@HtmlUnitNYI(IE = { "document", "body" })
public void scrollToEvents() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head>\n" + "<script>\n" + "  function log(msg) {\n" + "    var ta = document.getElementById('myTextArea');\n" + "    ta.value += msg + '; ';\n" + "  }\n" + "  function test() {\n" + "    document.addEventListener('scroll', function(e) { log(\"document\") });\n" + "    window.scrollTo(10, 20);\n" + "  }\n" + "</script>\n" + "</head>\n" + "<body onload='test()' onscroll='log(\"body\")'>\n" + "  <div onscroll='log(\"div\")' style='height: 1000px;'></div>\n" + "  <textarea id='myTextArea' cols='80' rows='30'></textarea>\n" + "</body>\n" + "</html>";
    final WebDriver driver = loadPage2(html);
    final WebElement textArea = driver.findElement(By.id("myTextArea"));
    assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebElement(org.openqa.selenium.WebElement) 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