Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compute pressure-related commands to testdriver #48035

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/writing-tests/testdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ the global scope.
.. js:autofunction:: test_driver.run_bounce_tracking_mitigations
```

### Compute Pressure ###
```eval_rst
.. js:autofunction:: test_driver.create_virtual_pressure_source
.. js:autofunction:: test_driver.update_virtual_pressure_source
.. js:autofunction:: test_driver.remove_virtual_pressure_source
```

### Using test_driver in other browsing contexts ###

Testdriver can be used in browsing contexts (i.e. windows or frames)
Expand Down
88 changes: 88 additions & 0 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,82 @@
*/
run_bounce_tracking_mitigations: function (context = null) {
return window.test_driver_internal.run_bounce_tracking_mitigations(context);
},

/**
* Creates a virtual pressure source.
*
* Matches the `Create virtual pressure source
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_
* WebDriver command.
*
* @param {String} source_type - A `virtual pressure source type
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
* such as "cpu".
* @param {Object} [metadata={}] - Optional parameters described
* in `Create virtual pressure source
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_.
* @param {WindowProxy} [context=null] - Browsing context in which to
* run the call, or null for the
* current browsing context.
*
* @returns {Promise} Fulfilled when virtual pressure source is created.
* Rejected in case the WebDriver command errors out
* (including if a virtual pressure source of the
* same type already exists).
*/
create_virtual_pressure_source: function(source_type, metadata={}, context=null) {
return window.test_driver_internal.create_virtual_pressure_source(source_type, metadata, context);
},

/**
* Causes a virtual pressure source to report a new reading.
*
* Matches the `Update virtual pressure source
* <https://w3c.github.io/compute-pressure/#update-virtual-pressure-source>`_
* WebDriver command.
*
* @param {String} source_type - A `virtual pressure source type
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
* such as "cpu".
* @param {String} sample - A `virtual pressure sample
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the spec, I think you meant "pressure state" instead of "pressure sample" here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in this reference the text talking about the spec should be changed and is changed in this commit 7cc8325

But the spec defines the parameter name as "sample" in Update virtual pressure source -chapter.

Also spec defines "sample" in sentence like "A pressure source
has an associated latest sample
".

And in one step of "Update virtual pressure source" service it says
"7. Let sample be the result of invoking get a property "sample" from parameters."

* <https://w3c.github.io/compute-pressure/#dom-pressurestate>`_
* such as "critical".
* @param {WindowProxy} [context=null] - Browsing context in which to
* run the call, or null for the
* current browsing context.
*
* @returns {Promise} Fulfilled after the reading update reaches the
* virtual pressure source. Rejected in case the
* WebDriver command errors out (including if a
* virtual pressure source of the given type does not
* exist).
*/
update_virtual_pressure_source: function(source_type, sample, context=null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sample -> state (or pressure_state)

return window.test_driver_internal.update_virtual_pressure_source(source_type, sample, context);
},

/**
* Removes created virtual pressure source.
*
* Matches the `Delete virtual pressure source
* <https://w3c.github.io/compute-pressure/#delete-virtual-pressure-source>`_
* WebDriver command.
*
* @param {String} source_type - A `virtual pressure source type
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
* such as "cpu".
* @param {WindowProxy} [context=null] - Browsing context in which to
* run the call, or null for the
* current browsing context.
*
* @returns {Promise} Fulfilled after the virtual pressure source has
* been removed or if a pressure source of the given
* type does not exist. Rejected in case the
* WebDriver command errors out.
*/
remove_virtual_pressure_source: function(source_type, context=null) {
return window.test_driver_internal.remove_virtual_pressure_source(source_type, context);
}
};

Expand Down Expand Up @@ -1356,6 +1432,18 @@

async run_bounce_tracking_mitigations(context=null) {
throw new Error("run_bounce_tracking_mitigations() is not implemented by testdriver-vendor.js");
},

async create_virtual_pressure_source(source_type, metadata={}, context=null) {
throw new Error("create_virtual_pressure_source() is not implemented by testdriver-vendor.js");
},

async update_virtual_pressure_source(source_type, sample, context=null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/sample/state/

throw new Error("update_virtual_pressure_source() is not implemented by testdriver-vendor.js");
},

async remove_virtual_pressure_source(source_type, context=null) {
throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js");
}
};
})();
41 changes: 40 additions & 1 deletion tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,42 @@ def __call__(self, payload):
self.logger.debug("Running bounce tracking mitigations")
return self.protocol.storage.run_bounce_tracking_mitigations()

class CreateVirtualPressureSourceAction:
name = "create_virtual_pressure_source"

def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol

def __call__(self, payload):
source_type = payload["source_type"]
metadata = payload["metadata"]
self.logger.debug("Creating %s pressure source with %s values" % (source_type, metadata))
return self.protocol.pressure.create_virtual_pressure_source(source_type, metadata)

class UpdateVirtualPressureSourceAction:
name = "update_virtual_pressure_source"

def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol

def __call__(self, payload):
source_type = payload["source_type"]
sample = payload["sample"]
return self.protocol.pressure.update_virtual_pressure_source(source_type, sample)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


class RemoveVirtualPressureSourceAction:
name = "remove_virtual_pressure_source"

def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol

def __call__(self, payload):
source_type = payload["source_type"]
return self.protocol.pressure.remove_virtual_pressure_source(source_type)

actions = [ClickAction,
DeleteAllCookiesAction,
GetAllCookiesAction,
Expand Down Expand Up @@ -511,4 +547,7 @@ def __call__(self, payload):
GetVirtualSensorInformationAction,
SetDevicePostureAction,
ClearDevicePostureAction,
RunBounceTrackingMitigationsAction]
RunBounceTrackingMitigationsAction,
CreateVirtualPressureSourceAction,
UpdateVirtualPressureSourceAction,
RemoveVirtualPressureSourceAction]
18 changes: 17 additions & 1 deletion tools/wptrunner/wptrunner/executors/executormarionette.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
DebugProtocolPart,
VirtualSensorProtocolPart,
DevicePostureProtocolPart,
VirtualPressureSourceProtocolPart,
merge_dicts)


Expand Down Expand Up @@ -761,6 +762,20 @@ def clear_device_posture(self):
raise NotImplementedError("clear_device_posture not yet implemented")


class MarionetteVirtualPressureSourceProtocolPart(VirtualPressureSourceProtocolPart):
def setup(self):
self.marionette = self.parent.marionette

def create_virtual_pressure_source(self, source_type, metadata):
raise NotImplementedError("create_virtual_pressure_source not yet implemented")

def update_virtual_pressure_source(self, source_type, sample):
raise NotImplementedError("update_virtual_pressure_source not yet implemented")

def remove_virtual_pressure_source(self, source_type):
raise NotImplementedError("remove_virtual_pressure_source not yet implemented")


class MarionetteProtocol(Protocol):
implements = [MarionetteBaseProtocolPart,
MarionetteTestharnessProtocolPart,
Expand All @@ -782,7 +797,8 @@ class MarionetteProtocol(Protocol):
MarionetteDebugProtocolPart,
MarionetteAccessibilityProtocolPart,
MarionetteVirtualSensorProtocolPart,
MarionetteDevicePostureProtocolPart]
MarionetteDevicePostureProtocolPart,
MarionetteVirtualPressureSourceProtocolPart]

def __init__(self, executor, browser, capabilities=None, timeout_multiplier=1, e10s=True, ccov=False):
do_delayed_imports()
Expand Down
20 changes: 19 additions & 1 deletion tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
BidiScriptProtocolPart,
DevicePostureProtocolPart,
StorageProtocolPart,
VirtualPressureSourceProtocolPart,
merge_dicts)

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

class WebDriverVirtualPressureSourceProtocolPart(VirtualPressureSourceProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver

def create_virtual_pressure_source(self, source_type, metadata):
body = {"type": source_type}
body.update(metadata)
return self.webdriver.send_session_command("POST", "pressuresource", body)

def update_virtual_pressure_source(self, source_type, sample):
body = {"sample": sample}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

return self.webdriver.send_session_command("POST", "pressuresource/%s" % source_type, body)

def remove_virtual_pressure_source(self, source_type):
return self.webdriver.send_session_command("DELETE", "pressuresource/%s" % source_type)

class WebDriverProtocol(Protocol):
enable_bidi = False
implements = [WebDriverBaseProtocolPart,
Expand All @@ -589,7 +606,8 @@ class WebDriverProtocol(Protocol):
WebDriverDebugProtocolPart,
WebDriverVirtualSensorPart,
WebDriverDevicePostureProtocolPart,
WebDriverStorageProtocolPart]
WebDriverStorageProtocolPart,
WebDriverVirtualPressureSourceProtocolPart]

def __init__(self, executor, browser, capabilities, **kwargs):
super().__init__(executor, browser)
Expand Down
18 changes: 18 additions & 0 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,21 @@ def set_device_posture(self, posture):
@abstractmethod
def clear_device_posture(self):
pass

class VirtualPressureSourceProtocolPart(ProtocolPart):
"""Protocol part for Virtual Pressure Source"""
__metaclass__ = ABCMeta

name = "pressure"

@abstractmethod
def create_virtual_pressure_source(self, source_type, metadata):
pass

@abstractmethod
def update_virtual_pressure_source(self, source_type, sample):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

pass

@abstractmethod
def remove_virtual_pressure_source(self, source_type):
pass
12 changes: 12 additions & 0 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,16 @@
window.test_driver_internal.run_bounce_tracking_mitigations = function (context = null) {
return create_action("run_bounce_tracking_mitigations", {context});
};

window.test_driver_internal.create_virtual_pressure_source = function(source_type, metadata={}, context=null) {
return create_context_action("create_virtual_pressure_source", context, {source_type, metadata});
};

window.test_driver_internal.update_virtual_pressure_source = function(source_type, sample, context=null) {
return create_context_action("update_virtual_pressure_source", context, {source_type, sample});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And finally here.

};

window.test_driver_internal.remove_virtual_pressure_source = function(source_type, context=null) {
return create_context_action("remove_virtual_pressure_source", context, {source_type});
};
})();