Bug 1285373 P3 Test that sdk/event/chrome observer channels can be GC'd. r=gabor
authorBen Kelly <ben@wanderview.com>
Wed, 20 Jul 2016 06:47:23 -0700
changeset 305905 2d1b1ed6f563c6f178dd487c0b5b58ca911ed284
parent 305904 8aa72f37debb9e3c0a556dc42f08863109392065
child 305906 b9f44fd406a34cafcc0c74cacfdbc50ddb096ddb
push id30474
push usercbook@mozilla.com
push dateThu, 21 Jul 2016 14:25:10 +0000
treeherdermozilla-central@6b180266ac16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1285373
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1285373 P3 Test that sdk/event/chrome observer channels can be GC'd. r=gabor
addon-sdk/source/test/leak/jetpack-package.ini
addon-sdk/source/test/leak/leak-utils.js
addon-sdk/source/test/leak/test-leak-event-chrome.js
--- a/addon-sdk/source/test/leak/jetpack-package.ini
+++ b/addon-sdk/source/test/leak/jetpack-package.ini
@@ -1,6 +1,7 @@
 [DEFAULT]
 support-files =
   leak-utils.js
 
 [test-leak-window-events.js]
 [test-leak-event-dom-closed-window.js]
+[test-leak-event-chrome.js]
--- a/addon-sdk/source/test/leak/leak-utils.js
+++ b/addon-sdk/source/test/leak/leak-utils.js
@@ -26,16 +26,17 @@ function gc() {
           resolve();
         }
       }
     }
 
     Cu.schedulePreciseGC(genGCCallback());
   });
 }
+exports.gc = gc;
 
 // Execute the given test function and verify that we did not leak windows
 // in the process.  The test function must return a promise or be a generator.
 // If the promise is resolved, or generator completes, with an sdk loader
 // object then it will be unloaded after the memory measurements.
 exports.asyncWindowLeakTest = function*(assert, asyncTestFunc) {
 
   // SelfSupportBackend periodically tries to open windows.  This can
new file mode 100644
--- /dev/null
+++ b/addon-sdk/source/test/leak/test-leak-event-chrome.js
@@ -0,0 +1,41 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { gc } = require("./leak-utils");
+const { Loader } = require("sdk/test/loader");
+const { Cu } = require("chrome");
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+
+exports["test sdk/event/chrome does not leak when not referenced"] = function*(assert) {
+  let loader = Loader(module);
+  let { observe } = loader.require("sdk/event/chrome");
+  let { on } = loader.require("sdk/event/core");
+
+  let gotFooEvent = false;
+  on(observe("test-foo"), "data", function(evt) {
+    gotFooEvent = true;
+  });
+
+  let bar = observe("test-bar");
+  let barPromise = new Promise(resolve => {
+    on(bar, "data", function(evt) {
+      assert.ok(!gotFooEvent, "should not have gotten test-foo event");
+      resolve();
+    });
+  });
+
+  // This should clear the test-foo observer channel because we are not
+  // holding a reference to it above.
+  yield gc();
+
+  Services.obs.notifyObservers(null, "test-foo", null);
+  Services.obs.notifyObservers(null, "test-bar", null);
+
+  yield barPromise;
+
+  loader.unload();
+}
+
+require("sdk/test").run(exports);