webapprt/test/chrome/head.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:201f93408c1e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 Cu.import("resource://gre/modules/Services.jsm");
6
7 // Some of the code we want to provide to chrome mochitests is in another file
8 // so we can share it with the mochitest shim window, thus we need to load it.
9 Services.scriptloader
10 .loadSubScript("chrome://webapprt/content/mochitest-shared.js", this);
11
12 const MANIFEST_URL_BASE = Services.io.newURI(
13 "http://test/webapprtChrome/webapprt/test/chrome/", null, null);
14
15 /**
16 * Load the webapp in the app browser.
17 *
18 * @param {String} manifestURL
19 * @see becomeWebapp
20 * @param {Object} parameters
21 * @see becomeWebapp
22 * @param {Function} onLoad
23 * The callback to call once the webapp is loaded.
24 */
25 function loadWebapp(manifest, parameters, onLoad) {
26 let url = Services.io.newURI(manifest, null, MANIFEST_URL_BASE);
27
28 becomeWebapp(url.spec, parameters, function onBecome() {
29 function onLoadApp() {
30 gAppBrowser.removeEventListener("DOMContentLoaded", onLoadApp, true);
31 onLoad();
32 }
33 gAppBrowser.addEventListener("DOMContentLoaded", onLoadApp, true);
34 gAppBrowser.setAttribute("src", WebappRT.launchURI);
35 });
36
37 registerCleanupFunction(function() {
38 // We load DOMApplicationRegistry into a local scope to avoid appearing
39 // to leak it.
40 let scope = {};
41 Cu.import("resource://gre/modules/Webapps.jsm", scope);
42 scope.DOMApplicationRegistry.uninstall(url.spec);
43 });
44 }

mercurial