LayoutTests/ChangeLog

 12011-09-13 Andy Estes <aestes@apple.com>
 2
 3 Having an empty listener to beforeload events changes the behavior of other scripts
 4 https://bugs.webkit.org/show_bug.cgi?id=45586
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * fast/dom/beforeload/cached-image-before-load-expected.txt: Added.
 9 * fast/dom/beforeload/cached-image-before-load.html: Added.
 10
1112011-09-12 Beth Dakin <bdakin@apple.com>
212
313 https://bugs.webkit.org/show_bug.cgi?id=67898

LayoutTests/fast/dom/beforeload/cached-image-before-load-expected.txt

 1This 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'.
 2
 3PASS: load fired after beforeload for a cached image.
 4PASS: image is 16px wide.
 5

LayoutTests/fast/dom/beforeload/cached-image-before-load.html

 1<script src="resources/print.js"></script>
 2<script>
 3 if (window.layoutTestController) {
 4 layoutTestController.dumpAsText();
 5 layoutTestController.waitUntilDone();
 6 }
 7
 8 window._beforeloadfired = false;
 9
 10 function runTest()
 11 {
 12 document.addEventListener("beforeload", function(event) {
 13 window._beforeloadfired = true;
 14 }, true);
 15
 16 cachedImage = new Image();
 17 document.body.appendChild(cachedImage);
 18 cachedImage.onload = function(event) {
 19 if (window._beforeloadfired)
 20 print("PASS: load fired after beforeload for a cached image.", "green");
 21 else
 22 print("FAIL: load fired before beforeload for a cached image.", "red");
 23
 24 if (this.width == 16)
 25 print("PASS: image is 16px wide.", "green");
 26 else
 27 print("FAIL: image claims not to be 16px wide.", "red");
 28
 29 if (window.layoutTestController)
 30 layoutTestController.notifyDone();
 31 }
 32 cachedImage.src = document.getElementById("originalImage").src;
 33 cachedImage.style.visibility = "hidden";
 34 }
 35</script>
 36<p>This is a regression test for <a href="http://webkit.org/b/45586">http://webkit.org/b/45586</a>. 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>
 37<div id="console"></div>
 38<img id="originalImage" style="visibility:hidden" onload="runTest()" src="../../images/resources/test-load.jpg">

Source/WebCore/ChangeLog

 12011-09-13 Andy Estes <aestes@apple.com>
 2
 3 Having an empty listener to beforeload events changes the behavior of other scripts
 4 https://bugs.webkit.org/show_bug.cgi?id=45586
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Test: fast/dom/beforeload/cached-image-before-load.html
 9
 10 When loading a cached image after a beforeload handler has been
 11 installed on the document, ImageLoader would dispatch both the
 12 beforeload and load events asynchronously in such a way that caused
 13 load to fire first. Since a side effect of firing the beforeload event
 14 is to wire up the CachedImage to its associated RenderImage object,
 15 this work was not done by the time load fired, and scripts that queried
 16 renderer-dependent attributes of the image in an onload handler would
 17 get bogus values in return.
 18
 19 Fix this by ensuring load fires after beforeload in the cached image case.
 20
 21 * loader/ImageLoader.cpp:
 22 (WebCore::ImageLoader::updateFromElement): Call setClient() after
 23 dispatching beforeload, since setClient() will dispatch the load event
 24 if the image is cached.
 25
1262011-09-12 Beth Dakin <bdakin@apple.com>
227
328 https://bugs.webkit.org/show_bug.cgi?id=67898

Source/WebCore/loader/ImageLoader.cpp

@@void ImageLoader::updateFromElement()
202202 m_imageComplete = !newImage;
203203
204204 if (newImage) {
205  newImage->addClient(this);
206205 if (!m_element->document()->hasListenerType(Document::BEFORELOAD_LISTENER))
207206 dispatchPendingBeforeLoadEvent();
208207 else
209208 beforeLoadEventSender().dispatchEventSoon(this);
 209 newImage->addClient(this);
210210 }
211211 if (oldImage)
212212 oldImage->removeClient(this);