Skip to content

Commit

Permalink
Add support for Protected Audience k-anonymity automation
Browse files Browse the repository at this point in the history
Adds support for Protected Audience k-anonymity automation based on
the Webdriver extension in
WICG/turtledove#1382
  • Loading branch information
brusshamilton committed Jan 15, 2025
1 parent 593b7d4 commit 4ec2c95
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
23 changes: 23 additions & 0 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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");
}
};
})();
14 changes: 13 additions & 1 deletion tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -550,4 +561,5 @@ def __call__(self, payload):
RunBounceTrackingMitigationsAction,
CreateVirtualPressureSourceAction,
UpdateVirtualPressureSourceAction,
RemoveVirtualPressureSourceAction]
RemoveVirtualPressureSourceAction,
SetProtectedAudienceKAnonymityAction]
11 changes: 10 additions & 1 deletion tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DevicePostureProtocolPart,
StorageProtocolPart,
VirtualPressureSourceProtocolPart,
ProtectedAudienceProtocolPart,
merge_dicts)

from typing import List, Optional, Tuple
Expand Down Expand Up @@ -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
Expand All @@ -693,7 +701,8 @@ class WebDriverProtocol(Protocol):
WebDriverVirtualSensorPart,
WebDriverDevicePostureProtocolPart,
WebDriverStorageProtocolPart,
WebDriverVirtualPressureSourceProtocolPart]
WebDriverVirtualPressureSourceProtocolPart,
WebDriverProtectedAudienceProtocolPart]

def __init__(self, executor, browser, capabilities, **kwargs):
super().__init__(executor, browser)
Expand Down
10 changes: 10 additions & 0 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
})();

0 comments on commit 4ec2c95

Please sign in to comment.