michael@0: // Test that having two frames that request installs at the same time doesn't michael@0: // cause callback ID conflicts (discussed in bug 926712) michael@0: michael@0: let {Promise} = Cu.import("resource://gre/modules/Promise.jsm"); michael@0: michael@0: let gConcurrentTabs = []; michael@0: let gQueuedForInstall = []; michael@0: let gResults = []; michael@0: michael@0: let gAddonAndWindowListener = { michael@0: onOpenWindow: function(win) { michael@0: var window = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); michael@0: info("Window opened"); michael@0: michael@0: waitForFocus(function() { michael@0: info("Focused!"); michael@0: // Initially the accept button is disabled on a countdown timer michael@0: let button = window.document.documentElement.getButton("accept"); michael@0: button.disabled = false; michael@0: if (gQueuedForInstall.length > 0) { michael@0: // Start downloading the next add-on while we accept this dialog: michael@0: installNext(); michael@0: } michael@0: window.document.documentElement.acceptDialog(); michael@0: }, window); michael@0: }, michael@0: onCloseWindow: function(win) { }, michael@0: onInstallEnded: function(install) { michael@0: install.cancel(); michael@0: }, michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediatorListener]) michael@0: }; michael@0: michael@0: function installNext() { michael@0: let tab = gQueuedForInstall.shift(); michael@0: tab.linkedBrowser.contentDocument.getElementById("installnow").click(); michael@0: } michael@0: michael@0: function winForTab(t) { michael@0: return t.linkedBrowser.contentDocument.defaultView; michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true); michael@0: Services.wm.addListener(gAddonAndWindowListener); michael@0: AddonManager.addInstallListener(gAddonAndWindowListener); michael@0: registerCleanupFunction(function() { michael@0: Services.wm.removeListener(gAddonAndWindowListener); michael@0: AddonManager.removeInstallListener(gAddonAndWindowListener); michael@0: Services.prefs.clearUserPref(PREF_LOGGING_ENABLED); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: Services.perms.remove("example.org", "install"); michael@0: michael@0: while (gConcurrentTabs.length) { michael@0: gBrowser.removeTab(gConcurrentTabs.shift()); michael@0: } michael@0: }); michael@0: michael@0: let pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: gConcurrentTabs.push(gBrowser.addTab(TESTROOT + "concurrent_installs.html")); michael@0: gConcurrentTabs.push(gBrowser.addTab(TESTROOT2 + "concurrent_installs.html")); michael@0: michael@0: let promises = gConcurrentTabs.map((t) => { michael@0: let deferred = Promise.defer(); michael@0: t.linkedBrowser.addEventListener("load", () => { michael@0: let win = winForTab(t); michael@0: if (win.location.host.startsWith("example")) { michael@0: win.wrappedJSObject.installTriggerCallback = function(rv) { michael@0: gResults.push(rv); michael@0: if (gResults.length == 2) { michael@0: executeSoon(endThisTest); michael@0: } michael@0: }; michael@0: deferred.resolve(); michael@0: } michael@0: }, true); michael@0: return deferred.promise; michael@0: }); michael@0: michael@0: Promise.all(promises).then(() => { michael@0: gQueuedForInstall = [...gConcurrentTabs]; michael@0: installNext(); michael@0: }); michael@0: } michael@0: michael@0: function endThisTest() { michael@0: is(gResults.length, 2, "Should have two urls"); michael@0: isnot(gResults[0].loc, gResults[1].loc, "Should not have results from the same page."); michael@0: isnot(gResults[0].xpi, gResults[1].xpi, "Should not have the same XPIs."); michael@0: for (let i = 0; i < 2; i++) { michael@0: let {loc, xpi} = gResults[i]; michael@0: if (loc.contains("example.org")) { michael@0: ok(xpi.contains("example.org"), "Should get .org XPI for .org loc"); michael@0: } else if (loc.contains("example.com")) { michael@0: ok(xpi.contains("example.com"), "Should get .com XPI for .com loc"); michael@0: } else { michael@0: ok(false, "Should never get anything that isn't from example.org or example.com"); michael@0: } michael@0: } michael@0: michael@0: finish(); michael@0: } michael@0: