webapprt/test/chrome/browser_window-title.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/webapprt/test/chrome/browser_window-title.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
     1.5 +Cu.import("resource://webapprt/modules/WebappRT.jsm");
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +
    1.10 +  loadWebapp("window-title.webapp", undefined, function onLoad() {
    1.11 +    is(document.documentElement.getAttribute("title"),
    1.12 +       WebappRT.config.app.manifest.name,
    1.13 +       "initial window title should be webapp name");
    1.14 +
    1.15 +    // Tests are triples of [URL to load, expected window title, test message].
    1.16 +    let tests = [
    1.17 +      ["http://example.com/webapprtChrome/webapprt/test/chrome/window-title.html",
    1.18 +       "http://example.com" + " - " + WebappRT.config.app.manifest.name,
    1.19 +       "window title should show origin of page at different origin"],
    1.20 +      ["http://test/webapprtChrome/webapprt/test/chrome/window-title.html",
    1.21 +       WebappRT.config.app.manifest.name,
    1.22 +       "after returning to app origin, window title should no longer show origin"],
    1.23 +    ];
    1.24 +
    1.25 +    let title, message;
    1.26 +
    1.27 +    let progressListener = {
    1.28 +      QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
    1.29 +                                             Ci.nsISupportsWeakReference]),
    1.30 +      onLocationChange: function onLocationChange(progress, request, location,
    1.31 +                                                  flags) {
    1.32 +        // Do test in timeout to give runtime time to change title.
    1.33 +        window.setTimeout(function() {
    1.34 +          is(document.documentElement.getAttribute("title"), title, message);
    1.35 +          testNext();
    1.36 +        }, 0);
    1.37 +      }
    1.38 +    };
    1.39 +
    1.40 +    gAppBrowser.addProgressListener(progressListener,
    1.41 +                                    Ci.nsIWebProgress.NOTIFY_LOCATION);
    1.42 +
    1.43 +    function testNext() {
    1.44 +      if (!tests.length) {
    1.45 +        gAppBrowser.removeProgressListener(progressListener);
    1.46 +        gAppBrowser.stop();
    1.47 +        finish();
    1.48 +        return;
    1.49 +      }
    1.50 +
    1.51 +      [gAppBrowser.contentDocument.location, title, message] = tests.shift();
    1.52 +    }
    1.53 +
    1.54 +    testNext();
    1.55 +  });
    1.56 +}

mercurial