Search in sources :

Example 6 with HtmlUnitNYI

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);
    }
}
Also used : UnexpectedPage(com.gargoylesoftware.htmlunit.UnexpectedPage) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) UnexpectedPage(com.gargoylesoftware.htmlunit.UnexpectedPage) Page(com.gargoylesoftware.htmlunit.Page) BufferedImage(java.awt.image.BufferedImage) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts) HtmlUnitNYI(com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)

Example 7 with HtmlUnitNYI

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

Example 8 with HtmlUnitNYI

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

Example 9 with HtmlUnitNYI

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

Example 10 with HtmlUnitNYI

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);
}
Also used : URL(java.net.URL) 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