Title: [95228] trunk
Revision
95228
Author
aes...@apple.com
Date
2011-09-15 14:21:11 -0700 (Thu, 15 Sep 2011)

Log Message

Having an empty listener to beforeload events changes the behavior of other scripts
https://bugs.webkit.org/show_bug.cgi?id=45586

Reviewed by Darin Adler.

Source/WebCore:

Test: fast/dom/beforeload/cached-image-before-load.html

When loading a cached image after a beforeload handler has been
installed on the document, ImageLoader would dispatch both the
beforeload and load events asynchronously in such a way that caused
load to fire first. Since a side effect of firing the beforeload event
is to wire up the CachedImage to its associated RenderImage object,
this work was not done by the time load fired, and scripts that queried
renderer-dependent attributes of the image in an onload handler would
get bogus values in return.

Fix this by ensuring load fires after beforeload in the cached image case.

* loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateFromElement): Call setClient() after
dispatching beforeload, since setClient() will dispatch the load event
if the image is cached.

LayoutTests:

* fast/dom/beforeload/cached-image-before-load-expected.txt: Added.
* fast/dom/beforeload/cached-image-before-load.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (95227 => 95228)


--- trunk/LayoutTests/ChangeLog	2011-09-15 21:10:27 UTC (rev 95227)
+++ trunk/LayoutTests/ChangeLog	2011-09-15 21:21:11 UTC (rev 95228)
@@ -1,3 +1,13 @@
+2011-09-15  Andy Estes  <aes...@apple.com>
+
+        Having an empty listener to beforeload events changes the behavior of other scripts
+        https://bugs.webkit.org/show_bug.cgi?id=45586
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/beforeload/cached-image-before-load-expected.txt: Added.
+        * fast/dom/beforeload/cached-image-before-load.html: Added.
+
 2011-09-15  Jon Lee  <jon...@apple.com>
 
         Submitting a form with target=_blank works only once

Added: trunk/LayoutTests/fast/dom/beforeload/cached-image-before-load-expected.txt (0 => 95228)


--- trunk/LayoutTests/fast/dom/beforeload/cached-image-before-load-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/beforeload/cached-image-before-load-expected.txt	2011-09-15 21:21:11 UTC (rev 95228)
@@ -0,0 +1,5 @@
+This is a regression test for http://webkit.org/b/45586. It verifies that the beforeload event fires before the load event when loading a cached image, and that the image's style attributes can be queried in the load event handler. On success, you should see two lines of green text starting with the word 'PASS'.
+
+PASS: load fired after beforeload for a cached image.
+PASS: image is 16px wide.
+ 

Added: trunk/LayoutTests/fast/dom/beforeload/cached-image-before-load.html (0 => 95228)


--- trunk/LayoutTests/fast/dom/beforeload/cached-image-before-load.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/beforeload/cached-image-before-load.html	2011-09-15 21:21:11 UTC (rev 95228)
@@ -0,0 +1,38 @@
+<script src=""
+<script>
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+
+    window._beforeloadfired = false;
+
+    function runTest()
+    {
+        document.addEventListener("beforeload", function(event) {
+            window._beforeloadfired = true;
+        }, true);
+
+        cachedImage = new Image();
+        document.body.appendChild(cachedImage);
+        cachedImage._onload_ = function(event) {
+            if (window._beforeloadfired)
+                print("PASS: load fired after beforeload for a cached image.", "green");
+            else
+                print("FAIL: load fired before beforeload for a cached image.", "red");
+                
+            if (this.width == 16)
+                print("PASS: image is 16px wide.", "green");
+            else
+                print("FAIL: image claims not to be 16px wide.", "red");
+
+            if (window.layoutTestController)
+                layoutTestController.notifyDone();
+        }
+        cachedImage.src = ""
+        cachedImage.style.visibility = "hidden";
+    }
+</script>
+<p>This is a regression test for <a href="" It verifies that the beforeload event fires before the load event when loading a cached image, and that the image's style attributes can be queried in the load event handler. On success, you should see two lines of green text starting with the word 'PASS'.</p>
+<div id="console"></div>
+<img id="originalImage" style="visibility:hidden" _onload_="runTest()" src=""

Modified: trunk/Source/WebCore/ChangeLog (95227 => 95228)


--- trunk/Source/WebCore/ChangeLog	2011-09-15 21:10:27 UTC (rev 95227)
+++ trunk/Source/WebCore/ChangeLog	2011-09-15 21:21:11 UTC (rev 95228)
@@ -1,3 +1,28 @@
+2011-09-15  Andy Estes  <aes...@apple.com>
+
+        Having an empty listener to beforeload events changes the behavior of other scripts
+        https://bugs.webkit.org/show_bug.cgi?id=45586
+
+        Reviewed by Darin Adler.
+
+        Test: fast/dom/beforeload/cached-image-before-load.html
+        
+        When loading a cached image after a beforeload handler has been
+        installed on the document, ImageLoader would dispatch both the
+        beforeload and load events asynchronously in such a way that caused
+        load to fire first. Since a side effect of firing the beforeload event
+        is to wire up the CachedImage to its associated RenderImage object,
+        this work was not done by the time load fired, and scripts that queried
+        renderer-dependent attributes of the image in an onload handler would
+        get bogus values in return.
+
+        Fix this by ensuring load fires after beforeload in the cached image case.
+
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::updateFromElement): Call setClient() after
+        dispatching beforeload, since setClient() will dispatch the load event
+        if the image is cached.
+
 2011-09-15  Anders Carlsson  <ander...@apple.com>
 
         Remove ScrollView::platformContentsSize

Modified: trunk/Source/WebCore/loader/ImageLoader.cpp (95227 => 95228)


--- trunk/Source/WebCore/loader/ImageLoader.cpp	2011-09-15 21:10:27 UTC (rev 95227)
+++ trunk/Source/WebCore/loader/ImageLoader.cpp	2011-09-15 21:21:11 UTC (rev 95228)
@@ -202,11 +202,15 @@
         m_imageComplete = !newImage;
 
         if (newImage) {
-            newImage->addClient(this);
             if (!m_element->document()->hasListenerType(Document::BEFORELOAD_LISTENER))
                 dispatchPendingBeforeLoadEvent();
             else
                 beforeLoadEventSender().dispatchEventSoon(this);
+
+            // If newImage is cached, addClient() will result in the load event
+            // being queued to fire. Ensure this happens after beforeload is
+            // dispatched.
+            newImage->addClient(this);
         }
         if (oldImage)
             oldImage->removeClient(this);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to