addon-sdk/source/test/test-cuddlefish.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/. */
     5 'use strict';
     7 const { Loader, Require, unload, override } = require('sdk/loader/cuddlefish');
     8 const packaging = require('@loader/options');
    10 exports['test loader'] = function(assert) {
    11   var prints = [];
    12   function print(message) {
    13     prints.push(message);
    14   }
    16   let loader = Loader(override(packaging, {
    17     globals: {
    18       print: print,
    19       foo: 1
    20     }
    21   }));
    22   let require = Require(loader, module);
    24   var fixture = require('./loader/fixture');
    26   assert.equal(fixture.foo, 1, 'custom globals must work.');
    27   assert.equal(fixture.bar, 2, 'exports are set');
    29   assert.equal(prints[0], 'testing', 'global print must be injected.');
    31   var unloadsCalled = '';
    33   require("sdk/system/unload").when(function(reason) {
    34     assert.equal(reason, 'test', 'unload reason is passed');
    35     unloadsCalled += 'a';
    36   });
    37   require('sdk/system/unload.js').when(function() {
    38     unloadsCalled += 'b';
    39   });
    41   unload(loader, 'test');
    43   assert.equal(unloadsCalled, 'ba',
    44                'loader.unload() must call listeners in LIFO order.');
    45 };
    47 require('test').run(exports);

mercurial