Title: [133747] trunk
Revision
133747
Author
commit-qu...@webkit.org
Date
2012-11-07 05:53:57 -0800 (Wed, 07 Nov 2012)

Log Message

Web Inspector: [Canvas] Save CanvasGradient objects state for a replay
https://bugs.webkit.org/show_bug.cgi?id=101432

Patch by Andrey Adaikin <aand...@chromium.org> on 2012-11-07
Reviewed by Pavel Feldman.

Source/WebCore:

Save CanvasGradient resource state for a subsequent replay. The gradient's state is modified by the gradient.addColorStop() call.

Test: inspector/profiler/canvas2d/canvas2d-gradient-capturing.html

* inspector/InjectedScriptCanvasModuleSource.js:
(.):

LayoutTests:

Alerts about API changes to CanvasGradient and CanvasPattern classes.
Checks capturing for CanvasGradient objects' state.

* inspector/profiler/canvas2d/canvas2d-api-changes-expected.txt:
* inspector/profiler/canvas2d/canvas2d-api-changes.html:
* inspector/profiler/canvas2d/canvas2d-gradient-capturing-expected.txt: Added.
* inspector/profiler/canvas2d/canvas2d-gradient-capturing.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (133746 => 133747)


--- trunk/LayoutTests/ChangeLog	2012-11-07 13:51:00 UTC (rev 133746)
+++ trunk/LayoutTests/ChangeLog	2012-11-07 13:53:57 UTC (rev 133747)
@@ -1,3 +1,18 @@
+2012-11-07  Andrey Adaikin  <aand...@chromium.org>
+
+        Web Inspector: [Canvas] Save CanvasGradient objects state for a replay
+        https://bugs.webkit.org/show_bug.cgi?id=101432
+
+        Reviewed by Pavel Feldman.
+
+        Alerts about API changes to CanvasGradient and CanvasPattern classes.
+        Checks capturing for CanvasGradient objects' state.
+
+        * inspector/profiler/canvas2d/canvas2d-api-changes-expected.txt:
+        * inspector/profiler/canvas2d/canvas2d-api-changes.html:
+        * inspector/profiler/canvas2d/canvas2d-gradient-capturing-expected.txt: Added.
+        * inspector/profiler/canvas2d/canvas2d-gradient-capturing.html: Added.
+
 2012-11-07  Raphael Kubo da Costa  <raphael.kubo.da.co...@intel.com>
 
         [EFL] Unreviewed gardening.

Modified: trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes-expected.txt (133746 => 133747)


--- trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes-expected.txt	2012-11-07 13:51:00 UTC (rev 133746)
+++ trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes-expected.txt	2012-11-07 13:53:57 UTC (rev 133747)
@@ -1,4 +1,6 @@
 Test to catch Canvas 2D API changes. If this test should ever fail, we should re-examine the Canvas 2D state saving/restoring logic in the InjectedScriptModule to include any latest changes to the API.
 
 New properties and functions that should be manually examined (should be empty to pass the test):
+New properties and functions of CanvasGradient object that should be manually examined (should be empty to pass the test):
+New properties and functions of CanvasPattern object that should be manually examined (should be empty to pass the test):
 

Modified: trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html (133746 => 133747)


--- trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html	2012-11-07 13:51:00 UTC (rev 133746)
+++ trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-api-changes.html	2012-11-07 13:53:57 UTC (rev 133747)
@@ -104,6 +104,15 @@
     "webkitPutImageDataHD"
 ];
 
+function collectPropertyNames(obj)
+{
+    var propertyNames = [];
+    for (var property in obj)
+        propertyNames.push(property);
+    propertyNames.sort();
+    return propertyNames;
+}
+
 function test()
 {
     var canvas = document.createElement("canvas");
@@ -112,13 +121,8 @@
         output("ERROR: Could not create canvas 2D context.");
         return;
     }
-
-    var propertyNames = [];
-    for (var property in ctx)
-        propertyNames.push(property);
-    propertyNames.sort();
-
     output("New properties and functions that should be manually examined (should be empty to pass the test):");
+    var propertyNames = collectPropertyNames(ctx);
     var trackedProperties = CanvasRenderingContext2DResource.AttributeProperties.concat(CanvasRenderingContext2DResource.PathMethods, CanvasRenderingContext2DResource.TransformationMatrixMethods, CanvasRenderingContext2DResource.IgnoreProperties);
     for (var i = 0; i < propertyNames.length; ++i) {
         var property = propertyNames[i];
@@ -126,6 +130,29 @@
             continue;
         output(property);
     }
+
+    var gradient = ctx.createLinearGradient(0, 0, 1, 1);
+    if (!gradient) {
+        output("ERROR: Could not create a gradient object.");
+        return;
+    }
+    output("New properties and functions of CanvasGradient object that should be manually examined (should be empty to pass the test):");
+    propertyNames = collectPropertyNames(gradient);
+    for (var i = 0; i < propertyNames.length; ++i) {
+        var property = propertyNames[i];
+        if (property === "addColorStop")
+            continue;
+        output(property);
+    }
+
+    var pattern = ctx.createPattern(new Image(), "repeat");
+    if (!pattern) {
+        output("ERROR: Could not create a pattern object.");
+        return;
+    }
+    output("New properties and functions of CanvasPattern object that should be manually examined (should be empty to pass the test):");
+    for (var property in pattern)
+        output(property);
 }
 
 function runTest()

Added: trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-gradient-capturing-expected.txt (0 => 133747)


--- trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-gradient-capturing-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-gradient-capturing-expected.txt	2012-11-07 13:53:57 UTC (rev 133747)
@@ -0,0 +1,3 @@
+Tests Canvas 2D capturing for CanvasGradient objects.
+
+Bug 101432

Added: trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-gradient-capturing.html (0 => 133747)


--- trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-gradient-capturing.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/profiler/canvas2d/canvas2d-gradient-capturing.html	2012-11-07 13:53:57 UTC (rev 133747)
@@ -0,0 +1,67 @@
+<html>
+<head>
+    <script src=""
+    <script src=""
+<script>
+
+var ctx;
+var rawCtx;
+var ctxResource;
+
+function testCanvasGradientCapturing()
+{
+    var gradient = ctx.createLinearGradient(0, 0, 10, 10);
+    console.assert(gradient, "Failed to create a CanvasGradient object");
+    gradient.addColorStop(0, '#fff');
+    gradient.addColorStop(0.3, '#aaa');
+    gradient.addColorStop(1, '#000');
+
+    var gradientResource = gradient["__resourceObject"];
+    console.assert(gradientResource, "CanvasGradient object is not wrapped");
+
+    var calls = gradientResource.calls();
+    var expectedLength = 4;
+    console.assert(calls.length === expectedLength, "Expected length of the log: " + expectedLength + ", but was: " + calls.length);
+}
+
+function createAndRunCanvas2DProgram()
+{
+    ctx = createCanvas2DContext();
+    console.assert(ctx, "Failed to create 2D context");
+
+    ctxResource = ctx["__resourceObject"];
+    console.assert(ctxResource, "2D context is not wrapped");
+
+    rawCtx = ctxResource.wrappedObject();
+    console.assert(rawCtx, "No raw 2D context found");
+    console.assert(ctx !== rawCtx, "Proxy and RAW contexts should not be the same");
+
+    testCanvasGradientCapturing();
+
+    return "SUCCESS";
+}
+
+function test()
+{
+    InspectorTest.enableCanvasAgent(step1);
+    function step1()
+    {
+        InspectorTest.evaluateInConsole("createAndRunCanvas2DProgram()", step2);
+    }
+    function step2(error)
+    {
+        InspectorTest.assertEquals("\"SUCCESS\"", error);
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+<body _onload_="runTest()">
+<p>
+Tests Canvas 2D capturing for CanvasGradient objects.
+</p>
+<a href="" 101432</a>
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (133746 => 133747)


--- trunk/Source/WebCore/ChangeLog	2012-11-07 13:51:00 UTC (rev 133746)
+++ trunk/Source/WebCore/ChangeLog	2012-11-07 13:53:57 UTC (rev 133747)
@@ -1,3 +1,17 @@
+2012-11-07  Andrey Adaikin  <aand...@chromium.org>
+
+        Web Inspector: [Canvas] Save CanvasGradient objects state for a replay
+        https://bugs.webkit.org/show_bug.cgi?id=101432
+
+        Reviewed by Pavel Feldman.
+
+        Save CanvasGradient resource state for a subsequent replay. The gradient's state is modified by the gradient.addColorStop() call.
+
+        Test: inspector/profiler/canvas2d/canvas2d-gradient-capturing.html
+
+        * inspector/InjectedScriptCanvasModuleSource.js:
+        (.):
+
 2012-11-07  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: [Regression] Snippets evaluations should not appear in Sources tab of navigator.

Modified: trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js (133746 => 133747)


--- trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js	2012-11-07 13:51:00 UTC (rev 133746)
+++ trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js	2012-11-07 13:53:57 UTC (rev 133747)
@@ -879,11 +879,11 @@
     },
 
     /**
-     * @return {Object.<string, Function>}
+     * @return {!Object.<string, Function>}
      */
     _customWrapFunctions: function()
     {
-        return {}; // May be overridden by subclasses.
+        return Object.create(null); // May be overridden by subclasses.
     }
 }
 
@@ -994,6 +994,39 @@
     return (obj instanceof ReplayableResource) ? obj.replay(cache).wrappedObject() : obj;
 }
 
+/**
+ * @constructor
+ * @extends {Resource}
+ */
+function LogEverythingResource(wrappedObject)
+{
+    Resource.call(this, wrappedObject);
+}
+
+LogEverythingResource.prototype = {
+    /**
+     * @override
+     * @return {!Object.<string, Function>}
+     */
+    _customWrapFunctions: function()
+    {
+        var wrapFunctions = Object.create(null);
+        var wrappedObject = this.wrappedObject();
+        if (wrappedObject) {
+            for (var property in wrappedObject) {
+                /** @this Resource.WrapFunction */
+                wrapFunctions[property] = function()
+                {
+                    this._resource.pushCall(this.call());
+                }
+            }
+        }
+        return wrapFunctions;
+    },
+
+    __proto__: Resource.prototype
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // WebGL
 ////////////////////////////////////////////////////////////////////////////////
@@ -1171,13 +1204,12 @@
         this.pushCall(call);
     },
 
-    pushCall_texParameteri: WebGLTextureResource.prototype.pushCall_texParameterf,
-
-    pushCall_copyTexSubImage2D: WebGLTextureResource.prototype.pushCall_copyTexImage2D,
-
     __proto__: WebGLBoundResource.prototype
 }
 
+WebGLTextureResource.prototype.pushCall_texParameteri = WebGLTextureResource.prototype.pushCall_texParameterf;
+WebGLTextureResource.prototype.pushCall_copyTexSubImage2D = WebGLTextureResource.prototype.pushCall_copyTexImage2D;
+
 /**
  * @constructor
  * @extends {Resource}
@@ -1787,7 +1819,7 @@
 
     /**
      * @override
-     * @return {Object.<string, Function>}
+     * @return {!Object.<string, Function>}
      */
     _customWrapFunctions: function()
     {
@@ -2191,7 +2223,7 @@
 
     /**
      * @override
-     * @return {Object.<string, Function>}
+     * @return {!Object.<string, Function>}
      */
     _customWrapFunctions: function()
     {
@@ -2199,10 +2231,9 @@
         if (!wrapFunctions) {
             wrapFunctions = Object.create(null);
 
-            // FIXME: Save state of the CanvasGradient objects.
-            wrapFunctions["createLinearGradient"] = Resource.WrapFunction.resourceFactoryMethod(Resource);
-            wrapFunctions["createRadialGradient"] = Resource.WrapFunction.resourceFactoryMethod(Resource);
-            wrapFunctions["createPattern"] = Resource.WrapFunction.resourceFactoryMethod(Resource);
+            wrapFunctions["createLinearGradient"] = Resource.WrapFunction.resourceFactoryMethod(LogEverythingResource);
+            wrapFunctions["createRadialGradient"] = Resource.WrapFunction.resourceFactoryMethod(LogEverythingResource);
+            wrapFunctions["createPattern"] = Resource.WrapFunction.resourceFactoryMethod(LogEverythingResource);
 
             /**
              * @param {string} methodName
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to