mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1481607 - Fix ExtensionStorageIDB storage.local.get when called with a string param. r=aswan
When the storage.local.get API method is called with a string parameter, it should return a result object that only include that property (if it is one of the key stored into the storage.local data backend). This patch fixes the behavior of the ExtensionStorageIDB in the above scenario, and also applies some related small changes to the tests (to add some additional assertion to verify this behavior as part of the automated tests and to fix a mistake on a storage.local.get call in one of the test case, which has been caught once fixed the storage.local.get behavior for the string parameter). Differential Revision: https://phabricator.services.mozilla.com/D2934 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
da9d4bb3c0
commit
cbd6a8ef9d
@ -251,7 +251,9 @@ class ExtensionStorageLocalIDB extends IndexedDB {
|
||||
let keys;
|
||||
let defaultValues;
|
||||
|
||||
if (Array.isArray(keysOrItems)) {
|
||||
if (typeof keysOrItems === "string") {
|
||||
keys = [keysOrItems];
|
||||
} else if (Array.isArray(keysOrItems)) {
|
||||
keys = keysOrItems;
|
||||
} else if (keysOrItems && typeof(keysOrItems) === "object") {
|
||||
keys = Object.keys(keysOrItems);
|
||||
|
@ -30,12 +30,18 @@ async function checkGetImpl(areaName, prop, value) {
|
||||
|
||||
data = await storage.get(prop);
|
||||
browser.test.assertEq(value, data[prop], `string getter worked for ${prop} in ${areaName}`);
|
||||
browser.test.assertEq(Object.keys(data).length, 1,
|
||||
`string getter should return an object with a single property`);
|
||||
|
||||
data = await storage.get([prop]);
|
||||
browser.test.assertEq(value, data[prop], `array getter worked for ${prop} in ${areaName}`);
|
||||
browser.test.assertEq(Object.keys(data).length, 1,
|
||||
`array getter with a single key should return an object with a single property`);
|
||||
|
||||
data = await storage.get({[prop]: undefined});
|
||||
browser.test.assertEq(value, data[prop], `object getter worked for ${prop} in ${areaName}`);
|
||||
browser.test.assertEq(Object.keys(data).length, 1,
|
||||
`object getter with a single key should return an object with a single property`);
|
||||
}
|
||||
|
||||
add_task(async function test_local_cache_invalidation() {
|
||||
|
@ -238,7 +238,7 @@ add_task(async function test_storage_local_should_not_cache_idb_open_rejections(
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await browser.storage.local.get("newvalue");
|
||||
const res = await browser.storage.local.get("newkey");
|
||||
browser.test.assertEq(expectedValue, res.newkey);
|
||||
browser.test.sendMessage("storage-local-get-resolved");
|
||||
} catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user