Skip to content

Commit

Permalink
Bug 1874206 - [bidi] Implement basic support for network.continueRequ…
Browse files Browse the repository at this point in the history
…est r=webdriver-reviewers,Sasha

Differential Revision: https://phabricator.services.mozilla.com/D199748
  • Loading branch information
juliandescottes committed Feb 5, 2024
1 parent d1aa250 commit 5fb3e4a
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 48 deletions.
148 changes: 148 additions & 0 deletions remote/webdriver-bidi/modules/root/network.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ const ContinueWithAuthAction = {
* @property {BytesValue} value
*/

/**
* @typedef {object} CookieHeader
* @property {string} name
* @property {BytesValue} value
*/

/**
* @typedef {object} FetchTimingInfo
* @property {number} timeOrigin
Expand Down Expand Up @@ -367,6 +373,136 @@ class NetworkModule extends Module {
};
}

/**
* Continues a request that is blocked by a network intercept at the
* beforeRequestSent phase.
*
* @param {object=} options
* @param {string} options.request
* The id of the blocked request that should be continued.
* @param {BytesValue=} options.body [unsupported]
* Optional BytesValue to replace the body of the request.
* @param {Array<CookieHeader>=} options.cookies [unsupported]
* Optional array of cookie header values to replace the cookie header of
* the request.
* @param {Array<Header>=} options.headers [unsupported]
* Optional array of headers to replace the headers of the request.
* request.
* @param {string=} options.method [unsupported]
* Optional string to replace the method of the request.
* @param {string=} options.url [unsupported]
* Optional string to replace the url of the request. If the provided url
* is not a valid URL, an InvalidArgumentError will be thrown.
*
* @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 continueRequest(options = {}) {
this.assertExperimentalCommandsEnabled("network.continueRequest");
const {
body = null,
cookies = null,
headers = null,
method = null,
url = null,
request: requestId,
} = options;

lazy.assert.string(
requestId,
`Expected "request" to be a string, got ${requestId}`
);

if (body !== null) {
this.#assertBytesValue(
body,
`Expected "body" to be a network.BytesValue, got ${body}`
);

throw new lazy.error.UnsupportedOperationError(
`"body" not supported yet in network.continueRequest`
);
}

if (cookies !== null) {
lazy.assert.array(
cookies,
`Expected "cookies" to be an array got ${cookies}`
);

for (const cookie of cookies) {
this.#assertHeader(
cookie,
`Expected values in "cookies" to be network.CookieHeader, got ${cookie}`
);
}

throw new lazy.error.UnsupportedOperationError(
`"cookies" not supported yet in network.continueRequest`
);
}

if (headers !== null) {
lazy.assert.array(
headers,
`Expected "headers" to be an array got ${headers}`
);

for (const header of headers) {
this.#assertHeader(
header,
`Expected values in "headers" to be network.Header, got ${header}`
);
}

throw new lazy.error.UnsupportedOperationError(
`"headers" not supported yet in network.continueRequest`
);
}

if (method !== null) {
lazy.assert.string(
method,
`Expected "method" to be a string, got ${method}`
);

throw new lazy.error.UnsupportedOperationError(
`"method" not supported yet in network.continueRequest`
);
}

if (url !== null) {
lazy.assert.string(url, `Expected "url" to be a string, got ${url}`);

throw new lazy.error.UnsupportedOperationError(
`"url" not supported yet in network.continueRequest`
);
}

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.BeforeRequestSent) {
throw new lazy.error.InvalidArgumentError(
`Expected blocked request to be in "beforeRequestSent" phase, got ${phase}`
);
}

const wrapper = ChannelWrapper.get(request);
wrapper.resume();

resolveBlockedEvent();
}

/**
* Continues a response that is blocked by a network intercept at the
* authRequired phase.
Expand Down Expand Up @@ -579,6 +715,18 @@ class NetworkModule extends Module {
});
}

#assertBytesValue(obj, msg) {
lazy.assert.object(obj, msg);
lazy.assert.string(obj.value, msg);
lazy.assert.in(obj.type, Object.values(BytesValueType), msg);
}

#assertHeader(value, msg) {
lazy.assert.object(value, msg);
lazy.assert.string(value.name, msg);
this.#assertBytesValue(value.value, msg);
}

#extractChallenges(responseData) {
let headerName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
[invalid.py]
expected:
if (os == "android") and not debug: [OK, TIMEOUT]
[test_params_method_invalid_type[False\]]
expected: FAIL

[test_params_method_invalid_type[42\]]
expected: FAIL

[test_params_method_invalid_type[value2\]]
expected: FAIL

[test_params_method_invalid_type[value3\]]
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

[test_params_url_invalid_type[False\]]
expected: FAIL

[test_params_url_invalid_type[42\]]
expected: FAIL

[test_params_url_invalid_type[value2\]]
expected: FAIL

[test_params_url_invalid_type[value3\]]
expected: FAIL

[test_params_url_invalid_value[:invalid-http\]]
expected: FAIL

Expand Down

0 comments on commit 5fb3e4a

Please sign in to comment.