Browse files

Merge pull request #685 from erikvold/disposable-unload-2loader

adding a test for disposables that unloading one loader does not affect the other r=@gozala
  • Loading branch information...
2 parents 7882a36 + b2e3cfe commit b205f229a706aa8d8c622d4a3cacda5e0705e5ed @Gozala Gozala committed Jan 3, 2013
Showing with 40 additions and 3 deletions.
  1. +40 −3 test/test-disposable.js
View
43 test/test-disposable.js
@@ -7,9 +7,7 @@
const { Loader } = require("sdk/test/loader");
const { Class } = require("sdk/core/heritage");
const { Cc, Ci, Cu } = require("chrome");
-const { setTimeout } = require("sdk/timers")
-
-
+const { setTimeout } = require("sdk/timers");
exports["test disposables are desposed on unload"] = function(assert) {
let loader = Loader(module);
@@ -125,4 +123,43 @@ exports["test disposables are GC-able"] = function(assert, done) {
}, 300);
}
+
+exports["test loader unloads do not affect other loaders"] = function(assert) {
+ let loader1 = Loader(module);
+ let loader2 = Loader(module);
+ let { Disposable: Disposable1 } = loader1.require("sdk/core/disposable");
+ let { Disposable: Disposable2 } = loader2.require("sdk/core/disposable");
+
+ let arg1 = {}
+ let arg2 = 2
+ let disposals = 0
+
+ let Foo1 = Class({
+ extends: Disposable1,
+ dispose: function dispose() {
+ disposals = disposals + 1;
+ }
+ });
+
+ let Foo2 = Class({
+ extends: Disposable2,
+ dispose: function dispose() {
+ disposals = disposals + 1;
+ }
+ });
+
+ let foo1 = Foo1(arg1, arg2);
+ let foo2 = Foo2(arg1, arg2);
+
+ assert.equal(disposals, 0, "no destroy calls");
+
+ loader1.unload();
+
+ assert.equal(disposals, 1, "1 destroy calls");
+
+ loader2.unload();
+
+ assert.equal(disposals, 2, "2 destroy calls");
+}
+
require('test').run(exports);

0 comments on commit b205f22

Please sign in to comment.