Title: [221996] trunk
Revision
221996
Author
[email protected]
Date
2017-09-13 15:00:13 -0700 (Wed, 13 Sep 2017)

Log Message

Followup (r221805): Address comments and add more tests
https://bugs.webkit.org/show_bug.cgi?id=176732

Patch by Said Abou-Hallawa <[email protected]> on 2017-09-13
Reviewed by Darin Adler.

Source/WebCore:

Test: http/tests/images/decode-slow-load-static-image.html

Code clean up and adding a new test to ensure multiple decode() promises
can be resolved or rejected simultaneously without any issues.

* loader/ImageLoader.cpp:
(WebCore::ImageLoader::decode):
(WebCore::ImageLoader::decodeError):
* loader/ImageLoader.h:
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::decode):
(WebCore::BitmapImage::callDecodingCallbacks):
* platform/graphics/BitmapImage.h:

LayoutTests:

* http/tests/images/decode-slow-load-static-image-expected.txt: Added.
* http/tests/images/decode-slow-load-static-image.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221995 => 221996)


--- trunk/LayoutTests/ChangeLog	2017-09-13 20:56:22 UTC (rev 221995)
+++ trunk/LayoutTests/ChangeLog	2017-09-13 22:00:13 UTC (rev 221996)
@@ -1,3 +1,13 @@
+2017-09-13  Said Abou-Hallawa  <[email protected]>
+
+        Followup (r221805): Address comments and add more tests
+        https://bugs.webkit.org/show_bug.cgi?id=176732
+
+        Reviewed by Darin Adler.
+
+        * http/tests/images/decode-slow-load-static-image-expected.txt: Added.
+        * http/tests/images/decode-slow-load-static-image.html: Added.
+
 2017-09-13  Youenn Fablet  <[email protected]>
 
         Internals clearCacheStorageMemoryRepresentation should return a Promise

Added: trunk/LayoutTests/http/tests/images/decode-slow-load-static-image-expected.txt (0 => 221996)


--- trunk/LayoutTests/http/tests/images/decode-slow-load-static-image-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/decode-slow-load-static-image-expected.txt	2017-09-13 22:00:13 UTC (rev 221996)
@@ -0,0 +1,11 @@
+Test rejecting/resolving multiple decode() promises issued for the same image source.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Decoding an image with unsupported format failed. Result is: EncodingError: Loading error.
+Decoding the image succeeded.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/images/decode-slow-load-static-image.html (0 => 221996)


--- trunk/LayoutTests/http/tests/images/decode-slow-load-static-image.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/decode-slow-load-static-image.html	2017-09-13 22:00:13 UTC (rev 221996)
@@ -0,0 +1,46 @@
+<head>
+    <script src=""
+</head>
+<body>
+    <div></div>
+    <script>
+        function rejectedImageSourceURL() {
+            return "http://127.0.0.1:8000/resources/load-and-stall.php"
+                 + "?name=../../../fast/images/resources/100x100-red.psd" 
+                 + "&mimeType=image%2Fvnd.adobe.photoshop"
+                 + "&stallAt=1024";
+                 + "&stallFor=1";
+        }
+
+        function resolvedImageSourceURL() {
+            return "http://127.0.0.1:8000/resources/load-and-stall.php"
+                 + "?name=../../../fast/images/resources/green-400x400.png" 
+                 + "&mimeType=image%2Fpng"
+                 + "&stallAt=1024";
+                 + "&stallFor=1";
+        }
+
+        function loadImages(imageSourceURL) {
+            var promises = [];
+            for (var index = 0; index < 5; ++index) {
+                var image = new Image;
+                image.src = ""    
+                promises.push(image.decode());
+            }
+            return promises;
+        }
+
+        description("Test rejecting/resolving multiple decode() promises issued for the same image source.");
+        jsTestIsAsync = true;
+
+        Promise.all(loadImages(rejectedImageSourceURL)).catch(reason => {
+            debug("Decoding an image with unsupported format failed. Result is: " + reason);
+
+            Promise.all(loadImages(resolvedImageSourceURL)).then(() => {
+                debug("Decoding the image succeeded.");
+                finishJSTest();
+            });
+        });
+    </script>
+    <script src=""
+</body>

Modified: trunk/Source/WebCore/ChangeLog (221995 => 221996)


--- trunk/Source/WebCore/ChangeLog	2017-09-13 20:56:22 UTC (rev 221995)
+++ trunk/Source/WebCore/ChangeLog	2017-09-13 22:00:13 UTC (rev 221996)
@@ -1,3 +1,24 @@
+2017-09-13  Said Abou-Hallawa  <[email protected]>
+
+        Followup (r221805): Address comments and add more tests
+        https://bugs.webkit.org/show_bug.cgi?id=176732
+
+        Reviewed by Darin Adler.
+
+        Test: http/tests/images/decode-slow-load-static-image.html
+
+        Code clean up and adding a new test to ensure multiple decode() promises
+        can be resolved or rejected simultaneously without any issues.
+
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::decode):
+        (WebCore::ImageLoader::decodeError):
+        * loader/ImageLoader.h:
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::decode):
+        (WebCore::BitmapImage::callDecodingCallbacks):
+        * platform/graphics/BitmapImage.h:
+
 2017-09-13  Youenn Fablet  <[email protected]>
 
         Internals clearCacheStorageMemoryRepresentation should return a Promise

Modified: trunk/Source/WebCore/loader/ImageLoader.cpp (221995 => 221996)


--- trunk/Source/WebCore/loader/ImageLoader.cpp	2017-09-13 20:56:22 UTC (rev 221995)
+++ trunk/Source/WebCore/loader/ImageLoader.cpp	2017-09-13 22:00:13 UTC (rev 221996)
@@ -386,7 +386,7 @@
     }
     
     AtomicString attr = element().imageSourceURL();
-    if (attr.isNull() || stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) {
+    if (stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) {
         decodeError("Missing source URL.");
         return;
     }
@@ -395,11 +395,11 @@
         decode();
 }
 
-void ImageLoader::decodeError(String&& message)
+void ImageLoader::decodeError(const char* message)
 {
     ASSERT(hasPendingDecodePromises());
     for (auto& promise : m_decodingPromises)
-        promise->reject(Exception { EncodingError, WTFMove(message) });
+        promise->reject(Exception { EncodingError, message });
     m_decodingPromises.clear();
 }
 

Modified: trunk/Source/WebCore/loader/ImageLoader.h (221995 => 221996)


--- trunk/Source/WebCore/loader/ImageLoader.h	2017-09-13 20:56:22 UTC (rev 221995)
+++ trunk/Source/WebCore/loader/ImageLoader.h	2017-09-13 22:00:13 UTC (rev 221996)
@@ -95,7 +95,7 @@
     void clearFailedLoadURL();
 
     bool hasPendingDecodePromises() const { return !m_decodingPromises.isEmpty(); }
-    void decodeError(String&&);
+    void decodeError(const char*);
     void decode();
     
     void timerFired();

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (221995 => 221996)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2017-09-13 20:56:22 UTC (rev 221995)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2017-09-13 22:00:13 UTC (rev 221996)
@@ -501,8 +501,11 @@
 
 void BitmapImage::decode(WTF::Function<void()>&& callback)
 {
-    m_decodingCallbacks.append(WTFMove(callback));
+    if (!m_decodingCallbacks)
+        m_decodingCallbacks = std::make_unique<Vector<Function<void()>, 1>>();
 
+    m_decodingCallbacks->append(WTFMove(callback));
+
     if (canAnimate())  {
         if (m_desiredFrameStartTime) {
             internalStartAnimation();
@@ -535,9 +538,11 @@
 
 void BitmapImage::callDecodingCallbacks()
 {
-    for (auto& decodingCallback : m_decodingCallbacks)
+    if (!m_decodingCallbacks)
+        return;
+    for (auto& decodingCallback : *m_decodingCallbacks)
         decodingCallback();
-    m_decodingCallbacks.clear();
+    m_decodingCallbacks = nullptr;
 }
 
 void BitmapImage::imageFrameAvailableAtIndex(size_t index)

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (221995 => 221996)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.h	2017-09-13 20:56:22 UTC (rev 221995)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h	2017-09-13 22:00:13 UTC (rev 221996)
@@ -213,7 +213,7 @@
     RepetitionCount m_repetitionsComplete { RepetitionCountNone }; // How many repetitions we've finished.
     MonotonicTime m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation().
 
-    Vector<Function<void()>, 1> m_decodingCallbacks;
+    std::unique_ptr<Vector<Function<void()>, 1>> m_decodingCallbacks;
     Seconds m_frameDecodingDurationForTesting;
     MonotonicTime m_desiredFrameDecodeTimeForTesting;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to