Sat, 03 Jan 2015 20:18:00 +0100
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 3" |
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" type="autocomplete" |
michael@0 | 14 | autocompletesearch="simple" |
michael@0 | 15 | onsearchcomplete="checkResult();"/> |
michael@0 | 16 | |
michael@0 | 17 | <script class="testbody" type="application/javascript"> |
michael@0 | 18 | <![CDATA[ |
michael@0 | 19 | |
michael@0 | 20 | // Set to indicate whether or not we want autoCompleteSimple to return a result |
michael@0 | 21 | var returnResult = true; |
michael@0 | 22 | |
michael@0 | 23 | const ACR = Components.interfaces.nsIAutoCompleteResult; |
michael@0 | 24 | |
michael@0 | 25 | // This result can't be constructed in-line, because otherwise we leak memory. |
michael@0 | 26 | function nsAutoCompleteSimpleResult(aString) |
michael@0 | 27 | { |
michael@0 | 28 | this.searchString = aString; |
michael@0 | 29 | if (returnResult) { |
michael@0 | 30 | this.searchResult = ACR.RESULT_SUCCESS; |
michael@0 | 31 | this.matchCount = 1; |
michael@0 | 32 | this._param = "Result"; |
michael@0 | 33 | } |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | nsAutoCompleteSimpleResult.prototype = { |
michael@0 | 37 | _param: "", |
michael@0 | 38 | searchString: null, |
michael@0 | 39 | searchResult: ACR.RESULT_FAILURE, |
michael@0 | 40 | defaultIndex: 0, |
michael@0 | 41 | errorDescription: null, |
michael@0 | 42 | matchCount: 0, |
michael@0 | 43 | getValueAt: function() { return this._param; }, |
michael@0 | 44 | getCommentAt: function() { return null; }, |
michael@0 | 45 | getStyleAt: function() { return null; }, |
michael@0 | 46 | getImageAt: function() { return null; }, |
michael@0 | 47 | getFinalCompleteValueAt: function() { return this.getValueAt(); }, |
michael@0 | 48 | getLabelAt: function() { return null; }, |
michael@0 | 49 | removeValueAt: function() {} |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | // A basic autocomplete implementation that either returns one result or none |
michael@0 | 53 | var autoCompleteSimpleID = Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca"); |
michael@0 | 54 | var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple" |
michael@0 | 55 | var autoCompleteSimple = { |
michael@0 | 56 | QueryInterface: function(iid) { |
michael@0 | 57 | if (iid.equals(Components.interfaces.nsISupports) || |
michael@0 | 58 | iid.equals(Components.interfaces.nsIFactory) || |
michael@0 | 59 | iid.equals(Components.interfaces.nsIAutoCompleteSearch)) |
michael@0 | 60 | return this; |
michael@0 | 61 | |
michael@0 | 62 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 63 | }, |
michael@0 | 64 | |
michael@0 | 65 | createInstance: function(outer, iid) { |
michael@0 | 66 | return this.QueryInterface(iid); |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | startSearch: function(aString, aParam, aResult, aListener) { |
michael@0 | 70 | var result = new nsAutoCompleteSimpleResult(aString); |
michael@0 | 71 | aListener.onSearchResult(this, result); |
michael@0 | 72 | }, |
michael@0 | 73 | |
michael@0 | 74 | stopSearch: function() {} |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | var componentManager = Components.manager |
michael@0 | 78 | .QueryInterface(Components.interfaces.nsIComponentRegistrar); |
michael@0 | 79 | componentManager.registerFactory(autoCompleteSimpleID, "Test Simple Autocomplete", |
michael@0 | 80 | autoCompleteSimpleName, autoCompleteSimple); |
michael@0 | 81 | |
michael@0 | 82 | |
michael@0 | 83 | // Test Bug 325842 - completeDefaultIndex |
michael@0 | 84 | |
michael@0 | 85 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 86 | setTimeout(startTest, 0); |
michael@0 | 87 | |
michael@0 | 88 | var currentTest = 0; |
michael@0 | 89 | |
michael@0 | 90 | // Note the entries for these tests (key) are incremental. |
michael@0 | 91 | const tests = [ |
michael@0 | 92 | { completeDefaultIndex: "false", key: "r", result: "r", |
michael@0 | 93 | start: 1, end: 1 }, |
michael@0 | 94 | { completeDefaultIndex: "true", key: "e", result: "result", |
michael@0 | 95 | start: 2, end: 6 }, |
michael@0 | 96 | { completeDefaultIndex: "true", key: "t", result: "ret >> Result", |
michael@0 | 97 | start: 3, end: 13 } |
michael@0 | 98 | ]; |
michael@0 | 99 | |
michael@0 | 100 | function startTest() { |
michael@0 | 101 | var autocomplete = $("autocomplete"); |
michael@0 | 102 | |
michael@0 | 103 | // These should not be set by default. |
michael@0 | 104 | is(autocomplete.hasAttribute("completedefaultindex"), false, |
michael@0 | 105 | "completedefaultindex not set by default"); |
michael@0 | 106 | |
michael@0 | 107 | autocomplete.completeDefaultIndex = "true"; |
michael@0 | 108 | |
michael@0 | 109 | is(autocomplete.getAttribute("completedefaultindex"), "true", |
michael@0 | 110 | "completedefaultindex attribute set correctly"); |
michael@0 | 111 | is(autocomplete.completeDefaultIndex, true, |
michael@0 | 112 | "autoFill getter returned correctly"); |
michael@0 | 113 | |
michael@0 | 114 | autocomplete.completeDefaultIndex = "false"; |
michael@0 | 115 | |
michael@0 | 116 | is(autocomplete.getAttribute("completedefaultindex"), "false", |
michael@0 | 117 | "completedefaultindex attribute set to false correctly"); |
michael@0 | 118 | is(autocomplete.completeDefaultIndex, false, |
michael@0 | 119 | "completeDefaultIndex getter returned false correctly"); |
michael@0 | 120 | |
michael@0 | 121 | checkNext(); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function checkNext() { |
michael@0 | 125 | var autocomplete = $("autocomplete"); |
michael@0 | 126 | |
michael@0 | 127 | autocomplete.completeDefaultIndex = tests[currentTest].completeDefaultIndex; |
michael@0 | 128 | autocomplete.focus(); |
michael@0 | 129 | |
michael@0 | 130 | synthesizeKey(tests[currentTest].key, {}); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | function checkResult() { |
michael@0 | 134 | var autocomplete = $("autocomplete"); |
michael@0 | 135 | var style = window.getComputedStyle(autocomplete, ""); |
michael@0 | 136 | |
michael@0 | 137 | is(autocomplete.value, tests[currentTest].result, |
michael@0 | 138 | "Test " + currentTest + ": autocomplete.value should equal '" + |
michael@0 | 139 | tests[currentTest].result + "'"); |
michael@0 | 140 | |
michael@0 | 141 | is(autocomplete.selectionStart, tests[currentTest].start, |
michael@0 | 142 | "Test " + currentTest + ": autocomplete selection should start at " + |
michael@0 | 143 | tests[currentTest].start); |
michael@0 | 144 | |
michael@0 | 145 | is(autocomplete.selectionEnd, tests[currentTest].end, |
michael@0 | 146 | "Test " + currentTest + ": autocomplete selection should end at " + |
michael@0 | 147 | tests[currentTest].end); |
michael@0 | 148 | |
michael@0 | 149 | ++currentTest; |
michael@0 | 150 | |
michael@0 | 151 | if (currentTest < tests.length) |
michael@0 | 152 | setTimeout(checkNext, 0); |
michael@0 | 153 | else { |
michael@0 | 154 | // TODO (bug 494809): Autocomplete-in-the-middle should take in count RTL |
michael@0 | 155 | // and complete on VK_RIGHT or VK_LEFT based on that. It should also revert |
michael@0 | 156 | // what user has typed to far if he moves in the opposite direction. |
michael@0 | 157 | if (autocomplete.value.indexOf(">>") == -1) { |
michael@0 | 158 | // Test result if user accepts autocomplete suggestion. |
michael@0 | 159 | synthesizeKey("VK_RIGHT", {}); |
michael@0 | 160 | is(autocomplete.value, "Result", |
michael@0 | 161 | "Test complete: autocomplete.value should equal 'Result'"); |
michael@0 | 162 | is(autocomplete.selectionStart, 6, |
michael@0 | 163 | "Test complete: autocomplete selection should start at 6"); |
michael@0 | 164 | is(autocomplete.selectionEnd, 6, |
michael@0 | 165 | "Test complete: autocomplete selection should end at 6"); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | setTimeout(function() { |
michael@0 | 169 | // Unregister the factory so that we don't get in the way of other tests |
michael@0 | 170 | componentManager.unregisterFactory(autoCompleteSimpleID, autoCompleteSimple); |
michael@0 | 171 | SimpleTest.finish(); |
michael@0 | 172 | }, 0); |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | ]]> |
michael@0 | 177 | </script> |
michael@0 | 178 | |
michael@0 | 179 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 180 | <p id="display"> |
michael@0 | 181 | </p> |
michael@0 | 182 | <div id="content" style="display: none"> |
michael@0 | 183 | </div> |
michael@0 | 184 | <pre id="test"> |
michael@0 | 185 | </pre> |
michael@0 | 186 | </body> |
michael@0 | 187 | |
michael@0 | 188 | </window> |