-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java][BiDi] implement emulation.setTimezoneOverride
#16530
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
Open
Delta456
wants to merge
13
commits into
SeleniumHQ:trunk
Choose a base branch
from
Delta456:timezone
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.
Open
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
03173c2
[java][BiDi] implement `emulation.setTimezoneOverride`
Delta456 3718fe7
Merge branch 'trunk' into timezone
Delta456 8e980b3
add SFC license to files
Delta456 24142e2
Merge branch 'trunk' into timezone
navin772 38caa7c
remove redundant secure
Delta456 cf11d73
Merge branch 'trunk' into timezone
Delta456 7d456a0
Merge branch 'trunk' into timezone
Delta456 879dcfd
fix test
Delta456 428b523
account for dst
Delta456 2fad149
use code suggestions
Delta456 8ee9053
Merge branch 'trunk' into timezone
Delta456 56dd650
single import
Delta456 83841ca
Merge branch 'trunk' into timezone
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
59 changes: 59 additions & 0 deletions
59
java/src/org/openqa/selenium/bidi/emulation/AbstractOverrideParameters.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,59 @@ | ||
| // 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 abstract class AbstractOverrideParameters implements OverrideParameters { | ||
| protected final Map<String, Object> map = new HashMap<>(); | ||
|
|
||
| @Override | ||
| public OverrideParameters contexts(List<String> contexts) { | ||
| if (contexts == null || contexts.isEmpty()) { | ||
| throw new IllegalArgumentException("Contexts cannot be null or empty"); | ||
| } | ||
| if (map.containsKey("userContexts")) { | ||
| throw new IllegalArgumentException("Cannot specify both contexts and userContexts"); | ||
| } | ||
| map.put("contexts", contexts); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public OverrideParameters userContexts(List<String> userContexts) { | ||
| if (userContexts == null || userContexts.isEmpty()) { | ||
| throw new IllegalArgumentException("User contexts cannot be null or empty"); | ||
| } | ||
| if (map.containsKey("contexts")) { | ||
| throw new IllegalArgumentException("Cannot specify both contexts and userContexts"); | ||
| } | ||
| map.put("userContexts", userContexts); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> toMap() { | ||
| // Validate that either contexts or userContexts is set | ||
| if (!map.containsKey("contexts") && !map.containsKey("userContexts")) { | ||
| throw new IllegalStateException("Must specify either contexts or userContexts"); | ||
| } | ||
| return map; | ||
| } | ||
| } |
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
29 changes: 29 additions & 0 deletions
29
java/src/org/openqa/selenium/bidi/emulation/OverrideParameters.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,29 @@ | ||
| // 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.List; | ||
| import java.util.Map; | ||
|
|
||
| public interface OverrideParameters { | ||
| OverrideParameters contexts(List<String> contexts); | ||
|
|
||
| OverrideParameters userContexts(List<String> userContexts); | ||
|
|
||
| Map<String, Object> toMap(); | ||
| } |
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
37 changes: 37 additions & 0 deletions
37
java/src/org/openqa/selenium/bidi/emulation/SetTimezoneOverrideParameters.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,37 @@ | ||
| // 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; | ||
|
|
||
| public class SetTimezoneOverrideParameters extends AbstractOverrideParameters { | ||
|
|
||
| public SetTimezoneOverrideParameters(String timezone) { | ||
| map.put("timezone", timezone); | ||
| } | ||
|
|
||
| @Override | ||
| public SetTimezoneOverrideParameters contexts(java.util.List<String> contexts) { | ||
| super.contexts(contexts); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public SetTimezoneOverrideParameters userContexts(java.util.List<String> userContexts) { | ||
| super.userContexts(userContexts); | ||
| return this; | ||
| } | ||
| } |
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
141 changes: 141 additions & 0 deletions
141
java/test/org/openqa/selenium/bidi/emulation/SetTimezoneOverrideTest.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,141 @@ | ||
| // 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 static org.openqa.selenium.testing.drivers.Browser.FIREFOX; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openqa.selenium.JavascriptExecutor; | ||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.WindowType; | ||
| import org.openqa.selenium.bidi.browsingcontext.BrowsingContext; | ||
| import org.openqa.selenium.bidi.browsingcontext.CreateContextParameters; | ||
| import org.openqa.selenium.bidi.browsingcontext.ReadinessState; | ||
| import org.openqa.selenium.bidi.module.Browser; | ||
| import org.openqa.selenium.testing.Ignore; | ||
| import org.openqa.selenium.testing.JupiterTestBase; | ||
| import org.openqa.selenium.testing.NeedsFreshDriver; | ||
|
|
||
| public class SetTimezoneOverrideTest extends JupiterTestBase { | ||
| String getTimezoneString(WebDriver driver, String context) { | ||
| JavascriptExecutor executor = (JavascriptExecutor) driver; | ||
|
|
||
| driver.switchTo().window(context); | ||
| return (String) | ||
| executor.executeScript("return Intl.DateTimeFormat().resolvedOptions().timeZone;"); | ||
| } | ||
|
|
||
| Number getTimezoneOffset(WebDriver driver, String context) { | ||
| JavascriptExecutor executor = (JavascriptExecutor) driver; | ||
|
|
||
| driver.switchTo().window(context); | ||
| return (Number) executor.executeScript("return new Date().getTimezoneOffset()"); | ||
| } | ||
|
|
||
| @Test | ||
| @NeedsFreshDriver | ||
| void canSetTimezoneOverrideInContext() { | ||
| BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); | ||
| String contextId = context.getId(); | ||
|
|
||
| String url = appServer.whereIs("blank.html"); | ||
| context.navigate(url, ReadinessState.COMPLETE); | ||
|
|
||
| Emulation emul = new Emulation(driver); | ||
| String timezone = "America/Los_Angeles"; | ||
| String tzOrg = getTimezoneString(driver, contextId); | ||
| emul.setTimezoneOverride( | ||
| new SetTimezoneOverrideParameters(timezone).contexts(List.of(contextId))); | ||
|
|
||
| String tzString = getTimezoneString(driver, contextId); | ||
| Number tzOffset = getTimezoneOffset(driver, contextId); | ||
|
|
||
| assert tzString.equals(timezone) | ||
| : "Timezone string mismatch: expected " + timezone + ", got " + tzString; | ||
| assert tzOffset.intValue() == 480 : "Timezone offset mismatch: expected 480, got " + tzOffset; | ||
Delta456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| emul.setTimezoneOverride(new SetTimezoneOverrideParameters(null).contexts(List.of(contextId))); | ||
| String TzNew = getTimezoneString(driver, contextId); | ||
| assert TzNew.equals(tzOrg) : "Timezone reset failed: expected " + tzOrg + ", got " + TzNew; | ||
| } | ||
|
|
||
| @Test | ||
| @NeedsFreshDriver | ||
| void canSetTimeZoneOverrideInUserContext() { | ||
| Browser browser = new Browser(driver); | ||
| String userContext = browser.createUserContext(); | ||
|
|
||
| BrowsingContext context = | ||
| new BrowsingContext( | ||
| driver, new CreateContextParameters(WindowType.TAB).userContext(userContext)); | ||
| String contextId = context.getId(); | ||
|
|
||
| String url = appServer.whereIs("blank.html"); | ||
| context.navigate(url, ReadinessState.COMPLETE); | ||
|
|
||
| Emulation emul = new Emulation(driver); | ||
| String timezone = "Europe/London"; | ||
| String tzOrg = getTimezoneString(driver, contextId); | ||
| emul.setTimezoneOverride( | ||
| new SetTimezoneOverrideParameters(timezone).userContexts(List.of(userContext))); | ||
|
|
||
| String tzString = getTimezoneString(driver, contextId); | ||
| Number tzOffset = getTimezoneOffset(driver, contextId); | ||
|
|
||
| assert tzString.equals(timezone) | ||
| : "Timezone string mismatch: expected " + timezone + ", got " + tzString; | ||
| assert tzOffset.intValue() == 0 : "Timezone offset mismatch: expected 0, got " + tzOffset; | ||
|
|
||
| emul.setTimezoneOverride( | ||
| new SetTimezoneOverrideParameters(null).userContexts(List.of(userContext))); | ||
| String TzNew = getTimezoneString(driver, contextId); | ||
| assert TzNew.equals(tzOrg) : "Timezone reset failed: expected " + tzOrg + ", got " + TzNew; | ||
|
|
||
| context.close(); | ||
| browser.removeUserContext(userContext); | ||
| } | ||
|
|
||
| @Test | ||
| @NeedsFreshDriver | ||
| @Ignore(FIREFOX) | ||
| void canSetTimezoneOverrideUsingOffset() { | ||
| BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle()); | ||
| String contextId = context.getId(); | ||
|
|
||
| String url = appServer.whereIs("blank.html"); | ||
| context.navigate(url, ReadinessState.COMPLETE); | ||
|
|
||
| Emulation emul = new Emulation(driver); | ||
| String timezone = "+05:30"; | ||
| String tzOrg = getTimezoneString(driver, contextId); | ||
|
|
||
| emul.setTimezoneOverride( | ||
| new SetTimezoneOverrideParameters(timezone).contexts(List.of(contextId))); | ||
|
|
||
| String tzString = getTimezoneString(driver, contextId); | ||
| Number tzOffset = getTimezoneOffset(driver, contextId); | ||
|
|
||
| assert tzOffset.intValue() == -330 : "Expected timezone offset -330, got " + tzOffset; | ||
| assert tzString.equals("+05:30") : "Expected timezone '+05:30', got " + tzString; | ||
|
|
||
| emul.setTimezoneOverride(new SetTimezoneOverrideParameters(null).contexts(List.of(contextId))); | ||
| String tzNew = getTimezoneString(driver, contextId); | ||
| assert tzNew.equals(tzOrg) : "Timezone reset failed: expected " + tzOrg + ", got " + tzNew; | ||
| } | ||
| } | ||
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.