tor-browser

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

browser_siteData_multi_select.js (3271B)


      1 "use strict";
      2 
      3 // Test selecting and removing partial sites
      4 add_task(async function () {
      5  await SiteDataTestUtils.clear();
      6 
      7  let hosts = await addTestData([
      8    {
      9      usage: 1024,
     10      origin: "https://127.0.0.1",
     11      persisted: false,
     12    },
     13    {
     14      usage: 1024 * 4,
     15      origin: "http://cinema.bar.com",
     16      persisted: true,
     17    },
     18    {
     19      usage: 1024 * 3,
     20      origin: "http://email.bar.com",
     21      persisted: false,
     22    },
     23    {
     24      usage: 1024 * 2,
     25      origin: "https://s3-us-west-2.amazonaws.com",
     26      persisted: true,
     27    },
     28    {
     29      usage: 1024 * 6,
     30      origin: "https://account.xyz.com",
     31      persisted: true,
     32    },
     33    {
     34      usage: 1024 * 5,
     35      origin: "https://shopping.xyz.com",
     36      persisted: false,
     37    },
     38    {
     39      usage: 1024 * 5,
     40      origin: "https://example.com",
     41      persisted: false,
     42    },
     43    {
     44      usage: 1024 * 5,
     45      origin: "https://example.net",
     46      persisted: false,
     47    },
     48  ]);
     49 
     50  // Align the order of test hosts with the order of the site data table.
     51  hosts.sort();
     52 
     53  let updatePromise = promiseSiteDataManagerSitesUpdated();
     54  await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
     55  await updatePromise;
     56  await openSiteDataSettingsDialog();
     57 
     58  let doc = gBrowser.selectedBrowser.contentDocument;
     59 
     60  // Test the initial state
     61  assertSitesListed(doc, hosts);
     62  let win = gBrowser.selectedBrowser.contentWindow;
     63  let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
     64  let removeBtn = frameDoc.getElementById("removeSelected");
     65  is(
     66    removeBtn.disabled,
     67    true,
     68    "Should start with disabled removeSelected button"
     69  );
     70 
     71  let hostCol = frameDoc.getElementById("hostCol");
     72  hostCol.click();
     73 
     74  let removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen(
     75    "accept",
     76    REMOVE_DIALOG_URL
     77  );
     78  let settingsDialogClosePromise = promiseSettingsDialogClose();
     79 
     80  // Select some sites to remove.
     81  let sitesList = frameDoc.getElementById("sitesList");
     82  hosts.slice(0, 2).forEach(host => {
     83    let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
     84    sitesList.addItemToSelection(site);
     85  });
     86 
     87  is(removeBtn.disabled, false, "Should enable the removeSelected button");
     88  removeBtn.doCommand();
     89  is(sitesList.selectedIndex, 0, "Should select next item");
     90  assertSitesListed(doc, hosts.slice(2));
     91 
     92  // Select some other sites to remove with Delete.
     93  hosts.slice(2, 4).forEach(host => {
     94    let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
     95    sitesList.addItemToSelection(site);
     96  });
     97 
     98  is(removeBtn.disabled, false, "Should enable the removeSelected button");
     99  // Move the focus from the search box to the list
    100  sitesList.focus();
    101  EventUtils.synthesizeKey("VK_DELETE");
    102  is(sitesList.selectedIndex, 0, "Should select next item");
    103  assertSitesListed(doc, hosts.slice(4));
    104 
    105  updatePromise = promiseSiteDataManagerSitesUpdated();
    106  let saveBtn = frameDoc.querySelector("dialog").getButton("accept");
    107  saveBtn.doCommand();
    108 
    109  await removeDialogOpenPromise;
    110  await settingsDialogClosePromise;
    111 
    112  await updatePromise;
    113  await openSiteDataSettingsDialog();
    114 
    115  assertSitesListed(doc, hosts.slice(4));
    116 
    117  await SiteDataTestUtils.clear();
    118  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    119 });