michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: 'use strict'; michael@0: michael@0: const { Loader, Require, unload, override } = require('sdk/loader/cuddlefish'); michael@0: const packaging = require('@loader/options'); michael@0: michael@0: exports['test loader'] = function(assert) { michael@0: var prints = []; michael@0: function print(message) { michael@0: prints.push(message); michael@0: } michael@0: michael@0: let loader = Loader(override(packaging, { michael@0: globals: { michael@0: print: print, michael@0: foo: 1 michael@0: } michael@0: })); michael@0: let require = Require(loader, module); michael@0: michael@0: var fixture = require('./loader/fixture'); michael@0: michael@0: assert.equal(fixture.foo, 1, 'custom globals must work.'); michael@0: assert.equal(fixture.bar, 2, 'exports are set'); michael@0: michael@0: assert.equal(prints[0], 'testing', 'global print must be injected.'); michael@0: michael@0: var unloadsCalled = ''; michael@0: michael@0: require("sdk/system/unload").when(function(reason) { michael@0: assert.equal(reason, 'test', 'unload reason is passed'); michael@0: unloadsCalled += 'a'; michael@0: }); michael@0: require('sdk/system/unload.js').when(function() { michael@0: unloadsCalled += 'b'; michael@0: }); michael@0: michael@0: unload(loader, 'test'); michael@0: michael@0: assert.equal(unloadsCalled, 'ba', michael@0: 'loader.unload() must call listeners in LIFO order.'); michael@0: }; michael@0: michael@0: require('test').run(exports);