B2G/gecko/toolkit/components/places/tests/inline/head_autocomplete.js
/**
 * @param aSearchString
 *        String to search.
 * @param aExpectedValue
 *        Expected value returned by autoFill.
 *        May be a string, or an object like
 *        {
 *          autoFilled: the value suggested by autofill,
 *          completed: the value completed on user's confirmation
 *        }
 *        In the latter case this will also check that on user's confirmation
 *        the result's casing is correctly applied.
 */
@param aSearchString
String to search.
@param aExpectedValue
Expected value returned by autoFill.
May be a string, or an object like
{
autoFilled: the value suggested by autofill,
completed: the value completed on user's confirmation
}
In the latter case this will also check that on user's confirmation
the result's casing is correctly applied.
@param aSearchString String to search . @param aExpectedValue Expected value returned by autoFill . May be a string or an object like { autoFilled : the value suggested by autofill completed : the value completed on user ' s confirmation } In the latter case this will also check that on user ' s confirmation the result ' s casing is correctly applied .
function ensure_results(aSearchString, aExpectedValue) {
  let autoFilledValue, completedValue;
  if (typeof(aExpectedValue) == "string") {
    autoFilledValue = aExpectedValue;
  }
  else {
    autoFilledValue = aExpectedValue.autoFilled;
    completedValue = aExpectedValue.completed;
  }
  let input = new AutoCompleteInput(["urlinline"]);
  input.textValue = aSearchString;
  let strLen = aSearchString.length;
  input.selectTextRange(strLen, strLen);
  do_check_eq(input.selectionStart, strLen);
  do_check_eq(input.selectionEnd, strLen);
  let controller = Cc["@mozilla.org/autocomplete/controller;1"].
                   getService(Ci.nsIAutoCompleteController);
  controller.input = input;
  let numSearchesStarted = 0;
  input.onSearchBegin = function() {
    numSearchesStarted++;
    do_check_eq(numSearchesStarted, 1);
  };
  input.onSearchComplete = function() {
    do_check_eq(numSearchesStarted, 1);
    do_check_eq(input.textValue, autoFilledValue);
    if (completedValue) {
      controller.handleEnter(false);
      do_check_eq(input.textValue, completedValue);
    }
    waitForCleanup(run_next_test);
  };
  do_log_info("Searching for: '" + aSearchString + "'");
  controller.startSearch(aSearchString);
}
function ensure_results ( aSearchString , aExpectedValue ) { let autoFilledValue , completedValue ; if ( typeof ( aExpectedValue ) == "string" ) { autoFilledValue = aExpectedValue ; } else { autoFilledValue = aExpectedValue . autoFilled ; completedValue = aExpectedValue . completed ; } let input = new AutoCompleteInput ( [ "urlinline" ] ) ; input . textValue = aSearchString ; let strLen = aSearchString . length ; input . selectTextRange ( strLen , strLen ) ; do_check_eq ( input . selectionStart , strLen ) ; do_check_eq ( input . selectionEnd , strLen ) ; let controller = Cc [ "@mozilla.org/autocomplete/controller;1" ] . getService ( Ci . nsIAutoCompleteController ) ; controller . input = input ; let numSearchesStarted = 0 ; input . onSearchBegin = function ( ) { numSearchesStarted ++ ; do_check_eq ( numSearchesStarted , 1 ) ; } ; input . onSearchComplete = function ( ) { do_check_eq ( numSearchesStarted , 1 ) ; do_check_eq ( input . textValue , autoFilledValue ) ; if ( completedValue ) { controller . handleEnter ( false ) ; do_check_eq ( input . textValue , completedValue ) ; } waitForCleanup ( run_next_test ) ; } ; do_log_info ( "Searching for: '" + aSearchString + "'" ) ; controller . startSearch ( aSearchString ) ; }
@param aSearchString
        String to search.
@param aSearchString String to search .
// Make an AutoCompleteInput that uses our searches and confirms results. // Caret must be at the end for autoFill to happen. // We should be running only one query. // Check the autoFilled result. // Now force completion and check correct casing of the result. // This ensures the controller is able to do its magic case-preserving // stuff and correct replacement of the user's casing with result's one.