browser_storage_cookies_edit.js (2823B)
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 // Basic test to check the editing of cookies. 6 7 "use strict"; 8 9 add_task(async function () { 10 const { toolbox, storage } = await openTabAndSetupStorage( 11 MAIN_DOMAIN + "storage-cookies.html" 12 ); 13 const doc = storage.panelWindow.document; 14 showAllColumns(true); 15 16 let id = getCookieId("test3", ".test1.example.org", "/browser"); 17 await editCell(id, "name", "newTest3"); 18 19 id = getCookieId("newTest3", ".test1.example.org", "/browser"); 20 await editCell(id, "host", "test1.example.org"); 21 22 id = getCookieId("newTest3", "test1.example.org", "/browser"); 23 await editCell(id, "path", "/"); 24 25 const date = new Date(); 26 date.setDate(date.getDate() + 8); 27 28 id = getCookieId("newTest3", "test1.example.org", "/"); 29 await editCell(id, "expires", date.toGMTString()); 30 await editCell(id, "value", "newValue3"); 31 await editCell(id, "isSecure", "true"); 32 await editCell(id, "isHttpOnly", "true"); 33 34 info( 35 "Check that setting values that make the cookie invalid displays a warning" 36 ); 37 38 // Sanity check 39 is( 40 toolbox.doc.querySelector(".notificationbox"), 41 null, 42 "No warning is displayed after editing valid cookies" 43 ); 44 isnot( 45 getCellLabelElement(doc, "newTest3"), 46 null, 47 "The expected name cell exists" 48 ); 49 50 id = getCookieId("newTest3", "test1.example.org", "/"); 51 // Adding a space prefix does make the cookie invalid 52 const invalidCookieName = " thisIsInvalid"; 53 await editCell(id, "name", invalidCookieName, /* validate */ false); 54 55 const notificationBox = await waitFor(() => 56 toolbox.doc.querySelector(".notificationbox") 57 ); 58 59 const notificationEl = notificationBox.querySelector(".notification"); 60 is( 61 notificationEl.getAttribute("data-key"), 62 "storage-cookie-edit-error", 63 "Notification has expected key" 64 ); 65 is( 66 notificationEl.getAttribute("data-type"), 67 "warning", 68 "Notification is a warning" 69 ); 70 71 const message = notificationEl.textContent; 72 ok( 73 notificationEl.textContent.startsWith("Cookie could not be updated"), 74 `The warning message is rendered as expected (${message})` 75 ); 76 77 is( 78 getCellLabelElement(doc, invalidCookieName), 79 null, 80 "The invalid cookie isn't visible anymore" 81 ); 82 83 isnot( 84 getRowItem(getCookieId("newTest3", "test1.example.org", "/")), 85 null, 86 "The cookie row for the original cookie is displayed" 87 ); 88 isnot( 89 getCellLabelElement(doc, "newTest3"), 90 null, 91 "The original cookie name is visible" 92 ); 93 }); 94 95 function getCellLabelElement(doc, labelValue) { 96 return doc.querySelector( 97 `#name.table-widget-column .table-widget-cell[value="${labelValue}"]` 98 ); 99 }