use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HTMLIFrameElement2Test method detachAppendExternalScript.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = { "iframe external script", "loaded", "null", "[object Window]", "about:blank", "iframe external script", "loaded" }, IE = { "iframe external script", "loaded", "null", "[object Window]", "§§URL§§", "iframe external script", "loaded" })
@HtmlUnitNYI(CHROME = { "iframe external script", "loaded", "null", "loaded", "[object Window]", "about:blank", "iframe external script", "loaded" }, EDGE = { "iframe external script", "loaded", "null", "loaded", "[object Window]", "about:blank", "iframe external script", "loaded" }, FF = { "iframe external script", "loaded", "null", "loaded", "[object Window]", "about:blank", "iframe external script", "loaded" }, FF_ESR = { "iframe external script", "loaded", "null", "loaded", "[object Window]", "about:blank", "iframe external script", "loaded" }, IE = { "iframe external script", "loaded", "null", "loaded", "[object Window]", "about:blank", "iframe external script", "loaded" })
public void detachAppendExternalScript() throws Exception {
final String html = "<html>\n" + "<head><script>\n" + " function log(msg) {\n" + " var ta = document.getElementById('myTextArea');\n" + " ta.value += msg + '; ';\n" + " }\n" + " function test() {\n" + " var myFrame = document.getElementById('i');\n" + " var parent = myFrame.parentNode;\n" + " parent.removeChild(myFrame);\n" + " log(myFrame.contentWindow);\n" + " parent.appendChild(myFrame);\n" + " log(myFrame.contentWindow);\n" + " log(myFrame.contentWindow.location);\n" + " }\n" + "</script></head>\n" + " <body>\n" + " <iframe id='i' onload='log(\"loaded\");' src='" + URL_SECOND + "'></iframe>\n" + " <textarea id='myTextArea' cols='80' rows='30'></textarea>\n" + " <button id='clickMe' onclick='test()'>Click Me</button>\n" + " </body>\n" + "</html>";
final String html2 = "<html><body>foo<script src='" + URL_SECOND + "ext.js'></script></body></html>";
getMockWebConnection().setResponse(URL_SECOND, html2);
final String js = "parent.log('iframe external script');";
getMockWebConnection().setResponse(new URL(URL_SECOND, "ext.js"), js, MimeType.APPLICATION_JAVASCRIPT);
final WebDriver driver = loadPage2(html);
Thread.sleep(DEFAULT_WAIT_TIME);
final int start = getMockWebConnection().getRequestCount();
driver.findElement(By.id("clickMe")).click();
Thread.sleep(DEFAULT_WAIT_TIME);
assertEquals(2, getMockWebConnection().getRequestCount() - start);
expandExpectedAlertsVariables(URL_SECOND);
final WebElement textArea = driver.findElement(By.id("myTextArea"));
assertEquals(String.join("; ", getExpectedAlerts()) + "; ", textArea.getAttribute("value"));
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HTMLIFrameElement3Test method recursiveContentRedirectHeader.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "loaded", "6" }, FF_ESR = { "loaded", "19" }, FF = { "loaded", "19" }, IE = { "loaded", "2" })
@BuggyWebDriver(IE = "")
// this kill the real ie
@HtmlUnitNYI(CHROME = { "loaded", "21" }, EDGE = { "loaded", "21" }, FF = { "loaded", "21" }, FF_ESR = { "loaded", "21" }, IE = { "loaded", "21" })
public void recursiveContentRedirectHeader() throws Exception {
final String html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + " <title>Deny</title>\n" + "</head>\n" + "<body>\n" + " <iframe id='frame1' src='content.html' " + "onLoad='alert(\"loaded\")'></iframe>\n" + "</body>\n" + "</html>";
final String content = "<html>" + "<head><title>IFrame Title</title></head>\n" + "<body>IFrame Content\n" + " <iframe id='frame1' src='content.html'></iframe>\n" + "</body>\n" + "</html>";
getMockWebConnection().setDefaultResponse(content);
final List<NameValuePair> headers = new ArrayList<>();
headers.add(new NameValuePair("Location", "content2.html"));
getMockWebConnection().setResponse(new URL(URL_FIRST, "content.html"), "", 302, "Moved", MimeType.TEXT_HTML, headers);
final String[] expectedAlerts = getExpectedAlerts();
setExpectedAlerts(Arrays.copyOf(expectedAlerts, 1));
loadPageWithAlerts2(html);
assertEquals(Integer.parseInt(expectedAlerts[1]), getMockWebConnection().getRequestCount());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HTMLIFrameElement3Test method recursive.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "loaded", "[object HTMLDocument]", "2" }, IE = { "loaded", "[object HTMLDocument]", "1" })
@HtmlUnitNYI(IE = { "loaded", "[object HTMLDocument]", "2" })
public void recursive() throws Exception {
final String html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + " <title>Deny</title>\n" + " <script>\n" + " function check() {\n" + " try {\n" + " alert(document.getElementById(\"frame1\").contentDocument);\n" + " } catch (e) { alert('error'); }\n" + " }\n" + " </script>\n" + "</head>\n" + "<body>\n" + " <iframe id='frame1' src='" + URL_FIRST + "' " + "onLoad='alert(\"loaded\")'></iframe>\n" + " <button type='button' id='clickme' onClick='check()'>Click me</a>\n" + "</body>\n" + "</html>";
final String[] expectedAlerts = getExpectedAlerts();
setExpectedAlerts(Arrays.copyOf(expectedAlerts, 1));
final WebDriver driver = loadPageWithAlerts2(html);
driver.findElement(By.id("clickme")).click();
verifyAlerts(driver, expectedAlerts[1]);
assertEquals(Integer.parseInt(expectedAlerts[2]), getMockWebConnection().getRequestCount());
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HTMLImageElementTest method onload.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = { "error2;error3;error4;load5;", "3" }, FF = { "error2;error3;error4;load5;", "4" }, FF_ESR = { "error2;error3;error4;load5;", "4" })
// at the moment we do not check the image content
@HtmlUnitNYI(CHROME = { "error2;error3;load4;load5;", "3" }, EDGE = { "error2;error3;load4;load5;", "3" }, FF = { "error2;load3;load4;load5;", "4" }, FF_ESR = { "error2;load3;load4;load5;", "4" }, IE = { "error2;error3;load4;load5;", "3" })
public void onload() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_SECOND, "img.jpg");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
getMockWebConnection().setResponse(URL_SECOND, "Test", 200, "OK", MimeType.TEXT_HTML, emptyList);
getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
}
final String html = "<html><head>\n" + "<script>\n" + " function showInfo(text) {\n" + " document.title += text + ';';\n" + " }\n" + "</script>\n" + "</head><body>\n" + " <img id='myImage1' onload='showInfo(\"load1\")' onerror='showInfo(\"error1\")'>\n" + " <img id='myImage2' src='' onload='showInfo(\"load2\")' onerror='showInfo(\"error2\")'>\n" + " <img id='myImage3' src=' ' onload='showInfo(\"load3\")' onerror='showInfo(\"error3\")'>\n" + " <img id='myImage4' src='" + URL_SECOND + "' onload='showInfo(\"load4\")' " + "onerror='showInfo(\"error4\")'>\n" + " <img id='myImage5' src='" + URL_SECOND + "img.jpg' onload='showInfo(\"load5\")' " + "onerror='showInfo(\"error5\")'>\n" + "</body></html>";
final int count = getMockWebConnection().getRequestCount();
final WebDriver driver = getWebDriver();
if (driver instanceof HtmlUnitDriver) {
((HtmlUnitDriver) driver).setDownloadImages(true);
}
loadPage2(html);
assertTitle(driver, getExpectedAlerts()[0]);
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), getMockWebConnection().getRequestCount() - count);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HTMLDocumentTest method lastModifiedAndDate.
/**
* Property lastModified returns the last modification date of the document.
* @throws Exception if the test fails
*/
@Test
@Alerts({ "string", "Fri, 16 Oct 2009 13:59:47 GMT" })
@HtmlUnitNYI(IE = { "string", "Fri, 16 Oct 2009 13:59:47 GMT" })
public void lastModifiedAndDate() throws Exception {
final List<NameValuePair> responseHeaders = new ArrayList<>();
responseHeaders.add(new NameValuePair("Last-Modified", "Fri, 16 Oct 2009 13:59:47 GMT"));
testLastModified(responseHeaders);
// Last-Modified header has priority compared to Date header
responseHeaders.add(new NameValuePair("Date", "Fri, 17 Oct 2009 13:59:47 GMT"));
testLastModified(responseHeaders);
// for some strange reasons, the selenium driven browser is in an invalid
// state after this test
releaseResources();
shutDownAll();
}
Aggregations