Changeset 222055 in webkit


Ignore:
Timestamp:
Sep 14, 2017 3:01:25 PM (7 years ago)
Author:
Matt Baker
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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r222054 r222055  
     12017-09-14  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Color created from an RGB/HSL triplet returns bad component arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=176811
     5        <rdar://problem/34397529>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Add tests for Colors constructed from a format and component array.
     10
     11        * inspector/model/color-expected.txt:
     12        * inspector/model/color.html:
     13        Drive-by cleanup: use InspectorTest.expectShallowEqual.
     14
    1152017-09-14  Ryan Haddad  <ryanhaddad@apple.com>
    216
  • trunk/LayoutTests/inspector/model/color-expected.txt

    r220119 r222055  
    104104PASS: '#11223345' should not be serializable as a short Hex
    105105
     106-- Running test case: WI.Color from components
     107Check components for color 'rgb(255, 0, 0)'.
     108PASS: Should have rgb of [255,0,0].
     109PASS: Should have rgba of [255,0,0,1].
     110PASS: Should have hsl of [0,100,50].
     111PASS: Should have hsla of [0,100,50,1].
     112Check components for color 'rgba(128, 128, 128, 0.5)'.
     113PASS: Should have rgb of [128,128,128].
     114PASS: Should have rgba of [128,128,128,0.5].
     115PASS: Should have hsl of [0,0,50].
     116PASS: Should have hsla of [0,0,50,0.5].
     117Check components for color 'hsl(0, 0%, 50%)'.
     118PASS: Should have rgb of [128,128,128].
     119PASS: Should have rgba of [128,128,128,1].
     120PASS: Should have hsl of [0,0,50].
     121PASS: Should have hsla of [0,0,50,1].
     122Check components for color 'hsla(0, 0%, 50%, 0.5)'.
     123PASS: Should have rgb of [128,128,128].
     124PASS: Should have rgba of [128,128,128,0.5].
     125PASS: Should have hsl of [0,0,50].
     126PASS: Should have hsla of [0,0,50,0.5].
     127
    106128-- Running test case: WI.Color.prototype.nextFormat
    107129PASS: All format phases of 'transparent' should be as expected.
  • trunk/LayoutTests/inspector/model/color.html

    r220119 r222055  
    116116        description: "Test different color properties.",
    117117        test(resolve, reject) {
    118             function shallowEqual(arr1, arr2) {
    119                 if (arr1.length !== arr2.length)
    120                     return false;
    121 
    122                 for (let i = 0; i < arr1.length; ++i) {
    123                     if (arr1[i] !== arr2[i])
    124                         return false;
    125                 }
    126 
    127                 return true;
    128             }
    129 
    130118            let color;
    131119
     
    134122            InspectorTest.expectThat(color.simple === true, "'red' should be simple.");
    135123            InspectorTest.expectThat(color.isKeyword() === true, "'red' should be a keyword.");
    136             InspectorTest.expectThat(shallowEqual(color.rgb, [255, 0, 0]), "'red' has rgb of [255, 0, 0].");
    137             InspectorTest.expectThat(shallowEqual(color.rgba, [255, 0, 0, 1]), "'red' has rgba of [255, 0, 0, 1].");
    138             InspectorTest.expectThat(shallowEqual(color.hsl, [0, 100, 50]), "'red' has hsl of [0, 100, 50].");
    139             InspectorTest.expectThat(shallowEqual(color.hsla, [0, 100, 50, 1]), "'red' has hsla of [0, 100, 50, 1].");
     124            InspectorTest.expectShallowEqual(color.rgb, [255, 0, 0], "'red' has rgb of [255, 0, 0].");
     125            InspectorTest.expectShallowEqual(color.rgba, [255, 0, 0, 1], "'red' has rgba of [255, 0, 0, 1].");
     126            InspectorTest.expectShallowEqual(color.hsl, [0, 100, 50], "'red' has hsl of [0, 100, 50].");
     127            InspectorTest.expectShallowEqual(color.hsla, [0, 100, 50, 1], "'red' has hsla of [0, 100, 50, 1].");
    140128            InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === true, "'red' should be serializable as a short Hex");
    141129
     
    144132            InspectorTest.expectThat(color.simple === false, "'transparent' should not be simple.");
    145133            InspectorTest.expectThat(color.isKeyword() === true, "'transparent' should be a keyword.");
    146             InspectorTest.expectThat(shallowEqual(color.rgb, [0, 0, 0]), "'transparent' has rgb of [0, 0, 0].");
    147             InspectorTest.expectThat(shallowEqual(color.rgba, [0, 0, 0, 0]), "'transparent' has rgba of [0, 0, 0, 0].");
    148             InspectorTest.expectThat(shallowEqual(color.hsl, [0, 0, 0]), "'transparent' has hsl of [0, 0, 0].");
    149             InspectorTest.expectThat(shallowEqual(color.hsla, [0, 0, 0, 0]), "'transparent' has hsla of [0, 0, 0, 0].");
     134            InspectorTest.expectShallowEqual(color.rgb, [0, 0, 0], "'transparent' has rgb of [0, 0, 0].");
     135            InspectorTest.expectShallowEqual(color.rgba, [0, 0, 0, 0], "'transparent' has rgba of [0, 0, 0, 0].");
     136            InspectorTest.expectShallowEqual(color.hsl, [0, 0, 0], "'transparent' has hsl of [0, 0, 0].");
     137            InspectorTest.expectShallowEqual(color.hsla, [0, 0, 0, 0], "'transparent' has hsla of [0, 0, 0, 0].");
    150138            InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === true, "'transparent' should be serializable as a short Hex");
    151139
     
    154142            InspectorTest.expectThat(color.simple === false, "'#11122233' should be not be simple.");
    155143            InspectorTest.expectThat(color.isKeyword() === false, "'#11122233' should not be a keyword.");
    156             InspectorTest.expectThat(shallowEqual(color.rgba, [17, 18, 34, 0.2]), "'#11122233' has rgba of [17, 18, 34, 0.2].");
    157             InspectorTest.expectThat(shallowEqual(color.hsla, [236, 33, 10, 0.2]), "'#11122233' has hsla of [236, 33, 10, 0.2].");
     144            InspectorTest.expectShallowEqual(color.rgba, [17, 18, 34, 0.2], "'#11122233' has rgba of [17, 18, 34, 0.2].");
     145            InspectorTest.expectShallowEqual(color.hsla, [236, 33, 10, 0.2], "'#11122233' has hsla of [236, 33, 10, 0.2].");
    158146            InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === false, "'#11122233' should not be serializable as a short Hex");
    159147
     
    163151            color = WI.Color.fromString("#11223345");
    164152            InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === false, "'#11223345' should not be serializable as a short Hex");
     153
     154            resolve();
     155        }
     156    });
     157
     158    suite.addTestCase({
     159        name: "WI.Color from components",
     160        description: "Test different three- and four-component colors.",
     161        test(resolve, reject) {
     162            function test(color, components) {
     163                InspectorTest.log(`Check components for color '${color.toString()}'.`);
     164                for (let key in components) {
     165                    let value = components[key];
     166                    InspectorTest.expectShallowEqual(color[key], value, `Should have ${key} of ${JSON.stringify(value)}.`);
     167                }
     168            }
     169
     170            test(new WI.Color(WI.Color.Format.RGB, [255, 0, 0]), {
     171                rgb: [255, 0, 0],
     172                rgba: [255, 0, 0, 1],
     173                hsl: [0, 100, 50],
     174                hsla: [0, 100, 50, 1],
     175            });
     176
     177            test(new WI.Color(WI.Color.Format.RGBA, [128, 128, 128, 0.5]), {
     178                rgb: [128, 128, 128],
     179                rgba: [128, 128, 128, 0.5],
     180                hsl: [0, 0, 50],
     181                hsla: [0, 0, 50, 0.5],
     182            });
     183
     184            test(new WI.Color(WI.Color.Format.HSL, [0, 0, 50]), {
     185                rgb: [128, 128, 128],
     186                rgba: [128, 128, 128, 1],
     187                hsl: [0, 0, 50],
     188                hsla: [0, 0, 50, 1],
     189            });
     190
     191            test(new WI.Color(WI.Color.Format.HSLA, [0, 0, 50, 0.5]), {
     192                rgb: [128, 128, 128],
     193                rgba: [128, 128, 128, 0.5],
     194                hsl: [0, 0, 50],
     195                hsla: [0, 0, 50, 0.5],
     196            });
    165197
    166198            resolve();
  • trunk/Source/WebInspectorUI/ChangeLog

    r222052 r222055  
     12017-09-14  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Color created from an RGB/HSL triplet returns bad component arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=176811
     5        <rdar://problem/34397529>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        A Color constructed from a format and RGB/HSL triplet should set its
     10        alpha component to 1 instead of leaving it undefined. Color properties
     11        and member functions expect the components array to have a length of four.
     12
     13        * UserInterface/Models/Color.js:
     14        (WI.Color):
     15
    1162017-09-14  Joseph Pecoraro  <pecoraro@apple.com>
    217
  • trunk/Source/WebInspectorUI/UserInterface/Models/Color.js

    r220119 r222055  
    3333    {
    3434        this.format = format;
     35
     36        if (components.length === 3)
     37            components.push(1);
    3538
    3639        if (format === WI.Color.Format.HSL || format === WI.Color.Format.HSLA)
Note: See TracChangeset for help on using the changeset viewer.