gecko/webapprt/test/chrome/browser_window-title.js
Myk Melez 782fce224f bug 770770: refactor webapp runtime test harness to reduce complexity/special-casing; r=adw
--HG--
extra : rebase_source : 183331b565d8c0577c9ba60a89f3c1ea6b11af9a
2012-08-14 15:27:26 -07:00

54 lines
1.9 KiB
JavaScript

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://webapprt/modules/WebappRT.jsm");
function test() {
waitForExplicitFinish();
loadWebapp("window-title.webapp", undefined, function onLoad() {
is(document.documentElement.getAttribute("title"),
WebappRT.config.app.manifest.name,
"initial window title should be webapp name");
// Tests are triples of [URL to load, expected window title, test message].
let tests = [
["http://example.com/webapprtChrome/webapprt/test/chrome/window-title.html",
"http://example.com" + " - " + WebappRT.config.app.manifest.name,
"window title should show origin of page at different origin"],
["http://mochi.test:8888/webapprtChrome/webapprt/test/chrome/window-title.html",
WebappRT.config.app.manifest.name,
"after returning to app origin, window title should no longer show origin"],
];
let title, message;
let progressListener = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference]),
onLocationChange: function onLocationChange(progress, request, location,
flags) {
// Do test in timeout to give runtime time to change title.
window.setTimeout(function() {
is(document.documentElement.getAttribute("title"), title, message);
testNext();
}, 0);
}
};
gAppBrowser.addProgressListener(progressListener,
Ci.nsIWebProgress.NOTIFY_LOCATION);
function testNext() {
if (!tests.length) {
gAppBrowser.removeProgressListener(progressListener);
gAppBrowser.stop();
finish();
return;
}
[gAppBrowser.contentDocument.location, title, message] = tests.shift();
}
testNext();
});
}