mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1285373 P3 Test that sdk/event/chrome observer channels can be GC'd. r=gabor
This commit is contained in:
parent
ac08e4b7de
commit
40b908d4b7
@ -4,3 +4,4 @@ support-files =
|
||||
|
||||
[test-leak-window-events.js]
|
||||
[test-leak-event-dom-closed-window.js]
|
||||
[test-leak-event-chrome.js]
|
||||
|
@ -31,6 +31,7 @@ function gc() {
|
||||
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.
|
||||
|
41
addon-sdk/source/test/leak/test-leak-event-chrome.js
Normal file
41
addon-sdk/source/test/leak/test-leak-event-chrome.js
Normal file
@ -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);
|
Loading…
Reference in New Issue
Block a user