PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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