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 file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: // Some of the code we want to provide to chrome mochitests is in another file michael@0: // so we can share it with the mochitest shim window, thus we need to load it. michael@0: Services.scriptloader michael@0: .loadSubScript("chrome://webapprt/content/mochitest-shared.js", this); michael@0: michael@0: const MANIFEST_URL_BASE = Services.io.newURI( michael@0: "http://test/webapprtChrome/webapprt/test/chrome/", null, null); michael@0: michael@0: /** michael@0: * Load the webapp in the app browser. michael@0: * michael@0: * @param {String} manifestURL michael@0: * @see becomeWebapp michael@0: * @param {Object} parameters michael@0: * @see becomeWebapp michael@0: * @param {Function} onLoad michael@0: * The callback to call once the webapp is loaded. michael@0: */ michael@0: function loadWebapp(manifest, parameters, onLoad) { michael@0: let url = Services.io.newURI(manifest, null, MANIFEST_URL_BASE); michael@0: michael@0: becomeWebapp(url.spec, parameters, function onBecome() { michael@0: function onLoadApp() { michael@0: gAppBrowser.removeEventListener("DOMContentLoaded", onLoadApp, true); michael@0: onLoad(); michael@0: } michael@0: gAppBrowser.addEventListener("DOMContentLoaded", onLoadApp, true); michael@0: gAppBrowser.setAttribute("src", WebappRT.launchURI); michael@0: }); michael@0: michael@0: registerCleanupFunction(function() { michael@0: // We load DOMApplicationRegistry into a local scope to avoid appearing michael@0: // to leak it. michael@0: let scope = {}; michael@0: Cu.import("resource://gre/modules/Webapps.jsm", scope); michael@0: scope.DOMApplicationRegistry.uninstall(url.spec); michael@0: }); michael@0: }