webapprt/test/chrome/head.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/webapprt/test/chrome/head.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     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 file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +Cu.import("resource://gre/modules/Services.jsm");
     1.9 +
    1.10 +// Some of the code we want to provide to chrome mochitests is in another file
    1.11 +// so we can share it with the mochitest shim window, thus we need to load it.
    1.12 +Services.scriptloader
    1.13 +        .loadSubScript("chrome://webapprt/content/mochitest-shared.js", this);
    1.14 +
    1.15 +const MANIFEST_URL_BASE = Services.io.newURI(
    1.16 +  "http://test/webapprtChrome/webapprt/test/chrome/", null, null);
    1.17 +
    1.18 +/**
    1.19 + * Load the webapp in the app browser.
    1.20 + *
    1.21 + * @param {String} manifestURL
    1.22 + *        @see becomeWebapp
    1.23 + * @param {Object} parameters
    1.24 + *        @see becomeWebapp
    1.25 + * @param {Function} onLoad
    1.26 + *        The callback to call once the webapp is loaded.
    1.27 + */
    1.28 +function loadWebapp(manifest, parameters, onLoad) {
    1.29 +  let url = Services.io.newURI(manifest, null, MANIFEST_URL_BASE);
    1.30 +
    1.31 +  becomeWebapp(url.spec, parameters, function onBecome() {
    1.32 +    function onLoadApp() {
    1.33 +      gAppBrowser.removeEventListener("DOMContentLoaded", onLoadApp, true);
    1.34 +      onLoad();
    1.35 +    }
    1.36 +    gAppBrowser.addEventListener("DOMContentLoaded", onLoadApp, true);
    1.37 +    gAppBrowser.setAttribute("src", WebappRT.launchURI);
    1.38 +  });
    1.39 +
    1.40 +  registerCleanupFunction(function() {
    1.41 +    // We load DOMApplicationRegistry into a local scope to avoid appearing
    1.42 +    // to leak it.
    1.43 +    let scope = {};
    1.44 +    Cu.import("resource://gre/modules/Webapps.jsm", scope);
    1.45 +    scope.DOMApplicationRegistry.uninstall(url.spec);
    1.46 +  });
    1.47 +}

mercurial