embedding/tests/unit/test_wwauthpromptfactory.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/embedding/tests/unit/test_wwauthpromptfactory.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +const Cc = Components.classes;
     1.5 +const Ci = Components.interfaces;
     1.6 +
     1.7 +var authPromptRequestReceived;
     1.8 +
     1.9 +const tPFCID = Components.ID("{749e62f4-60ae-4569-a8a2-de78b649660f}");
    1.10 +const tPFContract = "@mozilla.org/passwordmanager/authpromptfactory;1";
    1.11 +
    1.12 +/*
    1.13 + * TestPromptFactory
    1.14 + *
    1.15 + * Implements nsIPromptFactory
    1.16 + */
    1.17 +var TestPromptFactory = {
    1.18 +  QueryInterface: function tPF_qi(iid) {
    1.19 +    if (iid.equals(Ci.nsISupports) ||
    1.20 +        iid.equals(Ci.nsIFactory) ||
    1.21 +        iid.equals(Ci.nsIPromptFactory))
    1.22 +      return this;
    1.23 +    throw Components.results.NS_ERROR_NO_INTERFACE;
    1.24 +  },
    1.25 +
    1.26 +  createInstance: function tPF_ci(outer, iid) {
    1.27 +    if (outer)
    1.28 +      throw Components.results.NS_ERROR_NO_AGGREGATION;
    1.29 +    return this.QueryInterface(iid);
    1.30 +  },
    1.31 +
    1.32 +  lockFactory: function tPF_lockf(lock) {
    1.33 +    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
    1.34 +  },
    1.35 +
    1.36 +  getPrompt : function tPF_getPrompt(aWindow, aIID) {
    1.37 +    if (aIID.equals(Ci.nsIAuthPrompt) ||
    1.38 +        aIID.equals(Ci.nsIAuthPrompt2)) {
    1.39 +      authPromptRequestReceived = true;
    1.40 +      return {};
    1.41 +    }
    1.42 +
    1.43 +    throw Components.results.NS_ERROR_NO_INTERFACE;
    1.44 +  }
    1.45 +}; // end of TestPromptFactory implementation
    1.46 +
    1.47 +/*
    1.48 + * The tests
    1.49 + */
    1.50 +function run_test() {
    1.51 +  Components.manager.nsIComponentRegistrar.registerFactory(tPFCID,
    1.52 +    "TestPromptFactory", tPFContract, TestPromptFactory);
    1.53 +
    1.54 +  // Make sure that getting both nsIAuthPrompt and nsIAuthPrompt2 works
    1.55 +  // (these should work independently of whether the application has
    1.56 +  // nsIPromptService2)
    1.57 +  var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService();
    1.58 +
    1.59 +  authPromptRequestReceived = false;
    1.60 +
    1.61 +  do_check_neq(ww.nsIPromptFactory.getPrompt(null, Ci.nsIAuthPrompt), null);
    1.62 +
    1.63 +  do_check_true(authPromptRequestReceived);
    1.64 +
    1.65 +  authPromptRequestReceived = false;
    1.66 +
    1.67 +  do_check_neq(ww.nsIPromptFactory.getPrompt(null, Ci.nsIAuthPrompt2), null);
    1.68 +
    1.69 +  do_check_true(authPromptRequestReceived);
    1.70 +}

mercurial