toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.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.

     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 4"
     6         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     7         onload="runTest();">
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    11   <script type="application/javascript"
    12           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    13   <script type="application/javascript"
    14           src="chrome://global/content/globalOverlay.js"/>
    16 <textbox id="autocomplete"
    17          type="autocomplete"
    18          completedefaultindex="true"
    19          onsearchcomplete="searchComplete();"
    20          timeout="0"
    21          autocompletesearch="simple"/>
    23 <script class="testbody" type="application/javascript">
    24 <![CDATA[
    26 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    28 function autoCompleteSimpleResult(aString) {
    29   this.searchString = aString;
    30   this.searchResult = Components.interfaces.nsIAutoCompleteResult.RESULT_SUCCESS;
    31   this.matchCount = 1;
    32   this._param = "Result";
    33 }
    34 autoCompleteSimpleResult.prototype = {
    35  _param: "",
    36  searchString: null,
    37  searchResult: Components.interfaces.nsIAutoCompleteResult.RESULT_FAILURE,
    38  defaultIndex: 0,
    39  errorDescription: null,
    40  matchCount: 0,
    41  getValueAt: function() { return this._param; },
    42  getCommentAt: function() { return null; },
    43  getStyleAt: function() { return null; },
    44  getImageAt: function() { return null; },
    45  getFinalCompleteValueAt: function() { return this.getValueAt(); },
    46  getLabelAt: function() { return null; },
    47  removeValueAt: function() {}
    48 };
    50 // A basic autocomplete implementation that returns one result.
    51 let autoCompleteSimple = {
    52   classID: Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca"),
    53   contractID: "@mozilla.org/autocomplete/search;1?name=simple",
    54   QueryInterface: XPCOMUtils.generateQI([
    55     Components.interfaces.nsIFactory,
    56     Components.interfaces.nsIAutoCompleteSearch
    57   ]),
    58   createInstance: function (outer, iid) {
    59     return this.QueryInterface(iid);
    60   },
    62   registerFactory: function () {
    63     let registrar =
    64       Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
    65     registrar.registerFactory(this.classID, "Test Simple Autocomplete",
    66                               this.contractID, this);
    67   },
    68   unregisterFactory: function () {
    69     let registrar =
    70       Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
    71     registrar.unregisterFactory(this.classID, this);
    72   },
    74   startSearch: function (aString, aParam, aResult, aListener) {
    75     let result = new autoCompleteSimpleResult(aString);
    76     aListener.onSearchResult(this, result);
    77   },
    78   stopSearch: function () {}
    79 };
    81 SimpleTest.waitForExplicitFinish();
    83 // XPFE AutoComplete needs to register early.
    84 autoCompleteSimple.registerFactory();
    86 let gACTimer;
    87 let gAutoComplete;
    89 function searchComplete() {
    90   is(gAutoComplete.value, "result", "Value should be autocompleted now");
    91   ok(Date.now() - gACTimer  > 500, "There should be a delay before autocomplete");
    93   // Unregister the factory so that we don't get in the way of other tests
    94   autoCompleteSimple.unregisterFactory();
    95   SimpleTest.finish();
    96 }
    98 function runTest() {
    99   gAutoComplete = $("autocomplete");
   101   const SEARCH_STRING = "res";
   103   function cbCallback() {
   104     gAutoComplete.focus();
   105     synthesizeKey("v", { accelKey: true });
   106     is(gAutoComplete.value, SEARCH_STRING, "Value should not be autocompleted immediately");
   107   }
   109   SimpleTest.waitForClipboard(SEARCH_STRING, function () {
   110     gACTimer = Date.now();
   111     Components.classes["@mozilla.org/widget/clipboardhelper;1"]
   112       .getService(Components.interfaces.nsIClipboardHelper)
   113       .copyStringToClipboard(SEARCH_STRING, Components.interfaces.nsIClipboard.kGlobalClipboard, document);
   114   }, cbCallback, cbCallback);
   115 }
   116 ]]>
   117 </script>
   119 <body xmlns="http://www.w3.org/1999/xhtml">
   120 <p id="display">
   121 </p>
   122 <div id="content" style="display: none">
   123 </div>
   124 <pre id="test">
   125 </pre>
   126 </body>
   128 </window>

mercurial