Bug 1359935 - Don't call sendAsyncMessage in mockedSessionTransport.close() after tearDown. r=kershaw draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 28 Apr 2017 14:13:35 -0700
changeset 570437 668cade94eda6c52a299723b28b644c77298ec40
parent 570430 09c188b68ab25ed5ec2b8b2e7bc9f9037687511f
child 626496 cff639f76088d17e5a554e43864c06981e709956
push id56494
push userbmo:continuation@gmail.com
push dateFri, 28 Apr 2017 22:47:52 +0000
reviewerskershaw
bugs1359935
milestone55.0a1
Bug 1359935 - Don't call sendAsyncMessage in mockedSessionTransport.close() after tearDown. r=kershaw For some reason, when running test_presentation_sender_startWithDevice.html we end up running mockedSessionTransport.close() late in shutdown. The special powers code to do sendAsyncMessage has been torn down already, and we end up leaking in shutdown, without an extra GC. Also, this patch replaces some leading tabs with spaces. MozReview-Commit-ID: BnwMBgR8iYZ
dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
--- a/dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
+++ b/dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
@@ -284,18 +284,21 @@ const mockedSessionTransport = {
   },
   enableDataNotification: function() {
     sendAsyncMessage('data-transport-notification-enabled');
   },
   send: function(data) {
     sendAsyncMessage('message-sent', data);
   },
   close: function(reason) {
-    sendAsyncMessage('data-transport-closed', reason);
-    this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportClosed(reason);
+    // Don't send a message after tearDown, to avoid a leak.
+    if (this._callback) {
+      sendAsyncMessage('data-transport-closed', reason);
+      this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportClosed(reason);
+    }
   },
   simulateTransportReady: function() {
     this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportReady();
   },
   simulateIncomingMessage: function(message) {
     this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyData(message, false);
   },
   onOffer: function(aOffer) {
@@ -400,24 +403,24 @@ addMessageListener('trigger-device-promp
 addMessageListener('trigger-device-prompt-cancel', function(result) {
   mockedDevicePrompt.simulateCancel(result);
 });
 
 addMessageListener('trigger-incoming-session-request', function(url) {
   var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
                       .getService(Ci.nsIPresentationDeviceManager);
   deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
-	       .onSessionRequest(mockedDevice, url, sessionId, mockedControlChannel);
+               .onSessionRequest(mockedDevice, url, sessionId, mockedControlChannel);
 });
 
 addMessageListener('trigger-incoming-terminate-request', function() {
   var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
                       .getService(Ci.nsIPresentationDeviceManager);
   deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
-	       .onTerminateRequest(mockedDevice, sessionId, mockedControlChannel, true);
+               .onTerminateRequest(mockedDevice, sessionId, mockedControlChannel, true);
 });
 
 addMessageListener('trigger-reconnected-acked', function(url) {
     mockedControlChannel.notifyReconnected();
 });
 
 addMessageListener('trigger-incoming-offer', function() {
   mockedControlChannel.simulateOnOffer();