Skip to content

Commit 5fea2d4

Browse files
JuhaVainiomoz-wptsync-bot
authored andcommitted
Bug 1917534 [wpt PR 48035] - Add compute pressure-related commands to testdriver, a=testonly
Automatic update from web-platform-tests Add compute pressure-related commands to testdriver (#48035) * Add compute pressure-related commands to testdriver Spec PR: w3c/compute-pressure#284 This PR adds the required infrastructure to manipulate compute pressure from testdriver. The three new commands correspond to the three WebDriver extension commands added by the spec PR above. * Change the specification reference from "virtual pressure sample" to "virtual pressure state" -- wpt-commits: 384f5d9f4d9dccecb3374990ffdc9b3e181d5ff5 wpt-pr: 48035
1 parent 3a6a95d commit 5fea2d4

File tree

7 files changed

+201
-3
lines changed

7 files changed

+201
-3
lines changed

testing/web-platform/tests/docs/writing-tests/testdriver.md

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ the global scope.
131131
.. js:autofunction:: test_driver.run_bounce_tracking_mitigations
132132
```
133133

134+
### Compute Pressure ###
135+
```eval_rst
136+
.. js:autofunction:: test_driver.create_virtual_pressure_source
137+
.. js:autofunction:: test_driver.update_virtual_pressure_source
138+
.. js:autofunction:: test_driver.remove_virtual_pressure_source
139+
```
140+
134141
### Using test_driver in other browsing contexts ###
135142

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

testing/web-platform/tests/resources/testdriver.js

+88
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,82 @@
11411141
*/
11421142
run_bounce_tracking_mitigations: function (context = null) {
11431143
return window.test_driver_internal.run_bounce_tracking_mitigations(context);
1144+
},
1145+
1146+
/**
1147+
* Creates a virtual pressure source.
1148+
*
1149+
* Matches the `Create virtual pressure source
1150+
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_
1151+
* WebDriver command.
1152+
*
1153+
* @param {String} source_type - A `virtual pressure source type
1154+
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
1155+
* such as "cpu".
1156+
* @param {Object} [metadata={}] - Optional parameters described
1157+
* in `Create virtual pressure source
1158+
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_.
1159+
* @param {WindowProxy} [context=null] - Browsing context in which to
1160+
* run the call, or null for the
1161+
* current browsing context.
1162+
*
1163+
* @returns {Promise} Fulfilled when virtual pressure source is created.
1164+
* Rejected in case the WebDriver command errors out
1165+
* (including if a virtual pressure source of the
1166+
* same type already exists).
1167+
*/
1168+
create_virtual_pressure_source: function(source_type, metadata={}, context=null) {
1169+
return window.test_driver_internal.create_virtual_pressure_source(source_type, metadata, context);
1170+
},
1171+
1172+
/**
1173+
* Causes a virtual pressure source to report a new reading.
1174+
*
1175+
* Matches the `Update virtual pressure source
1176+
* <https://w3c.github.io/compute-pressure/#update-virtual-pressure-source>`_
1177+
* WebDriver command.
1178+
*
1179+
* @param {String} source_type - A `virtual pressure source type
1180+
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
1181+
* such as "cpu".
1182+
* @param {String} sample - A `virtual pressure state
1183+
* <https://w3c.github.io/compute-pressure/#dom-pressurestate>`_
1184+
* such as "critical".
1185+
* @param {WindowProxy} [context=null] - Browsing context in which to
1186+
* run the call, or null for the
1187+
* current browsing context.
1188+
*
1189+
* @returns {Promise} Fulfilled after the reading update reaches the
1190+
* virtual pressure source. Rejected in case the
1191+
* WebDriver command errors out (including if a
1192+
* virtual pressure source of the given type does not
1193+
* exist).
1194+
*/
1195+
update_virtual_pressure_source: function(source_type, sample, context=null) {
1196+
return window.test_driver_internal.update_virtual_pressure_source(source_type, sample, context);
1197+
},
1198+
1199+
/**
1200+
* Removes created virtual pressure source.
1201+
*
1202+
* Matches the `Delete virtual pressure source
1203+
* <https://w3c.github.io/compute-pressure/#delete-virtual-pressure-source>`_
1204+
* WebDriver command.
1205+
*
1206+
* @param {String} source_type - A `virtual pressure source type
1207+
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
1208+
* such as "cpu".
1209+
* @param {WindowProxy} [context=null] - Browsing context in which to
1210+
* run the call, or null for the
1211+
* current browsing context.
1212+
*
1213+
* @returns {Promise} Fulfilled after the virtual pressure source has
1214+
* been removed or if a pressure source of the given
1215+
* type does not exist. Rejected in case the
1216+
* WebDriver command errors out.
1217+
*/
1218+
remove_virtual_pressure_source: function(source_type, context=null) {
1219+
return window.test_driver_internal.remove_virtual_pressure_source(source_type, context);
11441220
}
11451221
};
11461222

@@ -1356,6 +1432,18 @@
13561432

13571433
async run_bounce_tracking_mitigations(context=null) {
13581434
throw new Error("run_bounce_tracking_mitigations() is not implemented by testdriver-vendor.js");
1435+
},
1436+
1437+
async create_virtual_pressure_source(source_type, metadata={}, context=null) {
1438+
throw new Error("create_virtual_pressure_source() is not implemented by testdriver-vendor.js");
1439+
},
1440+
1441+
async update_virtual_pressure_source(source_type, sample, context=null) {
1442+
throw new Error("update_virtual_pressure_source() is not implemented by testdriver-vendor.js");
1443+
},
1444+
1445+
async remove_virtual_pressure_source(source_type, context=null) {
1446+
throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js");
13591447
}
13601448
};
13611449
})();

testing/web-platform/tests/tools/wptrunner/wptrunner/executors/actions.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,42 @@ def __call__(self, payload):
475475
self.logger.debug("Running bounce tracking mitigations")
476476
return self.protocol.storage.run_bounce_tracking_mitigations()
477477

478+
class CreateVirtualPressureSourceAction:
479+
name = "create_virtual_pressure_source"
480+
481+
def __init__(self, logger, protocol):
482+
self.logger = logger
483+
self.protocol = protocol
484+
485+
def __call__(self, payload):
486+
source_type = payload["source_type"]
487+
metadata = payload["metadata"]
488+
self.logger.debug("Creating %s pressure source with %s values" % (source_type, metadata))
489+
return self.protocol.pressure.create_virtual_pressure_source(source_type, metadata)
490+
491+
class UpdateVirtualPressureSourceAction:
492+
name = "update_virtual_pressure_source"
493+
494+
def __init__(self, logger, protocol):
495+
self.logger = logger
496+
self.protocol = protocol
497+
498+
def __call__(self, payload):
499+
source_type = payload["source_type"]
500+
sample = payload["sample"]
501+
return self.protocol.pressure.update_virtual_pressure_source(source_type, sample)
502+
503+
class RemoveVirtualPressureSourceAction:
504+
name = "remove_virtual_pressure_source"
505+
506+
def __init__(self, logger, protocol):
507+
self.logger = logger
508+
self.protocol = protocol
509+
510+
def __call__(self, payload):
511+
source_type = payload["source_type"]
512+
return self.protocol.pressure.remove_virtual_pressure_source(source_type)
513+
478514
actions = [ClickAction,
479515
DeleteAllCookiesAction,
480516
GetAllCookiesAction,
@@ -511,4 +547,7 @@ def __call__(self, payload):
511547
GetVirtualSensorInformationAction,
512548
SetDevicePostureAction,
513549
ClearDevicePostureAction,
514-
RunBounceTrackingMitigationsAction]
550+
RunBounceTrackingMitigationsAction,
551+
CreateVirtualPressureSourceAction,
552+
UpdateVirtualPressureSourceAction,
553+
RemoveVirtualPressureSourceAction]

testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
DebugProtocolPart,
4747
VirtualSensorProtocolPart,
4848
DevicePostureProtocolPart,
49+
VirtualPressureSourceProtocolPart,
4950
merge_dicts)
5051

5152

@@ -714,6 +715,20 @@ def clear_device_posture(self):
714715
raise NotImplementedError("clear_device_posture not yet implemented")
715716

716717

718+
class MarionetteVirtualPressureSourceProtocolPart(VirtualPressureSourceProtocolPart):
719+
def setup(self):
720+
self.marionette = self.parent.marionette
721+
722+
def create_virtual_pressure_source(self, source_type, metadata):
723+
raise NotImplementedError("create_virtual_pressure_source not yet implemented")
724+
725+
def update_virtual_pressure_source(self, source_type, sample):
726+
raise NotImplementedError("update_virtual_pressure_source not yet implemented")
727+
728+
def remove_virtual_pressure_source(self, source_type):
729+
raise NotImplementedError("remove_virtual_pressure_source not yet implemented")
730+
731+
717732
class MarionetteProtocol(Protocol):
718733
implements = [MarionetteBaseProtocolPart,
719734
MarionetteTestharnessProtocolPart,
@@ -735,7 +750,8 @@ class MarionetteProtocol(Protocol):
735750
MarionetteDebugProtocolPart,
736751
MarionetteAccessibilityProtocolPart,
737752
MarionetteVirtualSensorProtocolPart,
738-
MarionetteDevicePostureProtocolPart]
753+
MarionetteDevicePostureProtocolPart,
754+
MarionetteVirtualPressureSourceProtocolPart]
739755

740756
def __init__(self, executor, browser, capabilities=None, timeout_multiplier=1, e10s=True, ccov=False):
741757
do_delayed_imports()

testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
BidiScriptProtocolPart,
4343
DevicePostureProtocolPart,
4444
StorageProtocolPart,
45+
VirtualPressureSourceProtocolPart,
4546
merge_dicts)
4647

4748
from typing import List, Optional, Tuple
@@ -568,6 +569,22 @@ def setup(self):
568569
def run_bounce_tracking_mitigations(self):
569570
return self.webdriver.send_session_command("DELETE", "storage/run_bounce_tracking_mitigations")
570571

572+
class WebDriverVirtualPressureSourceProtocolPart(VirtualPressureSourceProtocolPart):
573+
def setup(self):
574+
self.webdriver = self.parent.webdriver
575+
576+
def create_virtual_pressure_source(self, source_type, metadata):
577+
body = {"type": source_type}
578+
body.update(metadata)
579+
return self.webdriver.send_session_command("POST", "pressuresource", body)
580+
581+
def update_virtual_pressure_source(self, source_type, sample):
582+
body = {"sample": sample}
583+
return self.webdriver.send_session_command("POST", "pressuresource/%s" % source_type, body)
584+
585+
def remove_virtual_pressure_source(self, source_type):
586+
return self.webdriver.send_session_command("DELETE", "pressuresource/%s" % source_type)
587+
571588
class WebDriverProtocol(Protocol):
572589
enable_bidi = False
573590
implements = [WebDriverBaseProtocolPart,
@@ -589,7 +606,8 @@ class WebDriverProtocol(Protocol):
589606
WebDriverDebugProtocolPart,
590607
WebDriverVirtualSensorPart,
591608
WebDriverDevicePostureProtocolPart,
592-
WebDriverStorageProtocolPart]
609+
WebDriverStorageProtocolPart,
610+
WebDriverVirtualPressureSourceProtocolPart]
593611

594612
def __init__(self, executor, browser, capabilities, **kwargs):
595613
super().__init__(executor, browser)

testing/web-platform/tests/tools/wptrunner/wptrunner/executors/protocol.py

+18
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,21 @@ def set_device_posture(self, posture):
936936
@abstractmethod
937937
def clear_device_posture(self):
938938
pass
939+
940+
class VirtualPressureSourceProtocolPart(ProtocolPart):
941+
"""Protocol part for Virtual Pressure Source"""
942+
__metaclass__ = ABCMeta
943+
944+
name = "pressure"
945+
946+
@abstractmethod
947+
def create_virtual_pressure_source(self, source_type, metadata):
948+
pass
949+
950+
@abstractmethod
951+
def update_virtual_pressure_source(self, source_type, sample):
952+
pass
953+
954+
@abstractmethod
955+
def remove_virtual_pressure_source(self, source_type):
956+
pass

testing/web-platform/tests/tools/wptrunner/wptrunner/testdriver-extra.js

+12
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,16 @@
393393
window.test_driver_internal.run_bounce_tracking_mitigations = function (context = null) {
394394
return create_action("run_bounce_tracking_mitigations", {context});
395395
};
396+
397+
window.test_driver_internal.create_virtual_pressure_source = function(source_type, metadata={}, context=null) {
398+
return create_context_action("create_virtual_pressure_source", context, {source_type, metadata});
399+
};
400+
401+
window.test_driver_internal.update_virtual_pressure_source = function(source_type, sample, context=null) {
402+
return create_context_action("update_virtual_pressure_source", context, {source_type, sample});
403+
};
404+
405+
window.test_driver_internal.remove_virtual_pressure_source = function(source_type, context=null) {
406+
return create_context_action("remove_virtual_pressure_source", context, {source_type});
407+
};
396408
})();

0 commit comments

Comments
 (0)