michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: var authPromptRequestReceived; michael@0: michael@0: const tPFCID = Components.ID("{749e62f4-60ae-4569-a8a2-de78b649660f}"); michael@0: const tPFContract = "@mozilla.org/passwordmanager/authpromptfactory;1"; michael@0: michael@0: /* michael@0: * TestPromptFactory michael@0: * michael@0: * Implements nsIPromptFactory michael@0: */ michael@0: var TestPromptFactory = { michael@0: QueryInterface: function tPF_qi(iid) { michael@0: if (iid.equals(Ci.nsISupports) || michael@0: iid.equals(Ci.nsIFactory) || michael@0: iid.equals(Ci.nsIPromptFactory)) michael@0: return this; michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: }, michael@0: michael@0: createInstance: function tPF_ci(outer, iid) { michael@0: if (outer) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return this.QueryInterface(iid); michael@0: }, michael@0: michael@0: lockFactory: function tPF_lockf(lock) { michael@0: throw Components.results.NS_ERROR_NOT_IMPLEMENTED; michael@0: }, michael@0: michael@0: getPrompt : function tPF_getPrompt(aWindow, aIID) { michael@0: if (aIID.equals(Ci.nsIAuthPrompt) || michael@0: aIID.equals(Ci.nsIAuthPrompt2)) { michael@0: authPromptRequestReceived = true; michael@0: return {}; michael@0: } michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }; // end of TestPromptFactory implementation michael@0: michael@0: /* michael@0: * The tests michael@0: */ michael@0: function run_test() { michael@0: Components.manager.nsIComponentRegistrar.registerFactory(tPFCID, michael@0: "TestPromptFactory", tPFContract, TestPromptFactory); michael@0: michael@0: // Make sure that getting both nsIAuthPrompt and nsIAuthPrompt2 works michael@0: // (these should work independently of whether the application has michael@0: // nsIPromptService2) michael@0: var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(); michael@0: michael@0: authPromptRequestReceived = false; michael@0: michael@0: do_check_neq(ww.nsIPromptFactory.getPrompt(null, Ci.nsIAuthPrompt), null); michael@0: michael@0: do_check_true(authPromptRequestReceived); michael@0: michael@0: authPromptRequestReceived = false; michael@0: michael@0: do_check_neq(ww.nsIPromptFactory.getPrompt(null, Ci.nsIAuthPrompt2), null); michael@0: michael@0: do_check_true(authPromptRequestReceived); michael@0: }