Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

searchBar

The searchBar class simplifies the access for the searchbar.

Method overview

searchBar(in MozMillController controller);
checkSearchResultPage(in string searchTerm);
clear();
focus(in object event);
ElemBase getElement(in object spec);
array of string getSearchSuggestions(in string searchTerm);
boolean isEngineInstalled(in string name);
openEngineManager(in func_ptr handler);
removeEngine(in string name);
restoreDefaultEngines();
search(in object data);
type(in string searchTerm);

Attributes

Attribute Type Description
controller MozMillController Mozmill controller of the browser window.
engines array of object Properties of each engine (engine.name, engine.selected, engine.tooltipText).
enginesDropDownOpen boolean Open state of the search engine drop down popup.
installableEngines array of object Properties of each installable engine (engine.name, engine.selected, engine.tooltipText).
selectedEngine string Name of the currently selected search engine.
visibleEngines nsISearchEngine Retrieves all visible search engines (do not use for functional tests because it calls an API method).

Methods

searchBar()

Constructor of the searchBar class.

searchBar(
  in MozMillController controller
);
Parameters
controller
MozMillController of the browser window to operate on.

checkSearchResultPage()

Checks if the correct target URL has been opened for the search. An exception will be thrown if the search term cannot be found in the URL or if the current domain name in the location bar doesn't match the one from the search engine.

checkSearchResultPage(
  in string searchTerm
);
Parameters
searchTerm
Text which should be checked for.

clear()

Clears the search field.

clear();
Parameters

None.

focus()

Focus the search bar text field by using the specified event.

focus(
  in object event
);
Parameters
event
Event which should be used to focus the location bar (click or keyboard shortcut).
event.type (string) Description
"click" Use a mouse click.
"shortcut" Use the keyboard shortcut

getElement()

Retrieves an UI element based on the given spec object.

ElemBase getElement(
  in object spec
);
Parameters
spec
JSON object which specifies the element to retrieve. Use its attributes to specify the exact element. This example shows the correct usage.
spec.type  (string)
spec.subtype (string) spec.value (mixed) Description
"engine" nodeName
nodeValue
Get the search engine element from the engine drop down.
"engine_manager"
-
-
Get the engine manager element from the engine drop down.
"searchBar"
-
-
Get the search bar element.
"searchBar_contextMenu" -
-
Get the context menu element for the search bar.
"searchBar_dropDown" -
-
Get the engine drop down button element.
"searchBar_goButton"
-
-
Get the go button element.
"searchBar_input"
-
-
Get the input field element.
"searchBar_popup"
-
-
Get the popup element of the engine drop down.
"searchBar_textBox"
-
-
Get the whole text box element.
Return value

ElemBase instance of the requested element which matches the specifications.

getSearchSuggestions()

Returns the search suggestions for the search term.

array of string getSearchSuggestions(
  in string searchTerm
);
Parameters
searchTerm
Search term to enter into the search bar to get search suggestions for.
Return value

Array of all the shown search suggestions.

isEngineInstalled()

Check if a search engine is installed (This function calls an API method).

boolean isEngineInstalled(
  in string name
);
Parameters
name
Name of the search engine to check.
Return value

Returns true if the engine with the given name is installed.

openEngineManager()

Open the search engine manager.

openEngineManager(
  in func_ptr handler
);
Parameters
handler
Callback handler which will be called when the modal engine manager dialog has been opened.

removeEngine()

Remove the search engine with the given name (Ths function calls an API method).

removeEngine(
  in string name
);
Parameters
name
Name of the search engine to remove.

restoreDefaultEngines()

Restore the default set of search engines (This function calls an API method).

restoreDefaultEngines();
Parameters

None.

search()

Start a search with the given search term and check if the resulting URL contains the search term and the search engines domain name.

search(
  in object data
);
Parameters
data
JSON object which specifies the search text and action to use to start the search. This example shows the correct usage.
data.text  (string)
data.action (string) Description
search term
returnKey
Starts the search for the search term by synthesizing a return keypress.
search term
goButton
Starts the search for the search term by clicking the go button.

type()

Enters a search term into the search bar.

type(
  in string searchTerm
);
Parameters
searchTerm
Search term to enter into the search bar.
Return value

None.

Examples

var RELATIVE_ROOT = '../../shared-modules';
var MODULE_REQUIRES = ['SearchAPI'];

var setupModule = function(module)
{
  controller = mozmill.getBrowserController();
  engine = new SearchAPI.searchBar(controller);
}

var testClickAndSearch = function()
{
  engine.focus({type: "click"});
  engine.search({text: "Firefox", action: "goButton"});
  engine.clear();
}

Document Tags and Contributors

 Contributors to this page: Sheppy, Whimboo
 Last updated by: Sheppy,