addon-sdk/source/test/test-preferences-target.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial