Skip to content

Loading…

bug 710117 testing that pref listeners are removed on unload #306

Merged
merged 7 commits into from

2 participants

@erikvold

@Gozala mind taking a look at this one? I've removed the setTimeout that @mykmelez asked me to do finally.

@Gozala Gozala commented on the diff
packages/addon-kit/tests/test-simple-prefs.js
@@ -4,8 +4,8 @@
const { Loader } = require("./helpers");
-const setTimeout = require("timers").setTimeout;
-const notify = require("observer-service").notify;
+const { setTimeout } = require("timers");
@Gozala Mozilla member
Gozala added a note

This require is not necessary as setTimout is no longer used.

It's still used in line 120 for exports.testPrefRemoveListener, though that use should be removed too, I'd like to do that in a separate pull request.

@Gozala Mozilla member
Gozala added a note

Ahh sorry I just have not seen it in this request and assumed it was not used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Gozala
Mozilla member

In general I discourage use of loader.sandbox which we have added only in order to avoid rewriting old tests (which we'll do at some point in a future). So if there is any way to test API without an access to a sandbox that's much more preferred alternative. In this case I believe it should be possible to do it without emit by just changing an actual pref no ? If so do you mind doing it this way ?

@erikvold

@Gozala I've removed the use of loader.sandbox now

@Gozala Gozala commented on an outdated diff
packages/addon-kit/lib/simple-prefs.js
((11 lines not shown))
},
unload: function manager_unload() {
this._removeAllListeners();
branch.removeObserver("", this._prefObserver);
- },
+ },
+ emit: function(key, value) this._emit(key, value),
@Gozala Mozilla member
Gozala added a note

I think this changes are no longer required then are they ?

P.S.: It has a merge conflict now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Gozala Gozala commented on an outdated diff
packages/addon-kit/tests/test-simple-prefs.js
((5 lines not shown))
sp.prefs["test-listen2"] = true;
};
+
+// Bug 710117: Test that simple-pref listeners are removed on unload
+exports.testPrefUnloadListener = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs");
+ let counter = 0;
+
+ let listener = function() {
+ test.assertEqual(++counter, 1, "This listener should only be called once");
+
+ loader.unload();
+
+ sp.prefs["test-listen3"] = false;
@Gozala Mozilla member
Gozala added a note

This is nice but not quite what I meant, sorry I was not very clear about it. Can you instead of using sp.prefs a non-unloaded one (require('simple-prefs').prefs) to make sure that an actual pref change does not call's listeners on the unloaded prefs module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Gozala
Mozilla member

We're almost there, sorry for not being very clear first time around. Also could you please merge with upstream/master cause otherwise it won't auto merge. (P.S. getting rid of changes in simple-prefs.js before merge would probably make it easier)

@erikvold

Hey @Gozala I think I made the changes that you requested.

@Gozala Gozala merged commit ee036f5 into mozilla:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 16, 2011
  1. @erikvold
Commits on Mar 18, 2012
  1. @erikvold
  2. @erikvold
  3. @erikvold

    adding comment for test

    erikvold committed
Commits on Mar 22, 2012
  1. @erikvold
Commits on Mar 23, 2012
  1. @erikvold

    using module instance that hasn't been unloaded to change a pref, so …

    erikvold committed
    …that we are certain the pref is changed.
  2. @erikvold

    Merge remote-tracking branch 'mozilla/master' into bug-710117

    erikvold committed
    Conflicts:
    	packages/addon-kit/lib/simple-prefs.js
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 2 deletions.
  1. +30 −2 packages/addon-kit/tests/test-simple-prefs.js
View
32 packages/addon-kit/tests/test-simple-prefs.js
@@ -4,8 +4,8 @@
const { Loader } = require("./helpers");
-const setTimeout = require("timers").setTimeout;
-const notify = require("observer-service").notify;
+const { setTimeout } = require("timers");
@Gozala Mozilla member
Gozala added a note

This require is not necessary as setTimout is no longer used.

It's still used in line 120 for exports.testPrefRemoveListener, though that use should be removed too, I'd like to do that in a separate pull request.

@Gozala Mozilla member
Gozala added a note

Ahh sorry I just have not seen it in this request and assumed it was not used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+const { notify } = require("observer-service");
const { jetpackID } = require("@packaging");
exports.testSetGetBool = function(test) {
@@ -143,5 +143,33 @@ exports.testPrefRemoveListener = function(test) {
sp.on("test-listen2", listener);
+ // emit change
sp.prefs["test-listen2"] = true;
};
+
+// Bug 710117: Test that simple-pref listeners are removed on unload
+exports.testPrefUnloadListener = function(test) {
+ test.waitUntilDone();
+
+ let loader = Loader(module);
+ let sp = loader.require("simple-prefs");
+ let counter = 0;
+
+ let listener = function() {
+ test.assertEqual(++counter, 1, "This listener should only be called once");
+
+ loader.unload();
+
+ // this may not execute after unload, but definitely shouldn't fire listener
+ sp.prefs["test-listen3"] = false;
+ // this should execute, but also definitely shouldn't fire listener
+ require("simple-prefs").prefs["test-listen3"] = false; //
+
+ test.done();
+ };
+
+ sp.on("test-listen3", listener);
+
+ // emit change
+ sp.prefs["test-listen3"] = true;
+};
Something went wrong with that request. Please try again.