|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
|
4 type="text/css"?> |
|
5 <window title="Testing autocomplete with composition" |
|
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
7 |
|
8 <script type="application/javascript" |
|
9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
|
10 <script type="application/javascript" |
|
11 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" /> |
|
12 <script type="text/javascript" |
|
13 src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js" /> |
|
14 <script type="text/javascript" |
|
15 src="file_autocomplete_with_composition.js" /> |
|
16 |
|
17 <textbox id="textbox" type="autocomplete" |
|
18 autocompletesearch="simpleForComposition"/> |
|
19 |
|
20 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
21 <div id="content" style="display: none"> |
|
22 </div> |
|
23 <pre id="test"> |
|
24 </pre> |
|
25 </body> |
|
26 |
|
27 <script class="testbody" type="application/javascript"> |
|
28 <![CDATA[ |
|
29 |
|
30 SimpleTest.waitForExplicitFinish(); |
|
31 |
|
32 const nsIAutoCompleteResult = Components.interfaces.nsIAutoCompleteResult; |
|
33 |
|
34 // This result can't be constructed in-line, because otherwise we leak memory. |
|
35 function nsAutoCompleteSimpleResult(aString) |
|
36 { |
|
37 this.searchString = aString; |
|
38 if (aString == "" || aString == "Mozilla".substr(0, aString.length)) { |
|
39 this.searchResult = nsIAutoCompleteResult.RESULT_SUCCESS; |
|
40 this.matchCount = 1; |
|
41 this._value = "Mozilla"; |
|
42 } else { |
|
43 this.searchResult = nsIAutoCompleteResult.RESULT_NOMATCH; |
|
44 this.matchCount = 0; |
|
45 this._value = ""; |
|
46 } |
|
47 } |
|
48 |
|
49 nsAutoCompleteSimpleResult.prototype = { |
|
50 _value: "", |
|
51 searchString: null, |
|
52 searchResult: nsIAutoCompleteResult.RESULT_FAILURE, |
|
53 defaultIndex: 0, |
|
54 errorDescription: null, |
|
55 matchCount: 0, |
|
56 getValueAt: function(aIndex) { return aIndex == 0 ? this._value : null; }, |
|
57 getCommentAt: function() { return null; }, |
|
58 getStyleAt: function() { return null; }, |
|
59 getImageAt: function() { return null; }, |
|
60 getFinalCompleteValueAt: function(aIndex) { return this.getValueAt(aIndex); }, |
|
61 getLabelAt: function() { return null; }, |
|
62 removeValueAt: function() {} |
|
63 }; |
|
64 |
|
65 // A basic autocomplete implementation that either returns one result or none |
|
66 var autoCompleteSimpleID = |
|
67 Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca"); |
|
68 var autoCompleteSimpleName = |
|
69 "@mozilla.org/autocomplete/search;1?name=simpleForComposition" |
|
70 var autoCompleteSimple = { |
|
71 QueryInterface: function(iid) { |
|
72 if (iid.equals(Components.interfaces.nsISupports) || |
|
73 iid.equals(Components.interfaces.nsIFactory) || |
|
74 iid.equals(Components.interfaces.nsIAutoCompleteSearch)) |
|
75 return this; |
|
76 |
|
77 throw Components.results.NS_ERROR_NO_INTERFACE; |
|
78 }, |
|
79 |
|
80 createInstance: function(outer, iid) { |
|
81 return this.QueryInterface(iid); |
|
82 }, |
|
83 |
|
84 startSearch: function(aString, aParam, aResult, aListener) { |
|
85 var result = new nsAutoCompleteSimpleResult(aString); |
|
86 aListener.onSearchResult(this, result); |
|
87 }, |
|
88 |
|
89 stopSearch: function() {} |
|
90 }; |
|
91 |
|
92 var componentManager = |
|
93 Components.manager |
|
94 .QueryInterface(Components.interfaces.nsIComponentRegistrar); |
|
95 componentManager.registerFactory(autoCompleteSimpleID, |
|
96 "Test Simple Autocomplete for composition", |
|
97 autoCompleteSimpleName, autoCompleteSimple); |
|
98 |
|
99 function runTests() |
|
100 { |
|
101 var target = document.getElementById("textbox"); |
|
102 target.setAttribute("timeout", 1); |
|
103 var test1 = new nsDoTestsForAutoCompleteWithComposition( |
|
104 "Testing on XUL textbox (asynchronously search)", |
|
105 window, target, target.controller, is, |
|
106 function () { return target.value; }, |
|
107 function () { |
|
108 target.setAttribute("timeout", 0); |
|
109 var test2 = new nsDoTestsForAutoCompleteWithComposition( |
|
110 "Testing on XUL textbox (synchronously search)", |
|
111 window, target, target.controller, is, |
|
112 function () { return target.value; }, |
|
113 function () { |
|
114 // Unregister the factory so that we don't get in the way of other |
|
115 // tests |
|
116 componentManager.unregisterFactory(autoCompleteSimpleID, |
|
117 autoCompleteSimple); |
|
118 SimpleTest.finish(); |
|
119 }); |
|
120 }); |
|
121 } |
|
122 |
|
123 SimpleTest.waitForFocus(runTests); |
|
124 ]]> |
|
125 </script> |
|
126 </window> |