Container locking - simplified test code

This commit is contained in:
Francis McKenzie 2019-12-30 22:16:34 +01:00
parent 0bf47ad806
commit 6f55671f8f
2 changed files with 15 additions and 23 deletions

View file

@ -370,6 +370,16 @@ const Logic = {
value
});
},
lockOrUnlockContainer(userContextId, isLocked) {
return browser.runtime.sendMessage({
method: "lockOrUnlockContainer",
message: {
userContextId: userContextId,
isLocked: !!isLocked
}
});
},
generateIdentityName() {
const defaultName = "Container #";
@ -1041,16 +1051,10 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
Logic.addEnterHandler(lockElement, async () => {
try {
await browser.runtime.sendMessage({
method: "lockOrUnlockContainer",
message: {
userContextId: Logic.currentUserContextId(),
isLocked: !isLocked
}
});
await Logic.lockOrUnlockContainer(Logic.currentUserContextId(), !isLocked);
this.showAssignedContainers(assignments, !isLocked);
} catch (e) {
throw new Error("Failed to lock/unlock. ", e.message);
throw new Error("Failed to lock/unlock container: " + e.message);
}
});
/* Container locking end */

View file

@ -53,21 +53,9 @@ module.exports = {
// https://github.com/mozilla/multi-account-containers/issues/847
async setContainerIsLocked(cookieStoreId, isLocked) {
const identityStateKey = this.getIdentityStateContainerStoreKey(cookieStoreId);
const identityState = await background.browser.storage.local.get([identityStateKey]) || {};
if (isLocked) {
identityState.isLocked = "locked";
} else {
delete identityState.isLocked;
}
// Must have valid 'hiddenTabs', otherwise backgroundLogic.showTabs() throws error
if (!identityState.hiddenTabs) { identityState.hiddenTabs = []; }
await background.browser.storage.local.set({[identityStateKey]: identityState});
},
getIdentityStateContainerStoreKey(cookieStoreId) {
const storagePrefix = "identitiesState@@_";
return `${storagePrefix}${cookieStoreId}`;
const Logic = popup.dom.window.eval("Logic");
const userContextId = Logic.userContextId(cookieStoreId);
await Logic.lockOrUnlockContainer(userContextId, isLocked);
}
}
};