1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/webapprt/test/chrome/browser_window-open.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.5 +Cu.import("resource://webapprt/modules/WebappRT.jsm"); 1.6 +let { DOMApplicationRegistry } = 1.7 + Cu.import("resource://gre/modules/Webapps.jsm", {}); 1.8 + 1.9 +function test() { 1.10 + waitForExplicitFinish(); 1.11 + 1.12 + let appID = Ci.nsIScriptSecurityManager.NO_APP_ID; 1.13 + 1.14 + let progressListener = { 1.15 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, 1.16 + Ci.nsISupportsWeakReference]), 1.17 + onLocationChange: function(progress, request, location, flags) { 1.18 + ok(false, "Content redirected") 1.19 + finish(); 1.20 + } 1.21 + }; 1.22 + 1.23 + let winObserver = function(win, topic) { 1.24 + if (topic == "domwindowopened") { 1.25 + win.addEventListener("load", function onLoadWindow() { 1.26 + win.removeEventListener("load", onLoadWindow, false); 1.27 + 1.28 + if (win.location == "chrome://webapprt/content/webapp.xul") { 1.29 + let winAppBrowser = win.document.getElementById("content"); 1.30 + winAppBrowser.addEventListener("load", function onLoadBrowser() { 1.31 + winAppBrowser.removeEventListener("load", onLoadBrowser, true); 1.32 + 1.33 + is(winAppBrowser.getAttribute("src"), 1.34 + "http://test/webapprtChrome/webapprt/test/chrome/sample.html", 1.35 + "New window browser has correct src"); 1.36 + 1.37 + is(winAppBrowser.contentDocument.defaultView.document.nodePrincipal.appId, 1.38 + appID, 1.39 + "New window principal app ID correct"); 1.40 + 1.41 + win.close(); 1.42 + 1.43 + finish(); 1.44 + }, true); 1.45 + } 1.46 + }, false); 1.47 + } 1.48 + } 1.49 + 1.50 + Services.ww.registerNotification(winObserver); 1.51 + 1.52 + loadWebapp("window-open.webapp", undefined, function() { 1.53 + appID = gAppBrowser.contentDocument.defaultView.document.nodePrincipal.appId; 1.54 + 1.55 + is(DOMApplicationRegistry.getAppLocalIdByManifestURL(WebappRT.config.app.manifestURL), 1.56 + appID, 1.57 + "Principal app ID correct"); 1.58 + 1.59 + gAppBrowser.addProgressListener(progressListener, 1.60 + Ci.nsIWebProgress.NOTIFY_LOCATION); 1.61 + }); 1.62 + 1.63 + registerCleanupFunction(function() { 1.64 + Services.ww.unregisterNotification(winObserver); 1.65 + gAppBrowser.removeProgressListener(progressListener); 1.66 + }); 1.67 +}