tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_search_within_preferences_1.js (9849B)


      1 "use strict";
      2 /**
      3 * This file contains tests for the Preferences search bar.
      4 */
      5 
      6 requestLongerTimeout(6);
      7 
      8 /**
      9 * Tests to see if search bar is being shown when pref is turned on
     10 */
     11 add_task(async function show_search_bar_when_pref_is_enabled() {
     12  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     13    leaveOpen: true,
     14  });
     15  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
     16  is_element_visible(searchInput, "Search box should be shown");
     17  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     18 });
     19 
     20 /**
     21 * Test for "Search Result" panel.
     22 * After it runs a search, it tests if the "Search Results" panel is the only selected category.
     23 * The search is then cleared, it then tests if the "General" panel is the only selected category.
     24 */
     25 add_task(async function show_search_results_pane_only_then_revert_to_general() {
     26  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     27    leaveOpen: true,
     28  });
     29 
     30  // Performs search
     31  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
     32 
     33  is(
     34    searchInput,
     35    gBrowser.contentDocument.activeElement.closest("#searchInput"),
     36    "Search input should be focused when visiting preferences"
     37  );
     38 
     39  let query = "password";
     40  let searchCompletedPromise = BrowserTestUtils.waitForEvent(
     41    gBrowser.contentWindow,
     42    "PreferencesSearchCompleted",
     43    evt => evt.detail == query
     44  );
     45  EventUtils.sendString(query);
     46  await searchCompletedPromise;
     47 
     48  let categoriesList = gBrowser.contentDocument.getElementById("categories");
     49 
     50  for (let i = 0; i < categoriesList.childElementCount; i++) {
     51    let child = categoriesList.itemChildren[i];
     52    is(child.selected, false, "No other panel should be selected");
     53  }
     54  // Takes search off
     55  searchCompletedPromise = BrowserTestUtils.waitForEvent(
     56    gBrowser.contentWindow,
     57    "PreferencesSearchCompleted",
     58    evt => evt.detail == ""
     59  );
     60  let count = query.length;
     61  while (count--) {
     62    EventUtils.sendKey("BACK_SPACE");
     63  }
     64  await searchCompletedPromise;
     65 
     66  // Checks if back to generalPane
     67  for (let i = 0; i < categoriesList.childElementCount; i++) {
     68    let child = categoriesList.itemChildren[i];
     69    if (child.id == "category-general") {
     70      is(child.selected, true, "General panel should be selected");
     71    } else if (child.id) {
     72      is(child.selected, false, "No other panel should be selected");
     73    }
     74  }
     75 
     76  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     77 });
     78 
     79 /**
     80 * Test for "password" case. When we search "password", it should show the "passwordGroup"
     81 */
     82 add_task(async function search_for_password_show_passwordGroup() {
     83  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     84    leaveOpen: true,
     85  });
     86 
     87  // Performs search
     88  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
     89 
     90  is(
     91    searchInput,
     92    gBrowser.contentDocument.activeElement.closest("#searchInput"),
     93    "Search input should be focused when visiting preferences"
     94  );
     95 
     96  let query = "password";
     97  let searchCompletedPromise = BrowserTestUtils.waitForEvent(
     98    gBrowser.contentWindow,
     99    "PreferencesSearchCompleted",
    100    evt => evt.detail == query
    101  );
    102  EventUtils.sendString(query);
    103  await searchCompletedPromise;
    104 
    105  let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
    106 
    107  for (let i = 0; i < mainPrefTag.childElementCount; i++) {
    108    let child = mainPrefTag.children[i];
    109    if (
    110      child.id == "passwordsGroup" ||
    111      child.id == "weavePrefsDeck" ||
    112      child.id == "header-searchResults" ||
    113      child.id == "certSelection" ||
    114      child.id == "connectionGroup" ||
    115      child.id == "dataMigrationGroup"
    116    ) {
    117      is_element_visible(child, "Should be in search results");
    118    } else if (child.id) {
    119      is_element_hidden(child, "Should not be in search results");
    120    }
    121  }
    122 
    123  // Takes search off
    124  searchCompletedPromise = BrowserTestUtils.waitForEvent(
    125    gBrowser.contentWindow,
    126    "PreferencesSearchCompleted",
    127    evt => evt.detail == ""
    128  );
    129  let count = query.length;
    130  while (count--) {
    131    EventUtils.sendKey("BACK_SPACE");
    132  }
    133  await searchCompletedPromise;
    134 
    135  let expectedChildren = [
    136    "paneGeneral",
    137    "startupGroup",
    138    "languagesGroup",
    139    "webAppearanceGroup",
    140    "contrastControlGroup",
    141    "fontsGroup",
    142    "zoomGroup",
    143    "downloadsGroup",
    144    "applicationsGroup",
    145    "drmGroup",
    146    "browsingGroup",
    147    "performanceGroup",
    148    "connectionGroup",
    149    "generalCategory",
    150    "languageAndAppearanceCategory",
    151    "filesAndApplicationsCategory",
    152    "performanceCategory",
    153    "browsingCategory",
    154    "networkProxyCategory",
    155    "dataMigrationGroup",
    156    "translationsGroup",
    157  ];
    158  // Only visible for non-MSIX builds
    159  if (
    160    AppConstants.platform !== "win" ||
    161    !Services.sysinfo.getProperty("hasWinPackageId", false)
    162  ) {
    163    expectedChildren.push("updatesCategory");
    164    expectedChildren.push("updateApp");
    165  }
    166  // Checks if back to generalPane
    167  for (let i = 0; i < mainPrefTag.childElementCount; i++) {
    168    let child = mainPrefTag.children[i];
    169    if (expectedChildren.includes(child.id)) {
    170      is_element_visible(child, `Should be in general tab: ${child.id}`);
    171    } else if (child.id) {
    172      is_element_hidden(child, `Should not be in general tab: ${child.id}`);
    173    }
    174  }
    175 
    176  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    177 });
    178 
    179 /**
    180 * Test for if nothing is found
    181 */
    182 add_task(async function search_with_nothing_found() {
    183  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
    184    leaveOpen: true,
    185  });
    186 
    187  let noResultsEl = gBrowser.contentDocument.querySelector(
    188    "#no-results-message"
    189  );
    190  let sorryMsgQueryEl = gBrowser.contentDocument.getElementById(
    191    "sorry-message-query"
    192  );
    193 
    194  is_element_hidden(noResultsEl, "Should not be in search results yet");
    195 
    196  // Performs search
    197  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
    198 
    199  is(
    200    searchInput,
    201    gBrowser.contentDocument.activeElement.closest("#searchInput"),
    202    "Search input should be focused when visiting preferences"
    203  );
    204 
    205  let query = "coach";
    206  let searchCompletedPromise = BrowserTestUtils.waitForEvent(
    207    gBrowser.contentWindow,
    208    "PreferencesSearchCompleted",
    209    evt => evt.detail == query
    210  );
    211  EventUtils.sendString(query);
    212  await searchCompletedPromise;
    213 
    214  is_element_visible(noResultsEl, "Should be in search results");
    215  is(
    216    sorryMsgQueryEl.textContent,
    217    query,
    218    "sorry-message-query should contain the query"
    219  );
    220 
    221  // Takes search off
    222  searchCompletedPromise = BrowserTestUtils.waitForEvent(
    223    gBrowser.contentWindow,
    224    "PreferencesSearchCompleted",
    225    evt => evt.detail == ""
    226  );
    227  let count = query.length;
    228  while (count--) {
    229    EventUtils.sendKey("BACK_SPACE");
    230  }
    231  await searchCompletedPromise;
    232 
    233  is_element_hidden(noResultsEl, "Should not be in search results");
    234  is(
    235    sorryMsgQueryEl.textContent.length,
    236    0,
    237    "sorry-message-query should be empty"
    238  );
    239 
    240  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    241 });
    242 
    243 /**
    244 * Test for if we go back to general tab after search case
    245 */
    246 add_task(async function exiting_search_reverts_to_general_pane() {
    247  await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
    248  let generalPane = gBrowser.contentDocument.getElementById("generalCategory");
    249 
    250  is_element_hidden(generalPane, "Should not be in general");
    251 
    252  // Performs search
    253  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
    254 
    255  is(
    256    searchInput,
    257    gBrowser.contentDocument.activeElement.closest("#searchInput"),
    258    "Search input should be focused when visiting preferences"
    259  );
    260 
    261  let query = "password";
    262  let searchCompletedPromise = BrowserTestUtils.waitForEvent(
    263    gBrowser.contentWindow,
    264    "PreferencesSearchCompleted",
    265    evt => evt.detail == query
    266  );
    267  EventUtils.sendString(query);
    268  await searchCompletedPromise;
    269 
    270  // Takes search off
    271  searchCompletedPromise = BrowserTestUtils.waitForEvent(
    272    gBrowser.contentWindow,
    273    "PreferencesSearchCompleted",
    274    evt => evt.detail == ""
    275  );
    276  let count = query.length;
    277  while (count--) {
    278    EventUtils.sendKey("BACK_SPACE");
    279  }
    280  await searchCompletedPromise;
    281 
    282  // Checks if back to normal
    283  is_element_visible(generalPane, "Should be in generalPane");
    284 
    285  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    286 });
    287 
    288 /**
    289 * Test for if we go to another tab after searching
    290 */
    291 add_task(async function changing_tabs_after_searching() {
    292  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
    293    leaveOpen: true,
    294  });
    295  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
    296 
    297  is(
    298    searchInput,
    299    gBrowser.contentDocument.activeElement.closest("#searchInput"),
    300    "Search input should be focused when visiting preferences"
    301  );
    302 
    303  let query = "permission";
    304  let searchCompletedPromise = BrowserTestUtils.waitForEvent(
    305    gBrowser.contentWindow,
    306    "PreferencesSearchCompleted",
    307    evt => evt.detail == query
    308  );
    309  EventUtils.sendString(query);
    310  await searchCompletedPromise;
    311 
    312  // Search header should be shown for the permissions group
    313  let permissionsGroup = gBrowser.contentDocument.querySelector(
    314    "moz-fieldset#permissions"
    315  );
    316  is(permissionsGroup.hidden, false, "Permissions group should be visible");
    317 
    318  let privacyCategory =
    319    gBrowser.contentDocument.getElementById("category-privacy");
    320  privacyCategory.click();
    321  is(searchInput.value, "", "search input should be empty");
    322  let categoriesList = gBrowser.contentDocument.getElementById("categories");
    323  for (let i = 0; i < categoriesList.childElementCount; i++) {
    324    let child = categoriesList.itemChildren[i];
    325    if (child.id == "category-privacy") {
    326      is(child.selected, true, "Privacy panel should be selected");
    327    } else if (child.id) {
    328      is(child.selected, false, "No other panel should be selected");
    329    }
    330  }
    331 
    332  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    333 });