webapprt/test/chrome/browser_window-title.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
     2 Cu.import("resource://webapprt/modules/WebappRT.jsm");
     4 function test() {
     5   waitForExplicitFinish();
     7   loadWebapp("window-title.webapp", undefined, function onLoad() {
     8     is(document.documentElement.getAttribute("title"),
     9        WebappRT.config.app.manifest.name,
    10        "initial window title should be webapp name");
    12     // Tests are triples of [URL to load, expected window title, test message].
    13     let tests = [
    14       ["http://example.com/webapprtChrome/webapprt/test/chrome/window-title.html",
    15        "http://example.com" + " - " + WebappRT.config.app.manifest.name,
    16        "window title should show origin of page at different origin"],
    17       ["http://test/webapprtChrome/webapprt/test/chrome/window-title.html",
    18        WebappRT.config.app.manifest.name,
    19        "after returning to app origin, window title should no longer show origin"],
    20     ];
    22     let title, message;
    24     let progressListener = {
    25       QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
    26                                              Ci.nsISupportsWeakReference]),
    27       onLocationChange: function onLocationChange(progress, request, location,
    28                                                   flags) {
    29         // Do test in timeout to give runtime time to change title.
    30         window.setTimeout(function() {
    31           is(document.documentElement.getAttribute("title"), title, message);
    32           testNext();
    33         }, 0);
    34       }
    35     };
    37     gAppBrowser.addProgressListener(progressListener,
    38                                     Ci.nsIWebProgress.NOTIFY_LOCATION);
    40     function testNext() {
    41       if (!tests.length) {
    42         gAppBrowser.removeProgressListener(progressListener);
    43         gAppBrowser.stop();
    44         finish();
    45         return;
    46       }
    48       [gAppBrowser.contentDocument.location, title, message] = tests.shift();
    49     }
    51     testNext();
    52   });
    53 }

mercurial