toolkit/content/tests/chrome/test_autocomplete4.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window title="Autocomplete Widget Test 4"
michael@0 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 7
michael@0 8 <script type="application/javascript"
michael@0 9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 10 <script type="application/javascript"
michael@0 11 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 12
michael@0 13 <textbox id="autocomplete"
michael@0 14 type="autocomplete"
michael@0 15 completedefaultindex="true"
michael@0 16
michael@0 17 onsearchcomplete="searchComplete();"
michael@0 18 autocompletesearch="simple"/>
michael@0 19
michael@0 20 <script class="testbody" type="application/javascript">
michael@0 21 <![CDATA[
michael@0 22
michael@0 23 // Set to indicate whether or not we want autoCompleteSimple to return a result
michael@0 24 var returnResult = true;
michael@0 25
michael@0 26 const ACR = Components.interfaces.nsIAutoCompleteResult;
michael@0 27
michael@0 28 // This result can't be constructed in-line, because otherwise we leak memory.
michael@0 29 function nsAutoCompleteSimpleResult(aString)
michael@0 30 {
michael@0 31 this.searchString = aString;
michael@0 32 if (returnResult) {
michael@0 33 this.searchResult = ACR.RESULT_SUCCESS;
michael@0 34 this.matchCount = 1;
michael@0 35 this._param = "Result";
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 nsAutoCompleteSimpleResult.prototype = {
michael@0 40 _param: "",
michael@0 41 searchString: null,
michael@0 42 searchResult: ACR.RESULT_FAILURE,
michael@0 43 defaultIndex: 0,
michael@0 44 errorDescription: null,
michael@0 45 matchCount: 0,
michael@0 46 getValueAt: function() { return this._param; },
michael@0 47 getCommentAt: function() { return null; },
michael@0 48 getStyleAt: function() { return null; },
michael@0 49 getImageAt: function() { return null; },
michael@0 50 getFinalCompleteValueAt: function() { return this.getValueAt(); },
michael@0 51 getLabelAt: function() { return null; },
michael@0 52 removeValueAt: function() {}
michael@0 53 };
michael@0 54
michael@0 55 // A basic autocomplete implementation that either returns one result or none
michael@0 56 var autoCompleteSimpleID = Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca");
michael@0 57 var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
michael@0 58 var autoCompleteSimple = {
michael@0 59 QueryInterface: function(iid) {
michael@0 60 if (iid.equals(Components.interfaces.nsISupports) ||
michael@0 61 iid.equals(Components.interfaces.nsIFactory) ||
michael@0 62 iid.equals(Components.interfaces.nsIAutoCompleteSearch))
michael@0 63 return this;
michael@0 64
michael@0 65 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 66 },
michael@0 67
michael@0 68 createInstance: function(outer, iid) {
michael@0 69 return this.QueryInterface(iid);
michael@0 70 },
michael@0 71
michael@0 72 startSearch: function(aString, aParam, aResult, aListener) {
michael@0 73 var result = new nsAutoCompleteSimpleResult(aString);
michael@0 74 aListener.onSearchResult(this, result);
michael@0 75 },
michael@0 76
michael@0 77 stopSearch: function() {}
michael@0 78 };
michael@0 79
michael@0 80 var componentManager = Components.manager
michael@0 81 .QueryInterface(Components.interfaces.nsIComponentRegistrar);
michael@0 82 componentManager.registerFactory(autoCompleteSimpleID, "Test Simple Autocomplete",
michael@0 83 autoCompleteSimpleName, autoCompleteSimple);
michael@0 84
michael@0 85
michael@0 86 // Test Bug 325842 - completeDefaultIndex
michael@0 87
michael@0 88 SimpleTest.waitForExplicitFinish();
michael@0 89 setTimeout(nextTest, 0);
michael@0 90
michael@0 91 var currentTest = null;
michael@0 92
michael@0 93 // Note the entries for these tests (key) are incremental.
michael@0 94 const tests = [
michael@0 95 {
michael@0 96 desc: "HOME key remove selection",
michael@0 97 key: "VK_HOME",
michael@0 98 removeSelection: true,
michael@0 99 result: "re",
michael@0 100 start: 0, end: 0
michael@0 101 },
michael@0 102 {
michael@0 103 desc: "LEFT key remove selection",
michael@0 104 key: "VK_LEFT",
michael@0 105 removeSelection: true,
michael@0 106 result: "re",
michael@0 107 start: 1, end: 1
michael@0 108 },
michael@0 109 { desc: "RIGHT key remove selection",
michael@0 110 key: "VK_RIGHT",
michael@0 111 removeSelection: true,
michael@0 112 result: "re",
michael@0 113 start: 2, end: 2
michael@0 114 },
michael@0 115 { desc: "ENTER key remove selection",
michael@0 116 key: "VK_RETURN",
michael@0 117 removeSelection: true,
michael@0 118 result: "re",
michael@0 119 start: 2, end: 2
michael@0 120 },
michael@0 121 {
michael@0 122 desc: "HOME key",
michael@0 123 key: "VK_HOME",
michael@0 124 removeSelection: false,
michael@0 125 result: "Result",
michael@0 126 start: 0, end: 0
michael@0 127 },
michael@0 128 {
michael@0 129 desc: "LEFT key",
michael@0 130 key: "VK_LEFT",
michael@0 131 removeSelection: false,
michael@0 132 result: "Result",
michael@0 133 start: 5, end: 5
michael@0 134 },
michael@0 135 { desc: "RIGHT key",
michael@0 136 key: "VK_RIGHT",
michael@0 137 removeSelection: false,
michael@0 138 result: "Result",
michael@0 139 start: 6, end: 6
michael@0 140 },
michael@0 141 { desc: "RETURN key",
michael@0 142 key: "VK_RETURN",
michael@0 143 removeSelection: false,
michael@0 144 result: "Result",
michael@0 145 start: 6, end: 6
michael@0 146 },
michael@0 147 { desc: "TAB key should confirm suggestion when forcecomplete is set",
michael@0 148 key: "VK_TAB",
michael@0 149 removeSelection: false,
michael@0 150 forceComplete: true,
michael@0 151 result: "Result",
michael@0 152 start: 6, end: 6
michael@0 153 },
michael@0 154 ];
michael@0 155
michael@0 156 function nextTest() {
michael@0 157 if (!tests.length) {
michael@0 158 // No more tests to run, finish.
michael@0 159 setTimeout(function() {
michael@0 160 // Unregister the factory so that we don't get in the way of other tests
michael@0 161 componentManager.unregisterFactory(autoCompleteSimpleID, autoCompleteSimple);
michael@0 162 SimpleTest.finish();
michael@0 163 }, 0);
michael@0 164 return;
michael@0 165 }
michael@0 166
michael@0 167 var autocomplete = $("autocomplete");
michael@0 168 autocomplete.value = "";
michael@0 169 currentTest = tests.shift();
michael@0 170
michael@0 171 // HOME key works differently on Mac, so we skip tests using it.
michael@0 172 if (currentTest.key == "VK_HOME" && navigator.platform.indexOf("Mac") != -1)
michael@0 173 nextTest();
michael@0 174 else
michael@0 175 setTimeout(runCurrentTest, 0);
michael@0 176 }
michael@0 177
michael@0 178 function runCurrentTest() {
michael@0 179 var autocomplete = $("autocomplete");
michael@0 180
michael@0 181 autocomplete.focus();
michael@0 182
michael@0 183 synthesizeKey("r", {});
michael@0 184 synthesizeKey("e", {});
michael@0 185 }
michael@0 186
michael@0 187 function searchComplete() {
michael@0 188 var autocomplete = $("autocomplete");
michael@0 189 is(autocomplete.value, "result",
michael@0 190 "Test '" + currentTest.desc + "': autocomplete.value should equal 'result'");
michael@0 191
michael@0 192 autocomplete.setAttribute("forcecomplete", currentTest.forceComplete ? true : false);
michael@0 193
michael@0 194 if (autocomplete.selectionStart == 2) { // Finished inserting "re" string.
michael@0 195 if (currentTest.removeSelection) {
michael@0 196 // remove current selection
michael@0 197 synthesizeKey("VK_DELETE", {});
michael@0 198 }
michael@0 199
michael@0 200 synthesizeKey(currentTest.key, {});
michael@0 201
michael@0 202 checkResult();
michael@0 203 }
michael@0 204 }
michael@0 205
michael@0 206 function checkResult() {
michael@0 207 var autocomplete = $("autocomplete");
michael@0 208
michael@0 209 is(autocomplete.value, currentTest.result,
michael@0 210 "Test '" + currentTest.desc + "': autocomplete.value should equal '" +
michael@0 211 currentTest.result + "'");
michael@0 212
michael@0 213 is(autocomplete.selectionStart, currentTest.start,
michael@0 214 "Test '" + currentTest.desc + "': autocomplete selection should start at " +
michael@0 215 currentTest.start);
michael@0 216
michael@0 217 is(autocomplete.selectionEnd, currentTest.end,
michael@0 218 "Test '" + currentTest.desc + "': autocomplete selection should end at " +
michael@0 219 currentTest.end);
michael@0 220
michael@0 221 setTimeout(nextTest, 0);
michael@0 222 }
michael@0 223
michael@0 224 ]]>
michael@0 225 </script>
michael@0 226
michael@0 227 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 228 <p id="display">
michael@0 229 </p>
michael@0 230 <div id="content" style="display: none">
michael@0 231 </div>
michael@0 232 <pre id="test">
michael@0 233 </pre>
michael@0 234 </body>
michael@0 235
michael@0 236 </window>

mercurial