Skip to content

Commit 77f1c8a

Browse files
Add Testdriver extension for Global Privacy Control control
1 parent 77c563d commit 77f1c8a

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

docs/writing-tests/testdriver.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ the global scope.
192192
.. js:autofunction:: test_driver.clear_display_features
193193
```
194194

195+
### Global Privacy Control ###
196+
197+
```eval_rst
198+
.. js:autofunction:: test_driver.set_global_privacy_control
199+
.. js:autofunction:: test_driver.set_global_privacy_control
200+
```
201+
202+
195203
### Using test_driver in other browsing contexts ###
196204

197205
Testdriver can be used in browsing contexts (i.e. windows or frames)

resources/testdriver.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,32 @@
14071407
return window.test_driver_internal.set_permission(permission_params, context);
14081408
},
14091409

1410+
/**
1411+
* Gets the current globally-applied privacy control status
1412+
*
1413+
* @returns {Promise} Fulfils with an object with boolean property `gpc`
1414+
* that encodes the current "do not sell or share"
1415+
* signal the browser is configured to convey.
1416+
*/
1417+
get_global_privacy_control: function() {
1418+
return window.test_driver_internal.get_global_privacy_control();
1419+
},
1420+
1421+
/**
1422+
* Gets the current globally-applied privacy control status
1423+
*
1424+
* @param {bool} newValue - The a boolean that is true if the browers
1425+
* should convey a "do not sell or share" signal
1426+
* and false otherwise
1427+
*
1428+
* @returns {Promise} Fulfils with an object with boolean property `gpc`
1429+
* that encodes the new "do not sell or share"
1430+
* after applying the new value.
1431+
*/
1432+
set_global_privacy_control: function(newValue) {
1433+
return window.test_driver_internal.set_global_privacy_control(newValue);
1434+
},
1435+
14101436
/**
14111437
* Creates a virtual authenticator
14121438
*
@@ -2364,6 +2390,14 @@
23642390
throw new Error("set_permission() is not implemented by testdriver-vendor.js");
23652391
},
23662392

2393+
async set_global_privacy_control(newValue, context=null) {
2394+
throw new Error("set_global_privacy_control() is not implemented by testdriver-vendor.js");
2395+
},
2396+
2397+
async get_global_privacy_control(context=null) {
2398+
throw new Error("get_global_privacy_control() is not implemented by testdriver-vendor.js");
2399+
},
2400+
23672401
async add_virtual_authenticator(config, context=null) {
23682402
throw new Error("add_virtual_authenticator() is not implemented by testdriver-vendor.js");
23692403
},

tools/wptrunner/wptrunner/executors/actions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ def __call__(self, payload):
183183
self.logger.debug("Setting permission %s to %s" % (name, state))
184184
self.protocol.set_permission.set_permission(descriptor, state)
185185

186+
187+
class SetGlobalPrivacyControlAction:
188+
name = "set_global_privacy_control"
189+
190+
def __init__(self, logger, protocol):
191+
self.logger = logger
192+
self.protocol = protocol
193+
194+
def __call__(self, payload):
195+
gpc = payload["gpc"]
196+
return self.protocol.global_privacy_control.set_global_privacy_control(gpc)
197+
198+
class GetGlobalPrivacyControlAction:
199+
name = "get_global_privacy_control"
200+
201+
def __init__(self, logger, protocol):
202+
self.logger = logger
203+
self.protocol = protocol
204+
205+
def __call__(self, payload):
206+
return self.protocol.global_privacy_control.get_global_privacy_control()
207+
208+
209+
186210
class AddVirtualAuthenticatorAction:
187211
name = "add_virtual_authenticator"
188212

@@ -586,4 +610,6 @@ def __call__(self, payload):
586610
RemoveVirtualPressureSourceAction,
587611
SetProtectedAudienceKAnonymityAction,
588612
SetDisplayFeaturesAction,
589-
ClearDisplayFeaturesAction]
613+
ClearDisplayFeaturesAction,
614+
GetGlobalPrivacyControlAction,
615+
SetGlobalPrivacyControlAction]

tools/wptrunner/wptrunner/executors/executormarionette.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
DevicePostureProtocolPart,
3535
DisplayFeaturesProtocolPart,
3636
GenerateTestReportProtocolPart,
37+
GlobalPrivacyControlProtocolPart,
3738
PrefsProtocolPart,
3839
PrintProtocolPart,
3940
Protocol,
@@ -620,6 +621,29 @@ def set_permission(self, descriptor, state):
620621
raise NotImplementedError("set_permission not yet implemented") from e
621622

622623

624+
class MarionetteGlobalPrivacyControlProtocolPart(GlobalPrivacyControlProtocolPart):
625+
def setup(self):
626+
self.marionette = self.parent.marionette
627+
628+
def set_global_privacy_control(self, gpc):
629+
body = {
630+
"gpc": gpc,
631+
}
632+
try:
633+
return self.marionette._send_message("WebDriver:SetGlobalPrivacyControl", body)["value"]
634+
except errors.UnsupportedOperationException as e:
635+
raise NotImplementedError("set_global_privacy_control not yet implemented") from e
636+
637+
def get_global_privacy_control(self):
638+
try:
639+
return self.marionette._send_message("WebDriver:GetGlobalPrivacyControl")["value"]
640+
except errors.UnsupportedOperationException as e:
641+
raise NotImplementedError("get_global_privacy_control not yet implemented") from e
642+
643+
644+
645+
646+
623647
class MarionettePrintProtocolPart(PrintProtocolPart):
624648
def setup(self):
625649
self.marionette = self.parent.marionette
@@ -795,6 +819,7 @@ class MarionetteProtocol(Protocol):
795819
MarionetteGenerateTestReportProtocolPart,
796820
MarionetteVirtualAuthenticatorProtocolPart,
797821
MarionetteSetPermissionProtocolPart,
822+
MarionetteGlobalPrivacyControlProtocolPart,
798823
MarionettePrintProtocolPart,
799824
MarionetteDebugProtocolPart,
800825
MarionetteAccessibilityProtocolPart,

tools/wptrunner/wptrunner/executors/protocol.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,20 @@ def set_permission(self, descriptor, state):
736736
pass
737737

738738

739+
class GlobalPrivacyControlProtocolPart(ProtocolPart):
740+
"""Protocol part for reading and writing the GPC signal"""
741+
__metaclass__ = ABCMeta
742+
743+
name = "global_privacy_control"
744+
745+
@abstractmethod
746+
def set_global_privacy_control(self, value):
747+
pass
748+
749+
@abstractmethod
750+
def get_global_privacy_control(self):
751+
pass
752+
739753
class ActionSequenceProtocolPart(ProtocolPart):
740754
"""Protocol part for performing trusted clicks"""
741755
__metaclass__ = ABCMeta

tools/wptrunner/wptrunner/testdriver-extra.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@
536536
return create_context_action("set_permission", context, {permission_params});
537537
};
538538

539+
window.test_driver_internal.get_global_privacy_control = function(context=null) {
540+
return create_context_action("get_global_privacy_control", context, {});
541+
};
542+
543+
window.test_driver_internal.set_global_privacy_control = function(gpc, context=null) {
544+
return create_context_action("set_global_privacy_control", context, {gpc});
545+
};
546+
539547
window.test_driver_internal.add_virtual_authenticator = function(config, context=null) {
540548
return create_context_action("add_virtual_authenticator", context, {config});
541549
};

0 commit comments

Comments
 (0)