Skip to content

Commit fd27a60

Browse files
authored
Merge branch 'trunk' into greedy-slot-selector
2 parents 7d82d92 + b73da5e commit fd27a60

File tree

6 files changed

+965
-16
lines changed

6 files changed

+965
-16
lines changed

java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ public List<BrowsingContextInfo> getTree() {
148148
"browsingContext.getTree", Map.of("root", id), browsingContextInfoListMapper));
149149
}
150150

151+
public List<BrowsingContextInfo> getTree(String root) {
152+
return this.bidi.send(
153+
new Command<>(
154+
"browsingContext.getTree", Map.of("root", root), browsingContextInfoListMapper));
155+
}
156+
151157
public List<BrowsingContextInfo> getTree(int maxDepth) {
152158
return this.bidi.send(
153159
new Command<>(
@@ -158,6 +164,16 @@ public List<BrowsingContextInfo> getTree(int maxDepth) {
158164
browsingContextInfoListMapper));
159165
}
160166

167+
public List<BrowsingContextInfo> getTree(String root, int maxDepth) {
168+
return this.bidi.send(
169+
new Command<>(
170+
"browsingContext.getTree",
171+
Map.of(
172+
"root", root,
173+
"maxDepth", maxDepth),
174+
browsingContextInfoListMapper));
175+
}
176+
161177
public List<BrowsingContextInfo> getTopLevelContexts() {
162178
return this.bidi.send(
163179
new Command<>("browsingContext.getTree", new HashMap<>(), browsingContextInfoListMapper));

java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInfo.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public class BrowsingContextInfo {
3030

3131
private final List<BrowsingContextInfo> children;
3232

33+
private final String clientWindow;
34+
35+
private final String originalOpener;
36+
37+
private final String userContext;
38+
3339
private final String parentBrowsingContext;
3440

3541
public String getId() {
@@ -44,22 +50,46 @@ public List<BrowsingContextInfo> getChildren() {
4450
return children;
4551
}
4652

53+
public String getClientWindow() {
54+
return clientWindow;
55+
}
56+
57+
public String getOriginalOpener() {
58+
return originalOpener;
59+
}
60+
61+
public String getUserContext() {
62+
return userContext;
63+
}
64+
4765
public String getParentBrowsingContext() {
4866
return parentBrowsingContext;
4967
}
5068

5169
public BrowsingContextInfo(
52-
String id, String url, List<BrowsingContextInfo> children, String parentBrowsingContext) {
70+
String id,
71+
String url,
72+
List<BrowsingContextInfo> children,
73+
String clientWindow,
74+
String originalOpener,
75+
String userContext,
76+
String parentBrowsingContext) {
5377
this.id = id;
5478
this.url = url;
5579
this.children = children;
80+
this.clientWindow = clientWindow;
81+
this.originalOpener = originalOpener;
82+
this.userContext = userContext;
5683
this.parentBrowsingContext = parentBrowsingContext;
5784
}
5885

5986
public static BrowsingContextInfo fromJson(JsonInput input) {
6087
String id = null;
6188
String url = null;
6289
List<BrowsingContextInfo> children = null;
90+
String clientWindow = null;
91+
String originalOpener = null;
92+
String userContext = null;
6393
String parentBrowsingContext = null;
6494

6595
input.beginObject();
@@ -81,6 +111,18 @@ public static BrowsingContextInfo fromJson(JsonInput input) {
81111
parentBrowsingContext = input.read(String.class);
82112
break;
83113

114+
case "clientWindow":
115+
clientWindow = input.read(String.class);
116+
break;
117+
118+
case "originalOpener":
119+
originalOpener = input.read(String.class);
120+
break;
121+
122+
case "userContext":
123+
userContext = input.read(String.class);
124+
break;
125+
84126
default:
85127
input.skipValue();
86128
break;
@@ -89,6 +131,7 @@ public static BrowsingContextInfo fromJson(JsonInput input) {
89131

90132
input.endObject();
91133

92-
return new BrowsingContextInfo(id, url, children, parentBrowsingContext);
134+
return new BrowsingContextInfo(
135+
id, url, children, clientWindow, originalOpener, userContext, parentBrowsingContext);
93136
}
94137
}

java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,52 @@ void canGetTreeWithDepth() {
159159
BrowsingContextInfo info = contextInfoList.get(0);
160160
assertThat(info.getChildren()).isNull(); // since depth is 0
161161
assertThat(info.getId()).isEqualTo(referenceContextId);
162+
assertThat(info.getOriginalOpener()).isNull();
163+
assertThat(info.getClientWindow()).isNotNull();
164+
assertThat(info.getUserContext()).isEqualTo("default");
165+
}
166+
167+
@Test
168+
@NeedsFreshDriver
169+
void canGetTreeWithRootAndDepth() {
170+
String referenceContextId = driver.getWindowHandle();
171+
BrowsingContext parentWindow = new BrowsingContext(driver, referenceContextId);
172+
173+
String url = appServer.whereIs("iframes.html");
174+
175+
parentWindow.navigate(url, ReadinessState.COMPLETE);
176+
177+
List<BrowsingContextInfo> contextInfoList = parentWindow.getTree(referenceContextId, 1);
178+
179+
assertThat(contextInfoList.size()).isEqualTo(1);
180+
BrowsingContextInfo info = contextInfoList.get(0);
181+
assertThat(info.getChildren()).isNotNull(); // since depth is 1
182+
assertThat(info.getId()).isEqualTo(referenceContextId);
183+
assertThat(info.getOriginalOpener()).isNull();
184+
assertThat(info.getClientWindow()).isNotNull();
185+
assertThat(info.getUserContext()).isEqualTo("default");
186+
}
187+
188+
@Test
189+
@NeedsFreshDriver
190+
void canGetTreeWithRoot() {
191+
String referenceContextId = driver.getWindowHandle();
192+
BrowsingContext parentWindow = new BrowsingContext(driver, referenceContextId);
193+
194+
String url = appServer.whereIs("iframes.html");
195+
196+
parentWindow.navigate(url, ReadinessState.COMPLETE);
197+
198+
BrowsingContext tab = new BrowsingContext(driver, WindowType.TAB);
199+
200+
List<BrowsingContextInfo> contextInfoList = parentWindow.getTree(tab.getId());
201+
202+
assertThat(contextInfoList.size()).isEqualTo(1);
203+
BrowsingContextInfo info = contextInfoList.get(0);
204+
assertThat(info.getId()).isEqualTo(tab.getId());
205+
assertThat(info.getOriginalOpener()).isNull();
206+
assertThat(info.getClientWindow()).isNotNull();
207+
assertThat(info.getUserContext()).isEqualTo("default");
162208
}
163209

164210
@Test

0 commit comments

Comments
 (0)