зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1561584 - storage.StorageChange object has no oldValue when transitioning from a falsey value r=rpl
Differential Revision: https://phabricator.services.mozilla.com/D53012 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
2c486a628d
Коммит
55defdbcde
|
@ -1271,7 +1271,7 @@ class ExtensionStorageSync {
|
|||
changes[key] = {
|
||||
newValue: item,
|
||||
};
|
||||
if (oldRecord && oldRecord.data) {
|
||||
if (oldRecord) {
|
||||
// Extract the "data" field from the old record, which
|
||||
// represents the value part of the key-value store
|
||||
changes[key].oldValue = oldRecord.data;
|
||||
|
|
|
@ -292,6 +292,58 @@ async function test_background_page_storage(testAreaName) {
|
|||
clearGlobalChanges();
|
||||
}
|
||||
|
||||
async function testFalseyValues(areaName) {
|
||||
let storage = browser.storage[areaName];
|
||||
const dataInitial = {
|
||||
"test-falsey-value-bool": false,
|
||||
"test-falsey-value-string": "",
|
||||
"test-falsey-value-number": 0,
|
||||
};
|
||||
const dataUpdate = {
|
||||
"test-falsey-value-bool": true,
|
||||
"test-falsey-value-string": "non-empty-string",
|
||||
"test-falsey-value-number": 10,
|
||||
};
|
||||
|
||||
// Compute the expected changes.
|
||||
const onSetInitial = {
|
||||
"test-falsey-value-bool": { newValue: false },
|
||||
"test-falsey-value-string": { newValue: "" },
|
||||
"test-falsey-value-number": { newValue: 0 },
|
||||
};
|
||||
const onRemovedFalsey = {
|
||||
"test-falsey-value-bool": { oldValue: false },
|
||||
"test-falsey-value-string": { oldValue: "" },
|
||||
"test-falsey-value-number": { oldValue: 0 },
|
||||
};
|
||||
const onUpdatedFalsey = {
|
||||
"test-falsey-value-bool": { newValue: true, oldValue: false },
|
||||
"test-falsey-value-string": {
|
||||
newValue: "non-empty-string",
|
||||
oldValue: "",
|
||||
},
|
||||
"test-falsey-value-number": { newValue: 10, oldValue: 0 },
|
||||
};
|
||||
const keys = Object.keys(dataInitial);
|
||||
|
||||
// Test on removing falsey values.
|
||||
await storage.set(dataInitial);
|
||||
await checkChanges(areaName, onSetInitial, "set falsey values");
|
||||
await storage.remove(keys);
|
||||
await checkChanges(areaName, onRemovedFalsey, "remove falsey value");
|
||||
|
||||
// Test on updating falsey values.
|
||||
await storage.set(dataInitial);
|
||||
await checkChanges(areaName, onSetInitial, "set falsey values");
|
||||
await storage.set(dataUpdate);
|
||||
await checkChanges(areaName, onUpdatedFalsey, "set non-falsey values");
|
||||
|
||||
// Clear the storage state.
|
||||
await storage.clear();
|
||||
await globalChanges;
|
||||
clearGlobalChanges();
|
||||
}
|
||||
|
||||
/* eslint-disable dot-notation */
|
||||
async function runTests(areaName) {
|
||||
expectedAreaName = areaName;
|
||||
|
@ -398,36 +450,7 @@ async function test_background_page_storage(testAreaName) {
|
|||
"prop2 absent (remove array)"
|
||||
);
|
||||
|
||||
// Test that removing a falsey value fires the onChanged event.
|
||||
await storage.set({
|
||||
"test-falsey-value-bool": false,
|
||||
"test-falsey-value-string": "",
|
||||
"test-falsey-value-number": 0,
|
||||
});
|
||||
await checkChanges(
|
||||
areaName,
|
||||
{
|
||||
"test-falsey-value-bool": { newValue: false },
|
||||
"test-falsey-value-string": { newValue: "" },
|
||||
"test-falsey-value-number": { newValue: 0 },
|
||||
},
|
||||
"set falsey values"
|
||||
);
|
||||
|
||||
await storage.remove([
|
||||
"test-falsey-value-bool",
|
||||
"test-falsey-value-string",
|
||||
"test-falsey-value-number",
|
||||
]);
|
||||
await checkChanges(
|
||||
areaName,
|
||||
{
|
||||
"test-falsey-value-bool": { oldValue: false },
|
||||
"test-falsey-value-string": { oldValue: "" },
|
||||
"test-falsey-value-number": { oldValue: 0 },
|
||||
},
|
||||
"remove falsey value"
|
||||
);
|
||||
await testFalseyValues(areaName);
|
||||
|
||||
// test storage.clear
|
||||
await storage.set({ "test-prop1": "value1", "test-prop2": "value2" });
|
||||
|
|
Загрузка…
Ссылка в новой задаче