diff --git a/resources/testdriver.js b/resources/testdriver.js index aee319f57571d0..57f36478c35791 100644 --- a/resources/testdriver.js +++ b/resources/testdriver.js @@ -1326,6 +1326,25 @@ */ remove_virtual_pressure_source: function(source_type, context=null) { return window.test_driver_internal.remove_virtual_pressure_source(source_type, context); + }, + + /** + * Sets which hashes are considered k-anonymous for the Protected + * Audience interest group with specified `owner` and `name`. + * + * @param {String} owner - Origin of the owner of the interest group + * to modify + * @param {String} name - Name of the interest group to modify + * @param {Array} hashes - An array of strings, each of which is a + * base64 ecoded hash to consider k-anonymous. + * + * @returns {Promise} Fulfilled after the k-anonymity status for the + * specified Protected Audience interest group has + * been updated. + * + */ + set_protected_audience_k_anonymity: function(owner, name, hashes, context = null) { + return window.test_driver_internal.set_protected_audience_k_anonymity(owner, name, hashes, context); } }; @@ -1565,6 +1584,10 @@ async remove_virtual_pressure_source(source_type, context=null) { throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js"); + }, + + async set_protected_audience_k_anonymity(owner, name, hashes, context=null) { + throw new Error("set_protected_audience_k_anonymity() is not implemented by testdriver-vendor.js"); } }; })(); diff --git a/tools/wptrunner/wptrunner/executors/actions.py b/tools/wptrunner/wptrunner/executors/actions.py index 859ce8f4fa6044..86690cac2c8c70 100644 --- a/tools/wptrunner/wptrunner/executors/actions.py +++ b/tools/wptrunner/wptrunner/executors/actions.py @@ -511,6 +511,17 @@ def __call__(self, payload): source_type = payload["source_type"] return self.protocol.pressure.remove_virtual_pressure_source(source_type) +class SetProtectedAudienceKAnonymityAction: + name = "set_protected_audience_k_anonymity" + + def __init__(self, logger, protocol): + self.logger = logger + self.protocol = protocol + + def __call__(self, payload): + owner, name, hashes = payload["owner"], payload["name"], payload["hashes"] + return self.protocol.protected_audience.set_k_anonymity(owner, name, hashes) + actions = [ClickAction, DeleteAllCookiesAction, GetAllCookiesAction, @@ -550,4 +561,5 @@ def __call__(self, payload): RunBounceTrackingMitigationsAction, CreateVirtualPressureSourceAction, UpdateVirtualPressureSourceAction, - RemoveVirtualPressureSourceAction] + RemoveVirtualPressureSourceAction, + SetProtectedAudienceKAnonymityAction] diff --git a/tools/wptrunner/wptrunner/executors/executorwebdriver.py b/tools/wptrunner/wptrunner/executors/executorwebdriver.py index 7513887998d6cd..303eda8286deec 100644 --- a/tools/wptrunner/wptrunner/executors/executorwebdriver.py +++ b/tools/wptrunner/wptrunner/executors/executorwebdriver.py @@ -45,6 +45,7 @@ DevicePostureProtocolPart, StorageProtocolPart, VirtualPressureSourceProtocolPart, + ProtectedAudienceProtocolPart, merge_dicts) from typing import List, Optional, Tuple @@ -669,6 +670,13 @@ def update_virtual_pressure_source(self, source_type, sample): def remove_virtual_pressure_source(self, source_type): return self.webdriver.send_session_command("DELETE", "pressuresource/%s" % source_type) +class WebDriverProtectedAudienceProtocolPart(ProtectedAudienceProtocolPart): + def setup(self): + self.webdriver = self.parent.webdriver + + def set_k_anonymity(self, owner, name, hashes): + body = {"owner": owner, "name": name, "hashes": hashes} + return self.webdriver.send_session_command("POST", "protected_audience/set_k_anonymity", body) class WebDriverProtocol(Protocol): enable_bidi = False @@ -693,7 +701,8 @@ class WebDriverProtocol(Protocol): WebDriverVirtualSensorPart, WebDriverDevicePostureProtocolPart, WebDriverStorageProtocolPart, - WebDriverVirtualPressureSourceProtocolPart] + WebDriverVirtualPressureSourceProtocolPart, + WebDriverProtectedAudienceProtocolPart] def __init__(self, executor, browser, capabilities, **kwargs): super().__init__(executor, browser) diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index 19d5b49d2b7fb4..59fadb9c7edb71 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -982,3 +982,13 @@ def update_virtual_pressure_source(self, source_type, sample): @abstractmethod def remove_virtual_pressure_source(self, source_type): pass + +class ProtectedAudienceProtocolPart(ProtocolPart): + """Protocol part for Protected Audiences""" + __metaclass__ = ABCMeta + + name = "protected_audience" + + @abstractmethod + def set_k_anonymity(self, owner, name, hashes): + pass diff --git a/tools/wptrunner/wptrunner/testdriver-extra.js b/tools/wptrunner/wptrunner/testdriver-extra.js index 2dd9a70c829895..9beac84c0105c5 100644 --- a/tools/wptrunner/wptrunner/testdriver-extra.js +++ b/tools/wptrunner/wptrunner/testdriver-extra.js @@ -439,4 +439,10 @@ window.test_driver_internal.remove_virtual_pressure_source = function(source_type, context=null) { return create_context_action("remove_virtual_pressure_source", context, {source_type}); }; + + window.test_driver_internal.set_protected_audience_k_anonymity = function( + owner, name, hashes, context) { + return create_context_action( + 'set_protected_audience_k_anonymity', context, {owner, name, hashes}); + } })();