fix: Added missing chrome privacy api settings (#205)

This commit is contained in:
Manvel Saroyan 2019-11-21 15:21:06 +01:00 committed by Rob Wu
parent b8e374a37a
commit 87bdfa844d
2 changed files with 38 additions and 11 deletions

View File

@ -259,6 +259,9 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object.
// of. Create a sub-object wrapper for it with the appropriate child
// metadata.
value = wrapObject(value, wrappers[prop], metadata[prop]);
} else if (hasOwnProperty(metadata, "*")) {
// Wrap all properties in * namespace.
value = wrapObject(value, wrappers[prop], metadata["*"]);
} else {
// We don't need to do any wrapping for this property,
// so just forward all access to the underlying object.
@ -492,17 +495,9 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object.
set: {minArgs: 1, maxArgs: 1},
};
apiMetadata.privacy = {
network: {
networkPredictionEnabled: settingMetadata,
webRTCIPHandlingPolicy: settingMetadata,
},
services: {
passwordSavingEnabled: settingMetadata,
},
websites: {
hyperlinkAuditingEnabled: settingMetadata,
referrersEnabled: settingMetadata,
},
network: {"*": settingMetadata},
services: {"*": settingMetadata},
websites: {"*": settingMetadata},
};
return wrapObject(extensionAPIs, staticWrappers, apiMetadata);

View File

@ -181,4 +181,36 @@ describe("browser-polyfill", () => {
});
});
});
describe("Privacy API", () => {
it("Should wrap chrome.privacy.* API", () => {
let lazyInitCount = 0;
const fakeChrome = {
privacy: {
get network() {
++lazyInitCount;
const networkPredictionEnabled = {
get: () => {},
set: () => {},
clear: () => {},
};
return {networkPredictionEnabled};
},
},
};
return setupTestDOMWindow(fakeChrome).then(window => {
equal(lazyInitCount, 0, "chrome.privacy.network is not accessed first");
const {get, set, clear} = window.browser.privacy.network.networkPredictionEnabled;
equal(get({}).then !== undefined, true, "Privacy API get method is a Promise");
equal(set({}).then !== undefined, true, "Privacy API set method is a Promise");
equal(clear({}).then !== undefined, true, "Privacy API clear method is a Promise");
equal(lazyInitCount, 1, "chrome.privacy.network should be accessed only once");
window.browser.privacy.network.networkPredictionEnabled.get({});
equal(lazyInitCount, 1, "chrome.privacy.network should be accessed only once");
});
});
});
});