diff --git a/src/browser-polyfill.js b/src/browser-polyfill.js index 03d35d1..a081edd 100644 --- a/src/browser-polyfill.js +++ b/src/browser-polyfill.js @@ -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); diff --git a/test/test-proxied-properties.js b/test/test-proxied-properties.js index 2834508..7133a8f 100644 --- a/test/test-proxied-properties.js +++ b/test/test-proxied-properties.js @@ -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"); + }); + }); + }); });