tor-browser

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

browser_storage_overflow.js (2978B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Test endless scrolling when a lot of items are present in the storage
      6 // inspector table.
      7 "use strict";
      8 
      9 const ITEMS_PER_PAGE = 50;
     10 
     11 add_task(async function () {
     12  await openTabAndSetupStorage(MAIN_DOMAIN_SECURED + "storage-overflow.html");
     13 
     14  info("Run the tests with short DevTools");
     15  await runTests();
     16 
     17  info("Close Toolbox");
     18  await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
     19 
     20  info("Set a toolbox height of 1000px");
     21  await pushPref("devtools.toolbox.footer.height", 1000);
     22 
     23  info("Open storage panel again");
     24  await openStoragePanel();
     25 
     26  info("Run the tests with tall DevTools");
     27  await runTests(true);
     28 });
     29 
     30 async function runTests(tall) {
     31  if (tall) {
     32    // We need to zoom out and a tall storage panel in order to fit more than 50
     33    // items in the table. We do this to ensure that we load enough content to
     34    // show a scrollbar so that we can still use infinite scrolling.
     35    zoom(0.5);
     36  }
     37 
     38  gUI.tree.expandAll();
     39  await selectTreeItem(["localStorage", "https://test1.example.org"]);
     40 
     41  if (tall) {
     42    if (getCellLength() === ITEMS_PER_PAGE) {
     43      await scrollToAddItems();
     44      await waitForStorageData("item-100", "value-100");
     45    }
     46 
     47    if (getCellLength() === ITEMS_PER_PAGE * 2) {
     48      await scrollToAddItems();
     49      await waitForStorageData("item-150", "value-150");
     50    }
     51 
     52    if (getCellLength() === ITEMS_PER_PAGE * 3) {
     53      await scrollToAddItems();
     54      await waitForStorageData("item-151", "value-151");
     55    }
     56  } else {
     57    checkCellLength(ITEMS_PER_PAGE);
     58    await scrollToAddItems();
     59    await waitForStorageData("item-100", "value-100");
     60 
     61    checkCellLength(ITEMS_PER_PAGE * 2);
     62    await scrollToAddItems();
     63    await waitForStorageData("item-150", "value-150");
     64 
     65    checkCellLength(ITEMS_PER_PAGE * 3);
     66    await scrollToAddItems();
     67    await waitForStorageData("item-151", "value-151");
     68  }
     69 
     70  is(getCellLength(), 151, "Storage table contains 151 items");
     71 
     72  // Check that the columns are sorted in a human readable way (ascending).
     73  checkCellValues("ASC");
     74 
     75  // Sort descending.
     76  clickColumnHeader("name");
     77 
     78  // Check that the columns are sorted in a human readable way (descending).
     79  checkCellValues("DEC");
     80 
     81  if (tall) {
     82    zoom(1);
     83  }
     84 }
     85 
     86 function checkCellValues(order) {
     87  const cells = [
     88    ...gPanelWindow.document.querySelectorAll("#name .table-widget-cell"),
     89  ];
     90  cells.forEach(function (cell, index, arr) {
     91    const i = order === "ASC" ? index + 1 : arr.length - index;
     92    is(cell.value, `item-${i}`, `Cell value is "item-${i}" (${order}).`);
     93  });
     94 }
     95 
     96 async function scrollToAddItems() {
     97  info(`Scrolling to add ${ITEMS_PER_PAGE} items`);
     98  await scroll();
     99 }
    100 
    101 function zoom(zoomValue) {
    102  const bc = BrowsingContext.getFromWindow(gPanelWindow);
    103  bc.fullZoom = zoomValue;
    104 }