Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / xpfe / components / autocomplete / test / autocomplete_test.xul
blobd64319e767f9eecf4bf9998afd36195849984f24
1 <?xml-stylesheet href="chrome://messenger/skin/messenger.css" type="text/css"?> 
3 <?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
4 <?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>
6                    
7 <window id="actest"
8         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
9         xmlns:nc="http://home.netscape.com/NC-rdf#"
10                 orient="vertical"
11         width="750"
12         height="500"
13         onload="Initialize();"
14         >
15         
16 <script type="application/x-javascript">
18 var AutoCompleteSession = {
19     onStartLookup: function(value, prevResult, listener)
20     {
21         dump("Search Session: onStartLookup\n");
23         var results = Components.classes["@mozilla.org/autocomplete/results;1"].createInstance();
24         results = results.QueryInterface(Components.interfaces.nsIAutoCompleteResults);
25         results.searchString = value;
26         results.defaultItemIndex = 0;
27         results.param = null;
29         var item = Components.classes["@mozilla.org/autocomplete/item;1"].createInstance();
30         item = item.QueryInterface(Components.interfaces.nsIAutoCompleteItem);
31         item.value = "Jean-Francois Ducarroz";
32         item.comment = "[put your comment here]";
33         item.className = "";
34         item.param = null;
35         
36         results.items.AppendElement(item);
37         listener.onAutoComplete(results, Components.interfaces.nsIAutoCompleteStatus.matchFound);
38     },
40     onStopLookup: function()
41     {
42         dump("Search Session: onStopLookup\n");
43     },
45     onAutoComplete: function(value, prevResult, listener)
46     {
47         dump("Search Session: onAutoComplete, value =" + value + "\n");
48         
49         var results = Components.classes["@mozilla.org/autocomplete/results;1"].createInstance();
50         results = results.QueryInterface(Components.interfaces.nsIAutoCompleteResults);
51         results.searchString = value;
52         results.defaultItemIndex = 0;
53         results.param = null;
54         
55         var item = Components.classes["@mozilla.org/autocomplete/item;1"].createInstance();
56         item = item.QueryInterface(Components.interfaces.nsIAutoCompleteItem);
57         item.value = value + "@mozilla.org";
58         item.comment = "[put your comment here]";
59         item.className = "";
60         item.param = null;
61         
62         results.items.AppendElement(item);
64         item = Components.classes["@mozilla.org/autocomplete/item;1"].createInstance();
65         item = item.QueryInterface(Components.interfaces.nsIAutoCompleteItem);
66         item.value = value + "@netscape.com";
67         item.comment = "[put your comment here]";
68         item.className = "";
69         item.param = null;
71         results.items.AppendElement(item);
73         listener.onAutoComplete(results, Components.interfaces.nsIAutoCompleteStatus.matchFound);
74     }
77 function function1()
79     var myAutoComplete = document.getElementById("test");
80     value = myAutoComplete.value;
81     match = "Jean-Francois Ducarroz";
82     
83     lmatch = match.toLowerCase();
84     lvalue = value.toLowerCase();
86     dump("value = " + lvalue + ", match = " + lmatch + "\n");
87     
88     if (lvalue == lmatch)
89         dump("exact match\n");
90     else
91     {
92         dump("substring = " + lmatch.substring(0, lvalue.length) + "\n");
93         if (lmatch.substring(0, lvalue.length) == lvalue)
94         {
95             dump("Ok, we can merge\n");
96             myAutoComplete.value = value + match.substring(value.length, match.length);
97 //            myAutoComplete.anonymousContent[0].firstChild.anonymousContent[0].firstChild.setSelectionRange(value.length, match.length);
98         }
99         else
100        {
101             dump("oops, no match!\n");
102             myAutoComplete.value = value + " " + match;
103        }
104     }
105     
108 function Initialize()
110     dump("Initialize!!\n");
112     var myAutoComplete = document.getElementById("test");
113     dump("myAutoComplete = " + myAutoComplete + ", session = " + myAutoComplete.mSessions + "\n");
114     myAutoComplete.autoCompleteSession = AutoCompleteSession;
116     var secondAutoComplete = document.getElementById("test2");
117     abSession = secondAutoComplete.mSessions['addrbook'].QueryInterface(Components.interfaces.nsIAbAutoCompleteSession);
118     abSession.defaultDomain = "mozilla.org";
120     var thirdAutoComplete = document.getElementById("test3");
121     var abSession3 = thirdAutoComplete.mSessions['ldap'].QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
122     dump("\nthirdAutoComplete = " + thirdAutoComplete + "\n");
123     dump("thirdAutoComplete.mSessions['ldap'] = " +
124          thirdAutoComplete.mSessions['ldap'] + "\n");
125     dump("abSession3 = " + abSession3 + "\n");
127     var serverURL = Components.classes["@mozilla.org/network/ldap-url;1"].
128                     createInstance().QueryInterface(                                               Components.interfaces.nsILDAPURL);
130     //serverURL.spec = "ldap://ldap.bigfoot.com:389/??one?";
131     serverURL.spec = "ldap://nsdirectory.netscape.com/ou=People," +
132                      "dc=netscape,dc=com??one";
134     abSession3.serverURL = serverURL;
135     abSession3.filterTemplate = "sn=";
136     abSession3.outputFormat = "cn &lt;mail&gt;";
137     abSession3.sizeLimit = 10;
139     var fourthAutoComplete = document.getElementById("test3");
140     var abSession4 = fourthAutoComplete.mSessions['ldap'].QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
141     dump("\nfourthAutoComplete = " + fourthAutoComplete + "\n");
142     dump("fourthAutoComplete.mSessions['ldap'] = " +
143          fourthAutoComplete.mSessions['ldap'] + "\n");
144     dump("abSession4 = " + abSession4 + "\n");
146     var serverURL4 = Components.classes["@mozilla.org/network/ldap-url;1"].
147                     createInstance().QueryInterface(                                               Components.interfaces.nsILDAPURL);
149     //serverURL4.spec = "ldap://ldap.bigfoot.com:389/??one?";
150     serverURL4.spec = "ldap://nsdirectory.netscape.com/ou=People," +
151                       "dc=netscape,dc=com??one";
153     abSession3.serverURL = serverURL4;
154     abSession3.filterTemplate = "sn=";
155     abSession3.outputFormat = "cn &lt;mail&gt;";
156     abSession3.sizeLimit = 10;
160 </script>
162 <html>Inline JS:</html>
163 <textbox id="test" timeout="300" type="autocomplete" />
165 <html>addrbook:</html>
166 <textbox id="test2" 
167     type="autocomplete"
168     searchSessions="addrbook"
169     timeout="300"
170     onkeypress="if (event.keyCode == 13) dump('Done, value=' + this.value + '\n');"
173 <html>ldap:</html>
174 <textbox id="test3"
175     type="autocomplete"
176     searchSessions="ldap"
177     timeout="300"
178     onkeypress="if (event.keyCode == 13) dump('Done, value=' + this.value + '\n');"
181 <html>composite (addrbook, ldap):</html>
182 <textbox id="test3"
183     type="autocomplete"
184     searchSessions="addrbook ldap"
185     timeout="300"
186     onkeypress="if (event.keyCode == 13) dump('Done, value=' + this.value + '\n');"
189 </window>