addon-sdk/source/lib/sdk/test/runner.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 "use strict";
michael@0 5
michael@0 6 module.metadata = {
michael@0 7 "stability": "experimental"
michael@0 8 };
michael@0 9
michael@0 10 var { exit, stdout } = require("../system");
michael@0 11 var cfxArgs = require("@test/options");
michael@0 12
michael@0 13 function runTests(findAndRunTests) {
michael@0 14 var harness = require("./harness");
michael@0 15
michael@0 16 function onDone(tests) {
michael@0 17 stdout.write("\n");
michael@0 18 var total = tests.passed + tests.failed;
michael@0 19 stdout.write(tests.passed + " of " + total + " tests passed.\n");
michael@0 20
michael@0 21 if (tests.failed == 0) {
michael@0 22 if (tests.passed === 0)
michael@0 23 stdout.write("No tests were run\n");
michael@0 24 exit(0);
michael@0 25 } else {
michael@0 26 if (cfxArgs.verbose || cfxArgs.parseable)
michael@0 27 printFailedTests(tests, stdout.write);
michael@0 28 exit(1);
michael@0 29 }
michael@0 30 };
michael@0 31
michael@0 32 // We may have to run test on next cycle, otherwise XPCOM components
michael@0 33 // are not correctly updated.
michael@0 34 // For ex: nsIFocusManager.getFocusedElementForWindow may throw
michael@0 35 // NS_ERROR_ILLEGAL_VALUE exception.
michael@0 36 require("../timers").setTimeout(function () {
michael@0 37 harness.runTests({
michael@0 38 findAndRunTests: findAndRunTests,
michael@0 39 iterations: cfxArgs.iterations || 1,
michael@0 40 filter: cfxArgs.filter,
michael@0 41 profileMemory: cfxArgs.profileMemory,
michael@0 42 stopOnError: cfxArgs.stopOnError,
michael@0 43 verbose: cfxArgs.verbose,
michael@0 44 parseable: cfxArgs.parseable,
michael@0 45 print: stdout.write,
michael@0 46 onDone: onDone
michael@0 47 });
michael@0 48 }, 0);
michael@0 49 }
michael@0 50
michael@0 51 function printFailedTests(tests, print) {
michael@0 52 let iterationNumber = 0;
michael@0 53 let singleIteration = tests.testRuns.length == 1;
michael@0 54 let padding = singleIteration ? "" : " ";
michael@0 55
michael@0 56 print("\nThe following tests failed:\n");
michael@0 57
michael@0 58 for each (let testRun in tests.testRuns) {
michael@0 59 iterationNumber++;
michael@0 60
michael@0 61 if (!singleIteration)
michael@0 62 print(" Iteration " + iterationNumber + ":\n");
michael@0 63
michael@0 64 for each (let test in testRun) {
michael@0 65 if (test.failed > 0) {
michael@0 66 print(padding + " " + test.name + ": " + test.errors +"\n");
michael@0 67 }
michael@0 68 }
michael@0 69 print("\n");
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 function main() {
michael@0 74 var testsStarted = false;
michael@0 75
michael@0 76 if (!testsStarted) {
michael@0 77 testsStarted = true;
michael@0 78 runTests(function findAndRunTests(loader, nextIteration) {
michael@0 79 loader.require("../deprecated/unit-test").findAndRunTests({
michael@0 80 testOutOfProcess: false,
michael@0 81 testInProcess: true,
michael@0 82 stopOnError: cfxArgs.stopOnError,
michael@0 83 filter: cfxArgs.filter,
michael@0 84 onDone: nextIteration
michael@0 85 });
michael@0 86 });
michael@0 87 }
michael@0 88 };
michael@0 89
michael@0 90 if (require.main === module)
michael@0 91 main();
michael@0 92
michael@0 93 exports.runTestsFromModule = function runTestsFromModule(module) {
michael@0 94 let id = module.id;
michael@0 95 // Make a copy of exports as it may already be frozen by module loader
michael@0 96 let exports = {};
michael@0 97 Object.keys(module.exports).forEach(function(key) {
michael@0 98 exports[key] = module.exports[key];
michael@0 99 });
michael@0 100
michael@0 101 runTests(function findAndRunTests(loader, nextIteration) {
michael@0 102 // Consider that all these tests are CommonJS ones
michael@0 103 loader.require('../../test').run(exports);
michael@0 104
michael@0 105 // Reproduce what is done in unit-test-finder.findTests()
michael@0 106 let tests = [];
michael@0 107 for each (let name in Object.keys(exports).sort()) {
michael@0 108 tests.push({
michael@0 109 setup: exports.setup,
michael@0 110 teardown: exports.teardown,
michael@0 111 testFunction: exports[name],
michael@0 112 name: id + "." + name
michael@0 113 });
michael@0 114 }
michael@0 115
michael@0 116 // Reproduce what is done by unit-test.findAndRunTests()
michael@0 117 var { TestRunner } = loader.require("../deprecated/unit-test");
michael@0 118 var runner = new TestRunner();
michael@0 119 runner.startMany({
michael@0 120 tests: tests,
michael@0 121 stopOnError: cfxArgs.stopOnError,
michael@0 122 onDone: nextIteration
michael@0 123 });
michael@0 124 });
michael@0 125 }

mercurial