Commit f41a1479 authored by Ricky Chien's avatar Ricky Chien
Browse files

Bug 1397723 - Correct Preferences search matching approach for search feature r=mconley

MozReview-Commit-ID: 1t8oXYvwHbl

--HG--
extra : rebase_source : 2b54e538bec666b38d989a3af93f5ba99ee93a7e
parent 78f67a85
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -39,22 +39,20 @@ var gSearchResultsPane = {
  },

  /**
   * Check that the passed string matches the filter arguments.
   * Check that the text content contains the query string.
   *
   * @param String str
   *    to search for filter words in.
   * @param String filter
   *    is a string containing all of the words to filter on.
   * @param String content
   *    the text content to be searched
   * @param String query
   *    the query string
   * @returns boolean
   *    true when match in string else false
   *    true when the text content contains the query string else false
   */
  stringMatchesFilters(str, filter) {
    if (!filter || !str) {
  queryMatchesContent(content, query) {
    if (!content || !query) {
      return false;
    }
    let searchStr = str.toLowerCase();
    let filterStrings = filter.toLowerCase().split(/\s+/);
    return !filterStrings.some(f => searchStr.indexOf(f) == -1);
    return content.toLowerCase().includes(query.toLowerCase());
  },

  categoriesInitialized: false,
@@ -350,7 +348,6 @@ var gSearchResultsPane = {
        nodeObject.tagName == "description" ||
        nodeObject.tagName == "menulist") {
      let simpleTextNodes = this.textNodeDescendants(nodeObject);

      for (let node of simpleTextNodes) {
        let result = this.highlightMatches([node], [node.length], node.textContent.toLowerCase(), searchPhrase);
        matchesFound = matchesFound || result;
@@ -376,15 +373,15 @@ var gSearchResultsPane = {
      let complexTextNodesResult = this.highlightMatches(accessKeyTextNodes, nodeSizes, allNodeText.toLowerCase(), searchPhrase);

      // Searching some elements, such as xul:button, have a 'label' attribute that contains the user-visible text.
      let labelResult = this.stringMatchesFilters(nodeObject.getAttribute("label"), searchPhrase);
      let labelResult = this.queryMatchesContent(nodeObject.getAttribute("label"), searchPhrase);

      // Searching some elements, such as xul:label, store their user-visible text in a "value" attribute.
      // Value will be skipped for menuitem since value in menuitem could represent index number to distinct each item.
      let valueResult = nodeObject.tagName !== "menuitem" ?
       this.stringMatchesFilters(nodeObject.getAttribute("value"), searchPhrase) : false;
        this.queryMatchesContent(nodeObject.getAttribute("value"), searchPhrase) : false;

      // Searching some elements, such as xul:button, buttons to open subdialogs.
      let keywordsResult = this.stringMatchesFilters(nodeObject.getAttribute("searchkeywords"), searchPhrase);
      let keywordsResult = this.queryMatchesContent(nodeObject.getAttribute("searchkeywords"), searchPhrase);

      // Creating tooltips for buttons
      if (keywordsResult && (nodeObject.tagName === "button" || nodeObject.tagName == "menulist")) {
+1 −0
Original line number Diff line number Diff line
@@ -581,6 +581,7 @@
                                &backgroundColor2.label;
                                &useSystemColors.label;
                                &underlineLinks.label;
                                &links;
                                &linkColor2.label;
                                &visitedLinkColor2.label;"/>
      </hbox>
+1 −1
Original line number Diff line number Diff line
@@ -21,6 +21,6 @@ add_task(async function() {
 */
add_task(async function() {
  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
  await evaluateSearchResults("set location permissions", "permissionsGroup");
  await evaluateSearchResults("location permissions", "permissionsGroup");
  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
+3 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ add_task(async function() {
 */
add_task(async function() {
  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
  await evaluateSearchResults("set camera permissions", "permissionsGroup");
  await evaluateSearchResults("camera permissions", "permissionsGroup");
  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

@@ -23,7 +23,7 @@ add_task(async function() {
 */
add_task(async function() {
  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
  await evaluateSearchResults("set microphone permissions", "permissionsGroup");
  await evaluateSearchResults("microphone permissions", "permissionsGroup");
  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

@@ -32,6 +32,6 @@ add_task(async function() {
 */
add_task(async function() {
  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
  await evaluateSearchResults("set notifications permissions", "permissionsGroup");
  await evaluateSearchResults("notification permissions", "permissionsGroup");
  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});