use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented in project htmlunit by HtmlUnit.
the class CookieManagerTest method cookieExpires_GMT.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "cookie1=1", IE = "cookie1=1; cookie2=2")
@NotYetImplemented(IE)
public void cookieExpires_GMT() throws Exception {
final List<NameValuePair> responseHeader = new ArrayList<>();
responseHeader.add(new NameValuePair("Set-Cookie", "cookie1=1;expires=Sun Jan 20 2042 17:45:00 GMT+0800 (CST)"));
responseHeader.add(new NameValuePair("Set-Cookie", "cookie2=2;expires=Sun Jan 20 2004 17:45:00 GMT+0800 (CST)"));
getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
loadPageWithAlerts2(URL_FIRST);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented in project htmlunit by HtmlUnit.
the class HtmlPage3Test method shouldBeAbleToFindElementByXPathInXmlDocument.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = "error", CHROME = "Something", EDGE = "Something")
@NotYetImplemented({ IE, FF, FF_ESR })
public void shouldBeAbleToFindElementByXPathInXmlDocument() throws Exception {
final String html = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<html xmlns='http://www.w3.org/1999/xhtml'\n" + " xmlns:svg='http://www.w3.org/2000/svg'\n" + " xmlns:xlink='http://www.w3.org/1999/xlink'>\n" + "<body>\n" + " <svg:svg id='chart_container' height='220' width='400'>\n" + " <svg:text y='16' x='200' text-anchor='middle'>Something</svg:text>\n" + " </svg:svg>\n" + "</body>\n" + "</html>\n";
final WebDriver driver = loadPage2(html, URL_FIRST, "application/xhtml+xml", ISO_8859_1, null);
String actual;
try {
final WebElement element = driver.findElement(By.xpath("//svg:svg//svg:text"));
actual = element.getText();
} catch (final NoSuchElementException e) {
actual = "error";
}
assertEquals(getExpectedAlerts()[0], actual);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented in project htmlunit by HtmlUnit.
the class WebSocketTest method wasClean.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000 wasClean: true", "onClose code: 1000 wasClean: true" }, FF = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000 wasClean: false", "onClose code: 1000 wasClean: false" }, FF_ESR = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "§§URL§§", "", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "§§URL§§", "", "null", "onCloseListener code: 1000 wasClean: false", "onClose code: 1000 wasClean: false" }, IE = { "onOpenListener", "onOpen", "open", "[object WebSocket]", "[object WebSocket]", "undefined", "undefined", "undefined", "undefined", "onMessageTextListener", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "", "undefined", "null", "onMessageText", "message", "[object WebSocket]", "[object WebSocket]", "server_text", "", "undefined", "null", "onMessageBinaryListener", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "", "undefined", "null", "onMessageBinary", "message", "[object WebSocket]", "[object WebSocket]", "[object ArrayBuffer]", "", "undefined", "null", "onCloseListener code: 1000 wasClean: true", "onClose code: 1000 wasClean: true" })
@NotYetImplemented({ FF, FF_ESR })
public void wasClean() throws Exception {
expandExpectedAlertsVariables("ws://localhost:" + PORT);
final String expected = String.join("\n", getExpectedAlerts());
startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host", null, null, new EventsWebSocketHandler());
try {
final WebDriver driver = getWebDriver();
driver.get(URL_FIRST + "WebSocketTest_wasClean.html");
final WebElement logElement = driver.findElement(By.id("log"));
final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME;
String text;
do {
Thread.sleep(100);
text = logElement.getAttribute("value").trim().replaceAll("\r", "");
} while (text.length() <= expected.length() && System.currentTimeMillis() < maxWait);
assertEquals(expected, text);
} finally {
stopWebServers();
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented in project htmlunit by HtmlUnit.
the class Window3Test method onloadImg.
/**
* Tests load and error events of 'img' tags.
* Checks that they should be using EventTarget.fireEvent()
* rather than Event.executeEventLocally().
*
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "img2: window at error capture", "img2: document at error capture", "img2: element 2 onerror", "#document: document DOMContentLoaded", "#document: window DOMContentLoaded", "img1: document at load capture", "img1: element 1 onload", "#document: window at load", "#document: window at load capture", "#document: body onload" }, CHROME = { "#document: document DOMContentLoaded", "#document: window DOMContentLoaded", "img2: window at error capture", "img2: document at error capture", "img2: element 2 onerror", "img1: document at load capture", "img1: element 1 onload", "#document: window at load", "#document: window at load capture", "#document: body onload" }, IE = { "img1: document at load capture", "img1: element 1 onload", "#document: document DOMContentLoaded", "#document: window DOMContentLoaded", "#document: window at load", "#document: window at load capture", "#document: body onload", "SCRIPT: document at load capture", "img2: window at error capture", "img2: document at error capture", "img2: element 2 onerror" })
// The extra SCRIPT is not yet handled (waiting on onloadScript())
@NotYetImplemented(IE)
public void onloadImg() throws Exception {
final URL urlImage = new URL(URL_FIRST, "img.jpg");
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
}
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + " function log(msg, target) {\n" + " if (target) msg = (target.id ? target.id : target.nodeName) + ': ' + msg\n" + " window.parent.document.title += msg + ';';\n" + " }\n" + " window.addEventListener('load', function (event) { log('window at load', event.target) })\n" + " window.addEventListener('load', function (event) { " + "log('window at load capture', event.target) }, true)\n" + " window.addEventListener('error', function (event) { log('window at error', event.target) })\n" + " window.addEventListener('error', function (event) { " + "log('window at error capture', event.target) }, true)\n" + " window.addEventListener('DOMContentLoaded', function (event) { " + "log('window DOMContentLoaded', event.target) })\n" + " document.addEventListener('load', function (event) { log('document at load', event.target) })\n" + " document.addEventListener('load', function (event) { " + "log('document at load capture', event.target) }, true)\n" + " document.addEventListener('error', function (event) { log('document at error', event.target) })\n" + " document.addEventListener('error', function (event) { " + "log('document at error capture', event.target) }, true)\n" + " document.addEventListener('DOMContentLoaded', function (event) { " + "log('document DOMContentLoaded', event.target) })\n" + "</script>\n" + "</head>\n" + "<body onload='log(\"body onload\", document)'>\n" + " <img id='img1' src='" + urlImage + "' onload='log(\"element 1 onload\", this)' " + "onerror='log(\"element 1 onerror\", this)'>\n" + " <img id='img2' src='' onload='log(\"element 2 onload\", this)' " + "onerror='log(\"element 2 onerror\", this)'>\n" + "</body></html>";
// Image loads are usually asynchronous in browsers and ordering of these results are somewhat coincidental.
//
// Chrome/FF appears be synchronizing 'body.onload' so that it comes after all image loads, while Chrome
// alone also seems to be synchronizing 'DOMContentLoaded' so that it fires before image loads. IE11 is a mess
// with no clear synchronization between 'body.onload' and image loads.
//
// To preserve a semblance of sanity, we're sorting the results because this test isn't concerned with the
// ordering of img1 vs img2 vs #document (or even images vs 'body.onload'), and instead are only concerned
// the events propagate in correct order once triggered.
final Comparator<String> sorter = Comparator.comparing(s -> StringUtils.substringBefore(s, ":"));
final WebDriver driver = loadPage2(html);
Thread.sleep(200);
final String text = Pattern.compile(";").splitAsStream(driver.getTitle()).map(String::trim).sorted(sorter).collect(Collectors.joining("\n"));
final String expected = Arrays.stream(getExpectedAlerts()).sorted(sorter).collect(Collectors.joining("\n"));
assertEquals(expected, text);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented in project htmlunit by HtmlUnit.
the class Window3Test method onload.
/**
* Tests the ordering of DOMContentLoaded for window and document
* as well as how capturing / bubbling phases are handled.
* Tests the ordering of load for window and document, and how they
* relate to the onload property of 'body'.
* Verifies handling of the at target phase.
* Checks the state of event.eventPhase for a non-bubbling event after the bubbling phase.
*
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "window DOMContentLoaded 1 capture", "window DOMContentLoaded 2 capture", "document DOMContentLoaded 1", "document DOMContentLoaded 1 capture", "document DOMContentLoaded 2", "document DOMContentLoaded 2 capture", "window DOMContentLoaded 1", "window DOMContentLoaded 2", "window at load 1", "window at load 1 capture", "window at load 2", "onload 2", "window at load 2 capture", "after" }, IE = { "window DOMContentLoaded 1 capture", "window DOMContentLoaded 2 capture", "document DOMContentLoaded 1", "document DOMContentLoaded 1 capture", "document DOMContentLoaded 2", "document DOMContentLoaded 2 capture", "window DOMContentLoaded 1", "window DOMContentLoaded 2", "window at load 1", "window at load 1 capture", "window at load 2", "onload 2", "window at load 2 capture", "document at load 1 capture", "document at load 2 capture", "document at load 1 capture", "document at load 2 capture", "after" })
// The extra 'document at load' from <script> not yet handled (waiting on onloadScript())
@NotYetImplemented(IE)
public void onload() throws Exception {
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + " function log(msg) {\n" + " window.parent.document.title += msg + ';';\n" + " }\n" + // obtained via the first parameter of the event function in FF: e.g. function (event) { log('xyz', event) }
" window.addEventListener('load', function () { log('window at load 1') })\n" + " window.addEventListener('load', function () { log('window at load 1 capture') }, true)\n" + // This 'DOMContentLoaded' event targets 'document' and paths [window, document] as expected. (Chrome/FF)
" window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 1') })\n" + " window.addEventListener('DOMContentLoaded', " + "function () { log('window DOMContentLoaded 1 capture') }, true)\n" + " document.addEventListener('load', function () { log('document at load 1') })\n" + " document.addEventListener('load', function () { log('document at load 1 capture') }, true)\n" + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 1') })\n" + " document.addEventListener('DOMContentLoaded', " + "function () { log('document DOMContentLoaded 1 capture') }, true)\n" + "</script>\n" + "</head>\n" + "<body>\n" + "<script>\n" + " window.addEventListener('load', function () { log('window at load 2') })\n" + // window.onload = 123
" window.onload = function () { log('onload 2') }\n" + " window.addEventListener('load', function () { log('window at load 2 capture') }, true)\n" + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 2') })\n" + " window.addEventListener('DOMContentLoaded', " + "function () { log('window DOMContentLoaded 2 capture') }, true)\n" + " document.addEventListener('load', function () { log('document at load 2 capture') }, true)\n" + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 2') })\n" + " document.addEventListener('DOMContentLoaded', " + "function () { log('document DOMContentLoaded 2 capture') }, true)\n" + // This is for testing the state of event.eventPhase afterwards
" window.addEventListener('load', " + "function (event) { var x = event; " + "window.setTimeout(function () { log('after', x.eventPhase) }, 100) }, true)\n" + "</script>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
Thread.sleep(200);
final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
Aggregations