toolkit/components/passwordmgr/test/prompt_common.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:1a99299d7cb0
1 var Ci = SpecialPowers.Ci;
2 ok(Ci != null, "Access Ci");
3 var Cc = SpecialPowers.Cc;
4 ok(Cc != null, "Access Cc");
5
6 var didDialog;
7
8 var timer; // keep in outer scope so it's not GC'd before firing
9 function startCallbackTimer() {
10 didDialog = false;
11
12 // Delay before the callback twiddles the prompt.
13 const dialogDelay = 10;
14
15 // Use a timer to invoke a callback to twiddle the authentication dialog
16 timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
17 timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT);
18 }
19
20
21 var observer = SpecialPowers.wrapCallbackObject({
22 QueryInterface : function (iid) {
23 const interfaces = [Ci.nsIObserver,
24 Ci.nsISupports, Ci.nsISupportsWeakReference];
25
26 if (!interfaces.some( function(v) { return iid.equals(v) } ))
27 throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
28 return this;
29 },
30
31 observe : function (subject, topic, data) {
32 var doc = getDialogDoc();
33 if (doc)
34 handleDialog(doc, testNum);
35 else
36 startCallbackTimer(); // try again in a bit
37 }
38 });
39
40 function getDialogDoc() {
41 // Find the <browser> which contains notifyWindow, by looking
42 // through all the open windows and all the <browsers> in each.
43 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
44 getService(Ci.nsIWindowMediator);
45 //var enumerator = wm.getEnumerator("navigator:browser");
46 var enumerator = wm.getXULWindowEnumerator(null);
47
48 while (enumerator.hasMoreElements()) {
49 var win = enumerator.getNext();
50 var windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell;
51
52 var containedDocShells = windowDocShell.getDocShellEnumerator(
53 Ci.nsIDocShellTreeItem.typeChrome,
54 Ci.nsIDocShell.ENUMERATE_FORWARDS);
55 while (containedDocShells.hasMoreElements()) {
56 // Get the corresponding document for this docshell
57 var childDocShell = containedDocShells.getNext();
58 // We don't want it if it's not done loading.
59 if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE)
60 continue;
61 var childDoc = childDocShell.QueryInterface(Ci.nsIDocShell)
62 .contentViewer
63 .DOMDocument;
64
65 //ok(true, "Got window: " + childDoc.location.href);
66 if (childDoc.location.href == "chrome://global/content/commonDialog.xul")
67 return childDoc;
68 }
69 }
70
71 return null;
72 }

mercurial