@@ -625,6 +625,75 @@ TEST_P(NetworkReporterTest, testWebSocketCreatedWithInitiator) {
625625 })" );
626626}
627627
628+ TEST_P (NetworkReporterTest, testWebSocketCreatedWithInitiatorFramesToSkip) {
629+ InSequence s;
630+
631+ this ->expectMessageFromPage (JsonEq (R"( {
632+ "id": 0,
633+ "result": {}
634+ })" ));
635+ this ->toPage_ ->sendMessage (R"( {
636+ "id": 0,
637+ "method": "Debugger.enable"
638+ })" );
639+
640+ this ->expectMessageFromPage (JsonEq (R"( {
641+ "id": 1,
642+ "result": {}
643+ })" ));
644+ this ->toPage_ ->sendMessage (R"( {
645+ "id": 1,
646+ "method": "Network.enable"
647+ })" );
648+
649+ auto & runtime = engineAdapter_->getRuntime ();
650+
651+ // `apiShim` stands in for an API implementation (such as the `WebSocket`
652+ // constructor) that asks for its own frame to be omitted.
653+ auto requestId = this ->eval (R"( // line 0
654+ function apiShim() { // line 1
655+ return globalThis.__NETWORK_REPORTER__.createDevToolsRequestId(1); // line 2
656+ } // line 3
657+ function openSocket() { // line 4
658+ return apiShim(); // line 5
659+ } // line 6
660+ openSocket(); // line 7
661+
662+ //# sourceURL=webSocketInitiatorFramesToSkipTest.js
663+ )" )
664+ .asString (runtime)
665+ .utf8 (runtime);
666+
667+ this ->expectMessageFromPage (JsonParsed (AllOf (
668+ AtJsonPtr (" /method" , " Network.webSocketCreated" ),
669+ AtJsonPtr (" /params/requestId" , requestId),
670+ AtJsonPtr (" /params/url" , " wss://example.com/frames-to-skip" ),
671+ AtJsonPtr (" /params/initiator/type" , " script" ),
672+ AtJsonPtr (
673+ " /params/initiator/stack/callFrames" ,
674+ AllOf (
675+ Each (AtJsonPtr (" /url" , " webSocketInitiatorFramesToSkipTest.js" )),
676+ ElementsAre (
677+ AllOf (
678+ AtJsonPtr (" /functionName" , " openSocket" ),
679+ AtJsonPtr (" /lineNumber" , 5 )),
680+ AllOf (
681+ AtJsonPtr (" /functionName" , " global" ),
682+ AtJsonPtr (" /lineNumber" , 7 ))))))));
683+
684+ NetworkReporter::getInstance ().reportWebSocketCreated (
685+ requestId, " wss://example.com/frames-to-skip" );
686+
687+ this ->expectMessageFromPage (JsonEq (R"( {
688+ "id": 2,
689+ "result": {}
690+ })" ));
691+ this ->toPage_ ->sendMessage (R"( {
692+ "id": 2,
693+ "method": "Network.disable"
694+ })" );
695+ }
696+
628697TEST_P (NetworkReporterTest, testNetworkEventsWhenDisabled) {
629698 EXPECT_FALSE (NetworkReporter::getInstance ().isDebuggingEnabled ());
630699
0 commit comments