Bug 1853883 - [bidi] Implement network.failRequest command r=webdriver-reviewers,necko-reviewers,jesup,whimboo

Depends on D197652

Differential Revision: https://phabricator.services.mozilla.com/D197653
This commit is contained in:
Julian Descottes 2024-01-12 11:08:14 +00:00
Родитель b409a08fb3
Коммит 0ad981249f
3 изменённых файлов: 61 добавлений и 29 удалений

Просмотреть файл

@ -1420,6 +1420,8 @@ interface nsILoadInfo : nsISupports
const uint32_t BLOCKING_REASON_NOT_SAME_ORIGIN = 5000;
// The reason used when an extension cancels the request via the WebRequest api.
const uint32_t BLOCKING_REASON_EXTENSION_WEBREQUEST = 6000;
// The reason used when a request is cancelled via WebDriver BiDi network interception.
const uint32_t BLOCKING_REASON_WEBDRIVER_BIDI = 7000;
/**
* If the request associated with this load info was blocked by some of

Просмотреть файл

@ -462,6 +462,53 @@ class NetworkModule extends Module {
resolveBlockedEvent();
}
/**
* Fails a request that is blocked by a network intercept.
*
* @param {object=} options
* @param {string} options.request
* The id of the blocked request that should be continued.
*
* @throws {InvalidArgumentError}
* Raised if an argument is of an invalid type or value.
* @throws {NoSuchRequestError}
* Raised if the request id does not match any request in the blocked
* requests map.
*/
async failRequest(options = {}) {
this.assertExperimentalCommandsEnabled("network.failRequest");
const { request: requestId } = options;
lazy.assert.string(
requestId,
`Expected "request" to be a string, got ${requestId}`
);
if (!this.#blockedRequests.has(requestId)) {
throw new lazy.error.NoSuchRequestError(
`Blocked request with id ${requestId} not found`
);
}
const { phase, request, resolveBlockedEvent } =
this.#blockedRequests.get(requestId);
if (phase === InterceptPhase.AuthRequired) {
throw new lazy.error.InvalidArgumentError(
`Expected blocked request not to be in "authRequired" phase`
);
}
const wrapper = ChannelWrapper.get(request);
wrapper.resume();
wrapper.cancel(
Cr.NS_ERROR_ABORT,
Ci.nsILoadInfo.BLOCKING_REASON_WEBDRIVER_BIDI
);
resolveBlockedEvent();
}
/**
* Removes an existing network intercept.
*
@ -575,6 +622,10 @@ class NetworkModule extends Module {
};
}
#getSuspendMarkerText(requestData, phase) {
return `Request (id: ${requestData.request}) suspended by WebDriver BiDi in ${phase} phase`;
}
#getNetworkIntercepts(event, requestData) {
const intercepts = [];
@ -809,7 +860,10 @@ class NetworkModule extends Module {
if (beforeRequestSentEvent.isBlocked) {
// TODO: Requests suspended in beforeRequestSent still reach the server at
// the moment. https://bugzilla.mozilla.org/show_bug.cgi?id=1849686
requestChannel.suspend();
const wrapper = ChannelWrapper.get(requestChannel);
wrapper.suspend(
this.#getSuspendMarkerText(requestData, "beforeRequestSent")
);
this.#addBlockedRequest(
beforeRequestSentEvent.request.request,
@ -982,7 +1036,10 @@ class NetworkModule extends Module {
protocolEventName === "network.responseStarted" &&
responseEvent.isBlocked
) {
requestChannel.suspend();
const wrapper = ChannelWrapper.get(requestChannel);
wrapper.suspend(
this.#getSuspendMarkerText(requestData, "responseStarted")
);
this.#addBlockedRequest(
responseEvent.request.request,

Просмотреть файл

@ -1,27 +0,0 @@
[invalid.py]
[test_params_request_invalid_phase]
expected: FAIL
[test_params_request_invalid_type[None\]]
expected: FAIL
[test_params_request_invalid_type[False\]]
expected: FAIL
[test_params_request_invalid_type[42\]]
expected: FAIL
[test_params_request_invalid_type[value3\]]
expected: FAIL
[test_params_request_invalid_type[value4\]]
expected: FAIL
[test_params_request_invalid_value[\]]
expected: FAIL
[test_params_request_invalid_value[foo\]]
expected: FAIL
[test_params_request_no_such_request]
expected: FAIL