Bug 149155 - Web Inspector: Copying inline style text puts "undefined" in the pasteboard
Summary: Web Inspector: Copying inline style text puts "undefined" in the pasteboard
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-09-15 01:31 PDT by Devin Rousso
Modified: 2015-10-02 15:33 PDT (History)
8 users (show)

See Also:


Attachments
Patch (3.73 KB, patch)
2015-09-15 01:34 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (8.93 KB, patch)
2015-10-01 12:42 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (10.30 KB, patch)
2015-10-01 23:12 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2015-09-15 01:31:28 PDT
* STEPS TO REPRODUCE:
1. Go to https://www.apple.com/
2. Open the elements tab in Web Inspector
3. Select the <body> tag
4. Right click the "Style Attribute" text at the top of the Styles sidebar and select "Copy Rule"
5. Paste somewhere (Cmd+V)

  Expected:
body {
}

  Actual:
undefined
Comment 1 Radar WebKit Bug Importer 2015-09-15 01:31:44 PDT
<rdar://problem/22698991>
Comment 2 Devin Rousso 2015-09-15 01:34:45 PDT
Created attachment 261179 [details]
Patch
Comment 3 BJ Burg 2015-09-15 10:19:43 PDT
Comment on attachment 261179 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=261179&action=review

This approach definitely works, but it could be simpler, IMO. What do you think about adding getters to the CSSStyleDeclaration for mediaList and selectorText? Then you can avoid adding another special case parameter and hide that logic in the getter.

    let selectorText = this.selectorText;
    if (!selectorText)
        return;

    let styleText = "";
    let mediaQueriesCount = 0;

    let mediaList = this.mediaList;
    if (mediaList && mediaList.length) {
        mediaQueriesCount = mediaList.length;
        for (let i = mediaQueriesCount - 1; i >= 0; --i)
            styleText += `${"    ".repeat(mediaQueriesCount - i - 1)}@media ${mediaList[i].text} {\n`;
    }

    styleText += `${"    ".repeat(mediaQueriesCount)}${selectorText} {\n`;

> Source/WebInspectorUI/ChangeLog:7
> +

It would be helpful to describe why it wasn't working before, and how you fixed it.
Comment 4 BJ Burg 2015-09-15 10:22:19 PDT
Also, this behavior (what the generated string is for an inline style/rule) is definitely something for which we should write a test.
Comment 5 Devin Rousso 2015-10-01 12:42:34 PDT
Created attachment 262278 [details]
Patch
Comment 6 Timothy Hatcher 2015-10-01 13:02:43 PDT
Comment on attachment 262278 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=262278&action=review

> Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js:246
> +

No need for the empty line here.

> Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js:254
> +

Ditto.

> Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js:311
> +            styleText += "    ".repeat(mediaQueriesCount - i - 1) + "@media " + mediaList[i].text + " {\n";

Might be nice to put the "    " in a local that would eventuality be controlled by a tab/spaces setting.

> LayoutTests/inspector/css/generate-css-rule-string.html:30
> +        InspectorTest.completeTest();

This should use the new test suite way for inspector tests.
Comment 7 Devin Rousso 2015-10-01 13:30:19 PDT
Comment on attachment 262278 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=262278&action=review

>> LayoutTests/inspector/css/generate-css-rule-string.html:30
>> +        InspectorTest.completeTest();
> 
> This should use the new test suite way for inspector tests.

So I am a bit confused on this.  It seems like the new suite uses InspectorTest.expectThat and if we are planning on supporting different tab widths for indentation in the future, how would I ensure that it prints correctly?  Also, are we entirely using InspectorTest.expectThat or am I able to use InspectorTest.log?
Comment 8 Joseph Pecoraro 2015-10-01 14:25:04 PDT
> if we are planning on supporting different tab widths for indentation in the
> future, how would I ensure that it prints correctly?

Different tab widths would be a user preference. Tests would always use the default value of settings / preferences (or set to some non-default). Much like showing the shadow dom is a setting.


> Also, are we entirely using InspectorTest.expectThat or am I able to use InspectorTest.log?

You may use both. "expect" is nice because it prints out PASS / FAIL along with the message. With messages written of the form "X should be Y", if you get a Failure you know immediately what went wrong. X should be Y, but it wasn't.
Comment 9 BJ Burg 2015-10-01 14:27:25 PDT
Comment on attachment 262278 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=262278&action=review

>>> LayoutTests/inspector/css/generate-css-rule-string.html:30
>>> +        InspectorTest.completeTest();
>> 
>> This should use the new test suite way for inspector tests.
> 
> So I am a bit confused on this.  It seems like the new suite uses InspectorTest.expectThat and if we are planning on supporting different tab widths for indentation in the future, how would I ensure that it prints correctly?  Also, are we entirely using InspectorTest.expectThat or am I able to use InspectorTest.log?

See here for rationale: http://trac.webkit.org/wiki/WebInspectorTests#HowtoWriteTests
Comment 10 Devin Rousso 2015-10-01 23:12:57 PDT
Created attachment 262317 [details]
Patch
Comment 11 Devin Rousso 2015-10-01 23:14:20 PDT
(In reply to comment #10)
> Created attachment 262317 [details]
> Patch

So I tried updating the test to use the new suite, but I'm not sure if I did it right so please let me know if I need to change anything.
Comment 12 BJ Burg 2015-10-02 07:47:06 PDT
Comment on attachment 262317 [details]
Patch

Test looks good to me.
Comment 13 WebKit Commit Bot 2015-10-02 15:33:28 PDT
Comment on attachment 262317 [details]
Patch

Clearing flags on attachment: 262317

Committed r190528: <http://trac.webkit.org/changeset/190528>
Comment 14 WebKit Commit Bot 2015-10-02 15:33:32 PDT
All reviewed patches have been landed.  Closing bug.