mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 06:15:43 +00:00
Bug 1457071 - allow all extension-storage data to be deleted from the profile. r=glasserc
MozReview-Commit-ID: Dnb2kdcz1CH --HG-- extra : rebase_source : be65881f76e0fb004d718cbb6f841c44beeebe26
This commit is contained in:
parent
c1cfd9fede
commit
cc7fecadc3
@ -51,6 +51,11 @@ ExtensionStorageEngine.prototype = {
|
|||||||
}
|
}
|
||||||
return Svc.Prefs.get("engine.addons", false);
|
return Svc.Prefs.get("engine.addons", false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_wipeClient() {
|
||||||
|
return extensionStorageSync.clearAll();
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function ExtensionStorageTracker(name, engine) {
|
function ExtensionStorageTracker(name, engine) {
|
||||||
|
@ -48,6 +48,17 @@ add_task(async function test_calling_sync_calls__sync() {
|
|||||||
equal(syncMock.calls.length, 1);
|
equal(syncMock.calls.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_task(async function test_calling_wipeClient_calls_clearAll() {
|
||||||
|
let oldClearAll = extensionStorageSync.clearAll;
|
||||||
|
let clearMock = extensionStorageSync.clearAll = mock({returns: Promise.resolve()});
|
||||||
|
try {
|
||||||
|
await engine.wipeClient();
|
||||||
|
} finally {
|
||||||
|
extensionStorageSync.clearAll = oldClearAll;
|
||||||
|
}
|
||||||
|
equal(clearMock.calls.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
add_task(async function test_calling_sync_calls_ext_storage_sync() {
|
add_task(async function test_calling_sync_calls_ext_storage_sync() {
|
||||||
const extension = {id: "my-extension"};
|
const extension = {id: "my-extension"};
|
||||||
let oldSync = extensionStorageSync.syncAll;
|
let oldSync = extensionStorageSync.syncAll;
|
||||||
|
@ -1163,6 +1163,25 @@ class ExtensionStorageSync {
|
|||||||
histogram.add(extension.id, keys.length);
|
histogram.add(extension.id, keys.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Wipe local data for all collections without causing the changes to be synced */
|
||||||
|
async clearAll() {
|
||||||
|
const extensions = extensionContexts.keys();
|
||||||
|
const extIds = Array.from(extensions, extension => extension.id);
|
||||||
|
log.debug(`Clearing extension data for ${JSON.stringify(extIds)}`);
|
||||||
|
if (extIds.length) {
|
||||||
|
const promises = Array.from(extensionContexts.keys(), extension => {
|
||||||
|
return openCollection(this.cryptoCollection, extension).then(coll => {
|
||||||
|
return coll.clear();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await Promise.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
// and clear the crypto collection.
|
||||||
|
const cc = await this.cryptoCollection.getCollection();
|
||||||
|
await cc.clear();
|
||||||
|
}
|
||||||
|
|
||||||
async clear(extension, context) {
|
async clear(extension, context) {
|
||||||
// We can't call Collection#clear here, because that just clears
|
// We can't call Collection#clear here, because that just clears
|
||||||
// the local database. We have to explicitly delete everything so
|
// the local database. We have to explicitly delete everything so
|
||||||
|
@ -576,6 +576,39 @@ add_task(async function test_extension_id_to_collection_id() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_task(async function ensureCanSync_clearAll() {
|
||||||
|
const extensionId = uuid();
|
||||||
|
const extension = {id: extensionId};
|
||||||
|
|
||||||
|
await withContextAndServer(async function(context, server) {
|
||||||
|
await withSignedInUser(loggedInUser, async function(extensionStorageSync, fxaService) {
|
||||||
|
server.installCollection("storage-sync-crypto");
|
||||||
|
server.etag = 1000;
|
||||||
|
|
||||||
|
let newKeys = await extensionStorageSync.ensureCanSync([extensionId]);
|
||||||
|
ok(newKeys.hasKeysFor([extensionId]), `key isn't present for ${extensionId}`);
|
||||||
|
|
||||||
|
let posts = server.getPosts();
|
||||||
|
equal(posts.length, 1);
|
||||||
|
const post = posts[0];
|
||||||
|
assertPostedNewRecord(post);
|
||||||
|
|
||||||
|
// Set data for an extension and sync.
|
||||||
|
await extensionStorageSync.set(extension, {"my-key": 5}, context);
|
||||||
|
let keyValue = await extensionStorageSync.get(extension, ["my-key"], context);
|
||||||
|
equal(keyValue["my-key"], 5, "should get back the data we set");
|
||||||
|
|
||||||
|
// clear everything.
|
||||||
|
await extensionStorageSync.clearAll();
|
||||||
|
|
||||||
|
keyValue = await extensionStorageSync.get(extension, ["my-key"], context);
|
||||||
|
deepEqual(keyValue, {}, "should have lost the data");
|
||||||
|
// should have been no posts caused by the clear.
|
||||||
|
equal(posts.length, 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
add_task(async function ensureCanSync_posts_new_keys() {
|
add_task(async function ensureCanSync_posts_new_keys() {
|
||||||
const extensionId = uuid();
|
const extensionId = uuid();
|
||||||
await withContextAndServer(async function(context, server) {
|
await withContextAndServer(async function(context, server) {
|
||||||
|
Loading…
Reference in New Issue
Block a user