summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_cookies_delete_all.js
blob: a637b8a4ab62c95c90b870eb2429c4bab061f780 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* 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/. */

"use strict";

// Test deleting all cookies

async function performDelete(store, rowName, action) {
  const contextMenu = gPanelWindow.document.getElementById(
    "storage-table-popup"
  );
  const menuDeleteAllItem = contextMenu.querySelector(
    "#storage-table-popup-delete-all"
  );
  const menuDeleteAllSessionCookiesItem = contextMenu.querySelector(
    "#storage-table-popup-delete-all-session-cookies"
  );
  const menuDeleteAllFromItem = contextMenu.querySelector(
    "#storage-table-popup-delete-all-from"
  );

  const storeName = store.join(" > ");

  await selectTreeItem(store);

  const eventWait = gUI.once("store-objects-edit");
  const cells = getRowCells(rowName, true);

  await waitForContextMenu(contextMenu, cells.name, () => {
    info(`Opened context menu in ${storeName}, row '${rowName}'`);
    switch (action) {
      case "deleteAll":
        menuDeleteAllItem.click();
        break;
      case "deleteAllSessionCookies":
        menuDeleteAllSessionCookiesItem.click();
        break;
      case "deleteAllFrom":
        menuDeleteAllFromItem.click();
        const hostName = cells.host.value;
        ok(
          menuDeleteAllFromItem.getAttribute("label").includes(hostName),
          `Context menu item label contains '${hostName}'`
        );
        break;
    }
  });

  await eventWait;
}

add_task(async function () {
  // storage-listings.html explicitly mixes secure and insecure frames.
  // We should not enforce https for tests using this page.
  await pushPref("dom.security.https_first", false);

  await openTabAndSetupStorage(MAIN_DOMAIN + "storage-listings.html");

  info("test state before delete");
  await checkState([
    [
      ["cookies", "http://test1.example.org"],
      [
        getCookieId("c1", "test1.example.org", "/browser"),
        getCookieId("c3", "test1.example.org", "/"),
        getCookieId("cs2", ".example.org", "/"),
        getCookieId("c4", ".example.org", "/"),
        getCookieId("uc1", ".example.org", "/"),
        getCookieId("uc2", ".example.org", "/"),
      ],
    ],
    [
      ["cookies", "https://sectest1.example.org"],
      [
        getCookieId("cs2", ".example.org", "/"),
        getCookieId("c4", ".example.org", "/"),
        getCookieId(
          "sc1",
          "sectest1.example.org",
          "/browser/devtools/client/storage/test"
        ),
        getCookieId(
          "sc2",
          "sectest1.example.org",
          "/browser/devtools/client/storage/test"
        ),
        getCookieId("uc1", ".example.org", "/"),
        getCookieId("uc2", ".example.org", "/"),
      ],
    ],
  ]);

  info("delete all from domain");
  // delete only cookies that match the host exactly
  let id = getCookieId("c1", "test1.example.org", "/browser");
  await performDelete(
    ["cookies", "http://test1.example.org"],
    id,
    "deleteAllFrom"
  );

  info("test state after delete all from domain");
  await checkState([
    // Domain cookies (.example.org) must not be deleted.
    [
      ["cookies", "http://test1.example.org"],
      [
        getCookieId("cs2", ".example.org", "/"),
        getCookieId("c4", ".example.org", "/"),
        getCookieId("uc1", ".example.org", "/"),
        getCookieId("uc2", ".example.org", "/"),
      ],
    ],
    [
      ["cookies", "https://sectest1.example.org"],
      [
        getCookieId("cs2", ".example.org", "/"),
        getCookieId("c4", ".example.org", "/"),
        getCookieId("uc1", ".example.org", "/"),
        getCookieId("uc2", ".example.org", "/"),
        getCookieId(
          "sc1",
          "sectest1.example.org",
          "/browser/devtools/client/storage/test"
        ),
        getCookieId(
          "sc2",
          "sectest1.example.org",
          "/browser/devtools/client/storage/test"
        ),
      ],
    ],
  ]);

  info("delete all session cookies");
  // delete only session cookies
  id = getCookieId("cs2", ".example.org", "/");
  await performDelete(
    ["cookies", "http://sectest1.example.org"],
    id,
    "deleteAllSessionCookies"
  );

  info("test state after delete all session cookies");
  await checkState([
    // Cookies with expiry date must not be deleted.
    [
      ["cookies", "http://test1.example.org"],
      [
        getCookieId("c4", ".example.org", "/"),
        getCookieId("uc2", ".example.org", "/"),
      ],
    ],
    [
      ["cookies", "https://sectest1.example.org"],
      [
        getCookieId("c4", ".example.org", "/"),
        getCookieId("uc2", ".example.org", "/"),
        getCookieId(
          "sc2",
          "sectest1.example.org",
          "/browser/devtools/client/storage/test"
        ),
      ],
    ],
  ]);

  info("delete all");
  // delete all cookies for host, including domain cookies
  id = getCookieId("uc2", ".example.org", "/");
  await performDelete(
    ["cookies", "http://sectest1.example.org"],
    id,
    "deleteAll"
  );

  info("test state after delete all");
  await checkState([
    // Domain cookies (.example.org) are deleted too, so deleting in sectest1
    // also removes stuff from test1.
    [["cookies", "http://test1.example.org"], []],
    [["cookies", "https://sectest1.example.org"], []],
  ]);
});