Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 2" |
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 = false; |
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 = "SUCCESS"; |
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: -1, |
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 441530 - correctly setting "nomatch" |
michael@0 | 84 | // Test Bug 441526 - correctly setting style with "highlightnonmatches" |
michael@0 | 85 | |
michael@0 | 86 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 87 | setTimeout(startTest, 0); |
michael@0 | 88 | |
michael@0 | 89 | function startTest() { |
michael@0 | 90 | var autocomplete = $("autocomplete"); |
michael@0 | 91 | |
michael@0 | 92 | // Ensure highlightNonMatches can be set correctly. |
michael@0 | 93 | |
michael@0 | 94 | // This should not be set by default. |
michael@0 | 95 | is(autocomplete.hasAttribute("highlightnonmatches"), false, |
michael@0 | 96 | "highlight nonmatches not set by default"); |
michael@0 | 97 | |
michael@0 | 98 | autocomplete.highlightNonMatches = "true"; |
michael@0 | 99 | |
michael@0 | 100 | is(autocomplete.getAttribute("highlightnonmatches"), "true", |
michael@0 | 101 | "highlight non matches attribute set correctly"); |
michael@0 | 102 | is(autocomplete.highlightNonMatches, true, |
michael@0 | 103 | "highlight non matches getter returned correctly"); |
michael@0 | 104 | |
michael@0 | 105 | autocomplete.highlightNonMatches = "false"; |
michael@0 | 106 | |
michael@0 | 107 | is(autocomplete.getAttribute("highlightnonmatches"), "false", |
michael@0 | 108 | "highlight non matches attribute set to false correctly"); |
michael@0 | 109 | is(autocomplete.highlightNonMatches, false, |
michael@0 | 110 | "highlight non matches getter returned false correctly"); |
michael@0 | 111 | |
michael@0 | 112 | check(); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function check() { |
michael@0 | 116 | var autocomplete = $("autocomplete"); |
michael@0 | 117 | |
michael@0 | 118 | // Toggle this value, so we can re-use the one function. |
michael@0 | 119 | returnResult = !returnResult; |
michael@0 | 120 | |
michael@0 | 121 | // blur the field to ensure that the popup is closed and that the previous |
michael@0 | 122 | // search has stopped, then start a new search. |
michael@0 | 123 | autocomplete.blur(); |
michael@0 | 124 | autocomplete.focus(); |
michael@0 | 125 | synthesizeKey("r", {}); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function checkResult() { |
michael@0 | 129 | var autocomplete = $("autocomplete"); |
michael@0 | 130 | var style = window.getComputedStyle(autocomplete, ""); |
michael@0 | 131 | |
michael@0 | 132 | if (returnResult) { |
michael@0 | 133 | // Result was returned, so there should not be a nomatch attribute |
michael@0 | 134 | is(autocomplete.hasAttribute("nomatch"), false, |
michael@0 | 135 | "nomatch attribute shouldn't be present here"); |
michael@0 | 136 | |
michael@0 | 137 | // Ensure that the style is set correctly whichever way highlightNonMatches |
michael@0 | 138 | // is set. |
michael@0 | 139 | autocomplete.highlightNonMatches = "true"; |
michael@0 | 140 | |
michael@0 | 141 | isnot(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)", |
michael@0 | 142 | "not nomatch and highlightNonMatches - should not be red"); |
michael@0 | 143 | |
michael@0 | 144 | autocomplete.highlightNonMatches = "false"; |
michael@0 | 145 | |
michael@0 | 146 | isnot(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)", |
michael@0 | 147 | "not nomatch and not highlightNonMatches - should not be red"); |
michael@0 | 148 | |
michael@0 | 149 | setTimeout(check, 0); |
michael@0 | 150 | } |
michael@0 | 151 | else { |
michael@0 | 152 | // No result was returned, so there should be nomatch attribute |
michael@0 | 153 | is(autocomplete.getAttribute("nomatch"), "true", |
michael@0 | 154 | "nomatch attribute not correctly set when expected"); |
michael@0 | 155 | |
michael@0 | 156 | // Ensure that the style is set correctly whichever way highlightNonMatches |
michael@0 | 157 | // is set. |
michael@0 | 158 | autocomplete.highlightNonMatches = "true"; |
michael@0 | 159 | |
michael@0 | 160 | is(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)", |
michael@0 | 161 | "nomatch and highlightNonMatches - should be red"); |
michael@0 | 162 | |
michael@0 | 163 | autocomplete.highlightNonMatches = "false"; |
michael@0 | 164 | |
michael@0 | 165 | isnot(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)", |
michael@0 | 166 | "nomatch and not highlightNonMatches - should not be red"); |
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> |