Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Test that having two frames that request installs at the same time doesn't |
michael@0 | 2 | // cause callback ID conflicts (discussed in bug 926712) |
michael@0 | 3 | |
michael@0 | 4 | let {Promise} = Cu.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 5 | |
michael@0 | 6 | let gConcurrentTabs = []; |
michael@0 | 7 | let gQueuedForInstall = []; |
michael@0 | 8 | let gResults = []; |
michael@0 | 9 | |
michael@0 | 10 | let gAddonAndWindowListener = { |
michael@0 | 11 | onOpenWindow: function(win) { |
michael@0 | 12 | var window = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); |
michael@0 | 13 | info("Window opened"); |
michael@0 | 14 | |
michael@0 | 15 | waitForFocus(function() { |
michael@0 | 16 | info("Focused!"); |
michael@0 | 17 | // Initially the accept button is disabled on a countdown timer |
michael@0 | 18 | let button = window.document.documentElement.getButton("accept"); |
michael@0 | 19 | button.disabled = false; |
michael@0 | 20 | if (gQueuedForInstall.length > 0) { |
michael@0 | 21 | // Start downloading the next add-on while we accept this dialog: |
michael@0 | 22 | installNext(); |
michael@0 | 23 | } |
michael@0 | 24 | window.document.documentElement.acceptDialog(); |
michael@0 | 25 | }, window); |
michael@0 | 26 | }, |
michael@0 | 27 | onCloseWindow: function(win) { }, |
michael@0 | 28 | onInstallEnded: function(install) { |
michael@0 | 29 | install.cancel(); |
michael@0 | 30 | }, |
michael@0 | 31 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediatorListener]) |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | function installNext() { |
michael@0 | 35 | let tab = gQueuedForInstall.shift(); |
michael@0 | 36 | tab.linkedBrowser.contentDocument.getElementById("installnow").click(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function winForTab(t) { |
michael@0 | 40 | return t.linkedBrowser.contentDocument.defaultView; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function test() { |
michael@0 | 44 | waitForExplicitFinish(); |
michael@0 | 45 | |
michael@0 | 46 | Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true); |
michael@0 | 47 | Services.wm.addListener(gAddonAndWindowListener); |
michael@0 | 48 | AddonManager.addInstallListener(gAddonAndWindowListener); |
michael@0 | 49 | registerCleanupFunction(function() { |
michael@0 | 50 | Services.wm.removeListener(gAddonAndWindowListener); |
michael@0 | 51 | AddonManager.removeInstallListener(gAddonAndWindowListener); |
michael@0 | 52 | Services.prefs.clearUserPref(PREF_LOGGING_ENABLED); |
michael@0 | 53 | |
michael@0 | 54 | Services.perms.remove("example.com", "install"); |
michael@0 | 55 | Services.perms.remove("example.org", "install"); |
michael@0 | 56 | |
michael@0 | 57 | while (gConcurrentTabs.length) { |
michael@0 | 58 | gBrowser.removeTab(gConcurrentTabs.shift()); |
michael@0 | 59 | } |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | let pm = Services.perms; |
michael@0 | 63 | pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
michael@0 | 64 | pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION); |
michael@0 | 65 | |
michael@0 | 66 | gConcurrentTabs.push(gBrowser.addTab(TESTROOT + "concurrent_installs.html")); |
michael@0 | 67 | gConcurrentTabs.push(gBrowser.addTab(TESTROOT2 + "concurrent_installs.html")); |
michael@0 | 68 | |
michael@0 | 69 | let promises = gConcurrentTabs.map((t) => { |
michael@0 | 70 | let deferred = Promise.defer(); |
michael@0 | 71 | t.linkedBrowser.addEventListener("load", () => { |
michael@0 | 72 | let win = winForTab(t); |
michael@0 | 73 | if (win.location.host.startsWith("example")) { |
michael@0 | 74 | win.wrappedJSObject.installTriggerCallback = function(rv) { |
michael@0 | 75 | gResults.push(rv); |
michael@0 | 76 | if (gResults.length == 2) { |
michael@0 | 77 | executeSoon(endThisTest); |
michael@0 | 78 | } |
michael@0 | 79 | }; |
michael@0 | 80 | deferred.resolve(); |
michael@0 | 81 | } |
michael@0 | 82 | }, true); |
michael@0 | 83 | return deferred.promise; |
michael@0 | 84 | }); |
michael@0 | 85 | |
michael@0 | 86 | Promise.all(promises).then(() => { |
michael@0 | 87 | gQueuedForInstall = [...gConcurrentTabs]; |
michael@0 | 88 | installNext(); |
michael@0 | 89 | }); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function endThisTest() { |
michael@0 | 93 | is(gResults.length, 2, "Should have two urls"); |
michael@0 | 94 | isnot(gResults[0].loc, gResults[1].loc, "Should not have results from the same page."); |
michael@0 | 95 | isnot(gResults[0].xpi, gResults[1].xpi, "Should not have the same XPIs."); |
michael@0 | 96 | for (let i = 0; i < 2; i++) { |
michael@0 | 97 | let {loc, xpi} = gResults[i]; |
michael@0 | 98 | if (loc.contains("example.org")) { |
michael@0 | 99 | ok(xpi.contains("example.org"), "Should get .org XPI for .org loc"); |
michael@0 | 100 | } else if (loc.contains("example.com")) { |
michael@0 | 101 | ok(xpi.contains("example.com"), "Should get .com XPI for .com loc"); |
michael@0 | 102 | } else { |
michael@0 | 103 | ok(false, "Should never get anything that isn't from example.org or example.com"); |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | finish(); |
michael@0 | 108 | } |
michael@0 | 109 |