Skip to content

Commit 4ec2c95

Browse files
committed
Add support for Protected Audience k-anonymity automation
Adds support for Protected Audience k-anonymity automation based on the Webdriver extension in WICG/turtledove#1382
1 parent 593b7d4 commit 4ec2c95

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

resources/testdriver.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,25 @@
13261326
*/
13271327
remove_virtual_pressure_source: function(source_type, context=null) {
13281328
return window.test_driver_internal.remove_virtual_pressure_source(source_type, context);
1329+
},
1330+
1331+
/**
1332+
* Sets which hashes are considered k-anonymous for the Protected
1333+
* Audience interest group with specified `owner` and `name`.
1334+
*
1335+
* @param {String} owner - Origin of the owner of the interest group
1336+
* to modify
1337+
* @param {String} name - Name of the interest group to modify
1338+
* @param {Array} hashes - An array of strings, each of which is a
1339+
* base64 ecoded hash to consider k-anonymous.
1340+
*
1341+
* @returns {Promise} Fulfilled after the k-anonymity status for the
1342+
* specified Protected Audience interest group has
1343+
* been updated.
1344+
*
1345+
*/
1346+
set_protected_audience_k_anonymity: function(owner, name, hashes, context = null) {
1347+
return window.test_driver_internal.set_protected_audience_k_anonymity(owner, name, hashes, context);
13291348
}
13301349
};
13311350

@@ -1565,6 +1584,10 @@
15651584

15661585
async remove_virtual_pressure_source(source_type, context=null) {
15671586
throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js");
1587+
},
1588+
1589+
async set_protected_audience_k_anonymity(owner, name, hashes, context=null) {
1590+
throw new Error("set_protected_audience_k_anonymity() is not implemented by testdriver-vendor.js");
15681591
}
15691592
};
15701593
})();

tools/wptrunner/wptrunner/executors/actions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,17 @@ def __call__(self, payload):
511511
source_type = payload["source_type"]
512512
return self.protocol.pressure.remove_virtual_pressure_source(source_type)
513513

514+
class SetProtectedAudienceKAnonymityAction:
515+
name = "set_protected_audience_k_anonymity"
516+
517+
def __init__(self, logger, protocol):
518+
self.logger = logger
519+
self.protocol = protocol
520+
521+
def __call__(self, payload):
522+
owner, name, hashes = payload["owner"], payload["name"], payload["hashes"]
523+
return self.protocol.protected_audience.set_k_anonymity(owner, name, hashes)
524+
514525
actions = [ClickAction,
515526
DeleteAllCookiesAction,
516527
GetAllCookiesAction,
@@ -550,4 +561,5 @@ def __call__(self, payload):
550561
RunBounceTrackingMitigationsAction,
551562
CreateVirtualPressureSourceAction,
552563
UpdateVirtualPressureSourceAction,
553-
RemoveVirtualPressureSourceAction]
564+
RemoveVirtualPressureSourceAction,
565+
SetProtectedAudienceKAnonymityAction]

tools/wptrunner/wptrunner/executors/executorwebdriver.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
DevicePostureProtocolPart,
4646
StorageProtocolPart,
4747
VirtualPressureSourceProtocolPart,
48+
ProtectedAudienceProtocolPart,
4849
merge_dicts)
4950

5051
from typing import List, Optional, Tuple
@@ -669,6 +670,13 @@ def update_virtual_pressure_source(self, source_type, sample):
669670
def remove_virtual_pressure_source(self, source_type):
670671
return self.webdriver.send_session_command("DELETE", "pressuresource/%s" % source_type)
671672

673+
class WebDriverProtectedAudienceProtocolPart(ProtectedAudienceProtocolPart):
674+
def setup(self):
675+
self.webdriver = self.parent.webdriver
676+
677+
def set_k_anonymity(self, owner, name, hashes):
678+
body = {"owner": owner, "name": name, "hashes": hashes}
679+
return self.webdriver.send_session_command("POST", "protected_audience/set_k_anonymity", body)
672680

673681
class WebDriverProtocol(Protocol):
674682
enable_bidi = False
@@ -693,7 +701,8 @@ class WebDriverProtocol(Protocol):
693701
WebDriverVirtualSensorPart,
694702
WebDriverDevicePostureProtocolPart,
695703
WebDriverStorageProtocolPart,
696-
WebDriverVirtualPressureSourceProtocolPart]
704+
WebDriverVirtualPressureSourceProtocolPart,
705+
WebDriverProtectedAudienceProtocolPart]
697706

698707
def __init__(self, executor, browser, capabilities, **kwargs):
699708
super().__init__(executor, browser)

tools/wptrunner/wptrunner/executors/protocol.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,3 +982,13 @@ def update_virtual_pressure_source(self, source_type, sample):
982982
@abstractmethod
983983
def remove_virtual_pressure_source(self, source_type):
984984
pass
985+
986+
class ProtectedAudienceProtocolPart(ProtocolPart):
987+
"""Protocol part for Protected Audiences"""
988+
__metaclass__ = ABCMeta
989+
990+
name = "protected_audience"
991+
992+
@abstractmethod
993+
def set_k_anonymity(self, owner, name, hashes):
994+
pass

tools/wptrunner/wptrunner/testdriver-extra.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,10 @@
439439
window.test_driver_internal.remove_virtual_pressure_source = function(source_type, context=null) {
440440
return create_context_action("remove_virtual_pressure_source", context, {source_type});
441441
};
442+
443+
window.test_driver_internal.set_protected_audience_k_anonymity = function(
444+
owner, name, hashes, context) {
445+
return create_context_action(
446+
'set_protected_audience_k_anonymity', context, {owner, name, hashes});
447+
}
442448
})();

0 commit comments

Comments
 (0)