-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bidi] Add provide response command (#13708)
- Loading branch information
Showing
6 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
java/src/org/openqa/selenium/bidi/network/ProvideResponseParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.bidi.network; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ProvideResponseParameters { | ||
private final Map<String, Object> map = new HashMap<>(); | ||
|
||
public ProvideResponseParameters(String request) { | ||
map.put("request", request); | ||
} | ||
|
||
public ProvideResponseParameters body(BytesValue value) { | ||
map.put("body", value.toMap()); | ||
return this; | ||
} | ||
|
||
public ProvideResponseParameters cookies(List<SetCookieHeader> cookieHeaders) { | ||
List<Map<String, Object>> cookies = | ||
cookieHeaders.stream().map(SetCookieHeader::toMap).collect(Collectors.toList()); | ||
map.put("cookies", cookies); | ||
return this; | ||
} | ||
|
||
public ProvideResponseParameters headers(List<Header> headers) { | ||
List<Map<String, Object>> headerList = | ||
headers.stream().map(Header::toMap).collect(Collectors.toList()); | ||
map.put("headers", headerList); | ||
return this; | ||
} | ||
|
||
public ProvideResponseParameters reasonPhrase(String reasonPhrase) { | ||
map.put("reasonPhrase", reasonPhrase); | ||
return this; | ||
} | ||
|
||
public ProvideResponseParameters statusCode(int statusCode) { | ||
map.put("statusCode", statusCode); | ||
return this; | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
javascript/node/selenium-webdriver/bidi/provideResponseParameters.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
const { BytesValue, Header } = require('./networkTypes') | ||
|
||
class ProvideResponseParameters { | ||
#map = new Map() | ||
|
||
constructor(request) { | ||
this.#map.set('request', request) | ||
} | ||
|
||
body(value) { | ||
if (!(value instanceof BytesValue)) { | ||
throw new Error(`Value must be an instance of BytesValue. Received: ${typeof value} with value: ${value}`) | ||
} | ||
this.#map.set('body', Object.fromEntries(value.asMap())) | ||
return this | ||
} | ||
|
||
cookies(cookieHeaders) { | ||
const cookies = [] | ||
cookieHeaders.forEach((header) => { | ||
if (!(header instanceof Header)) { | ||
throw new Error(`CookieHeader must be an instance of Header. Received:'${header}'`) | ||
} | ||
cookies.push(Object.fromEntries(header.asMap())) | ||
}) | ||
|
||
this.#map.set('cookies', cookies) | ||
return this | ||
} | ||
|
||
headers(headers) { | ||
const headerList = [] | ||
headers.forEach((header) => { | ||
if (!(header instanceof Header)) { | ||
throw new Error(`Header must be an instance of Header. Received:'${header}'`) | ||
} | ||
headerList.push(Object.fromEntries(header.asMap())) | ||
}) | ||
|
||
this.#map.set('headers', headerList) | ||
return this | ||
} | ||
|
||
reasonPhrase(reasonPhrase) { | ||
if (typeof reasonPhrase !== 'string') { | ||
throw new Error(`Reason phrase must be a string. Received: '${reasonPhrase})'`) | ||
} | ||
this.#map.set('reasonPhrase', reasonPhrase) | ||
return this | ||
} | ||
|
||
statusCode(statusCode) { | ||
if (!Number.isInteger(statusCode)) { | ||
throw new Error(`Status must be an integer. Received:'${statusCode}'`) | ||
} | ||
|
||
this.#map.set('statusCode', statusCode) | ||
return this | ||
} | ||
|
||
asMap() { | ||
return this.#map | ||
} | ||
} | ||
|
||
module.exports = { ProvideResponseParameters } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters