[HtmlUnit] SVN: [13724] trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HtmlUnit] SVN: [13724] trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit

asashour-2
Revision: 13724
          http://sourceforge.net/p/htmlunit/code/13724
Author:   asashour
Date:     2017-03-14 07:48:54 +0000 (Tue, 14 Mar 2017)
Log Message:
-----------
Fix HTMLImageElementTest.complete

Modified Paths:
--------------
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-03-14 07:16:52 UTC (rev 13723)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-03-14 07:48:54 UTC (rev 13724)
@@ -1206,7 +1206,7 @@
      * @throws Exception if an error occurs
      * @see #toHtmlElement(WebElement)
      */
-    protected WebWindow getWebWindowOf(final HtmlUnitDriver driver) throws Exception {
+    protected static WebWindow getWebWindowOf(final HtmlUnitDriver driver) throws Exception {
         final Field driverField = HtmlUnitDriver.class.getDeclaredField("driver");
         driverField.setAccessible(true);
         final HtmlUnitLocalDriver localDriver = (HtmlUnitLocalDriver) driverField.get(driver);
@@ -1216,6 +1216,19 @@
     }
 
     /**
+     * Sets whether to automatically download images or not.
+     * @param driver the driver
+     * @param downloadImages whether to automatically download images or not
+     * @throws Exception if an error occurs
+     */
+    protected static void setDownloadImages(final HtmlUnitDriver driver, final boolean downloadImages) throws Exception {
+        final Field driverField = HtmlUnitDriver.class.getDeclaredField("driver");
+        driverField.setAccessible(true);
+        final HtmlUnitLocalDriver localDriver = (HtmlUnitLocalDriver) driverField.get(driver);
+        localDriver.setDownloadImages(downloadImages);
+    }
+
+    /**
      * Whether {@link WebClient} is cached or not, defaults to {@code false}.
      *
      * <p>This is needed to be {@code true} for huge test class, as we could run out of sockets.

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2017-03-14 07:16:52 UTC (rev 13723)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2017-03-14 07:48:54 UTC (rev 13724)
@@ -29,6 +29,7 @@
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
+import org.openqa.selenium.htmlunit.HtmlUnitDriver;
 
 import com.gargoylesoftware.htmlunit.BrowserRunner;
 import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts;
@@ -601,7 +602,6 @@
             + "<script>\n"
             + "  function showInfo(imageId) {\n"
             + "    var img = document.getElementById(imageId);\n"
-            + "    img.width;\n" // this forces image loading in htmlunit
             + "    alert(img.complete);\n"
             + "  }\n"
             + "  function test() {\n"
@@ -617,6 +617,10 @@
             + "  <img id='myImage3' src='" + URL_SECOND + "'>\n"
             + "  <img id='myImage4' src='" + URL_SECOND + "img.jpg'>\n"
             + "</body></html>";
+        final WebDriver driver = getWebDriver();
+        if (driver instanceof HtmlUnitDriver) {
+            setDownloadImages((HtmlUnitDriver) driver, true);
+        }
 
         loadPageWithAlerts2(html);
     }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...