Thu, 15 Jan 2015 15:59:08 +0100
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 { on, once, off, emit, count } = require("sdk/event/core"); |
michael@0 | 8 | |
michael@0 | 9 | function scenario(setup) { |
michael@0 | 10 | return function(unit) { |
michael@0 | 11 | return function(assert) { |
michael@0 | 12 | let actual = []; |
michael@0 | 13 | let input = {}; |
michael@0 | 14 | unit(input, function(output, events, expected, message) { |
michael@0 | 15 | let result = setup(output, expected, actual); |
michael@0 | 16 | |
michael@0 | 17 | events.forEach(function(event) emit(input, "data", event)); |
michael@0 | 18 | |
michael@0 | 19 | assert.deepEqual(actual, result, message); |
michael@0 | 20 | }); |
michael@0 | 21 | } |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | exports.emits = scenario(function(output, expected, actual) { |
michael@0 | 26 | on(output, "data", function(data) actual.push(this, data)); |
michael@0 | 27 | |
michael@0 | 28 | return expected.reduce(function($$, $) $$.concat(output, $), []); |
michael@0 | 29 | }); |
michael@0 | 30 | |
michael@0 | 31 | exports.registerOnce = scenario(function(output, expected, actual) { |
michael@0 | 32 | function listener(data) actual.push(data); |
michael@0 | 33 | on(output, "data", listener); |
michael@0 | 34 | on(output, "data", listener); |
michael@0 | 35 | on(output, "data", listener); |
michael@0 | 36 | |
michael@0 | 37 | return expected; |
michael@0 | 38 | }); |
michael@0 | 39 | |
michael@0 | 40 | exports.ignoreNew = scenario(function(output, expected, actual) { |
michael@0 | 41 | on(output, "data", function(data) { |
michael@0 | 42 | actual.push(data + "#1"); |
michael@0 | 43 | on(output, "data", function(data) { |
michael@0 | 44 | actual.push(data + "#2"); |
michael@0 | 45 | }); |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | return expected.map(function($) $ + "#1"); |
michael@0 | 49 | }); |
michael@0 | 50 | |
michael@0 | 51 | exports.FIFO = scenario(function(target, expected, actual) { |
michael@0 | 52 | on(target, "data", function($) actual.push($ + "#1")); |
michael@0 | 53 | on(target, "data", function($) actual.push($ + "#2")); |
michael@0 | 54 | on(target, "data", function($) actual.push($ + "#3")); |
michael@0 | 55 | |
michael@0 | 56 | return expected.reduce(function(result, value) { |
michael@0 | 57 | return result.concat(value + "#1", value + "#2", value + "#3"); |
michael@0 | 58 | }, []); |
michael@0 | 59 | }); |