Title: [222055] trunk
Revision
222055
Author
mattba...@apple.com
Date
2017-09-14 15:01:25 -0700 (Thu, 14 Sep 2017)

Log Message

Web Inspector: Color created from an RGB/HSL triplet returns bad component arrays
https://bugs.webkit.org/show_bug.cgi?id=176811
<rdar://problem/34397529>

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

A Color constructed from a format and RGB/HSL triplet should set its
alpha component to 1 instead of leaving it undefined. Color properties
and member functions expect the components array to have a length of four.

* UserInterface/Models/Color.js:
(WI.Color):

LayoutTests:

Add tests for Colors constructed from a format and component array.

* inspector/model/color-expected.txt:
* inspector/model/color.html:
Drive-by cleanup: use InspectorTest.expectShallowEqual.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (222054 => 222055)


--- trunk/LayoutTests/ChangeLog	2017-09-14 22:00:11 UTC (rev 222054)
+++ trunk/LayoutTests/ChangeLog	2017-09-14 22:01:25 UTC (rev 222055)
@@ -1,3 +1,17 @@
+2017-09-14  Matt Baker  <mattba...@apple.com>
+
+        Web Inspector: Color created from an RGB/HSL triplet returns bad component arrays
+        https://bugs.webkit.org/show_bug.cgi?id=176811
+        <rdar://problem/34397529>
+
+        Reviewed by Joseph Pecoraro.
+
+        Add tests for Colors constructed from a format and component array.
+
+        * inspector/model/color-expected.txt:
+        * inspector/model/color.html:
+        Drive-by cleanup: use InspectorTest.expectShallowEqual.
+
 2017-09-14  Ryan Haddad  <ryanhad...@apple.com>
 
         Mark imported/w3c/web-platform-tests/streams/piping/error-propagation-forward.dedicatedworker.html as flaky.

Modified: trunk/LayoutTests/inspector/model/color-expected.txt (222054 => 222055)


--- trunk/LayoutTests/inspector/model/color-expected.txt	2017-09-14 22:00:11 UTC (rev 222054)
+++ trunk/LayoutTests/inspector/model/color-expected.txt	2017-09-14 22:01:25 UTC (rev 222055)
@@ -103,6 +103,28 @@
 PASS: '#11223344' should be serializable as a short Hex
 PASS: '#11223345' should not be serializable as a short Hex
 
+-- Running test case: WI.Color from components
+Check components for color 'rgb(255, 0, 0)'.
+PASS: Should have rgb of [255,0,0].
+PASS: Should have rgba of [255,0,0,1].
+PASS: Should have hsl of [0,100,50].
+PASS: Should have hsla of [0,100,50,1].
+Check components for color 'rgba(128, 128, 128, 0.5)'.
+PASS: Should have rgb of [128,128,128].
+PASS: Should have rgba of [128,128,128,0.5].
+PASS: Should have hsl of [0,0,50].
+PASS: Should have hsla of [0,0,50,0.5].
+Check components for color 'hsl(0, 0%, 50%)'.
+PASS: Should have rgb of [128,128,128].
+PASS: Should have rgba of [128,128,128,1].
+PASS: Should have hsl of [0,0,50].
+PASS: Should have hsla of [0,0,50,1].
+Check components for color 'hsla(0, 0%, 50%, 0.5)'.
+PASS: Should have rgb of [128,128,128].
+PASS: Should have rgba of [128,128,128,0.5].
+PASS: Should have hsl of [0,0,50].
+PASS: Should have hsla of [0,0,50,0.5].
+
 -- Running test case: WI.Color.prototype.nextFormat
 PASS: All format phases of 'transparent' should be as expected.
 PASS: All format phases of 'red' should be as expected.

Modified: trunk/LayoutTests/inspector/model/color.html (222054 => 222055)


--- trunk/LayoutTests/inspector/model/color.html	2017-09-14 22:00:11 UTC (rev 222054)
+++ trunk/LayoutTests/inspector/model/color.html	2017-09-14 22:01:25 UTC (rev 222055)
@@ -115,18 +115,6 @@
         name: "WI.Color properties",
         description: "Test different color properties.",
         test(resolve, reject) {
-            function shallowEqual(arr1, arr2) {
-                if (arr1.length !== arr2.length)
-                    return false;
-
-                for (let i = 0; i < arr1.length; ++i) {
-                    if (arr1[i] !== arr2[i])
-                        return false;
-                }
-
-                return true;
-            }
-
             let color;
 
             color = WI.Color.fromString("red");
@@ -133,10 +121,10 @@
             InspectorTest.expectThat(color.alpha === 1, "'red' should have alpha of 1.");
             InspectorTest.expectThat(color.simple === true, "'red' should be simple.");
             InspectorTest.expectThat(color.isKeyword() === true, "'red' should be a keyword.");
-            InspectorTest.expectThat(shallowEqual(color.rgb, [255, 0, 0]), "'red' has rgb of [255, 0, 0].");
-            InspectorTest.expectThat(shallowEqual(color.rgba, [255, 0, 0, 1]), "'red' has rgba of [255, 0, 0, 1].");
-            InspectorTest.expectThat(shallowEqual(color.hsl, [0, 100, 50]), "'red' has hsl of [0, 100, 50].");
-            InspectorTest.expectThat(shallowEqual(color.hsla, [0, 100, 50, 1]), "'red' has hsla of [0, 100, 50, 1].");
+            InspectorTest.expectShallowEqual(color.rgb, [255, 0, 0], "'red' has rgb of [255, 0, 0].");
+            InspectorTest.expectShallowEqual(color.rgba, [255, 0, 0, 1], "'red' has rgba of [255, 0, 0, 1].");
+            InspectorTest.expectShallowEqual(color.hsl, [0, 100, 50], "'red' has hsl of [0, 100, 50].");
+            InspectorTest.expectShallowEqual(color.hsla, [0, 100, 50, 1], "'red' has hsla of [0, 100, 50, 1].");
             InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === true, "'red' should be serializable as a short Hex");
 
             color = WI.Color.fromString("transparent");
@@ -143,10 +131,10 @@
             InspectorTest.expectThat(color.alpha === 0, "'transparent' should have alpha of 0.");
             InspectorTest.expectThat(color.simple === false, "'transparent' should not be simple.");
             InspectorTest.expectThat(color.isKeyword() === true, "'transparent' should be a keyword.");
-            InspectorTest.expectThat(shallowEqual(color.rgb, [0, 0, 0]), "'transparent' has rgb of [0, 0, 0].");
-            InspectorTest.expectThat(shallowEqual(color.rgba, [0, 0, 0, 0]), "'transparent' has rgba of [0, 0, 0, 0].");
-            InspectorTest.expectThat(shallowEqual(color.hsl, [0, 0, 0]), "'transparent' has hsl of [0, 0, 0].");
-            InspectorTest.expectThat(shallowEqual(color.hsla, [0, 0, 0, 0]), "'transparent' has hsla of [0, 0, 0, 0].");
+            InspectorTest.expectShallowEqual(color.rgb, [0, 0, 0], "'transparent' has rgb of [0, 0, 0].");
+            InspectorTest.expectShallowEqual(color.rgba, [0, 0, 0, 0], "'transparent' has rgba of [0, 0, 0, 0].");
+            InspectorTest.expectShallowEqual(color.hsl, [0, 0, 0], "'transparent' has hsl of [0, 0, 0].");
+            InspectorTest.expectShallowEqual(color.hsla, [0, 0, 0, 0], "'transparent' has hsla of [0, 0, 0, 0].");
             InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === true, "'transparent' should be serializable as a short Hex");
 
             color = WI.Color.fromString("#11122233");
@@ -153,8 +141,8 @@
             InspectorTest.expectThat(color.alpha !== 0, "'#11122233' should not have alpha of 0.");
             InspectorTest.expectThat(color.simple === false, "'#11122233' should be not be simple.");
             InspectorTest.expectThat(color.isKeyword() === false, "'#11122233' should not be a keyword.");
-            InspectorTest.expectThat(shallowEqual(color.rgba, [17, 18, 34, 0.2]), "'#11122233' has rgba of [17, 18, 34, 0.2].");
-            InspectorTest.expectThat(shallowEqual(color.hsla, [236, 33, 10, 0.2]), "'#11122233' has hsla of [236, 33, 10, 0.2].");
+            InspectorTest.expectShallowEqual(color.rgba, [17, 18, 34, 0.2], "'#11122233' has rgba of [17, 18, 34, 0.2].");
+            InspectorTest.expectShallowEqual(color.hsla, [236, 33, 10, 0.2], "'#11122233' has hsla of [236, 33, 10, 0.2].");
             InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === false, "'#11122233' should not be serializable as a short Hex");
 
             color = WI.Color.fromString("#11223344");
@@ -168,6 +156,50 @@
     });
 
     suite.addTestCase({
+        name: "WI.Color from components",
+        description: "Test different three- and four-component colors.",
+        test(resolve, reject) {
+            function test(color, components) {
+                InspectorTest.log(`Check components for color '${color.toString()}'.`);
+                for (let key in components) {
+                    let value = components[key];
+                    InspectorTest.expectShallowEqual(color[key], value, `Should have ${key} of ${JSON.stringify(value)}.`);
+                }
+            }
+
+            test(new WI.Color(WI.Color.Format.RGB, [255, 0, 0]), {
+                rgb: [255, 0, 0],
+                rgba: [255, 0, 0, 1],
+                hsl: [0, 100, 50],
+                hsla: [0, 100, 50, 1],
+            });
+
+            test(new WI.Color(WI.Color.Format.RGBA, [128, 128, 128, 0.5]), {
+                rgb: [128, 128, 128],
+                rgba: [128, 128, 128, 0.5],
+                hsl: [0, 0, 50],
+                hsla: [0, 0, 50, 0.5],
+            });
+
+            test(new WI.Color(WI.Color.Format.HSL, [0, 0, 50]), {
+                rgb: [128, 128, 128],
+                rgba: [128, 128, 128, 1],
+                hsl: [0, 0, 50],
+                hsla: [0, 0, 50, 1],
+            });
+
+            test(new WI.Color(WI.Color.Format.HSLA, [0, 0, 50, 0.5]), {
+                rgb: [128, 128, 128],
+                rgba: [128, 128, 128, 0.5],
+                hsl: [0, 0, 50],
+                hsla: [0, 0, 50, 0.5],
+            });
+
+            resolve();
+        }
+    });
+
+    suite.addTestCase({
         name: "WI.Color.prototype.nextFormat",
         description: "Test we can cycle through color formats for different colors.",
         test(resolve, reject) {

Modified: trunk/Source/WebInspectorUI/ChangeLog (222054 => 222055)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-09-14 22:00:11 UTC (rev 222054)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-09-14 22:01:25 UTC (rev 222055)
@@ -1,3 +1,18 @@
+2017-09-14  Matt Baker  <mattba...@apple.com>
+
+        Web Inspector: Color created from an RGB/HSL triplet returns bad component arrays
+        https://bugs.webkit.org/show_bug.cgi?id=176811
+        <rdar://problem/34397529>
+
+        Reviewed by Joseph Pecoraro.
+
+        A Color constructed from a format and RGB/HSL triplet should set its
+        alpha component to 1 instead of leaving it undefined. Color properties
+        and member functions expect the components array to have a length of four.
+
+        * UserInterface/Models/Color.js:
+        (WI.Color):
+
 2017-09-14  Joseph Pecoraro  <pecor...@apple.com>
 
         Layout test inspector/debugger/breakpoints/resolved-dump-all-pause-locations.html is flaky.

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Color.js (222054 => 222055)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Color.js	2017-09-14 22:00:11 UTC (rev 222054)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Color.js	2017-09-14 22:01:25 UTC (rev 222055)
@@ -33,6 +33,9 @@
     {
         this.format = format;
 
+        if (components.length === 3)
+            components.push(1);
+
         if (format === WI.Color.Format.HSL || format === WI.Color.Format.HSLA)
             this._hsla = components;
         else
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to