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.
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" type="text/css"?>
5 <window title="Autocomplete Widget Test 2"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
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"/>
13 <textbox id="autocomplete" type="autocomplete"
14 autocompletesearch="simple"
15 onsearchcomplete="checkResult();"/>
17 <script class="testbody" type="application/javascript">
18 <![CDATA[
20 // Set to indicate whether or not we want autoCompleteSimple to return a result
21 var returnResult = false;
23 const ACR = Components.interfaces.nsIAutoCompleteResult;
25 // This result can't be constructed in-line, because otherwise we leak memory.
26 function nsAutoCompleteSimpleResult(aString)
27 {
28 this.searchString = aString;
29 if (returnResult) {
30 this.searchResult = ACR.RESULT_SUCCESS;
31 this.matchCount = 1;
32 this._param = "SUCCESS";
33 }
34 }
36 nsAutoCompleteSimpleResult.prototype = {
37 _param: "",
38 searchString: null,
39 searchResult: ACR.RESULT_FAILURE,
40 defaultIndex: -1,
41 errorDescription: null,
42 matchCount: 0,
43 getValueAt: function() { return this._param; },
44 getCommentAt: function() { return null; },
45 getStyleAt: function() { return null; },
46 getImageAt: function() { return null; },
47 getFinalCompleteValueAt: function() { return this.getValueAt(); },
48 getLabelAt: function() { return null; },
49 removeValueAt: function() {}
50 };
52 // A basic autocomplete implementation that either returns one result or none
53 var autoCompleteSimpleID = Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca");
54 var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
55 var autoCompleteSimple = {
56 QueryInterface: function(iid) {
57 if (iid.equals(Components.interfaces.nsISupports) ||
58 iid.equals(Components.interfaces.nsIFactory) ||
59 iid.equals(Components.interfaces.nsIAutoCompleteSearch))
60 return this;
62 throw Components.results.NS_ERROR_NO_INTERFACE;
63 },
65 createInstance: function(outer, iid) {
66 return this.QueryInterface(iid);
67 },
69 startSearch: function(aString, aParam, aResult, aListener) {
70 var result = new nsAutoCompleteSimpleResult(aString);
71 aListener.onSearchResult(this, result);
72 },
74 stopSearch: function() {}
75 };
77 var componentManager = Components.manager
78 .QueryInterface(Components.interfaces.nsIComponentRegistrar);
79 componentManager.registerFactory(autoCompleteSimpleID, "Test Simple Autocomplete",
80 autoCompleteSimpleName, autoCompleteSimple);
83 // Test Bug 441530 - correctly setting "nomatch"
84 // Test Bug 441526 - correctly setting style with "highlightnonmatches"
86 SimpleTest.waitForExplicitFinish();
87 setTimeout(startTest, 0);
89 function startTest() {
90 var autocomplete = $("autocomplete");
92 // Ensure highlightNonMatches can be set correctly.
94 // This should not be set by default.
95 is(autocomplete.hasAttribute("highlightnonmatches"), false,
96 "highlight nonmatches not set by default");
98 autocomplete.highlightNonMatches = "true";
100 is(autocomplete.getAttribute("highlightnonmatches"), "true",
101 "highlight non matches attribute set correctly");
102 is(autocomplete.highlightNonMatches, true,
103 "highlight non matches getter returned correctly");
105 autocomplete.highlightNonMatches = "false";
107 is(autocomplete.getAttribute("highlightnonmatches"), "false",
108 "highlight non matches attribute set to false correctly");
109 is(autocomplete.highlightNonMatches, false,
110 "highlight non matches getter returned false correctly");
112 check();
113 }
115 function check() {
116 var autocomplete = $("autocomplete");
118 // Toggle this value, so we can re-use the one function.
119 returnResult = !returnResult;
121 // blur the field to ensure that the popup is closed and that the previous
122 // search has stopped, then start a new search.
123 autocomplete.blur();
124 autocomplete.focus();
125 synthesizeKey("r", {});
126 }
128 function checkResult() {
129 var autocomplete = $("autocomplete");
130 var style = window.getComputedStyle(autocomplete, "");
132 if (returnResult) {
133 // Result was returned, so there should not be a nomatch attribute
134 is(autocomplete.hasAttribute("nomatch"), false,
135 "nomatch attribute shouldn't be present here");
137 // Ensure that the style is set correctly whichever way highlightNonMatches
138 // is set.
139 autocomplete.highlightNonMatches = "true";
141 isnot(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)",
142 "not nomatch and highlightNonMatches - should not be red");
144 autocomplete.highlightNonMatches = "false";
146 isnot(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)",
147 "not nomatch and not highlightNonMatches - should not be red");
149 setTimeout(check, 0);
150 }
151 else {
152 // No result was returned, so there should be nomatch attribute
153 is(autocomplete.getAttribute("nomatch"), "true",
154 "nomatch attribute not correctly set when expected");
156 // Ensure that the style is set correctly whichever way highlightNonMatches
157 // is set.
158 autocomplete.highlightNonMatches = "true";
160 is(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)",
161 "nomatch and highlightNonMatches - should be red");
163 autocomplete.highlightNonMatches = "false";
165 isnot(style.getPropertyCSSValue("color").cssText, "rgb(255, 0, 0)",
166 "nomatch and not highlightNonMatches - should not be red");
168 setTimeout(function() {
169 // Unregister the factory so that we don't get in the way of other tests
170 componentManager.unregisterFactory(autoCompleteSimpleID, autoCompleteSimple);
171 SimpleTest.finish();
172 }, 0);
173 }
174 }
176 ]]>
177 </script>
179 <body xmlns="http://www.w3.org/1999/xhtml">
180 <p id="display">
181 </p>
182 <div id="content" style="display: none">
183 </div>
184 <pre id="test">
185 </pre>
186 </body>
188 </window>