[HtmlUnit] SVN: [14750] trunk/htmlunit/src

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

[HtmlUnit] SVN: [14750] trunk/htmlunit/src

HtmlUnit - Dev mailing list
Revision: 14750
          http://sourceforge.net/p/htmlunit/code/14750
Author:   rbri
Date:     2017-08-01 15:39:26 +0000 (Tue, 01 Aug 2017)
Log Message:
-----------
latest Chrome - bring our impl in sync (wip)

Modified Paths:
--------------
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-01 13:58:48 UTC (rev 14749)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-01 15:39:26 UTC (rev 14750)
@@ -416,6 +416,10 @@
     @BrowserFeature(CHROME)
     HTMLIMAGE_HTMLUNKNOWNELEMENT,
 
+    /** Mark the image as invisible if the download failes. */
+    @BrowserFeature(CHROME)
+    HTMLIMAGE_INVISIBLE_NOT_AVAILABLE,
+
     /** Mark the image as invisible if no src attribute defined. */
     @BrowserFeature({CHROME, FF})
     HTMLIMAGE_INVISIBLE_NO_SRC,

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-08-01 13:58:48 UTC (rev 14749)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-08-01 15:39:26 UTC (rev 14750)
@@ -18,6 +18,7 @@
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_EMPTY_SRC_DISPLAY_FALSE;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_HTMLELEMENT;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_HTMLUNKNOWNELEMENT;
+import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_INVISIBLE_NOT_AVAILABLE;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_INVISIBLE_NO_SRC;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST;
 
@@ -78,6 +79,7 @@
     private int width_ = -1;
     private int height_ = -1;
     private boolean downloaded_;
+    private boolean isComplete_;
     private boolean onloadInvoked_;
     private boolean createdByJavascript_;
 
@@ -137,6 +139,7 @@
                 // onload handlers may need to be invoked again, and a new image may need to be downloaded
                 onloadInvoked_ = false;
                 downloaded_ = false;
+                isComplete_ = false;
                 width_ = -1;
                 height_ = -1;
                 if (imageData_ != null) {
@@ -467,7 +470,8 @@
                 imageData_.close();
                 imageData_ = null;
             }
-            downloaded_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST)
+            downloaded_ = true;
+            isComplete_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST)
                     || (imageWebResponse_ != null && imageWebResponse_.getContentType().contains("image"));
 
             width_ = -1;
@@ -639,10 +643,9 @@
      * @return true if the image was successfully downloaded
      */
     public boolean isComplete() {
-        return downloaded_
-                || (hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST)
-                ? ATTRIBUTE_NOT_DEFINED == getSrcAttribute()
-                : imageData_ != null);
+        return isComplete_ || (hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST)
+                                ? ATTRIBUTE_NOT_DEFINED == getSrcAttribute()
+                                : imageData_ != null);
     }
 
     /**
@@ -666,6 +669,18 @@
                     || (hasFeature(HTMLIMAGE_EMPTY_SRC_DISPLAY_FALSE) && StringUtils.isEmpty(src)))) {
             return false;
         }
+
+        if (hasFeature(HTMLIMAGE_INVISIBLE_NOT_AVAILABLE)) {
+            try {
+                downloadImageIfNeeded();
+                if (imageWebResponse_ == null || !imageWebResponse_.getContentType().contains("image")) {
+                    return false;
+                }
+            }
+            catch (final IOException e) {
+                return false;
+            }
+        }
         return super.isDisplayed();
     }
 

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java 2017-08-01 13:58:48 UTC (rev 14749)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java 2017-08-01 15:39:26 UTC (rev 14750)
@@ -14,6 +14,8 @@
  */
 package com.gargoylesoftware.htmlunit.html;
 
+import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE;
+
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Collections;
@@ -28,6 +30,7 @@
 
 import com.gargoylesoftware.htmlunit.BrowserRunner;
 import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts;
+import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented;
 import com.gargoylesoftware.htmlunit.WebDriverTestCase;
 import com.gargoylesoftware.htmlunit.util.NameValuePair;
 
@@ -85,6 +88,17 @@
         loadImage("src='unknown'");
     }
 
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    @Alerts(DEFAULT = "2",
+            IE = "1")
+    @NotYetImplemented(IE)
+    public void loadImageWrongType() throws Exception {
+        loadImage("src='" + URL_FIRST + "'");
+    }
+
     private void loadImage(final String src) throws Exception {
         try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
             final byte[] directBytes = IOUtils.toByteArray(is);
@@ -97,6 +111,8 @@
             + "<script>\n"
             + "  function test() {\n"
             + "    var img = document.getElementById('myImage');\n"
+            + "    img.width + img.width;\n"
+            + "    img.height + img.height;\n"
             + "  }\n"
             + "</script>\n"
             + "</head><body onload='test()'>\n"
@@ -161,6 +177,16 @@
         isDisplayed("src='unknown.gif'");
     }
 
+    /**
+     * @throws Exception if an error occurs
+     */
+    @Test
+    @Alerts(DEFAULT = "true",
+            CHROME = "false")
+    public void isDisplayedWrongType() throws Exception {
+        isDisplayed("src='" + URL_FIRST + "'");
+    }
+
     private void isDisplayed(final String src) throws Exception {
         try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) {
             final byte[] directBytes = IOUtils.toByteArray(is);


------------------------------------------------------------------------------
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