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