|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 'use strict'; |
|
5 |
|
6 const { PrefsTarget } = require('sdk/preferences/event-target'); |
|
7 const { get, set, reset } = require('sdk/preferences/service'); |
|
8 const { Loader } = require('sdk/test/loader'); |
|
9 const { setTimeout } = require('sdk/timers'); |
|
10 |
|
11 const root = PrefsTarget(); |
|
12 |
|
13 exports.testPrefsTarget = function(assert, done) { |
|
14 let loader = Loader(module); |
|
15 let pt = loader.require('sdk/preferences/event-target').PrefsTarget({}); |
|
16 let name = 'test'; |
|
17 |
|
18 assert.equal(get(name, ''), '', 'test pref is blank'); |
|
19 |
|
20 pt.once(name, function() { |
|
21 assert.equal(pt.prefs[name], 2, 'test pref is 2'); |
|
22 |
|
23 pt.once(name, function() { |
|
24 assert.fail('should not have heard a pref change'); |
|
25 }); |
|
26 loader.unload(); |
|
27 root.once(name, function() { |
|
28 assert.pass('test pref was changed'); |
|
29 reset(name); |
|
30 |
|
31 // NOTE: using setTimeout to make sure that the other listener had |
|
32 // a chance to fail |
|
33 // end test |
|
34 setTimeout(done); |
|
35 }); |
|
36 set(name, 3); |
|
37 }); |
|
38 |
|
39 pt.prefs[name] = 2; |
|
40 }; |
|
41 |
|
42 require('sdk/test').run(exports); |