webapprt/test/chrome/browser_window-title.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:6929f1acee04
1 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
2 Cu.import("resource://webapprt/modules/WebappRT.jsm");
3
4 function test() {
5 waitForExplicitFinish();
6
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");
11
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 ];
21
22 let title, message;
23
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 };
36
37 gAppBrowser.addProgressListener(progressListener,
38 Ci.nsIWebProgress.NOTIFY_LOCATION);
39
40 function testNext() {
41 if (!tests.length) {
42 gAppBrowser.removeProgressListener(progressListener);
43 gAppBrowser.stop();
44 finish();
45 return;
46 }
47
48 [gAppBrowser.contentDocument.location, title, message] = tests.shift();
49 }
50
51 testNext();
52 });
53 }

mercurial