Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012, Mozilla Foundation and contributors |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | 'use strict'; |
michael@0 | 18 | |
michael@0 | 19 | require('../test/suite'); |
michael@0 | 20 | |
michael@0 | 21 | var examiner = require('../testharness/examiner'); |
michael@0 | 22 | var stati = require('../testharness/status').stati; |
michael@0 | 23 | var helpers = require('../test/helpers'); |
michael@0 | 24 | var Requisition = require('../cli').Requisition; |
michael@0 | 25 | var createRequisitionAutomator = require('../test/automators/requisition').createRequisitionAutomator; |
michael@0 | 26 | |
michael@0 | 27 | exports.optionsContainer = []; |
michael@0 | 28 | |
michael@0 | 29 | exports.items = [ |
michael@0 | 30 | { |
michael@0 | 31 | item: 'type', |
michael@0 | 32 | name: 'suite', |
michael@0 | 33 | parent: 'selection', |
michael@0 | 34 | cacheable: true, |
michael@0 | 35 | lookup: function() { |
michael@0 | 36 | return Object.keys(examiner.suites).map(function(name) { |
michael@0 | 37 | return { name: name, value: examiner.suites[name] }; |
michael@0 | 38 | }); |
michael@0 | 39 | } |
michael@0 | 40 | }, |
michael@0 | 41 | { |
michael@0 | 42 | item: 'command', |
michael@0 | 43 | name: 'test', |
michael@0 | 44 | description: 'Run GCLI unit tests', |
michael@0 | 45 | params: [ |
michael@0 | 46 | { |
michael@0 | 47 | name: 'suite', |
michael@0 | 48 | type: 'suite', |
michael@0 | 49 | description: 'Test suite to run.', |
michael@0 | 50 | defaultValue: examiner |
michael@0 | 51 | }, |
michael@0 | 52 | { |
michael@0 | 53 | name: 'usehost', |
michael@0 | 54 | type: 'boolean', |
michael@0 | 55 | description: 'Run the unit tests in the host window', |
michael@0 | 56 | option: true |
michael@0 | 57 | } |
michael@0 | 58 | ], |
michael@0 | 59 | returnType: 'examiner-output', |
michael@0 | 60 | noRemote: true, |
michael@0 | 61 | exec: function(args, context) { |
michael@0 | 62 | if (args.usehost && exports.optionsContainer.length === 0) { |
michael@0 | 63 | throw new Error('Can\'t use --usehost without injected options'); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | var options; |
michael@0 | 67 | if (args.usehost) { |
michael@0 | 68 | options = exports.optionsContainer[0]; |
michael@0 | 69 | } |
michael@0 | 70 | else { |
michael@0 | 71 | options = { |
michael@0 | 72 | isNode: (typeof(process) !== 'undefined' && process.title === 'node'), |
michael@0 | 73 | isFirefox: false, |
michael@0 | 74 | isPhantomjs: false, |
michael@0 | 75 | isNoDom: true, |
michael@0 | 76 | requisition: new Requisition() |
michael@0 | 77 | }; |
michael@0 | 78 | options.automator = createRequisitionAutomator(options.requisition); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | var requisition = options.requisition; |
michael@0 | 82 | requisition.canon.getCommand('mocks').on(requisition); |
michael@0 | 83 | helpers.resetResponseTimes(); |
michael@0 | 84 | examiner.reset(); |
michael@0 | 85 | |
michael@0 | 86 | return args.suite.run(options).then(function() { |
michael@0 | 87 | requisition.canon.getCommand('mocks').off(requisition); |
michael@0 | 88 | return examiner.toRemote(); |
michael@0 | 89 | }); |
michael@0 | 90 | } |
michael@0 | 91 | }, |
michael@0 | 92 | { |
michael@0 | 93 | item: 'converter', |
michael@0 | 94 | from: 'examiner-output', |
michael@0 | 95 | to: 'string', |
michael@0 | 96 | exec: function(output, conversionContext) { |
michael@0 | 97 | var reply = '\n' + examiner.detailedResultLog('NodeJS/NoDom') + |
michael@0 | 98 | '\n' + helpers.timingSummary; |
michael@0 | 99 | |
michael@0 | 100 | if (output.summary.status === stati.pass) { |
michael@0 | 101 | return reply; |
michael@0 | 102 | } |
michael@0 | 103 | else { |
michael@0 | 104 | throw reply; |
michael@0 | 105 | } |
michael@0 | 106 | } |
michael@0 | 107 | }, |
michael@0 | 108 | { |
michael@0 | 109 | item: 'converter', |
michael@0 | 110 | from: 'examiner-output', |
michael@0 | 111 | to: 'view', |
michael@0 | 112 | exec: function(output, conversionContext) { |
michael@0 | 113 | return { |
michael@0 | 114 | html: |
michael@0 | 115 | '<div>\n' + |
michael@0 | 116 | ' <table class="gcliTestResults">\n' + |
michael@0 | 117 | ' <thead>\n' + |
michael@0 | 118 | ' <tr>\n' + |
michael@0 | 119 | ' <th class="gcliTestSuite">Suite</th>\n' + |
michael@0 | 120 | ' <th>Test</th>\n' + |
michael@0 | 121 | ' <th>Results</th>\n' + |
michael@0 | 122 | ' <th>Checks</th>\n' + |
michael@0 | 123 | ' <th>Notes</th>\n' + |
michael@0 | 124 | ' </tr>\n' + |
michael@0 | 125 | ' </thead>\n' + |
michael@0 | 126 | ' <tbody foreach="suite in ${suites}">\n' + |
michael@0 | 127 | ' <tr foreach="test in ${suite.tests}" title="${suite.name}.${test.name}()">\n' + |
michael@0 | 128 | ' <td class="gcliTestSuite">${suite.name}</td>\n' + |
michael@0 | 129 | ' <td class="gcliTestTitle">${test.title}</td>\n' + |
michael@0 | 130 | ' <td class="gcliTest${test.status.name}">${test.status.name}</td>\n' + |
michael@0 | 131 | ' <td class="gcliTestChecks">${test.checks}</td>\n' + |
michael@0 | 132 | ' <td class="gcliTestMessages">\n' + |
michael@0 | 133 | ' <div foreach="failure in ${test.failures}">\n' + |
michael@0 | 134 | ' ${failure.message}\n' + |
michael@0 | 135 | ' <ul if="${failure.params}">\n' + |
michael@0 | 136 | ' <li>P1: ${failure.p1}</li>\n' + |
michael@0 | 137 | ' <li>P2: ${failure.p2}</li>\n' + |
michael@0 | 138 | ' </ul>\n' + |
michael@0 | 139 | ' </div>\n' + |
michael@0 | 140 | ' </td>\n' + |
michael@0 | 141 | ' </tr>\n' + |
michael@0 | 142 | ' </tbody>\n' + |
michael@0 | 143 | ' <tfoot>\n' + |
michael@0 | 144 | ' <tr>\n' + |
michael@0 | 145 | ' <th></th>\n' + |
michael@0 | 146 | ' <th>Total</th>\n' + |
michael@0 | 147 | ' <th>${summary.status.name}</th>\n' + |
michael@0 | 148 | ' <th class="gcliTestChecks">${summary.checks}</th>\n' + |
michael@0 | 149 | ' <th></th>\n' + |
michael@0 | 150 | ' </tr>\n' + |
michael@0 | 151 | ' </tfoot>\n' + |
michael@0 | 152 | ' </table>\n' + |
michael@0 | 153 | '</div>', |
michael@0 | 154 | css: |
michael@0 | 155 | '.gcliTestSkipped {\n' + |
michael@0 | 156 | ' background-color: #EEE;\n' + |
michael@0 | 157 | ' color: #000;\n' + |
michael@0 | 158 | '}\n' + |
michael@0 | 159 | '\n' + |
michael@0 | 160 | '.gcliTestExecuting {\n' + |
michael@0 | 161 | ' background-color: #888;\n' + |
michael@0 | 162 | ' color: #FFF;\n' + |
michael@0 | 163 | '}\n' + |
michael@0 | 164 | '\n' + |
michael@0 | 165 | '.gcliTestWaiting {\n' + |
michael@0 | 166 | ' background-color: #FFA;\n' + |
michael@0 | 167 | ' color: #000;\n' + |
michael@0 | 168 | '}\n' + |
michael@0 | 169 | '\n' + |
michael@0 | 170 | '.gcliTestPass {\n' + |
michael@0 | 171 | ' background-color: #8F8;\n' + |
michael@0 | 172 | ' color: #000;\n' + |
michael@0 | 173 | '}\n' + |
michael@0 | 174 | '\n' + |
michael@0 | 175 | '.gcliTestFail {\n' + |
michael@0 | 176 | ' background-color: #F00;\n' + |
michael@0 | 177 | ' color: #FFF;\n' + |
michael@0 | 178 | '}\n' + |
michael@0 | 179 | '\n' + |
michael@0 | 180 | 'td.gcliTestSuite {\n' + |
michael@0 | 181 | ' font-family: monospace;\n' + |
michael@0 | 182 | ' font-size: 90%;\n' + |
michael@0 | 183 | ' text-align: right;\n' + |
michael@0 | 184 | '}\n' + |
michael@0 | 185 | '\n' + |
michael@0 | 186 | '.gcliTestResults th.gcliTestSuite,\n' + |
michael@0 | 187 | '.gcliTestResults .gcliTestChecks {\n' + |
michael@0 | 188 | ' text-align: right;\n' + |
michael@0 | 189 | '}\n' + |
michael@0 | 190 | '\n' + |
michael@0 | 191 | '.gcliTestResults th {\n' + |
michael@0 | 192 | ' text-align: left;\n' + |
michael@0 | 193 | '}\n' + |
michael@0 | 194 | '\n' + |
michael@0 | 195 | '.gcliTestMessages ul {\n' + |
michael@0 | 196 | ' margin: 0 0 10px;\n' + |
michael@0 | 197 | ' padding-left: 20px;\n' + |
michael@0 | 198 | ' list-style-type: square;\n' + |
michael@0 | 199 | '}\n', |
michael@0 | 200 | cssId: 'gcli-test', |
michael@0 | 201 | data: output, |
michael@0 | 202 | options: { allowEval: true, stack: 'test.html' } |
michael@0 | 203 | }; |
michael@0 | 204 | } |
michael@0 | 205 | } |
michael@0 | 206 | ]; |