-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[M111][Privacy Sandbox] Support compatibility privacySandboxEnabled API
The existing privacySandboxEnabled Chrome Extension API is being depreciated in favour of three new k-APIs - topicsEnabled, fledgeEnabled and adMeasurementEnabled in M111. This CL enables the existing privacySandboxEnabled API to be respected and compatible with the new k-APIs during the migration period. If an extension has disabled the privacySandboxEnabled API, then the new k-APIs must also be disabled. If an extension clears the privacySandboxEnabled API, then the new k-APIs are also cleared. See a screen recording of an extension disabling the privacySandbox API: http://dr/file/d/1MoLhOVmmh4bqW18lkdDctQRmsTo-Hjdy/view Test extension for Privacy Sandbox Extension APIs used: http://dr/file/d/1Wlk3TzECpU7j_23H9UUZxUdSY2UDTMQc/view Experiment #privacy-sandbox-settings-4 was enabled. (cherry picked from commit 5fc51e7) Bug: 1378703, b/254414152 Change-Id: Id5e711149e85ceb84217e2b59d6b2ebaffef8997 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4133664 Commit-Queue: Filipa Senra <fsenra@google.com> Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1097899} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4202368 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/branch-heads/5563@{#44} Cr-Branched-From: 3ac59a6-refs/heads/main@{#1097615}
- Loading branch information
Filipa Senra
authored and
Chromium LUCI CQ
committed
Jan 31, 2023
1 parent
e8eea85
commit cfa336a
Showing
6 changed files
with
330 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
chrome/test/data/extensions/api_test/preference/privacy_sandbox_migration/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name" : "Preferences API Test Extension for Privacy Sandbox Migration", | ||
"version" : "0.1", | ||
"manifest_version": 2, | ||
"description" : "Preferences API Test Extension for Privacy Sandbox Migration", | ||
"permissions": [ "privacy" ], | ||
"background": { | ||
"scripts": ["test.js"], | ||
"persistent": false | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
chrome/test/data/extensions/api_test/preference/privacy_sandbox_migration/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Privacy Sandbox Migration API test | ||
// Run with browser_tests | ||
// --gtest_filter=ExtensionPreferenceApiTest.PrivacySandboxMigration | ||
|
||
var privacyWebsitesNamespace = chrome.privacy.websites; | ||
|
||
function expect(expected, message) { | ||
return chrome.test.callbackPass(function(value) { | ||
chrome.test.assertEq(expected, value, message); | ||
}); | ||
} | ||
|
||
// Verifies that the preference has the expected default value. | ||
function expectDefault(prefName, defaultValue) { | ||
return expect( | ||
{value: defaultValue, levelOfControl: 'controllable_by_this_extension'}, | ||
'`' + prefName + '` is expected to be the default, which is ' + | ||
defaultValue); | ||
} | ||
|
||
// Verifies that the preference is properly controlled by the extension. | ||
function expectControlled(prefName, newValue) { | ||
return expect( | ||
{ | ||
value: newValue, | ||
levelOfControl: 'controlled_by_this_extension', | ||
}, | ||
'`' + prefName + '` is expected to be controlled by this extension'); | ||
} | ||
|
||
function setToFalsePref() { | ||
chrome.test.getConfig(function(config) { | ||
chrome.test.runTests([ | ||
// Setting the deprecated pref to false |kPrivacySandboxApisEnabled| | ||
// should also set to false the new Privacy Sandbox APIs in order to | ||
// maintain backward compatibility during the migration period. | ||
function testSetToFalsePrivacyGuideEnabled() { | ||
privacyWebsitesNamespace.privacySandboxEnabled.set( | ||
{value: false}, function() { | ||
privacyWebsitesNamespace.topicsEnabled.get( | ||
{}, expectControlled('topicsEnabled', false)); | ||
privacyWebsitesNamespace.fledgeEnabled.get( | ||
{}, expectControlled('fledgeEnabled', false)); | ||
privacyWebsitesNamespace.adMeasurementEnabled.get( | ||
{}, expectControlled('adMeasurementEnabled', false)); | ||
}); | ||
}, | ||
]) | ||
}) | ||
} | ||
|
||
function setToTruePref() { | ||
chrome.test.getConfig(function(config) { | ||
chrome.test.runTests([ | ||
// Setting the deprecated pref to true |kPrivacySandboxApisEnabled| | ||
// should clear the new Privacy Sandbox APIs in order to | ||
// maintain backward compatibility during the migration period. | ||
function testSetToTruePrivacyGuideEnabled() { | ||
privacyWebsitesNamespace.privacySandboxEnabled.set( | ||
{value: true}, function() { | ||
privacyWebsitesNamespace.topicsEnabled.get( | ||
{}, expectDefault('topicsEnabled', true)); | ||
privacyWebsitesNamespace.fledgeEnabled.get( | ||
{}, expectDefault('fledgeEnabled', true)); | ||
privacyWebsitesNamespace.adMeasurementEnabled.get( | ||
{}, expectDefault('adMeasurementEnabled', true)); | ||
}); | ||
}, | ||
]) | ||
}) | ||
} | ||
|
||
function clearPref() { | ||
chrome.test.getConfig(function(config) { | ||
chrome.test.runTests([ | ||
// Clearing the deprecated pref|kPrivacySandboxApisEnabled| | ||
// should also clear the new k-APIs in order to maintain backward | ||
// compatibility during the migration period. | ||
function testClearPrivacyGuideEnabled() { | ||
privacyWebsitesNamespace.privacySandboxEnabled.clear({}, function() { | ||
privacyWebsitesNamespace.topicsEnabled.get( | ||
{}, expectDefault('topicsEnabled', true)); | ||
privacyWebsitesNamespace.fledgeEnabled.get( | ||
{}, expectDefault('fledgeEnabled', true)); | ||
privacyWebsitesNamespace.adMeasurementEnabled.get( | ||
{}, expectDefault('adMeasurementEnabled', true)); | ||
}); | ||
}, | ||
]) | ||
}) | ||
} | ||
|
||
chrome.test.sendMessage('ready', function(message) { | ||
if (message == 'run set to false test') { | ||
setToFalsePref(); | ||
} else if (message == 'run set to true test') { | ||
setToTruePref(); | ||
} else if (message == 'run clear test') { | ||
clearPref(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters