browser/base/content/test/general/browser_bug356571.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Bug 356571 - loadOneOrMoreURIs gives up if one of the URLs has an unknown protocol
michael@0 2
michael@0 3 const Cr = Components.results;
michael@0 4 const Cm = Components.manager;
michael@0 5
michael@0 6 // Set to true when docShell alerts for unknown protocol error
michael@0 7 var didFail = false;
michael@0 8
michael@0 9 // Override Alert to avoid blocking the test due to unknown protocol error
michael@0 10 const kPromptServiceUUID = "{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}";
michael@0 11 const kPromptServiceContractID = "@mozilla.org/embedcomp/prompt-service;1";
michael@0 12
michael@0 13 // Save original prompt service factory
michael@0 14 const kPromptServiceFactory = Cm.getClassObject(Cc[kPromptServiceContractID],
michael@0 15 Ci.nsIFactory);
michael@0 16
michael@0 17 let fakePromptServiceFactory = {
michael@0 18 createInstance: function(aOuter, aIid) {
michael@0 19 if (aOuter != null)
michael@0 20 throw Cr.NS_ERROR_NO_AGGREGATION;
michael@0 21 return promptService.QueryInterface(aIid);
michael@0 22 }
michael@0 23 };
michael@0 24
michael@0 25 let promptService = {
michael@0 26 QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptService]),
michael@0 27 alert: function() {
michael@0 28 didFail = true;
michael@0 29 }
michael@0 30 };
michael@0 31
michael@0 32 /* FIXME
michael@0 33 Cm.QueryInterface(Ci.nsIComponentRegistrar)
michael@0 34 .registerFactory(Components.ID(kPromptServiceUUID), "Prompt Service",
michael@0 35 kPromptServiceContractID, fakePromptServiceFactory);
michael@0 36 */
michael@0 37
michael@0 38 const kCompleteState = Ci.nsIWebProgressListener.STATE_STOP +
michael@0 39 Ci.nsIWebProgressListener.STATE_IS_NETWORK;
michael@0 40
michael@0 41 const kDummyPage = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
michael@0 42 const kURIs = [
michael@0 43 "bad://www.mozilla.org/",
michael@0 44 kDummyPage,
michael@0 45 kDummyPage,
michael@0 46 ];
michael@0 47
michael@0 48 var gProgressListener = {
michael@0 49 _runCount: 0,
michael@0 50 onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
michael@0 51 if ((aStateFlags & kCompleteState) == kCompleteState) {
michael@0 52 if (++this._runCount != kURIs.length)
michael@0 53 return;
michael@0 54 // Check we failed on unknown protocol (received an alert from docShell)
michael@0 55 ok(didFail, "Correctly failed on unknown protocol");
michael@0 56 // Check we opened all tabs
michael@0 57 ok(gBrowser.tabs.length == kURIs.length, "Correctly opened all expected tabs");
michael@0 58 finishTest();
michael@0 59 }
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 function test() {
michael@0 64 todo(false, "temp. disabled");
michael@0 65 return; /* FIXME */
michael@0 66 waitForExplicitFinish();
michael@0 67 // Wait for all tabs to finish loading
michael@0 68 gBrowser.addTabsProgressListener(gProgressListener);
michael@0 69 loadOneOrMoreURIs(kURIs.join("|"));
michael@0 70 }
michael@0 71
michael@0 72 function finishTest() {
michael@0 73 // Unregister the factory so we do not leak
michael@0 74 Cm.QueryInterface(Ci.nsIComponentRegistrar)
michael@0 75 .unregisterFactory(Components.ID(kPromptServiceUUID),
michael@0 76 fakePromptServiceFactory);
michael@0 77
michael@0 78 // Restore the original factory
michael@0 79 Cm.QueryInterface(Ci.nsIComponentRegistrar)
michael@0 80 .registerFactory(Components.ID(kPromptServiceUUID), "Prompt Service",
michael@0 81 kPromptServiceContractID, kPromptServiceFactory);
michael@0 82
michael@0 83 // Remove the listener
michael@0 84 gBrowser.removeTabsProgressListener(gProgressListener);
michael@0 85
michael@0 86 // Close opened tabs
michael@0 87 for (var i = gBrowser.tabs.length-1; i > 0; i--)
michael@0 88 gBrowser.removeTab(gBrowser.tabs[i]);
michael@0 89
michael@0 90 finish();
michael@0 91 }

mercurial