michael@0: // Bug 356571 - loadOneOrMoreURIs gives up if one of the URLs has an unknown protocol michael@0: michael@0: const Cr = Components.results; michael@0: const Cm = Components.manager; michael@0: michael@0: // Set to true when docShell alerts for unknown protocol error michael@0: var didFail = false; michael@0: michael@0: // Override Alert to avoid blocking the test due to unknown protocol error michael@0: const kPromptServiceUUID = "{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}"; michael@0: const kPromptServiceContractID = "@mozilla.org/embedcomp/prompt-service;1"; michael@0: michael@0: // Save original prompt service factory michael@0: const kPromptServiceFactory = Cm.getClassObject(Cc[kPromptServiceContractID], michael@0: Ci.nsIFactory); michael@0: michael@0: let fakePromptServiceFactory = { michael@0: createInstance: function(aOuter, aIid) { michael@0: if (aOuter != null) michael@0: throw Cr.NS_ERROR_NO_AGGREGATION; michael@0: return promptService.QueryInterface(aIid); michael@0: } michael@0: }; michael@0: michael@0: let promptService = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptService]), michael@0: alert: function() { michael@0: didFail = true; michael@0: } michael@0: }; michael@0: michael@0: /* FIXME michael@0: Cm.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .registerFactory(Components.ID(kPromptServiceUUID), "Prompt Service", michael@0: kPromptServiceContractID, fakePromptServiceFactory); michael@0: */ michael@0: michael@0: const kCompleteState = Ci.nsIWebProgressListener.STATE_STOP + michael@0: Ci.nsIWebProgressListener.STATE_IS_NETWORK; michael@0: michael@0: const kDummyPage = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; michael@0: const kURIs = [ michael@0: "bad://www.mozilla.org/", michael@0: kDummyPage, michael@0: kDummyPage, michael@0: ]; michael@0: michael@0: var gProgressListener = { michael@0: _runCount: 0, michael@0: onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { michael@0: if ((aStateFlags & kCompleteState) == kCompleteState) { michael@0: if (++this._runCount != kURIs.length) michael@0: return; michael@0: // Check we failed on unknown protocol (received an alert from docShell) michael@0: ok(didFail, "Correctly failed on unknown protocol"); michael@0: // Check we opened all tabs michael@0: ok(gBrowser.tabs.length == kURIs.length, "Correctly opened all expected tabs"); michael@0: finishTest(); michael@0: } michael@0: } michael@0: } michael@0: michael@0: function test() { michael@0: todo(false, "temp. disabled"); michael@0: return; /* FIXME */ michael@0: waitForExplicitFinish(); michael@0: // Wait for all tabs to finish loading michael@0: gBrowser.addTabsProgressListener(gProgressListener); michael@0: loadOneOrMoreURIs(kURIs.join("|")); michael@0: } michael@0: michael@0: function finishTest() { michael@0: // Unregister the factory so we do not leak michael@0: Cm.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .unregisterFactory(Components.ID(kPromptServiceUUID), michael@0: fakePromptServiceFactory); michael@0: michael@0: // Restore the original factory michael@0: Cm.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .registerFactory(Components.ID(kPromptServiceUUID), "Prompt Service", michael@0: kPromptServiceContractID, kPromptServiceFactory); michael@0: michael@0: // Remove the listener michael@0: gBrowser.removeTabsProgressListener(gProgressListener); michael@0: michael@0: // Close opened tabs michael@0: for (var i = gBrowser.tabs.length-1; i > 0; i--) michael@0: gBrowser.removeTab(gBrowser.tabs[i]); michael@0: michael@0: finish(); michael@0: }