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 5" |
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 | ontextentered="checkTextEntered();" |
michael@0 | 16 | ontextreverted="checkTextReverted();" |
michael@0 | 17 | onsearchbegin="checkSearchBegin();" |
michael@0 | 18 | onsearchcomplete="checkSearchCompleted();"/> |
michael@0 | 19 | |
michael@0 | 20 | <script class="testbody" type="application/javascript"> |
michael@0 | 21 | <![CDATA[ |
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 | this.searchResult = ACR.RESULT_SUCCESS; |
michael@0 | 30 | this.matchCount = 1; |
michael@0 | 31 | this._param = "SUCCESS"; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | nsAutoCompleteSimpleResult.prototype = { |
michael@0 | 35 | _param: "", |
michael@0 | 36 | searchString: null, |
michael@0 | 37 | searchResult: ACR.RESULT_FAILURE, |
michael@0 | 38 | defaultIndex: -1, |
michael@0 | 39 | errorDescription: null, |
michael@0 | 40 | matchCount: 0, |
michael@0 | 41 | getValueAt: function() { return this._param; }, |
michael@0 | 42 | getCommentAt: function() { return null; }, |
michael@0 | 43 | getStyleAt: function() { return null; }, |
michael@0 | 44 | getImageAt: function() { return null; }, |
michael@0 | 45 | getFinalCompleteValueAt: function() { return this.getValueAt(); }, |
michael@0 | 46 | getLabelAt: function() { return null; }, |
michael@0 | 47 | removeValueAt: function() {} |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | // A basic autocomplete implementation that either returns one result or none |
michael@0 | 51 | var autoCompleteSimpleID = Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca"); |
michael@0 | 52 | var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple" |
michael@0 | 53 | var autoCompleteSimple = { |
michael@0 | 54 | QueryInterface: function(iid) { |
michael@0 | 55 | if (iid.equals(Components.interfaces.nsISupports) || |
michael@0 | 56 | iid.equals(Components.interfaces.nsIFactory) || |
michael@0 | 57 | iid.equals(Components.interfaces.nsIAutoCompleteSearch)) |
michael@0 | 58 | return this; |
michael@0 | 59 | |
michael@0 | 60 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 61 | }, |
michael@0 | 62 | |
michael@0 | 63 | createInstance: function(outer, iid) { |
michael@0 | 64 | return this.QueryInterface(iid); |
michael@0 | 65 | }, |
michael@0 | 66 | |
michael@0 | 67 | startSearch: function(aString, aParam, aResult, aListener) { |
michael@0 | 68 | var result = new nsAutoCompleteSimpleResult(aString); |
michael@0 | 69 | aListener.onSearchResult(this, result); |
michael@0 | 70 | }, |
michael@0 | 71 | |
michael@0 | 72 | stopSearch: function() {} |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | var componentManager = Components.manager |
michael@0 | 76 | .QueryInterface(Components.interfaces.nsIComponentRegistrar); |
michael@0 | 77 | componentManager.registerFactory(autoCompleteSimpleID, "Test Simple Autocomplete", |
michael@0 | 78 | autoCompleteSimpleName, autoCompleteSimple); |
michael@0 | 79 | |
michael@0 | 80 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 81 | setTimeout(startTest, 0); |
michael@0 | 82 | |
michael@0 | 83 | function startTest() { |
michael@0 | 84 | let autocomplete = $("autocomplete"); |
michael@0 | 85 | |
michael@0 | 86 | // blur the field to ensure that the popup is closed and that the previous |
michael@0 | 87 | // search has stopped, then start a new search. |
michael@0 | 88 | autocomplete.blur(); |
michael@0 | 89 | autocomplete.focus(); |
michael@0 | 90 | synthesizeKey("r", {}); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | let hasTextEntered = false; |
michael@0 | 94 | let hasSearchBegun = false; |
michael@0 | 95 | |
michael@0 | 96 | function checkSearchBegin() { |
michael@0 | 97 | hasSearchBegun = true; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | let test = 0; |
michael@0 | 101 | function checkSearchCompleted() { |
michael@0 | 102 | is(hasSearchBegun, true, "onsearchbegin handler has been correctly called."); |
michael@0 | 103 | |
michael@0 | 104 | if (test == 0) { |
michael@0 | 105 | hasSearchBegun = false; |
michael@0 | 106 | synthesizeKey("VK_RETURN", { }); |
michael@0 | 107 | } else if (test == 1) { |
michael@0 | 108 | hasSearchBegun = false; |
michael@0 | 109 | synthesizeKey("VK_ESCAPE", { }); |
michael@0 | 110 | } else { |
michael@0 | 111 | throw "checkSearchCompleted should only be called twice."; |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function checkTextEntered() { |
michael@0 | 116 | is(test, 0, "checkTextEntered should be reached from first test."); |
michael@0 | 117 | is(hasSearchBegun, false, "onsearchbegin handler should not be called on text revert."); |
michael@0 | 118 | |
michael@0 | 119 | // fire second test |
michael@0 | 120 | test++; |
michael@0 | 121 | |
michael@0 | 122 | let autocomplete = $("autocomplete"); |
michael@0 | 123 | autocomplete.textValue = ""; |
michael@0 | 124 | autocomplete.blur(); |
michael@0 | 125 | autocomplete.focus(); |
michael@0 | 126 | synthesizeKey("r", {}); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function checkTextReverted() { |
michael@0 | 130 | is(test, 1, "checkTextReverted should be the second test reached."); |
michael@0 | 131 | is(hasSearchBegun, false, "onsearchbegin handler should not be called on text revert."); |
michael@0 | 132 | |
michael@0 | 133 | setTimeout(function() { |
michael@0 | 134 | // Unregister the factory so that we don't get in the way of other tests |
michael@0 | 135 | componentManager.unregisterFactory(autoCompleteSimpleID, autoCompleteSimple); |
michael@0 | 136 | SimpleTest.finish(); |
michael@0 | 137 | }, 0); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | ]]> |
michael@0 | 141 | </script> |
michael@0 | 142 | |
michael@0 | 143 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 144 | <p id="display"> |
michael@0 | 145 | </p> |
michael@0 | 146 | <div id="content" style="display: none"> |
michael@0 | 147 | </div> |
michael@0 | 148 | <pre id="test"> |
michael@0 | 149 | </pre> |
michael@0 | 150 | </body> |
michael@0 | 151 | |
michael@0 | 152 | </window> |