diff options
Diffstat (limited to 'devtools/client/storage/test/browser_storage_dynamic_updates_localStorage.js')
-rw-r--r-- | devtools/client/storage/test/browser_storage_dynamic_updates_localStorage.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/devtools/client/storage/test/browser_storage_dynamic_updates_localStorage.js b/devtools/client/storage/test/browser_storage_dynamic_updates_localStorage.js new file mode 100644 index 0000000000..f220d16b0c --- /dev/null +++ b/devtools/client/storage/test/browser_storage_dynamic_updates_localStorage.js @@ -0,0 +1,70 @@ +/* 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 dynamic updates in the storage inspector for localStorage. + +add_task(async function () { + const TEST_HOST = "https://test1.example.org"; + + await openTabAndSetupStorage(MAIN_DOMAIN_SECURED + "storage-updates.html"); + + gUI.tree.expandAll(); + + ok(gUI.sidebar.hidden, "Sidebar is initially hidden"); + + const expectedKeys = ["1", "2", "3", "4", "5", "null", "non-json-parsable"]; + + // Test on string keys that JSON.parse can parse without throwing + // (to verify the issue fixed by Bug 1578447 doesn't regress). + await testRemoveAndChange("null", expectedKeys, TEST_HOST); + await testRemoveAndChange("4", expectedKeys, TEST_HOST); + // Test on a string that makes JSON.parse to throw. + await testRemoveAndChange("non-json-parsable", expectedKeys, TEST_HOST); + + // Clearing items. + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { + content.wrappedJSObject.clear(); + }); + + await gUI.once("store-objects-cleared"); + + await checkState([[["localStorage", TEST_HOST], []]]); +}); + +async function testRemoveAndChange(targetKey, expectedKeys, host) { + await checkState([[["localStorage", host], expectedKeys]]); + + await removeLocalStorageItem(targetKey); + await gUI.once("store-objects-edit"); + await checkState([ + [["localStorage", host], expectedKeys.filter(key => key !== targetKey)], + ]); + + await setLocalStorageItem(targetKey, "again"); + await gUI.once("store-objects-edit"); + await checkState([[["localStorage", host], expectedKeys]]); + + // Updating a row set to the string "null" + await setLocalStorageItem(targetKey, `key-${targetKey}-changed`); + await gUI.once("store-objects-edit"); + checkCell(targetKey, "value", `key-${targetKey}-changed`); +} + +async function setLocalStorageItem(key, value) { + await SpecialPowers.spawn( + gBrowser.selectedBrowser, + [[key, value]], + ([innerKey, innerValue]) => { + content.wrappedJSObject.localStorage.setItem(innerKey, innerValue); + } + ); +} + +async function removeLocalStorageItem(key) { + await SpecialPowers.spawn(gBrowser.selectedBrowser, [key], innerKey => { + content.wrappedJSObject.localStorage.removeItem(innerKey); + }); +} |