-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bidi] Update browsing context create method (#13766)
- Loading branch information
Showing
6 changed files
with
223 additions
and
22 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
51 changes: 51 additions & 0 deletions
51
java/src/org/openqa/selenium/bidi/browsingcontext/CreateContextParameters.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,51 @@ | ||
// 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.browsingcontext; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.openqa.selenium.WindowType; | ||
|
||
public class CreateContextParameters { | ||
private final Map<String, Object> map = new HashMap<>(); | ||
private final WindowType windowType; | ||
|
||
public CreateContextParameters(WindowType type) { | ||
this.windowType = type; | ||
} | ||
|
||
public CreateContextParameters referenceContext(String id) { | ||
map.put("referenceContext", id); | ||
return this; | ||
} | ||
|
||
public CreateContextParameters background(boolean background) { | ||
map.put("background", background); | ||
return this; | ||
} | ||
|
||
public CreateContextParameters userContext(String userContext) { | ||
map.put("userContext", userContext); | ||
return this; | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
map.put("type", windowType.toString()); | ||
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
73 changes: 73 additions & 0 deletions
73
javascript/node/selenium-webdriver/bidi/createContextParameters.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,73 @@ | ||
// 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. | ||
|
||
/** | ||
* Represents a set of parameters for creating a context. | ||
* Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-create. | ||
*/ | ||
class CreateContextParameters { | ||
#map = new Map() | ||
|
||
/** | ||
* Sets the reference context. | ||
* @param {string} id - The ID of the reference context. | ||
* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining. | ||
* @throws {Error} - If the provided ID is not a string. | ||
*/ | ||
referenceContext(id) { | ||
if (typeof id !== 'string') { | ||
throw new Error(`ReferenceContext must be string. Received:'${id}'`) | ||
} | ||
this.#map.set('referenceContext', id) | ||
return this | ||
} | ||
|
||
/** | ||
* Sets the background parameter. | ||
* | ||
* @param {boolean} background - The background value to set. | ||
* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining. | ||
* @throws {Error} - If the background parameter is not a boolean. | ||
*/ | ||
background(background) { | ||
if (typeof background !== 'boolean') { | ||
throw new Error(`Background must be boolean. Received:'${background}'`) | ||
} | ||
this.#map.set('background', background) | ||
return this | ||
} | ||
|
||
/** | ||
* Sets the user context. | ||
* @param {string} userContext - The user context to set. | ||
* @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining. | ||
* @throws {Error} - If the userContext parameter is not a string. | ||
*/ | ||
userContext(userContext) { | ||
if (typeof userContext !== 'string') { | ||
throw new Error(`UserContext must be string. Received:'${userContext}'`) | ||
} | ||
this.#map.set('userContext', userContext) | ||
return this | ||
} | ||
|
||
asMap() { | ||
return this.#map | ||
} | ||
} | ||
|
||
module.exports = { CreateContextParameters } |
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