summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_overflow.js
blob: 21b931c8e032be79ae51a19e9ed5c0fee48b68cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Test endless scrolling when a lot of items are present in the storage
// inspector table.
"use strict";

const ITEMS_PER_PAGE = 50;

add_task(function* () {
  yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-overflow.html");

  gUI.tree.expandAll();
  yield selectTreeItem(["localStorage", "http://test1.example.org"]);
  checkCellLength(ITEMS_PER_PAGE);
 
  yield scroll();
  checkCellLength(ITEMS_PER_PAGE * 2);

  yield scroll();
  checkCellLength(ITEMS_PER_PAGE * 3);

  // Check that the columns are sorted in a human readable way (ascending).
  checkCellValues("ASC");

  // Sort descending.
  clickColumnHeader("name");

  // Check that the columns are sorted in a human readable way (descending).
  checkCellValues("DEC");

  yield finishTests();
});

function checkCellLength(len) {
  let cells = gPanelWindow.document
                          .querySelectorAll("#name .table-widget-cell");
  let msg = `Table should initially display ${len} items`;

  is(cells.length, len, msg);
}

function checkCellValues(order) {
  let cells = [...gPanelWindow.document
                              .querySelectorAll("#name .table-widget-cell")];
  cells.forEach(function (cell, index, arr) {
    let i = order === "ASC" ? index + 1 : arr.length - index;
    is(cell.value, `item-${i}`, `Cell value is correct (${order}).`);
  });
}

function* scroll() {
  let $ = id => gPanelWindow.document.querySelector(id);

  let table = $("#storage-table .table-widget-body");
  let cell = $("#name .table-widget-cell");
  let cellHeight = cell.getBoundingClientRect().height;

  let onStoresUpdate = gUI.once("store-objects-updated");
  table.scrollTop += cellHeight * 50;
  yield onStoresUpdate;
}