Bug 771294 - Install App doorhanger remains visible when installing page immediately loads another page. r=myk

--HG--
rename : dom/tests/mochitest/webapps/bug_765063.xul => dom/tests/mochitest/webapps/install_and_redirect_helper.xul
This commit is contained in:
Marco Castelluccio 2013-08-05 16:30:41 -04:00
parent cacd35ced5
commit dfc9d0934f
5 changed files with 99 additions and 40 deletions

View File

@ -34,9 +34,10 @@ this.webappsUI = {
switch(aTopic) {
case "webapps-ask-install":
let [chromeWin, browser] = this._getBrowserForId(data.oid);
if (chromeWin)
this.doInstall(data, browser, chromeWin);
let win = this._getWindowForId(data.oid);
if (win && win.location.href == data.from) {
this.doInstall(data, win);
}
break;
case "webapps-launch":
WebappOSUtils.launch(data);
@ -47,6 +48,13 @@ this.webappsUI = {
}
},
_getWindowForId: function(aId) {
let someWindow = Services.wm.getMostRecentWindow(null);
return someWindow && someWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.getOuterWindowWithId(aId);
},
openURL: function(aUrl, aOrigin) {
let browserEnumerator = Services.wm.getEnumerator("navigator:browser");
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
@ -86,21 +94,13 @@ this.webappsUI = {
}
},
_getBrowserForId: function(aId) {
let content = Services.wm.getOuterWindowWithId(aId);
if (content) {
let browser = content.QueryInterface(Ci.nsIInterfaceRequestor)
doInstall: function(aData, aWindow) {
let browser = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell).chromeEventHandler;
let win = browser.ownerDocument.defaultView;
return [win, browser];
}
return [null, null];
},
doInstall: function(aData, aBrowser, aWindow) {
let bundle = aWindow.gNavigatorBundle;
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
let chromeWin = browser.ownerDocument.defaultView;
let bundle = chromeWin.gNavigatorBundle;
let mainAction = {
label: bundle.getString("webapps.install"),
@ -117,7 +117,7 @@ this.webappsUI = {
DOMApplicationRegistry.confirmInstall(aData, false, localDir, null,
function (aManifest) {
if (WebappsInstaller.install(aData, aManifest)) {
installationSuccessNotification(aData, app, aWindow);
installationSuccessNotification(aData, app, chromeWin);
}
}
);
@ -127,7 +127,7 @@ this.webappsUI = {
}
};
let requestingURI = aWindow.makeURI(aData.from);
let requestingURI = chromeWin.makeURI(aData.from);
let jsonManifest = aData.isPackage ? aData.app.updateManifest : aData.app.manifest;
let manifest = new ManifestHelper(jsonManifest, aData.app.origin);
@ -141,7 +141,7 @@ this.webappsUI = {
let message = bundle.getFormattedString("webapps.requestInstall",
[manifest.name, host], 2);
aWindow.PopupNotifications.show(aBrowser, "webapps-install", message,
chromeWin.PopupNotifications.show(browser, "webapps-install", message,
"webapps-notification-icon", mainAction);
}

View File

@ -11,11 +11,12 @@ relativesrcdir = @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MOCHITEST_CHROME_FILES = \
bug_765063.xul \
install_and_redirect_helper.xul \
cross_origin.html \
head.js \
test_bug_765063.xul \
test_bug_795164.xul \
test_bug_771294.xul \
test_cross_origin.xul \
test_install_app.xul \
test_list_api.xul \

View File

@ -3,8 +3,7 @@
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Mozilla Bug 765063 Helper">
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
navigator.mozApps.install(url, null);

View File

@ -22,26 +22,23 @@ SimpleTest.waitForExplicitFinish();
makeAllAppsLaunchable();
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
var mmListener = {
receiveMessage: function(aMessage) {
ppmm.removeMessageListener("Webapps:Install", mmListener);
// Observe app installation and confirm that the install origin didn't change.
var observer = {
observe: function observe(subject, topic, data) {
Services.obs.removeObserver(observer, "webapps-sync-install");
is(JSON.parse(data).installOrigin, "http://test",
"the install origin didn't change");
var msg = aMessage.json;
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(msg.from, null, null);
is(uri.prePath, "http://test", "the install origin didn't change");
navigator.mozApps.mgmt.getAll().onsuccess = function onGetAll() {
var app = [a for (a of this.result) if (a.manifestURL == url)][0];
navigator.mozApps.mgmt.uninstall(app).onsuccess = function onUninstall() {
SimpleTest.finish();
}
}
}
};
Components.utils.import("resource://gre/modules/Services.jsm");
Services.obs.addObserver(observer, "webapps-sync-install", false);
var ppmm = Components.classes["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Components.interfaces.nsIMessageBroadcaster);
ppmm.addMessageListener("Webapps:Install", mmListener);
// We call this here, even though the app is installed by the helper page,
// because the helper page redirect would cause its install listener to unload
@ -53,6 +50,6 @@ confirmNextInstall();
<!-- Load a page that initiates an app installation and then immediately
- redirects to a page at a different origin. We can't do this directly
- inside this test page, because that would cause the test to hang. -->
<iframe src="http://test/chrome/dom/tests/mochitest/webapps/bug_765063.xul"/>
<iframe src="http://test/chrome/dom/tests/mochitest/webapps/install_and_redirect_helper.xul"/>
</window>

View File

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Mozilla Bug 771294">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="head.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=771294"
target="_blank">Mozilla Bug 771294</a>
</body>
<script>
const Ci = Components.interfaces;
const Cu = Components.utils;
SimpleTest.waitForExplicitFinish();
makeAllAppsLaunchable();
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PopupNotifications.jsm");
let blocked = true;
window.top.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler.ownerDocument.defaultView
.PopupNotifications.panel
.addEventListener("popupshowing", function() {
blocked = false;
}, false);
Services.obs.addObserver(
function observeInstalling() {
Services.obs.removeObserver(observeInstalling, "webapps-ask-install");
// Spin the event loop before running the test to give the registry time
// to process the install request and (hopefully not) show the doorhanger.
setTimeout(function verify() {
ok(blocked, "Install panel was blocked after immediate redirect");
SimpleTest.finish();
}, 0);
},
"webapps-ask-install",
false
);
</script>
<!-- Load a page that initiates an app installation and then immediately
- redirects to a page at a different origin. We can't do this directly
- inside this test page, because that would cause the test to hang. -->
<iframe src="http://test/chrome/dom/tests/mochitest/webapps/install_and_redirect_helper.xul"/>
</window>