--- a/browser/base/content/test/general/browser_bug553455.js
+++ b/browser/base/content/test/general/browser_bug553455.js
@@ -1,15 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
const TESTROOT2 = "http://example.org/browser/toolkit/mozapps/extensions/test/xpinstall/";
const SECUREROOT = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
+const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts";
const PROGRESS_NOTIFICATION = "addon-progress";
var rootDir = getRootDirectory(gTestPath);
var path = rootDir.split('/');
var chromeName = path[0] + '//' + path[2];
var croot = chromeName + "/content/browser/toolkit/mozapps/extensions/test/xpinstall/";
var jar = getJar(croot);
@@ -81,16 +82,62 @@ function wait_for_notification(aId, aCal
function wait_for_notification_close(aCallback) {
info("Waiting for notification to close");
PopupNotifications.panel.addEventListener("popuphidden", function() {
PopupNotifications.panel.removeEventListener("popuphidden", arguments.callee, false);
aCallback();
}, false);
}
+function wait_for_install_dialog(aCallback) {
+ if (Preferences.get("xpinstall.customConfirmationUI", false)) {
+ wait_for_notification("addon-install-confirmation", function(aPanel) {
+ aCallback();
+ });
+ return;
+ }
+
+ info("Waiting for install dialog");
+
+ Services.wm.addListener({
+ onOpenWindow: function(aXULWindow) {
+ info("Install dialog opened, waiting for focus");
+ Services.wm.removeListener(this);
+
+ var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+ waitForFocus(function() {
+ info("Saw install dialog");
+ is(domwindow.document.location.href, XPINSTALL_URL, "Should have seen the right window open");
+
+ // Override the countdown timer on the accept button
+ var button = domwindow.document.documentElement.getButton("accept");
+ button.disabled = false;
+
+ aCallback();
+ }, domwindow);
+ },
+
+ onCloseWindow: function(aXULWindow) {
+ },
+
+ onWindowTitleChange: function(aXULWindow, aNewTitle) {
+ }
+ });
+}
+
+function accept_install_dialog() {
+ if (Preferences.get("xpinstall.customConfirmationUI", false)) {
+ document.getElementById("addon-install-confirmation-accept").click();
+ } else {
+ let win = Services.wm.getMostRecentWindow("Addons:Install");
+ win.document.documentElement.acceptDialog();
+ }
+}
+
function wait_for_single_notification(aCallback) {
function inner_waiter() {
info("Waiting for single notification");
// Notification should never close while we wait
ok(PopupNotifications.isPanelOpen, "Notification should still be open");
if (PopupNotifications.panel.childNodes.length == 2) {
executeSoon(inner_waiter);
return;
@@ -160,17 +207,17 @@ function test_blocked_install() {
is(notification.button.label, "Allow", "Should have seen the right button");
is(notification.getAttribute("originhost"), "example.com",
"Should have seen the right origin host");
is(notification.getAttribute("label"),
gApp + " prevented this site from asking you to install software on your computer.",
"Should have seen the right message");
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.button.label, "Restart Now", "Should have seen the right button");
is(notification.getAttribute("label"),
"XPI Test will be installed after you restart " + gApp + ".",
"Should have seen the right message");
@@ -178,17 +225,17 @@ function test_blocked_install() {
is(aInstalls.length, 1, "Should be one pending install");
aInstalls[0].cancel();
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
// Click on Allow
EventUtils.synthesizeMouse(notification.button, 20, 10, {});
// Notification should have changed to progress notification
ok(PopupNotifications.isPanelOpen, "Notification should still be open");
notification = aPanel.childNodes[0];
@@ -203,17 +250,17 @@ function test_blocked_install() {
},
function test_whitelisted_install() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
gBrowser.selectedTab = originalTab;
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
is(gBrowser.selectedTab, tab,
"tab selected in response to the addon-install-confirmation notification");
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.button.label, "Restart Now", "Should have seen the right button");
is(notification.getAttribute("label"),
@@ -225,17 +272,17 @@ function test_whitelisted_install() {
aInstalls[0].cancel();
Services.perms.remove("example.com", "install");
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"XPI": "unsigned.xpi"
@@ -326,17 +373,17 @@ function test_incompatible() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
},
function test_restartless() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.getAttribute("label"),
"XPI Test has been installed successfully.",
"Should have seen the right message");
AddonManager.getAllInstalls(function(aInstalls) {
@@ -347,17 +394,17 @@ function test_restartless() {
Services.perms.remove("example.com", "install");
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"XPI": "restartless.xpi"
@@ -365,17 +412,17 @@ function test_restartless() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
},
function test_multiple() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.button.label, "Restart Now", "Should have seen the right button");
is(notification.getAttribute("label"),
"2 add-ons will be installed after you restart " + gApp + ".",
"Should have seen the right message");
@@ -388,17 +435,17 @@ function test_multiple() {
Services.perms.remove("example.com", "install");
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": "unsigned.xpi",
@@ -407,17 +454,17 @@ function test_multiple() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
},
function test_url() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.button.label, "Restart Now", "Should have seen the right button");
is(notification.getAttribute("label"),
"XPI Test will be installed after you restart " + gApp + ".",
"Should have seen the right message");
@@ -425,17 +472,17 @@ function test_url() {
is(aInstalls.length, 1, "Should be one pending install");
aInstalls[0].cancel();
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "unsigned.xpi");
},
function test_localfile() {
@@ -494,17 +541,17 @@ function test_wronghost() {
}, true);
gBrowser.loadURI(TESTROOT2 + "enabled.html");
},
function test_reload() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.button.label, "Restart Now", "Should have seen the right button");
is(notification.getAttribute("label"),
"XPI Test will be installed after you restart " + gApp + ".",
"Should have seen the right message");
@@ -529,17 +576,17 @@ function test_reload() {
Services.perms.remove("example.com", "install");
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
}, true);
gBrowser.loadURI(TESTROOT2 + "enabled.html");
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": "unsigned.xpi"
@@ -547,17 +594,17 @@ function test_reload() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
},
function test_theme() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
let notification = aPanel.childNodes[0];
is(notification.button.label, "Restart Now", "Should have seen the right button");
is(notification.getAttribute("label"),
"Theme Test will be installed after you restart " + gApp + ".",
"Should have seen the right message");
@@ -572,17 +619,17 @@ function test_theme() {
Services.perms.remove("example.com", "install");
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Theme XPI": "theme.xpi"
@@ -625,54 +672,54 @@ function test_renotify_blocked() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
},
function test_renotify_installed() {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
// Dismiss the notification
wait_for_notification_close(function () {
// Install another
executeSoon(function () {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the install confirmation dialog
- wait_for_notification("addon-install-confirmation", function(aPanel) {
+ wait_for_install_dialog(function() {
info("Timeouts after this probably mean bug 589954 regressed");
// Wait for the complete notification
wait_for_notification("addon-install-complete", function(aPanel) {
AddonManager.getAllInstalls(function(aInstalls) {
is(aInstalls.length, 1, "Should be one pending installs");
aInstalls[0].cancel();
Services.perms.remove("example.com", "install");
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
});
});
// hide the panel (this simulates the user dismissing it)
aPanel.hidePopup();
});
- document.getElementById("addon-install-confirmation-accept").click();
+ accept_install_dialog();
});
});
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"XPI": "unsigned.xpi"