Bug 169175 - Web Inspector: Add tests for webSocketFrameSent and webSocketFrameReceived
Summary: Web Inspector: Add tests for webSocketFrameSent and webSocketFrameReceived
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: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on: 167520 170609 170760
Blocks:
  Show dependency treegraph
 
Reported: 2017-03-04 14:46 PST by Nikita Vasilyev
Modified: 2017-04-14 23:56 PDT (History)
4 users (show)

See Also:


Attachments
Patch (12.88 KB, patch)
2017-04-06 12:36 PDT, Nikita Vasilyev
joepeck: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2017-03-04 14:46:06 PST
NetworkObserver#webSocketFrameReceived and NetworkObserver#webSocketFrameSent were implemented in Bug 167520: Web Inspector: Show Web Socket connections in Network tab.

These two methods are currently untested.
Comment 1 Radar WebKit Bug Importer 2017-03-04 14:46:25 PST
<rdar://problem/30853154>
Comment 2 Nikita Vasilyev 2017-04-06 12:36:33 PDT
Created attachment 306409 [details]
Patch
Comment 3 Joseph Pecoraro 2017-04-06 14:16:33 PDT
Comment on attachment 306409 [details]
Patch

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

The tests looks good but I want to see updated versions addressing most of my comments.

Is there a test for `webSocketFrameError` in the works?

> LayoutTests/ChangeLog:9
> +        Test recieving and sending text and binary (blob and array buffer) data.

Typo: recieving

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary-expected.txt:4
> +== Running test suite: WebSocket.Binary

Do we have the size of the binary message? I think that would be useful.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary-expected.txt:17
> +PASS: Message walltime is greater than the first one.

A stricter test could check that the time is greater than the last message, not the first message.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html:11
> +    setTimeout(() => webSocket.close(), 500);

A timeout of 500ms could cause this to be flakey.

I'd suggest something like:

    // Global variable to keep it alive.
    let webSocket = null;

    function createWebSocket(type) {
        closeWebSocketConnection();
        webSocket = new WebSocket(...);
        webSocket.binaryType = type;
    }

    function closeWebSocketConnection() {
        if (webSocket) {
            webSocket.close();
            webSocket = null;
        }
    }

And at the end of `resourceWasAdded` before calling resolve you can evaluateInPage(`closeWebSocketConnection()`) to clean up if you want.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html:53
> +        setTimeout(() => reject(), 500);

This will likely cause the test to be flakey. I'd suggest just dropping it.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html:58
> +        description: "WebInspector.WebSocketResource.Event.ReadyStateChanged events are fired in order when WebSocket connection is closed by the client.",

This description doesn't match the test.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html:61
> +

Nit: Drop this empty line.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html:62
> +            InspectorTest.evaluateInPage("createWebSocketConnection(\"blob\")");

Style: What I've tended to do is to use template strings for code, which eliminates tedious escaping of quotes and it makes code strings appear differently in good editors. So you would have:

    `createWebSocketConnection("blob")`

> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html:68
> +        description: "WebInspector.WebSocketResource.Event.ReadyStateChanged events are fired in order when WebSocket connection is closed by the client.",

This description doesn't match the test.

> LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive-expected.txt:7
> +PASS: Message is a text type.

If its text we can show it!

> LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive.html:27
> +        description: "WebInspector.WebSocketResource.Event.ReadyStateChanged events are fired in order when WebSocket connection is closed by the client.",

This description does not match the test.
Comment 4 Nikita Vasilyev 2017-04-06 16:52:27 PDT
(In reply to Joseph Pecoraro from comment #3)
> Comment on attachment 306409 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=306409&action=review
> 
> The tests looks good but I want to see updated versions addressing most of
> my comments.
> 
> Is there a test for `webSocketFrameError` in the works?

Yes. It's more complicated since there're many reasons a connection may fail. I'm planning on adding webSocketFrameError tests at the same time as the UI for displaying these errors in WebSocketContentView, separately from this patch.
Comment 5 Joseph Pecoraro 2017-04-06 20:15:16 PDT
> Yes. It's more complicated since there're many reasons a connection may
> fail. I'm planning on adding webSocketFrameError tests at the same time as
> the UI for displaying these errors in WebSocketContentView, separately from
> this patch.

Okay! Can you point me to the bug covering that? Thanks
Comment 6 Nikita Vasilyev 2017-04-07 10:58:04 PDT
(In reply to Joseph Pecoraro from comment #5)
> > Yes. It's more complicated since there're many reasons a connection may
> > fail. I'm planning on adding webSocketFrameError tests at the same time as
> > the UI for displaying these errors in WebSocketContentView, separately from
> > this patch.
> 
> Okay! Can you point me to the bug covering that? Thanks

<rdar://problem/31389605>
Comment 7 Nikita Vasilyev 2017-04-07 18:38:59 PDT
Comment on attachment 306409 [details]
Patch

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

>> LayoutTests/http/tests/websocket/tests/hybi/inspector/binary-expected.txt:4
>> +== Running test suite: WebSocket.Binary
> 
> Do we have the size of the binary message? I think that would be useful.

Yes, but it was incorrect.
Bug 170609 - Web Inspector: WebSockets: Transferred size is incorrect.
Comment 8 BJ Burg 2017-04-10 13:07:15 PDT
<rdar://problem/30853154>
Comment 9 Nikita Vasilyev 2017-04-12 15:39:07 PDT
Comment on attachment 306409 [details]
Patch

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

>> LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive-expected.txt:7
>> +PASS: Message is a text type.
> 
> If its text we can show it!

I'm not sure what you're suggesting.

    InspectorTest.expectEqual(frame.opcode, WebInspector.WebSocketResource.OpCodes.TextFrame, frame.data);

?
Comment 10 Joseph Pecoraro 2017-04-12 18:06:43 PDT
(In reply to Nikita Vasilyev from comment #9)
> Comment on attachment 306409 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=306409&action=review
> 
> >> LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive-expected.txt:7
> >> +PASS: Message is a text type.
> > 
> > If its text we can show it!
> 
> I'm not sure what you're suggesting.
> 
>     InspectorTest.expectEqual(frame.opcode,
> WebInspector.WebSocketResource.OpCodes.TextFrame, frame.data);
> 
> ?

    InspectorTest.expectEqual(frame.opcode, OpCodes.TextFrame, "Frame should be text");
    InspectorTest.expectEqual(frame.data, "Hello world", "Frame data should be 'Hello world'");
Comment 11 Nikita Vasilyev 2017-04-14 23:56:15 PDT
Fixed in https://trac.webkit.org/changeset/215388/webkit.