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