-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* <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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
}; | ||
|
||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} | ||
}; | ||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -511,4 +547,7 @@ def __call__(self, payload): | |
GetVirtualSensorInformationAction, | ||
SetDevicePostureAction, | ||
ClearDevicePostureAction, | ||
RunBounceTrackingMitigationsAction] | ||
RunBounceTrackingMitigationsAction, | ||
CreateVirtualPressureSourceAction, | ||
UpdateVirtualPressureSourceAction, | ||
RemoveVirtualPressureSourceAction] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
BidiScriptProtocolPart, | ||
DevicePostureProtocolPart, | ||
StorageProtocolPart, | ||
VirtualPressureSourceProtocolPart, | ||
merge_dicts) | ||
|
||
from typing import List, Optional, Tuple | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -589,7 +606,8 @@ class WebDriverProtocol(Protocol): | |
WebDriverDebugProtocolPart, | ||
WebDriverVirtualSensorPart, | ||
WebDriverDevicePostureProtocolPart, | ||
WebDriverStorageProtocolPart] | ||
WebDriverStorageProtocolPart, | ||
WebDriverVirtualPressureSourceProtocolPart] | ||
|
||
def __init__(self, executor, browser, capabilities, **kwargs): | ||
super().__init__(executor, browser) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}); | ||
}; | ||
})(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 sourcehas 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."