addon-sdk/source/test/test-test-utils-async.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.

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

mercurial