summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_cookies_sort.js
blob: 7ed0feb0adc9245c5d168dd77b4f35b39e4f8ef5 (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
60
61
62
63
64
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Test column sorting works and sorts dates correctly (including "session"
// cookies).

"use strict";

add_task(async function () {
  const TEST_URL = MAIN_DOMAIN + "storage-cookies-sort.html";
  await openTabAndSetupStorage(TEST_URL);
  showAllColumns(true);

  info("Sort on the expires column, ascending order");
  clickColumnHeader("expires");

  // Note that here we only specify `test_session` for `test_session1` and
  // `test_session2`. Since we sort on the "expires" column, there is no point
  // in asserting the order between those 2 items.
  checkCells([
    "test_session",
    "test_session",
    "test_hour",
    "test_day",
    "test_year",
  ]);

  info("Sort on the expires column, descending order");
  clickColumnHeader("expires");

  // Again, only assert `test_session` for `test_session1` and `test_session2`.
  checkCells([
    "test_year",
    "test_day",
    "test_hour",
    "test_session",
    "test_session",
  ]);

  info("Sort on the name column, ascending order");
  clickColumnHeader("name");
  checkCells([
    "test_day",
    "test_hour",
    "test_session1",
    "test_session2",
    "test_year",
  ]);
});

function checkCells(expected) {
  const cells = [
    ...gPanelWindow.document.querySelectorAll("#name .table-widget-cell"),
  ];
  cells.forEach(function (cell, i) {
    // We use startsWith in order to avoid asserting the relative order of
    // "session" cookies when sorting on the "expires" column.
    ok(
      cell.value.startsWith(expected[i]),
      `Cell value starts with "${expected[i]}".`
    );
  });
}