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

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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';
     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');
    11 const root = PrefsTarget();
    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';
    18   assert.equal(get(name, ''), '', 'test pref is blank');
    20   pt.once(name, function() {
    21     assert.equal(pt.prefs[name], 2, 'test pref is 2');
    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);
    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   });
    39   pt.prefs[name] = 2;
    40 };
    42 require('sdk/test').run(exports);

mercurial