use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HtmlAnchor2Test method clickWithDownloadAttributeDataUrl.
/**
* Not testable with Selenium.
*
* @exception Exception If the test fails
*/
@Test
@Alerts(DEFAULT = { "1", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" }, IE = { "0", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" })
@HtmlUnitNYI(IE = { "1", "First", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAL" + "GPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1l" + "bnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C" + "7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI" + "97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" })
public void clickWithDownloadAttributeDataUrl() throws Exception {
final String html = "<html>\n" + "<head>\n" + " <title>First</title>\n" + "</head>\n" + "<body>\n" + " <a id='clickMe' href='data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP" + "C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA" + "AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J" + "REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq" + "ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0" + "vr4MkhoXe0rZigAAAABJRU5ErkJggg==' download='lora.html'>Click Me</a>\n" + "</body></html>";
getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
final int windowsSize = getWebClient().getWebWindows().size();
final HtmlPage page = loadPage(html);
page.getElementById("clickMe").click();
assertEquals("Should have opened a new window", windowsSize + Integer.parseInt(getExpectedAlerts()[0]), getWebClient().getWebWindows().size());
assertEquals("Should not have navigated away", getExpectedAlerts()[1], page.getTitleText());
final WebWindow dataWindow = getWebClient().getWebWindows().get(getWebClient().getWebWindows().size() - 1);
final Page dataPage = dataWindow.getEnclosedPage();
assertTrue("Should be an UnexpectedPage", dataPage instanceof UnexpectedPage);
try (InputStream resultInputStream = ((UnexpectedPage) dataPage).getInputStream()) {
final ImageInputStream resultImageIS = ImageIO.createImageInputStream(resultInputStream);
final BufferedImage resultBufferedIIS = ImageIO.read(resultImageIS);
compareImages(getExpectedAlerts()[2], null, resultBufferedIIS);
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HtmlScript2Test method deferDynamicExternal.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = { "dcl listener added", "head-end", "end", "deferred-2", "deferred-1", "deferred-3", "dcLoaded", "onload" }, CHROME = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-3", "dcLoaded", "deferred-2", "onload" }, EDGE = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-3", "dcLoaded", "deferred-2", "onload" }, IE = { "dcl listener added", "head-end", "deferred-2", "end", "deferred-1", "deferred-3", "dcLoaded", "onload" })
@HtmlUnitNYI(CHROME = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-2", "deferred-3", "dcLoaded", "onload" }, EDGE = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-2", "deferred-3", "dcLoaded", "onload" }, FF = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-2", "deferred-3", "dcLoaded", "onload" }, FF_ESR = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-2", "deferred-3", "dcLoaded", "onload" }, IE = { "dcl listener added", "head-end", "end", "deferred-1", "deferred-2", "deferred-3", "dcLoaded", "onload" })
public void deferDynamicExternal() throws Exception {
final String html = "<html>\n" + "<head>\n" + " <script>\n" + LOG_TITLE_FUNCTION + " document.addEventListener('DOMContentLoaded', function(event) { log('dcLoaded') });\n" + " log('dcl listener added')</script>" + " </script>\n" + " <script defer src='script1.js'></script>\n" + " <script>\n" + " head = document.getElementsByTagName('head')[0];\n" + " script = document.createElement('script');\n" + " script.setAttribute('defer', 'defer');\n" + " script.setAttribute('src', 'script2.js');\n" + " head.appendChild(script);\n" + " </script>\n" + " <script defer src='script3.js'></script>\n" + " <script>log('head-end')</script>\n" + "</head>\n" + "<body onload='log(\"onload\")'>\n" + " <div id='abc'>Test</div>\n" + "</body>\n" + "<script>log('end')</script>\n" + "</html>";
getMockWebConnection().setResponse(new URL(URL_FIRST, "script1.js"), "log('deferred-1');");
getMockWebConnection().setResponse(new URL(URL_FIRST, "script2.js"), "log('deferred-2');");
getMockWebConnection().setResponse(new URL(URL_FIRST, "script3.js"), "log('deferred-3');");
loadPageVerifyTitle2(html);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HtmlImageInputTest method resolveImageOnChange.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts({ "", "§§URL§§abcd/img.gif", "1", "2" })
@HtmlUnitNYI(CHROME = { "", "§§URL§§abcd/img.gif", "1", "1" }, EDGE = { "", "§§URL§§abcd/img.gif", "1", "1" }, FF = { "", "§§URL§§abcd/img.gif", "1", "1" }, FF_ESR = { "", "§§URL§§abcd/img.gif", "1", "1" }, IE = { "", "§§URL§§abcd/img.gif", "1", "1" })
public void resolveImageOnChange() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-gif.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_FIRST, "abcd/img.gif");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", MimeType.IMAGE_GIF, emptyList);
}
final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " var input = document.getElementById('myInput');\n" + " alert(input.src);\n" + " }\n" + " function update() {\n" + " var input = document.getElementById('myInput');\n" + " input.src='" + URL_FIRST + "abcd/img.gif';\n" + " alert(input.src);\n" + " }\n" + "</script>\n" + "</head>\n" + "<body onload='test()'>\n" + " <input id='myInput' type='image'>\n" + " <button id='myUpdate' onclick='update()'>Update</button>\n" + "</body>\n" + "</html>";
final int startCount = getMockWebConnection().getRequestCount();
final int expectedRequestCount = Integer.parseInt(getExpectedAlerts()[2]);
final int expectedRequestCount2 = Integer.parseInt(getExpectedAlerts()[3]);
expandExpectedAlertsVariables(URL_FIRST);
final String secondUrl = getExpectedAlerts()[1];
setExpectedAlerts(getExpectedAlerts()[0]);
final WebDriver driver = loadPageWithAlerts2(html);
assertEquals(expectedRequestCount, getMockWebConnection().getRequestCount() - startCount);
driver.findElement(By.id("myUpdate")).click();
verifyAlerts(driver, secondUrl);
// CHROME processes the image async
Thread.sleep(400);
assertEquals(expectedRequestCount2, getMockWebConnection().getRequestCount() - startCount);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class HtmlImageInputTest method resolveImage.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts({ "§§URL§§abcd/img.gif", "2" })
@HtmlUnitNYI(CHROME = { "§§URL§§abcd/img.gif", "1" }, EDGE = { "§§URL§§abcd/img.gif", "1" }, FF = { "§§URL§§abcd/img.gif", "1" }, FF_ESR = { "§§URL§§abcd/img.gif", "1" }, IE = { "§§URL§§abcd/img.gif", "1" })
public void resolveImage() throws Exception {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-gif.img")) {
final byte[] directBytes = IOUtils.toByteArray(is);
final URL urlImage = new URL(URL_SECOND, "abcd/img.gif");
final List<NameValuePair> emptyList = Collections.emptyList();
getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", MimeType.IMAGE_GIF, emptyList);
}
final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " var input = document.getElementById('myInput');\n" + " log(input.src);\n" + " }\n" + "</script>\n" + "</head>\n" + "<body onload='test()'>\n" + " <input id='myInput' type='image' src='" + URL_SECOND + "abcd/img.gif'>\n" + "</body>\n" + "</html>";
final int startCount = getMockWebConnection().getRequestCount();
final int expectedRequestCount = Integer.parseInt(getExpectedAlerts()[1]);
expandExpectedAlertsVariables(URL_SECOND);
setExpectedAlerts(getExpectedAlerts()[0]);
loadPageVerifyTitle2(html);
assertEquals(expectedRequestCount, getMockWebConnection().getRequestCount() - startCount);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI in project htmlunit by HtmlUnit.
the class CSSImportRuleTest method mediaQuery.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = { "2", "only screen and (color)", "print and (max-width: 12cm) and (min-width: 30em)", "only screen and (color), print and (max-width: 12cm) and (min-width: 30em)", "@import url(\"imp.css\") only screen and (color), " + "print and (max-width: 12cm) and (min-width: 30em);" }, IE = { "2", "only screen and (color)", "print and (max-width:12cm) and (min-width:30em)", "only screen and (color), print and (max-width:12cm) and (min-width:30em)", "@import url( imp.css ) only screen and (color), print and (max-width:12cm) and (min-width:30em);" })
@HtmlUnitNYI(IE = { "2", "only screen and (color)", "print and (max-width: 12cm) and (min-width: 30em)", "only screen and (color), print and (max-width: 12cm) and (min-width: 30em)", "@import url( imp.css ) only screen and (color), " + "print and (max-width: 12cm) and (min-width: 30em);" })
public void mediaQuery() throws Exception {
final String html = "<html><body>\n" + "<style>\n" + " @import 'imp.css' only screen and (color ),print and ( max-width:12cm) and (min-width: 30em);\n" + "</style>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " var styleSheet = document.styleSheets[0];\n" + " var rule = styleSheet.cssRules[0];\n" + " var mediaList = rule.media;\n" + " log(mediaList.length);\n" + " for (var i = 0; i < mediaList.length; i++) {\n" + " log(mediaList.item(i));\n" + " }\n" + " log(mediaList.mediaText);\n" + " log(rule.cssText);\n" + "</script>\n" + "</body></html>";
final String css = "#d { color: green }";
getMockWebConnection().setResponse(new URL(URL_FIRST, "imp.css"), css, MimeType.TEXT_CSS);
loadPageVerifyTitle2(html);
}
Aggregations