forked from mirrors/gecko-dev
		
	 53847edbe6
			
		
	
	
		53847edbe6
		
	
	
	
	
		
			
			The websocket uses the innerWindowId of the window where the script lives when triggering events for devtools. This is may not be the same as the websocket owner window as mentioned here https://searchfox.org/mozilla-central/rev/f1159268add2fd0959e9f91b474f5da74c90f305/dom/websocket/WebSocket.cpp#206-207,212 This seems to be the case when we have iframes within a page. The devtools do not get the events for the websockets channels opened within iframes as the innerWindowId is that of the top-level window. `...->TopWindowContext()->InnerWindowId()` also always point to the top-level window. This patch fixes these issues by switching to use the websocket owner window which the iframe. Note: The parent revsion contains the changes for the devtools fission work that depends on this fix. i did this to make it easy to test and review. Differential Revision: https://phabricator.services.mozilla.com/D106607
		
			
				
	
	
		
			163 lines
		
	
	
	
		
			4.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			163 lines
		
	
	
	
		
			4.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!DOCTYPE HTML>
 | |
| <html>
 | |
| <!--
 | |
| -->
 | |
| <head>
 | |
|   <title>Basic websocket frame interception test</title>
 | |
|   <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 | |
|   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
 | |
| </head>
 | |
| <body>
 | |
| <script class="testbody" type="text/javascript">
 | |
| 
 | |
| const URI = "ws://mochi.test:8888/tests/dom/websocket/tests/file_websocket_basic";
 | |
| 
 | |
| var frameReceivedCounter = 0;
 | |
| var frameSentCounter = 0;
 | |
| var webSocketCreatedCounter = 0;
 | |
| var webSocketOpenedCounter = 0;
 | |
| var webSocketMessageAvailableCounter = 0;
 | |
| var webSocketClosedCounter = 0;
 | |
| 
 | |
| ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 | |
| 
 | |
| var tests = [
 | |
|   { payload: "Hello world!" },
 | |
|   { payload: (function() { var buffer = ""; for (var i = 0; i < 120; ++i) buffer += i; return buffer; }()) },
 | |
| ]
 | |
| 
 | |
| var innerId = window.windowGlobalChild.innerWindowId;
 | |
| ok(innerId, "We have a valid innerWindowID: " + innerId);
 | |
| 
 | |
| var service = Cc["@mozilla.org/websocketevent/service;1"]
 | |
|                 .getService(Ci.nsIWebSocketEventService);
 | |
| ok(!!service, "We have the nsIWebSocketEventService");
 | |
| 
 | |
| var listener = {
 | |
|   QueryInterface: ChromeUtils.generateQI(["nsIWebSocketEventListener"]),
 | |
| 
 | |
|   webSocketCreated(aWebSocketSerialID, aURI, aProtocols) {
 | |
|     info("WebSocketCreated");
 | |
| 
 | |
|     is(aURI, URI, "URI matches");
 | |
|     is(aProtocols, "frame", "Protocol matches");
 | |
| 
 | |
|     webSocketCreatedCounter++;
 | |
|   },
 | |
| 
 | |
|   webSocketOpened(aWebSocketSerialID, aEffectiveURI, aProtocols, aExtensions, httpChannelId) {
 | |
|     info("WebSocketOpened");
 | |
| 
 | |
|     is(aEffectiveURI, URI, "EffectiveURI matches");
 | |
|     is(aProtocols, "frame", "Protocol matches");
 | |
|     is(aExtensions, "permessage-deflate", "No extensions");
 | |
|     ok(httpChannelId > 0, "Channel ID received");
 | |
| 
 | |
|     webSocketOpenedCounter++;
 | |
|   },
 | |
| 
 | |
|   webSocketMessageAvailable(aWebSocketSerialID, aData, aMessageType) {
 | |
|     info("WebSocketMessageAvailable");
 | |
| 
 | |
|     if (tests.length) {
 | |
|       is(aData, tests[0].payload, "Message matches!");
 | |
|       is(aMessageType, Ci.nsIWebSocketEventListener.TYPE_STRING, "The type is 'string'");
 | |
| 
 | |
|       webSocketMessageAvailableCounter++;
 | |
| 
 | |
|       tests.shift();
 | |
|       if (tests.length) {
 | |
|         ws.send(tests[0].payload);
 | |
|       } else {
 | |
|         ws.send("end");
 | |
|       }
 | |
|     }
 | |
|   },
 | |
| 
 | |
|   webSocketClosed(aWebSocketSerialID, aWasClean,
 | |
|                             aCode, aReason) {
 | |
|     info("WebSocketClosed");
 | |
| 
 | |
|     ok(aWasClean, "The socket is closed in a clean state");
 | |
|     is(aCode, 1000, "Exit code 1000");
 | |
|     ok(!aReason.length, "No reason");
 | |
| 
 | |
|     webSocketClosedCounter++;
 | |
|     checkListener();
 | |
|   },
 | |
| 
 | |
|   frameReceived(aWebSocketSerialID, aFrame) {
 | |
|     ok(!!aFrame, "We have received a frame");
 | |
| 
 | |
|     if (tests.length) {
 | |
|       ok(aFrame.timeStamp, "Checking timeStamp: " + aFrame.timeStamp);
 | |
|       is(aFrame.finBit, true, "Checking finBit");
 | |
|       is(aFrame.rsvBit1, true, "Checking rsvBit1");
 | |
|       is(aFrame.rsvBit2, false, "Checking rsvBit2");
 | |
|       is(aFrame.rsvBit3, false, "Checking rsvBit3");
 | |
|       is(aFrame.opCode, aFrame.OPCODE_TEXT, "Checking opCode");
 | |
|       is(aFrame.maskBit, false, "Checking maskBit");
 | |
|       is(aFrame.mask, 0, "Checking mask");
 | |
|       is(aFrame.payload, tests[0].payload, "Checking payload: " + aFrame.payload);
 | |
|     }
 | |
| 
 | |
|     frameReceivedCounter++;
 | |
|   },
 | |
| 
 | |
|   frameSent(aWebSocketSerialID, aFrame) {
 | |
|     ok(!!aFrame, "We have sent a frame");
 | |
| 
 | |
|     if (tests.length) {
 | |
|       ok(aFrame.timeStamp, "Checking timeStamp: " + aFrame.timeStamp);
 | |
|       is(aFrame.finBit, true, "Checking finBit");
 | |
|       is(aFrame.rsvBit1, true, "Checking rsvBit1");
 | |
|       is(aFrame.rsvBit2, false, "Checking rsvBit2");
 | |
|       is(aFrame.rsvBit3, false, "Checking rsvBit3");
 | |
|       is(aFrame.opCode, aFrame.OPCODE_TEXT, "Checking opCode");
 | |
|       is(aFrame.maskBit, true, "Checking maskBit");
 | |
|       ok(!!aFrame.mask, "Checking mask: " + aFrame.mask);
 | |
|       is(aFrame.payload, tests[0].payload, "Checking payload: " + aFrame.payload);
 | |
|     }
 | |
| 
 | |
|     frameSentCounter++;
 | |
|   }
 | |
| };
 | |
| 
 | |
| service.addListener(innerId, listener);
 | |
| ok(true, "Listener added");
 | |
| 
 | |
| function checkListener() {
 | |
|   service.removeListener(innerId, listener);
 | |
| 
 | |
|   ok(frameReceivedCounter, "We received some frames!");
 | |
|   ok(frameSentCounter, "We sent some frames!");
 | |
|   ok(webSocketCreatedCounter, "We have a create notification");
 | |
|   ok(webSocketOpenedCounter, "We have a open notification");
 | |
|   ok(webSocketMessageAvailableCounter, "We have a messageAvailable notification");
 | |
|   ok(webSocketClosedCounter, "We have a close notification");
 | |
|   SimpleTest.finish();
 | |
| }
 | |
| 
 | |
| var ws = new WebSocket(URI, "frame");
 | |
| ws.onopen = function(e) {
 | |
|   info("onopen");
 | |
| 
 | |
|   ws.send(tests[0].payload);
 | |
| }
 | |
| 
 | |
| ws.onclose = function(e) {
 | |
|   info("onclose");
 | |
| }
 | |
| 
 | |
| ws.onmessage = function(e) {
 | |
|   info("onmessage");
 | |
|   if (tests.length) {
 | |
|     is(e.data, tests[0].payload, "Wrong data");
 | |
|   }
 | |
| }
 | |
| 
 | |
| SimpleTest.waitForExplicitFinish();
 | |
| 
 | |
| </script>
 | |
| </body>
 | |
| </html>
 |