/embedding/tests/unit/test_wwauthpromptfactory.js

http://github.com/zpao/v8monkey · JavaScript · 67 lines · 41 code · 15 blank · 11 comment · 3 complexity · b37702d18562c30422343d5486ee790e MD5 · raw file

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