webapprt/test/chrome/browser_window-open.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:825b178ff69c
1 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
2 Cu.import("resource://webapprt/modules/WebappRT.jsm");
3 let { DOMApplicationRegistry } =
4 Cu.import("resource://gre/modules/Webapps.jsm", {});
5
6 function test() {
7 waitForExplicitFinish();
8
9 let appID = Ci.nsIScriptSecurityManager.NO_APP_ID;
10
11 let progressListener = {
12 QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
13 Ci.nsISupportsWeakReference]),
14 onLocationChange: function(progress, request, location, flags) {
15 ok(false, "Content redirected")
16 finish();
17 }
18 };
19
20 let winObserver = function(win, topic) {
21 if (topic == "domwindowopened") {
22 win.addEventListener("load", function onLoadWindow() {
23 win.removeEventListener("load", onLoadWindow, false);
24
25 if (win.location == "chrome://webapprt/content/webapp.xul") {
26 let winAppBrowser = win.document.getElementById("content");
27 winAppBrowser.addEventListener("load", function onLoadBrowser() {
28 winAppBrowser.removeEventListener("load", onLoadBrowser, true);
29
30 is(winAppBrowser.getAttribute("src"),
31 "http://test/webapprtChrome/webapprt/test/chrome/sample.html",
32 "New window browser has correct src");
33
34 is(winAppBrowser.contentDocument.defaultView.document.nodePrincipal.appId,
35 appID,
36 "New window principal app ID correct");
37
38 win.close();
39
40 finish();
41 }, true);
42 }
43 }, false);
44 }
45 }
46
47 Services.ww.registerNotification(winObserver);
48
49 loadWebapp("window-open.webapp", undefined, function() {
50 appID = gAppBrowser.contentDocument.defaultView.document.nodePrincipal.appId;
51
52 is(DOMApplicationRegistry.getAppLocalIdByManifestURL(WebappRT.config.app.manifestURL),
53 appID,
54 "Principal app ID correct");
55
56 gAppBrowser.addProgressListener(progressListener,
57 Ci.nsIWebProgress.NOTIFY_LOCATION);
58 });
59
60 registerCleanupFunction(function() {
61 Services.ww.unregisterNotification(winObserver);
62 gAppBrowser.removeProgressListener(progressListener);
63 });
64 }

mercurial