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