summaryrefslogtreecommitdiffstats
path: root/browser/components/preferences/tests/siteData/browser_siteData_multi_select.js
blob: 5ce9d7e1e12cd3a6db277e3ea105cc3cf21dc823 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"use strict";

// Test selecting and removing partial sites
add_task(async function () {
  await SiteDataTestUtils.clear();

  let hosts = await addTestData([
    {
      usage: 1024,
      origin: "https://127.0.0.1",
      persisted: false,
    },
    {
      usage: 1024 * 4,
      origin: "http://cinema.bar.com",
      persisted: true,
    },
    {
      usage: 1024 * 3,
      origin: "http://email.bar.com",
      persisted: false,
    },
    {
      usage: 1024 * 2,
      origin: "https://s3-us-west-2.amazonaws.com",
      persisted: true,
    },
    {
      usage: 1024 * 6,
      origin: "https://account.xyz.com",
      persisted: true,
    },
    {
      usage: 1024 * 5,
      origin: "https://shopping.xyz.com",
      persisted: false,
    },
    {
      usage: 1024 * 5,
      origin: "https://example.com",
      persisted: false,
    },
    {
      usage: 1024 * 5,
      origin: "https://example.net",
      persisted: false,
    },
  ]);

  // Align the order of test hosts with the order of the site data table.
  hosts.sort();

  let updatePromise = promiseSiteDataManagerSitesUpdated();
  await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
  await updatePromise;
  await openSiteDataSettingsDialog();

  let doc = gBrowser.selectedBrowser.contentDocument;

  // Test the initial state
  assertSitesListed(doc, hosts);
  let win = gBrowser.selectedBrowser.contentWindow;
  let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
  let removeBtn = frameDoc.getElementById("removeSelected");
  is(
    removeBtn.disabled,
    true,
    "Should start with disabled removeSelected button"
  );

  let hostCol = frameDoc.getElementById("hostCol");
  hostCol.click();

  let removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen(
    "accept",
    REMOVE_DIALOG_URL
  );
  let settingsDialogClosePromise = promiseSettingsDialogClose();

  // Select some sites to remove.
  let sitesList = frameDoc.getElementById("sitesList");
  hosts.slice(0, 2).forEach(host => {
    let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
    sitesList.addItemToSelection(site);
  });

  is(removeBtn.disabled, false, "Should enable the removeSelected button");
  removeBtn.doCommand();
  is(sitesList.selectedIndex, 0, "Should select next item");
  assertSitesListed(doc, hosts.slice(2));

  // Select some other sites to remove with Delete.
  hosts.slice(2, 4).forEach(host => {
    let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
    sitesList.addItemToSelection(site);
  });

  is(removeBtn.disabled, false, "Should enable the removeSelected button");
  // Move the focus from the search box to the list
  sitesList.focus();
  EventUtils.synthesizeKey("VK_DELETE");
  is(sitesList.selectedIndex, 0, "Should select next item");
  assertSitesListed(doc, hosts.slice(4));

  updatePromise = promiseSiteDataManagerSitesUpdated();
  let saveBtn = frameDoc.querySelector("dialog").getButton("accept");
  saveBtn.doCommand();

  await removeDialogOpenPromise;
  await settingsDialogClosePromise;

  await updatePromise;
  await openSiteDataSettingsDialog();

  assertSitesListed(doc, hosts.slice(4));

  await SiteDataTestUtils.clear();
  BrowserTestUtils.removeTab(gBrowser.selectedTab);
});