B2G/gecko/browser/components/places/tests/browser/browser_library_search.js
/**
 * Performs a search for a given folder and search string and ensures that the
 * URI of the right pane's content tree is as expected for the folder and search
 * string.  Also ensures that the search scope button is as expected after the
 * search.
 *
 * @param  aFolderId
 *         the item ID of a node in the left pane's tree
 * @param  aSearchStr
 *         the search text; may be empty to reset the search
 * @param  aExpectedScopeButtonId
 *         after searching the selected scope button should be this
 */
Performs a search for a given folder and search string and ensures that the
URI of the right pane's content tree is as expected for the folder and search
string.  Also ensures that the search scope button is as expected after the
search.

@param  aFolderId
the item ID of a node in the left pane's tree
@param  aSearchStr
the search text; may be empty to reset the search
@param  aExpectedScopeButtonId
after searching the selected scope button should be this
Performs a search for a given folder and search string and ensures that the URI of the right pane ' s content tree is as expected for the folder and search string . Also ensures that the search scope button is as expected after the search . @param aFolderId the item ID of a node in the left pane ' s tree @param aSearchStr the search text ; may be empty to reset the search @param aExpectedScopeButtonId after searching the selected scope button should be this
function search(aFolderId, aSearchStr, aExpectedScopeButtonId) {
  let doc = gLibrary.document;
  let folderTree = doc.getElementById("placesList");
  let contentTree = doc.getElementById("placeContent");
  if (aFolderId) {
    folderTree.selectItems([aFolderId]);
    isnot(folderTree.selectedNode, null,
       "Sanity check: left pane tree should have selection after selecting!");
    if (aFolderId !== PlacesUIUtils.leftPaneQueries["History"] &&
        aFolderId !== PlacesUIUtils.leftPaneQueries["Downloads"]) {
      let query = queryStringToQuery(contentTree.result.root.uri);
      is(query.getFolders()[0], aFolderId,
         "Content tree's folder should be what was selected in the left pane");
    }
  }
  let searchBox = doc.getElementById("searchFilter");
  searchBox.value = aSearchStr;
  gLibrary.PlacesSearchBox.search(searchBox.value);
  let query = queryStringToQuery(contentTree.result.root.uri);
  if (aSearchStr) {
    is(query.searchTerms, aSearchStr,
       "Content tree's searchTerms should be text in search box");
    is(doc.getElementById("searchModifiers").hidden, false,
       "Scope bar should not be hidden after searching");
    let scopeButtonId = getSelectedScopeButtonId();
    if (scopeButtonId == "scopeBarDownloads" ||
        scopeButtonId == "scopeBarHistory" ||
        scopeButtonId == "scopeBarAll" ||
        aFolderId == PlacesUtils.unfiledBookmarksFolderId) {
      let url, count;
      if (scopeButtonId == "scopeBarDownloads") {
        url = TEST_DOWNLOAD_URL;
        count = 1;
      }
      else {
        url = TEST_URL;
        count = scopeButtonId == "scopeBarHistory" ? 2 : 1;
      }
      is(contentTree.view.rowCount, count, "Found correct number of results");
      let node = null;
      for (let i = 0; i < contentTree.view.rowCount; i++) {
        node = contentTree.view.nodeForTreeIndex(i);
        if (node.uri === url)
          break;
      }
      isnot(node, null, "At least the target node should be in the tree");
      is(node.uri, url, "URI of node should match target URL");
    }
  }
  else {
    is(query.hasSearchTerms, false,
       "Content tree's searchTerms should not exist after search reset");
    ok(doc.getElementById("searchModifiers").hidden,
       "Scope bar should be hidden after search reset");
  }
  is(getSelectedScopeButtonId(), aExpectedScopeButtonId,
     "Proper scope button should be selected after searching or resetting");
}
function search ( aFolderId , aSearchStr , aExpectedScopeButtonId ) { let doc = gLibrary . document ; let folderTree = doc . getElementById ( "placesList" ) ; let contentTree = doc . getElementById ( "placeContent" ) ; if ( aFolderId ) { folderTree . selectItems ( [ aFolderId ] ) ; isnot ( folderTree . selectedNode , null , "Sanity check: left pane tree should have selection after selecting!" ) ; if ( aFolderId !== PlacesUIUtils . leftPaneQueries [ "History" ] && aFolderId !== PlacesUIUtils . leftPaneQueries [ "Downloads" ] ) { let query = queryStringToQuery ( contentTree . result . root . uri ) ; is ( query . getFolders ( ) [ 0 ] , aFolderId , "Content tree's folder should be what was selected in the left pane" ) ; } } let searchBox = doc . getElementById ( "searchFilter" ) ; searchBox . value = aSearchStr ; gLibrary . PlacesSearchBox . search ( searchBox . value ) ; let query = queryStringToQuery ( contentTree . result . root . uri ) ; if ( aSearchStr ) { is ( query . searchTerms , aSearchStr , "Content tree's searchTerms should be text in search box" ) ; is ( doc . getElementById ( "searchModifiers" ) . hidden , false , "Scope bar should not be hidden after searching" ) ; let scopeButtonId = getSelectedScopeButtonId ( ) ; if ( scopeButtonId == "scopeBarDownloads" || scopeButtonId == "scopeBarHistory" || scopeButtonId == "scopeBarAll" || aFolderId == PlacesUtils . unfiledBookmarksFolderId ) { let url , count ; if ( scopeButtonId == "scopeBarDownloads" ) { url = TEST_DOWNLOAD_URL ; count = 1 ; } else { url = TEST_URL ; count = scopeButtonId == "scopeBarHistory" ? 2 : 1 ; } is ( contentTree . view . rowCount , count , "Found correct number of results" ) ; let node = null ; for ( let i = 0 ; i < contentTree . view . rowCount ; i ++ ) { node = contentTree . view . nodeForTreeIndex ( i ) ; if ( node . uri === url ) break ; } isnot ( node , null , "At least the target node should be in the tree" ) ; is ( node . uri , url , "URI of node should match target URL" ) ; } } else { is ( query . hasSearchTerms , false , "Content tree's searchTerms should not exist after search reset" ) ; ok ( doc . getElementById ( "searchModifiers" ) . hidden , "Scope bar should be hidden after search reset" ) ; } is ( getSelectedScopeButtonId ( ) , aExpectedScopeButtonId , "Proper scope button should be selected after searching or resetting" ) ; }
Performs a search for a given folder and search string and ensures that the
 URI of the right pane's content tree is as expected for the folder and search
 string.
Performs a search for a given folder and search string and ensures that the URI of the right pane ' s content tree is as expected for the folder and search string .
// First, ensure that selecting the folder in the left pane updates the // content tree properly. // getFolders() on a History query returns an empty array, so no use // comparing against aFolderId in that case. // contentTree.place should be equal to contentTree.result.root.uri, // but it's not until bug 476952 is fixed. // Second, ensure that searching updates the content tree and search UI // properly. // Check that the target node exists in the tree's search results.