-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[java][BiDi] implement emulation #16070
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
Draft
Delta456
wants to merge
13
commits into
SeleniumHQ:trunk
Choose a base branch
from
Delta456:java_bidi_emulation
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3e93134
[java][BiDi] implement emulation
Delta456 7be9945
add license
Delta456 6a8a069
Merge branch 'trunk' into java_bidi_emulation
Delta456 26a1129
add license
Delta456 2a8d42c
Merge branch 'trunk' into java_bidi_emulation
Delta456 2ccc6db
Merge branch 'trunk' into java_bidi_emulation
Delta456 18ad7d8
try to fix remote
Delta456 9159f6f
try again
Delta456 216dde6
comment out code
Delta456 4c45cf3
Merge branch 'trunk' into java_bidi_emulation
Delta456 3adb987
try again
Delta456 3f755a7
fix `getBrowserGeolocation`
navin772 ac558cc
try fix again
navin772 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,23 @@ | ||
load("//java:defs.bzl", "java_library") | ||
|
||
java_library( | ||
name = "emulation", | ||
srcs = glob( | ||
[ | ||
"*.java", | ||
], | ||
), | ||
visibility = [ | ||
"//java/src/org/openqa/selenium/bidi:__subpackages__", | ||
"//java/src/org/openqa/selenium/remote:__pkg__", | ||
"//java/test/org/openqa/selenium/bidi:__subpackages__", | ||
"//java/test/org/openqa/selenium/grid:__subpackages__", | ||
], | ||
deps = [ | ||
"//java/src/org/openqa/selenium:core", | ||
"//java/src/org/openqa/selenium/bidi", | ||
"//java/src/org/openqa/selenium/bidi/browsingcontext", | ||
"//java/src/org/openqa/selenium/json", | ||
"//java/src/org/openqa/selenium/remote/http", | ||
], | ||
) |
46 changes: 46 additions & 0 deletions
46
java/src/org/openqa/selenium/bidi/emulation/Emulation.java
This file contains hidden or 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,46 @@ | ||
// 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.emulation; | ||
|
||
import java.util.Map; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.bidi.BiDi; | ||
import org.openqa.selenium.bidi.Command; | ||
import org.openqa.selenium.bidi.HasBiDi; | ||
import org.openqa.selenium.internal.Require; | ||
|
||
public class Emulation { | ||
private final BiDi bidi; | ||
|
||
public Emulation(WebDriver driver) { | ||
Require.nonNull("WebDriver", driver); | ||
|
||
if (!(driver instanceof HasBiDi)) { | ||
throw new IllegalArgumentException("WebDriver must implement BiDi interface"); | ||
} | ||
|
||
this.bidi = ((HasBiDi) driver).getBiDi(); | ||
} | ||
|
||
public Map<String, Object> setGeolocationOverride(SetGeolocationOverrideParameters parameters) { | ||
Require.nonNull("SetGeolocationOverride parameters", parameters); | ||
|
||
return bidi.send( | ||
new Command<>("emulation.setGeolocationOverride", parameters.toMap(), Map.class)); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
java/src/org/openqa/selenium/bidi/emulation/GeolocationCoordinates.java
This file contains hidden or 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,130 @@ | ||
// 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.emulation; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class GeolocationCoordinates { | ||
private final double latitude; | ||
private final double longitude; | ||
private final double accuracy; | ||
private final Double altitude; | ||
private final Double altitudeAccuracy; | ||
private final Double heading; | ||
private final Double speed; | ||
|
||
// Constructor with default accuracy = 1.0 | ||
public GeolocationCoordinates( | ||
double latitude, | ||
double longitude, | ||
Double altitude, | ||
Double altitudeAccuracy, | ||
Double heading, | ||
Double speed) { | ||
this(latitude, longitude, 1.0, altitude, altitudeAccuracy, heading, speed); | ||
} | ||
|
||
public GeolocationCoordinates( | ||
double latitude, | ||
double longitude, | ||
double accuracy, | ||
Double altitude, | ||
Double altitudeAccuracy, | ||
Double heading, | ||
Double speed) { | ||
|
||
if (latitude < -90.0 || latitude > 90.0) { | ||
throw new IllegalArgumentException("Latitude must be between -90.0 and 90.0"); | ||
} | ||
if (longitude < -180.0 || longitude > 180.0) { | ||
throw new IllegalArgumentException("Longitude must be between -180.0 and 180.0"); | ||
} | ||
if (accuracy < 0.0) { | ||
throw new IllegalArgumentException("Accuracy must be >= 0.0"); | ||
} | ||
if (altitudeAccuracy != null && altitude == null) { | ||
throw new IllegalArgumentException("altitudeAccuracy cannot be set without altitude"); | ||
} | ||
if (altitudeAccuracy != null && altitudeAccuracy < 0.0) { | ||
throw new IllegalArgumentException("Altitude accuracy must be >= 0.0"); | ||
} | ||
if (heading != null && (heading < 0.0 || heading >= 360.0)) { | ||
throw new IllegalArgumentException("Heading must be between 0.0 and 360.0"); | ||
} | ||
if (speed != null && speed < 0.0) { | ||
throw new IllegalArgumentException("Speed must be >= 0.0"); | ||
} | ||
|
||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
this.accuracy = accuracy; | ||
this.altitude = altitude; | ||
this.altitudeAccuracy = altitudeAccuracy; | ||
this.heading = heading; | ||
this.speed = speed; | ||
} | ||
|
||
public double getLatitude() { | ||
return latitude; | ||
} | ||
|
||
public double getLongitude() { | ||
return longitude; | ||
} | ||
|
||
public double getAccuracy() { | ||
return accuracy; | ||
} | ||
|
||
public Double getAltitude() { | ||
return altitude; | ||
} | ||
|
||
public Double getAltitudeAccuracy() { | ||
return altitudeAccuracy; | ||
} | ||
|
||
public Double getHeading() { | ||
return heading; | ||
} | ||
|
||
public Double getSpeed() { | ||
return speed; | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("latitude", getLatitude()); | ||
map.put("longitude", getLongitude()); | ||
map.put("accuracy", getAccuracy()); | ||
if (getAltitude() != null) { | ||
map.put("altitude", getAltitude()); | ||
} | ||
if (getAltitudeAccuracy() != null) { | ||
map.put("altitudeAccuracy", getAltitudeAccuracy()); | ||
} | ||
if (getHeading() != null) { | ||
map.put("heading", getHeading()); | ||
} | ||
if (getSpeed() != null) { | ||
map.put("speed", getSpeed()); | ||
} | ||
return Map.copyOf(map); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
java/src/org/openqa/selenium/bidi/emulation/GeolocationPositionError.java
This file contains hidden or 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,28 @@ | ||
// 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.emulation; | ||
|
||
import java.util.Map; | ||
|
||
public class GeolocationPositionError { | ||
String type = "positionUnavailable"; | ||
|
||
public Map<String, Object> toMap() { | ||
return Map.of("type", type); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
java/src/org/openqa/selenium/bidi/emulation/SetGeolocationOverrideParameters.java
This file contains hidden or 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,72 @@ | ||||||
// 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.emulation; | ||||||
|
||||||
import java.util.HashMap; | ||||||
import java.util.List; | ||||||
import java.util.Map; | ||||||
|
||||||
public class SetGeolocationOverrideParameters { | ||||||
private final GeolocationCoordinates coordinates; | ||||||
private final GeolocationPositionError error; | ||||||
private final List<String> contexts; | ||||||
private final List<String> userContexts; | ||||||
|
||||||
SetGeolocationOverrideParameters( | ||||||
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. The constructor has package-private visibility, which may limit API usability. Consider making it public to allow external instantiation of parameters.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
GeolocationCoordinates coordinates, | ||||||
GeolocationPositionError error, | ||||||
List<String> contexts, | ||||||
List<String> userContexts) { | ||||||
|
||||||
this.coordinates = coordinates; | ||||||
this.error = error; | ||||||
this.contexts = contexts; | ||||||
this.userContexts = userContexts; | ||||||
|
||||||
if (this.coordinates != null && this.error != null) { | ||||||
throw new IllegalArgumentException("Cannot specify both coordinates and error"); | ||||||
} | ||||||
if (this.contexts != null && this.userContexts != null) { | ||||||
throw new IllegalArgumentException("Cannot specify both contexts and userContexts"); | ||||||
} | ||||||
|
||||||
if (this.contexts == null && this.userContexts == null) { | ||||||
throw new IllegalArgumentException("Must specify either contexts or userContexts"); | ||||||
} | ||||||
} | ||||||
|
||||||
public Map<String, Object> toMap() { | ||||||
Map<String, Object> param = new HashMap<>(); | ||||||
|
||||||
if (this.coordinates != null) { | ||||||
param.put("coordinates", this.coordinates.toMap()); | ||||||
} | ||||||
|
||||||
if (this.error != null) { | ||||||
param.put("error", this.error.toMap()); | ||||||
} | ||||||
|
||||||
if (this.contexts != null) { | ||||||
param.put("contexts", this.contexts); | ||||||
} else { | ||||||
param.put("userContexts", this.userContexts); | ||||||
} | ||||||
|
||||||
return Map.copyOf(param); | ||||||
} | ||||||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
load("@rules_jvm_external//:defs.bzl", "artifact") | ||
load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite") | ||
|
||
java_selenium_test_suite( | ||
name = "large-tests", | ||
size = "large", | ||
srcs = glob(["*Test.java"]), | ||
browsers = [ | ||
"firefox", | ||
"chrome", | ||
], | ||
tags = [ | ||
"selenium-remote", | ||
], | ||
deps = [ | ||
"//java/src/org/openqa/selenium/bidi", | ||
"//java/src/org/openqa/selenium/bidi/browsingcontext", | ||
"//java/src/org/openqa/selenium/bidi/emulation", | ||
"//java/src/org/openqa/selenium/bidi/log", | ||
"//java/src/org/openqa/selenium/bidi/module", | ||
"//java/src/org/openqa/selenium/bidi/network", | ||
"//java/src/org/openqa/selenium/bidi/script", | ||
"//java/src/org/openqa/selenium/firefox", | ||
"//java/src/org/openqa/selenium/grid/security", | ||
"//java/src/org/openqa/selenium/json", | ||
"//java/src/org/openqa/selenium/remote", | ||
"//java/src/org/openqa/selenium/support", | ||
"//java/test/org/openqa/selenium/environment", | ||
"//java/test/org/openqa/selenium/testing:annotations", | ||
"//java/test/org/openqa/selenium/testing:test-base", | ||
"//java/test/org/openqa/selenium/testing/drivers", | ||
artifact("com.google.guava:guava"), | ||
artifact("org.junit.jupiter:junit-jupiter-api"), | ||
artifact("org.assertj:assertj-core"), | ||
] + JUNIT5_DEPS, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The field should be private and final since it's not intended to be modified. Consider adding 'private final' modifiers.
Copilot uses AI. Check for mistakes.