michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: const { PrefsTarget } = require('sdk/preferences/event-target'); michael@0: const { get, set, reset } = require('sdk/preferences/service'); michael@0: const { Loader } = require('sdk/test/loader'); michael@0: const { setTimeout } = require('sdk/timers'); michael@0: michael@0: const root = PrefsTarget(); michael@0: michael@0: exports.testPrefsTarget = function(assert, done) { michael@0: let loader = Loader(module); michael@0: let pt = loader.require('sdk/preferences/event-target').PrefsTarget({}); michael@0: let name = 'test'; michael@0: michael@0: assert.equal(get(name, ''), '', 'test pref is blank'); michael@0: michael@0: pt.once(name, function() { michael@0: assert.equal(pt.prefs[name], 2, 'test pref is 2'); michael@0: michael@0: pt.once(name, function() { michael@0: assert.fail('should not have heard a pref change'); michael@0: }); michael@0: loader.unload(); michael@0: root.once(name, function() { michael@0: assert.pass('test pref was changed'); michael@0: reset(name); michael@0: michael@0: // NOTE: using setTimeout to make sure that the other listener had michael@0: // a chance to fail michael@0: // end test michael@0: setTimeout(done); michael@0: }); michael@0: set(name, 3); michael@0: }); michael@0: michael@0: pt.prefs[name] = 2; michael@0: }; michael@0: michael@0: require('sdk/test').run(exports);