Skip to content

Commit 2be5dd9

Browse files
committed
add ClientWindowState enum and active bool field
1 parent f783dd5 commit 2be5dd9

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

java/src/org/openqa/selenium/bidi/browser/ClientWindowInfo.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,46 @@
2121

2222
public class ClientWindowInfo {
2323
private final String clientWindow;
24-
private final String state;
24+
private final ClientWindowState state;
2525
private final Integer width;
2626
private final Integer height;
2727
private final Integer x;
2828
private final Integer y;
29+
private final boolean active;
2930

3031
public ClientWindowInfo(
31-
String clientWindow, String state, Integer width, Integer height, Integer x, Integer y) {
32+
String clientWindow,
33+
ClientWindowState state,
34+
Integer width,
35+
Integer height,
36+
Integer x,
37+
Integer y,
38+
boolean active) {
3239
this.clientWindow = clientWindow;
3340
this.state = state;
3441
this.width = width;
3542
this.height = height;
3643
this.x = x;
3744
this.y = y;
45+
this.active = active;
3846
}
3947

4048
public static ClientWindowInfo fromJson(Map<String, Object> map) {
4149
return new ClientWindowInfo(
4250
(String) map.get("clientWindow"),
43-
(String) map.get("state"),
51+
ClientWindowState.fromString((String) map.get("state")),
4452
((Number) map.get("width")).intValue(),
4553
((Number) map.get("height")).intValue(),
4654
((Number) map.get("x")).intValue(),
47-
((Number) map.get("y")).intValue());
55+
((Number) map.get("y")).intValue(),
56+
(Boolean) map.get("active"));
4857
}
4958

5059
public String getClientWindow() {
5160
return clientWindow;
5261
}
5362

54-
public String getState() {
63+
public ClientWindowState getState() {
5564
return state;
5665
}
5766

@@ -70,4 +79,8 @@ public Integer getX() {
7079
public Integer getY() {
7180
return y;
7281
}
82+
83+
public boolean isActive() {
84+
return active;
85+
}
7386
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.browser;
19+
20+
public enum ClientWindowState {
21+
FULLSCREEN("fullscreen"),
22+
MAXIMIZED("maximized"),
23+
MINIMIZED("minimized"),
24+
NORMAL("normal");
25+
26+
private final String state;
27+
28+
ClientWindowState(String state) {
29+
this.state = state;
30+
}
31+
32+
public String toString() {
33+
return state;
34+
}
35+
36+
public static ClientWindowState fromString(String state) {
37+
for (ClientWindowState windowState : values()) {
38+
if (windowState.state.equals(state)) {
39+
return windowState;
40+
}
41+
}
42+
throw new IllegalArgumentException("Invalid window state: " + state);
43+
}
44+
}

java/test/org/openqa/selenium/bidi/browser/BrowserCommandsTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ void canGetClientWindows() {
8686

8787
ClientWindowInfo windowInfo = clientWindows.get(0);
8888
assertThat(windowInfo.getClientWindow()).isNotNull();
89-
assertThat(windowInfo.getState()).isNotNull();
89+
assertThat(windowInfo.getState()).isInstanceOf(ClientWindowState.class);
90+
assertThat(windowInfo.getWidth()).isGreaterThan(0);
91+
assertThat(windowInfo.getHeight()).isGreaterThan(0);
92+
assertThat(windowInfo.isActive()).isIn(true, false);
9093
}
9194
}

0 commit comments

Comments
 (0)