addon-sdk/source/test/test-test-utils-sync.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 { defer: async } = require('sdk/lang/functional');
     8 const { before, after } = require('sdk/test/utils');
    10 let AFTER_RUN = 0;
    11 let BEFORE_RUN = 0;
    13 /*
    14  * Tests are dependent on ordering, as the before and after functions
    15  * are called outside of each test, and sometimes checked in the next test
    16  * (like in the `after` tests)
    17  */
    18 exports.testABeforeAsync = function (assert, done) {
    19   assert.equal(BEFORE_RUN, 1, 'before function was called');
    20   BEFORE_RUN = 0;
    21   AFTER_RUN = 0;
    22   async(done)();
    23 };
    25 exports.testABeforeNameAsync = function (assert, done) {
    26   assert.equal(BEFORE_RUN, 2, 'before function was called with name');
    27   BEFORE_RUN = 0;
    28   AFTER_RUN = 0;
    29   async(done)();
    30 };
    32 exports.testAfterAsync = function (assert, done) {
    33   assert.equal(AFTER_RUN, 1, 'after function was called previously');
    34   BEFORE_RUN = 0;
    35   AFTER_RUN = 0;
    36   async(done)();
    37 };
    39 exports.testAfterNameAsync = function (assert, done) {
    40   assert.equal(AFTER_RUN, 2, 'after function was called with name');
    41   BEFORE_RUN = 0;
    42   AFTER_RUN = 0;
    43   async(done)();
    44 };
    46 exports.testSyncABefore = function (assert) {
    47   assert.equal(BEFORE_RUN, 1, 'before function was called for sync test');
    48   BEFORE_RUN = 0;
    49   AFTER_RUN = 0;
    50 };
    52 exports.testSyncAfter = function (assert) {
    53   assert.equal(AFTER_RUN, 1, 'after function was called for sync test');
    54   BEFORE_RUN = 0;
    55   AFTER_RUN = 0;
    56 };
    58 before(exports, (name, assert) => {
    59   if (name === 'testABeforeNameAsync')
    60     BEFORE_RUN = 2;
    61   else
    62     BEFORE_RUN = 1;
    63   assert.pass('assert passed into before function');
    64 });
    66 after(exports, (name, assert) => {
    67   // testAfterName runs after testAfter, which is where this
    68   // check occurs in the assertation
    69   if (name === 'testAfterAsync')
    70     AFTER_RUN = 2;
    71   else
    72     AFTER_RUN = 1;
    73   assert.pass('assert passed into after function');
    74 });
    76 require('sdk/test').run(exports);

mercurial