Skip to content

Commit

Permalink
fix: Added missing chrome privacy api settings (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manvel authored and Rob--W committed Nov 21, 2019
1 parent b8e374a commit 87bdfa8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/browser-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions test/test-proxied-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});
});

0 comments on commit 87bdfa8

Please sign in to comment.