embedding/tests/unit/test_wwauthpromptfactory.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 const Cc = Components.classes;
michael@0 2 const Ci = Components.interfaces;
michael@0 3
michael@0 4 var authPromptRequestReceived;
michael@0 5
michael@0 6 const tPFCID = Components.ID("{749e62f4-60ae-4569-a8a2-de78b649660f}");
michael@0 7 const tPFContract = "@mozilla.org/passwordmanager/authpromptfactory;1";
michael@0 8
michael@0 9 /*
michael@0 10 * TestPromptFactory
michael@0 11 *
michael@0 12 * Implements nsIPromptFactory
michael@0 13 */
michael@0 14 var TestPromptFactory = {
michael@0 15 QueryInterface: function tPF_qi(iid) {
michael@0 16 if (iid.equals(Ci.nsISupports) ||
michael@0 17 iid.equals(Ci.nsIFactory) ||
michael@0 18 iid.equals(Ci.nsIPromptFactory))
michael@0 19 return this;
michael@0 20 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 21 },
michael@0 22
michael@0 23 createInstance: function tPF_ci(outer, iid) {
michael@0 24 if (outer)
michael@0 25 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 26 return this.QueryInterface(iid);
michael@0 27 },
michael@0 28
michael@0 29 lockFactory: function tPF_lockf(lock) {
michael@0 30 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
michael@0 31 },
michael@0 32
michael@0 33 getPrompt : function tPF_getPrompt(aWindow, aIID) {
michael@0 34 if (aIID.equals(Ci.nsIAuthPrompt) ||
michael@0 35 aIID.equals(Ci.nsIAuthPrompt2)) {
michael@0 36 authPromptRequestReceived = true;
michael@0 37 return {};
michael@0 38 }
michael@0 39
michael@0 40 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 41 }
michael@0 42 }; // end of TestPromptFactory implementation
michael@0 43
michael@0 44 /*
michael@0 45 * The tests
michael@0 46 */
michael@0 47 function run_test() {
michael@0 48 Components.manager.nsIComponentRegistrar.registerFactory(tPFCID,
michael@0 49 "TestPromptFactory", tPFContract, TestPromptFactory);
michael@0 50
michael@0 51 // Make sure that getting both nsIAuthPrompt and nsIAuthPrompt2 works
michael@0 52 // (these should work independently of whether the application has
michael@0 53 // nsIPromptService2)
michael@0 54 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService();
michael@0 55
michael@0 56 authPromptRequestReceived = false;
michael@0 57
michael@0 58 do_check_neq(ww.nsIPromptFactory.getPrompt(null, Ci.nsIAuthPrompt), null);
michael@0 59
michael@0 60 do_check_true(authPromptRequestReceived);
michael@0 61
michael@0 62 authPromptRequestReceived = false;
michael@0 63
michael@0 64 do_check_neq(ww.nsIPromptFactory.getPrompt(null, Ci.nsIAuthPrompt2), null);
michael@0 65
michael@0 66 do_check_true(authPromptRequestReceived);
michael@0 67 }

mercurial