Title: [248688] trunk
Revision
248688
Author
drou...@apple.com
Date
2019-08-14 14:59:24 -0700 (Wed, 14 Aug 2019)

Log Message

Web Inspector: support `console.screenshot` with dataURL strings
https://bugs.webkit.org/show_bug.cgi?id=199307

Reviewed by Joseph Pecoraro.

Source/WebCore:

Test: inspector/console/console-screenshot.html

* page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::screenshot):

LayoutTests:

* inspector/console/console-screenshot.html:
* inspector/console/console-screenshot-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (248687 => 248688)


--- trunk/LayoutTests/ChangeLog	2019-08-14 20:33:14 UTC (rev 248687)
+++ trunk/LayoutTests/ChangeLog	2019-08-14 21:59:24 UTC (rev 248688)
@@ -1,3 +1,13 @@
+2019-08-14  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: support `console.screenshot` with dataURL strings
+        https://bugs.webkit.org/show_bug.cgi?id=199307
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/console/console-screenshot.html:
+        * inspector/console/console-screenshot-expected.txt:
+
 2019-08-14  Ryan Haddad  <ryanhad...@apple.com>
 
         [WebAuthN] Enable LocalAuthenticator for macOS

Modified: trunk/LayoutTests/inspector/console/console-screenshot-expected.txt (248687 => 248688)


--- trunk/LayoutTests/inspector/console/console-screenshot-expected.txt	2019-08-14 20:33:14 UTC (rev 248687)
+++ trunk/LayoutTests/inspector/console/console-screenshot-expected.txt	2019-08-14 21:59:24 UTC (rev 248688)
@@ -6,8 +6,11 @@
 CONSOLE MESSAGE: [object ImageData]
 CONSOLE MESSAGE: [object ImageBitmap]
 CONSOLE MESSAGE: [object CanvasRenderingContext2D]
+CONSOLE MESSAGE: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII=
 CONSOLE MESSAGE: Viewport
 CONSOLE MESSAGE: Viewport
+CONSOLE MESSAGE: Viewport
+CONSOLE MESSAGE: Viewport
 Tests for the console.screenshot API.
 
 
@@ -57,6 +60,24 @@
 PASS: The image width should be 2px.
 PASS: The image height should be 2px.
 
+-- Running test case: console.screenshot.String.Base64.Valid
+PASS: The added message should be an image.
+PASS: The image should not be empty.
+PASS: The image width should be 2px.
+PASS: The image height should be 2px.
+
+-- Running test case: console.screenshot.String.Base64.NoContent
+PASS: The added message should be an image.
+PASS: The image should not be empty.
+PASS: The image width should be greater than 2px.
+PASS: The image height should be greater than 2px.
+
+-- Running test case: console.screenshot.String.Base64.Invalid
+PASS: The added message should be an image.
+PASS: The image should not be empty.
+PASS: The image width should be greater than 2px.
+PASS: The image height should be greater than 2px.
+
 -- Running test case: console.screenshot.NonScreenshotableTarget
 PASS: The added message should be an image.
 PASS: The image should not be empty.

Modified: trunk/LayoutTests/inspector/console/console-screenshot.html (248687 => 248688)


--- trunk/LayoutTests/inspector/console/console-screenshot.html	2019-08-14 20:33:14 UTC (rev 248687)
+++ trunk/LayoutTests/inspector/console/console-screenshot.html	2019-08-14 21:59:24 UTC (rev 248688)
@@ -52,32 +52,33 @@
 {
     let suite = InspectorTest.createAsyncSuite("console.screenshot");
 
-    function addTest({name, _expression_, imageMessageAddedCallback, shouldError}) {
+    function addTest({name, _expression_, imageMessageAddedCallback, shouldCaptureViewport, shouldError}) {
         suite.addTestCase({
             name,
-            test(resolve, reject) {
-                let listener = WI.consoleManager.addEventListener(WI.ConsoleManager.Event.MessageAdded, async (event) => {
-                    let {message} = event.data;
+            async test() {
+                let [event] = await Promise.all([
+                    WI.consoleManager.awaitEvent(WI.ConsoleManager.Event.MessageAdded),
+                    InspectorTest.evaluateInPage(_expression_),
+                ]);
 
-                    let isError = message.level === WI.ConsoleMessage.MessageLevel.Error;
-                    if (isError || message.type === WI.ConsoleMessage.MessageType.Image) {
-                        WI.consoleManager.removeEventListener(WI.ConsoleManager.Event.MessageAdded, listener);
+                let {message} = event.data;
 
-                        if (isError)
-                            InspectorTest.expectThat(shouldError, message.messageText);
-                        else
-                            InspectorTest.expectEqual(message.type, WI.ConsoleMessage.MessageType.Image, "The added message should be an image.");
+                if (message.level === WI.ConsoleMessage.MessageLevel.Error) {
+                    InspectorTest.expectThat(shouldError, message.messageText);
+                    return;
+                }
 
-                        if (imageMessageAddedCallback)
-                            await imageMessageAddedCallback(message);
+                InspectorTest.expectEqual(message.type, WI.ConsoleMessage.MessageType.Image, "The added message should be an image.");
+                InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
 
-                        resolve();
-                        return;
-                    }
-                });
-
-                InspectorTest.evaluateInPage(_expression_)
-                .catch(reject);
+                let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
+                if (shouldCaptureViewport) {
+                    InspectorTest.expectGreaterThan(img.width, 2, "The image width should be greater than 2px.");
+                    InspectorTest.expectGreaterThan(img.height, 2, "The image height should be greater than 2px.");
+                } else {
+                    InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
+                    InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
+                }
             },
         });
     }
@@ -85,49 +86,21 @@
     addTest({
         name: "console.screenshot.Node.SingleArgument",
         _expression_: `console.screenshot(document.querySelector("#testNode"))`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
     });
 
     addTest({
         name: "console.screenshot.Node.MultipleArguments",
         _expression_: `console.screenshot(document.querySelector("#testNode"), "test")`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
     });
 
     addTest({
         name: "console.screenshot.Node.DetachedScreenshotable.Image",
         _expression_: `testHTMLImageElement()`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
     });
 
     addTest({
         name: "console.screenshot.Node.DetachedScreenshotable.Picture",
         _expression_: `testHTMLPictureElement()`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
     });
 
     addTest({
@@ -139,61 +112,45 @@
     addTest({
         name: "console.screenshot.ImageData",
         _expression_: `console.screenshot(new ImageData(2, 2))`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
     });
 
     addTest({
         name: "console.screenshot.ImageBitmap",
         _expression_: `testImageBitmap()`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
     });
 
     addTest({
         name: "console.screenshot.CanvasRenderingContext2D",
         _expression_: `console.screenshot(createCanvas2DTest())`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
+    });
 
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectEqual(img.width, 2, "The image width should be 2px.");
-            InspectorTest.expectEqual(img.height, 2, "The image height should be 2px.");
-        },
+    addTest({
+        name: "console.screenshot.String.Base64.Valid",
+        _expression_: `console.screenshot("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII=")`, // 2x2 red square
     });
 
     addTest({
+        name: "console.screenshot.String.Base64.NoContent",
+        _expression_: `console.screenshot("data:image/png;a1=b2;base64,")`,
+        shouldCaptureViewport: true,
+    });
+
+    addTest({
+        name: "console.screenshot.String.Base64.Invalid",
+        _expression_: `console.screenshot("invalid")`,
+        shouldCaptureViewport: true,
+    });
+
+    addTest({
         name: "console.screenshot.NonScreenshotableTarget",
         _expression_: `console.screenshot(42)`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectGreaterThan(img.width, 2, "The image width should be greater than 2px.");
-            InspectorTest.expectGreaterThan(img.height, 2, "The image height should be greater than 2px.");
-        },
+        shouldCaptureViewport: true,
     });
 
     addTest({
         name: "console.screenshot.NoArguments",
         _expression_: `console.screenshot()`,
-        async imageMessageAddedCallback(message) {
-            InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty.");
-
-            let img = await WI.ImageUtilities.promisifyLoad(message.messageText);
-            InspectorTest.expectGreaterThan(img.width, 2, "The image width should be greater than 2px.");
-            InspectorTest.expectGreaterThan(img.height, 2, "The image height should be greater than 2px.");
-        },
+        shouldCaptureViewport: true,
     });
 
     suite.runTestCasesAndFinish();

Modified: trunk/Source/WebCore/ChangeLog (248687 => 248688)


--- trunk/Source/WebCore/ChangeLog	2019-08-14 20:33:14 UTC (rev 248687)
+++ trunk/Source/WebCore/ChangeLog	2019-08-14 21:59:24 UTC (rev 248688)
@@ -1,3 +1,15 @@
+2019-08-14  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: support `console.screenshot` with dataURL strings
+        https://bugs.webkit.org/show_bug.cgi?id=199307
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: inspector/console/console-screenshot.html
+
+        * page/PageConsoleClient.cpp:
+        (WebCore::PageConsoleClient::screenshot):
+
 2019-08-14  Zalan Bujtas  <za...@apple.com>
 
         [ContentChangeObserver] Stop content change observation explicitly.

Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (248687 => 248688)


--- trunk/Source/WebCore/page/PageConsoleClient.cpp	2019-08-14 20:33:14 UTC (rev 248687)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp	2019-08-14 21:59:24 UTC (rev 248688)
@@ -64,6 +64,7 @@
 #include "Settings.h"
 #include <_javascript_Core/ConsoleMessage.h>
 #include <_javascript_Core/JSCInlines.h>
+#include <_javascript_Core/RegularExpression.h>
 #include <_javascript_Core/ScriptArguments.h>
 #include <_javascript_Core/ScriptCallStack.h>
 #include <_javascript_Core/ScriptCallStackFactory.h>
@@ -367,6 +368,15 @@
             }
 
             // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
+        } else {
+            String base64;
+            if (possibleTarget.getString(state, base64)) {
+                JSC::Yarr::RegularExpression regex("^data:image/(?:[^;]+;)+base64,.+$"_s, JSC::Yarr::TextCaseSensitivity::TextCaseInsensitive);
+                if (regex.match(base64) != -1) {
+                    target = possibleTarget;
+                    dataURL = base64;
+                }
+            }
         }
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to