browser_storage_cookies_delete_all.js (6346B)
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 "use strict"; 6 7 // Test deleting all cookies 8 9 async function performDelete(store, rowName, action) { 10 const contextMenu = gPanelWindow.document.getElementById( 11 "storage-table-popup" 12 ); 13 const menuDeleteAllItem = contextMenu.querySelector( 14 "#storage-table-popup-delete-all" 15 ); 16 const menuDeleteAllSessionCookiesItem = contextMenu.querySelector( 17 "#storage-table-popup-delete-all-session-cookies" 18 ); 19 const menuDeleteAllFromItem = contextMenu.querySelector( 20 "#storage-table-popup-delete-all-from" 21 ); 22 23 const storeName = store.join(" > "); 24 25 await selectTreeItem(store); 26 27 const eventWait = gUI.once("store-objects-edit"); 28 const cells = getRowCells(rowName, true); 29 30 await waitForContextMenu(contextMenu, cells.name, () => { 31 info(`Opened context menu in ${storeName}, row '${rowName}'`); 32 switch (action) { 33 case "deleteAll": 34 menuDeleteAllItem.click(); 35 break; 36 case "deleteAllSessionCookies": 37 menuDeleteAllSessionCookiesItem.click(); 38 break; 39 case "deleteAllFrom": { 40 menuDeleteAllFromItem.click(); 41 const hostName = cells.host.value; 42 ok( 43 menuDeleteAllFromItem.getAttribute("label").includes(hostName), 44 `Context menu item label contains '${hostName}'` 45 ); 46 break; 47 } 48 } 49 }); 50 51 await eventWait; 52 } 53 54 add_task(async function () { 55 // storage-listings.html explicitly mixes secure and insecure frames. 56 // We should not enforce https for tests using this page. 57 await pushPref("dom.security.https_first", false); 58 59 await openTabAndSetupStorage(MAIN_DOMAIN + "storage-listings.html"); 60 61 info("test state before delete"); 62 await checkState([ 63 [ 64 ["cookies", "http://test1.example.org"], 65 [ 66 getCookieId("c1", "test1.example.org", "/browser"), 67 getCookieId("c3", "test1.example.org", "/"), 68 getCookieId("cs2", ".example.org", "/"), 69 getCookieId("c4", ".example.org", "/"), 70 getCookieId("uc1", ".example.org", "/"), 71 getCookieId("uc2", ".example.org", "/"), 72 ], 73 ], 74 [ 75 ["cookies", "https://sectest1.example.org"], 76 [ 77 getCookieId("cs2", ".example.org", "/"), 78 getCookieId("c4", ".example.org", "/"), 79 getCookieId( 80 "sc1", 81 "sectest1.example.org", 82 "/browser/devtools/client/storage/test" 83 ), 84 getCookieId( 85 "sc2", 86 "sectest1.example.org", 87 "/browser/devtools/client/storage/test" 88 ), 89 getCookieId("uc1", ".example.org", "/"), 90 getCookieId("uc2", ".example.org", "/"), 91 ], 92 ], 93 ]); 94 95 info("delete all from domain"); 96 // delete only cookies that match the host exactly 97 let id = getCookieId("c1", "test1.example.org", "/browser"); 98 await performDelete( 99 ["cookies", "http://test1.example.org"], 100 id, 101 "deleteAllFrom" 102 ); 103 104 info("test state after delete all from domain"); 105 await checkState([ 106 // Domain cookies (.example.org) must not be deleted. 107 [ 108 ["cookies", "http://test1.example.org"], 109 [ 110 getCookieId("cs2", ".example.org", "/"), 111 getCookieId("c4", ".example.org", "/"), 112 getCookieId("uc1", ".example.org", "/"), 113 getCookieId("uc2", ".example.org", "/"), 114 ], 115 ], 116 [ 117 ["cookies", "https://sectest1.example.org"], 118 [ 119 getCookieId("cs2", ".example.org", "/"), 120 getCookieId("c4", ".example.org", "/"), 121 getCookieId("uc1", ".example.org", "/"), 122 getCookieId("uc2", ".example.org", "/"), 123 getCookieId( 124 "sc1", 125 "sectest1.example.org", 126 "/browser/devtools/client/storage/test" 127 ), 128 getCookieId( 129 "sc2", 130 "sectest1.example.org", 131 "/browser/devtools/client/storage/test" 132 ), 133 ], 134 ], 135 ]); 136 137 info("delete all session cookies"); 138 // delete only session cookies 139 id = getCookieId("cs2", ".example.org", "/"); 140 await performDelete( 141 ["cookies", "http://sectest1.example.org"], 142 id, 143 "deleteAllSessionCookies" 144 ); 145 146 info("test state after delete all session cookies"); 147 await checkState([ 148 // Cookies with expiry date must not be deleted. 149 [ 150 ["cookies", "http://test1.example.org"], 151 [ 152 getCookieId("c4", ".example.org", "/"), 153 getCookieId("uc2", ".example.org", "/"), 154 ], 155 ], 156 [ 157 ["cookies", "https://sectest1.example.org"], 158 [ 159 getCookieId("c4", ".example.org", "/"), 160 getCookieId("uc2", ".example.org", "/"), 161 getCookieId( 162 "sc2", 163 "sectest1.example.org", 164 "/browser/devtools/client/storage/test" 165 ), 166 ], 167 ], 168 ]); 169 170 info("delete all"); 171 // delete all cookies for host, including domain cookies 172 id = getCookieId("uc2", ".example.org", "/"); 173 await performDelete( 174 ["cookies", "http://sectest1.example.org"], 175 id, 176 "deleteAll" 177 ); 178 179 info("test state after delete all"); 180 await checkState([ 181 // Domain cookies (.example.org) are deleted too, so deleting in sectest1 182 // also removes stuff from test1. 183 [["cookies", "http://test1.example.org"], []], 184 [["cookies", "https://sectest1.example.org"], []], 185 ]); 186 }); 187 188 add_task(async function testDeleteWithDomain() { 189 // Test that cookies whose host starts with "." are properly deleted 190 await openTabAndSetupStorage(MAIN_DOMAIN + "storage-cookies.html"); 191 192 await checkState([ 193 [ 194 ["cookies", "http://test1.example.org"], 195 [ 196 getCookieId("test1", ".test1.example.org", "/browser"), 197 getCookieId("test2", "test1.example.org", "/browser"), 198 getCookieId("test3", ".test1.example.org", "/browser"), 199 getCookieId("test4", "test1.example.org", "/browser"), 200 getCookieId("test5", ".test1.example.org", "/browser"), 201 ], 202 ], 203 ]); 204 205 // delete all cookies for host, including domain cookies 206 const id = getCookieId("test1", ".test1.example.org", "/browser"); 207 await performDelete(["cookies", "http://test1.example.org"], id, "deleteAll"); 208 209 info("test state after delete all"); 210 await checkState([[["cookies", "http://test1.example.org"], []]]); 211 });