-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
24 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 1a5e178
commit workaround
Delta456 2a0e969
cleanup
Delta456 2892f69
remove extra flags
Delta456 a68bbfb
Merge branch 'trunk' into java_bidi_emulation
Delta456 c9e057d
add telescoping constructors
Delta456 70c56a5
Merge branch 'trunk' into java_bidi_emulation
pujagani ef53996
use PartialCookie approach
Delta456 155e875
use java pattern for setgeolocationoverrideparameters
Delta456 bd1a194
fmt
Delta456 654a72b
fmt x2
Delta456 725f4ac
Merge branch 'trunk' into java_bidi_emulation
Delta456 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)); | ||
| } | ||
| } |
118 changes: 118 additions & 0 deletions
118
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,118 @@ | ||
| // 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 Map<String, Object> map = new HashMap<>(); | ||
|
|
||
| public GeolocationCoordinates(double latitude, double longitude) { | ||
| 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"); | ||
| } | ||
|
|
||
| map.put("latitude", latitude); | ||
| map.put("longitude", longitude); | ||
| map.put("accuracy", 1.0); // Default accuracy | ||
| } | ||
|
|
||
| public GeolocationCoordinates accuracy(double accuracy) { | ||
| if (accuracy < 0.0) { | ||
| throw new IllegalArgumentException("Accuracy must be >= 0.0"); | ||
| } | ||
| map.put("accuracy", accuracy); | ||
| return this; | ||
| } | ||
|
|
||
| public GeolocationCoordinates altitude(Double altitude) { | ||
| if (altitude != null) { | ||
| map.put("altitude", altitude); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public GeolocationCoordinates altitudeAccuracy(Double altitudeAccuracy) { | ||
| if (altitudeAccuracy != null) { | ||
| if (!map.containsKey("altitude")) { | ||
| throw new IllegalArgumentException("altitudeAccuracy cannot be set without altitude"); | ||
| } | ||
| if (altitudeAccuracy < 0.0) { | ||
| throw new IllegalArgumentException("Altitude accuracy must be >= 0.0"); | ||
| } | ||
| map.put("altitudeAccuracy", altitudeAccuracy); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public GeolocationCoordinates heading(Double heading) { | ||
| if (heading != null) { | ||
| if (heading < 0.0 || heading >= 360.0) { | ||
| throw new IllegalArgumentException("Heading must be between 0.0 and 360.0"); | ||
| } | ||
| map.put("heading", heading); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public GeolocationCoordinates speed(Double speed) { | ||
| if (speed != null) { | ||
| if (speed < 0.0) { | ||
| throw new IllegalArgumentException("Speed must be >= 0.0"); | ||
| } | ||
| map.put("speed", speed); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public double getLatitude() { | ||
| return (Double) map.get("latitude"); | ||
| } | ||
|
|
||
| public double getLongitude() { | ||
| return (Double) map.get("longitude"); | ||
| } | ||
|
|
||
| public double getAccuracy() { | ||
| return (Double) map.get("accuracy"); | ||
| } | ||
|
|
||
| public Double getAltitude() { | ||
| return (Double) map.get("altitude"); | ||
| } | ||
|
|
||
| public Double getAltitudeAccuracy() { | ||
| return (Double) map.get("altitudeAccuracy"); | ||
| } | ||
|
|
||
| public Double getHeading() { | ||
| return (Double) map.get("heading"); | ||
| } | ||
|
|
||
| public Double getSpeed() { | ||
| return (Double) map.get("speed"); | ||
| } | ||
|
|
||
| public Map<String, Object> toMap() { | ||
| 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 { | ||
|
|
||
| public Map<String, Object> toMap() { | ||
| String type = "positionUnavailable"; | ||
| return Map.of("type", type); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
| // 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; | ||
|
|
||
| public SetGeolocationOverrideParameters( | ||
| GeolocationCoordinates coordinates, | ||
| GeolocationPositionError error, | ||
| List<String> contexts, | ||
| List<String> userContexts) { | ||
|
|
||
| this.coordinates = coordinates; | ||
| this.error = error; | ||
| this.contexts = contexts; | ||
Delta456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.userContexts = userContexts; | ||
|
|
||
| if (this.coordinates != null && this.error != null) { | ||
| throw new IllegalArgumentException("Cannot specify both coordinates and error"); | ||
| } | ||
Delta456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 SetGeolocationOverrideParameters( | ||
| GeolocationCoordinates coordinates, GeolocationPositionError error) { | ||
| this(coordinates, error, null, null); | ||
| } | ||
|
|
||
| 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,37 @@ | ||
| 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", | ||
| "edge", | ||
| ], | ||
| 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.
Uh oh!
There was an error while loading. Please reload this page.