addon-sdk/source/test/addons/main/main.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/addons/main/main.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +'use strict';
     1.8 +
     1.9 +const { setTimeout } = require('sdk/timers');
    1.10 +
    1.11 +let mainStarted = false;
    1.12 +
    1.13 +exports.main = function main(options, callbacks) {
    1.14 +  mainStarted = true;
    1.15 +
    1.16 +  let tests = {};
    1.17 +
    1.18 +  tests.testMainArguments = function(assert) {
    1.19 +  	assert.ok(!!options, 'options argument provided to main');
    1.20 +    assert.ok('loadReason' in options, 'loadReason is in options provided by main');
    1.21 +    assert.equal(typeof callbacks.print, 'function', 'callbacks.print is a function');
    1.22 +    assert.equal(typeof callbacks.quit, 'function', 'callbacks.quit is a function');
    1.23 +    assert.equal(options.loadReason, 'install', 'options.loadReason is install');
    1.24 +  }
    1.25 +
    1.26 +  require('sdk/test/runner').runTestsFromModule({exports: tests});
    1.27 +}
    1.28 +
    1.29 +// this causes a fail if main does not start
    1.30 +setTimeout(function() {
    1.31 +  if (mainStarted)
    1.32 +  	return;
    1.33 +
    1.34 +  // main didn't start, fail..
    1.35 +  require("sdk/test/runner").runTestsFromModule({exports: {
    1.36 +  	testFail: function(assert) assert.fail('Main did not start..')
    1.37 +  }});
    1.38 +}, 500);

mercurial