Skip to content

Commit 46b3ac6

Browse files
committed
[bidi][java] Add window proxy properties class
1 parent e7d902e commit 46b3ac6

File tree

3 files changed

+107
-4
lines changed

3 files changed

+107
-4
lines changed

java/src/org/openqa/selenium/bidi/script/RemoteValue.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ private Map<String, Object> toJson() {
193193
}
194194

195195
private static Object deserializeValue(Object value, Type type) {
196+
Object finalValue;
196197

197198
switch (type) {
198199
case ARRAY:
199200
case SET:
200201
try (StringReader reader = new StringReader(JSON.toJson(value));
201202
JsonInput input = JSON.newInput(reader)) {
202-
value = input.read(new TypeToken<List<RemoteValue>>() {}.getType());
203+
finalValue = input.read(new TypeToken<List<RemoteValue>>() {}.getType());
203204
}
204205
break;
205206

@@ -222,16 +223,27 @@ private static Object deserializeValue(Object value, Type type) {
222223
map.put(key, value1);
223224
}
224225
}
225-
value = map;
226+
finalValue = map;
226227
break;
227228

228229
case REGULAR_EXPRESSION:
229230
try (StringReader reader = new StringReader(JSON.toJson(value));
230231
JsonInput input = JSON.newInput(reader)) {
231-
value = input.read(RegExpValue.class);
232+
finalValue = input.read(RegExpValue.class);
232233
}
234+
break;
235+
236+
case WINDOW:
237+
try (StringReader reader = new StringReader(JSON.toJson(value));
238+
JsonInput input = JSON.newInput(reader)) {
239+
finalValue = input.read(WindowProxyProperties.class);
240+
}
241+
break;
242+
243+
default:
244+
finalValue = value;
233245
}
234246

235-
return value;
247+
return finalValue;
236248
}
237249
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
package org.openqa.selenium.bidi.script;
18+
19+
import org.openqa.selenium.json.JsonInput;
20+
21+
public class WindowProxyProperties {
22+
23+
private final String browsingContext;
24+
25+
private WindowProxyProperties(String browsingContext) {
26+
this.browsingContext = browsingContext;
27+
}
28+
29+
public static WindowProxyProperties fromJson(JsonInput input) {
30+
String browsingContext = null;
31+
32+
input.beginObject();
33+
while (input.hasNext()) {
34+
switch (input.nextName()) {
35+
case "context":
36+
browsingContext = input.read(String.class);
37+
break;
38+
39+
default:
40+
input.skipValue();
41+
break;
42+
}
43+
}
44+
45+
input.endObject();
46+
47+
return new WindowProxyProperties(browsingContext);
48+
}
49+
50+
public String getBrowsingContext() {
51+
return browsingContext;
52+
}
53+
}

java/test/org/openqa/selenium/bidi/script/ScriptCommandsTest.java

+38
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.junit.jupiter.api.AfterEach;
3939
import org.junit.jupiter.api.BeforeEach;
4040
import org.junit.jupiter.api.Test;
41+
import org.openqa.selenium.By;
4142
import org.openqa.selenium.WebDriverException;
4243
import org.openqa.selenium.WindowType;
4344
import org.openqa.selenium.bidi.LogInspector;
@@ -114,6 +115,43 @@ void canCallFunctionWithArguments() {
114115
assertThat(((List<Object>) successResult.getResult().getValue().get()).size()).isEqualTo(2);
115116
}
116117

118+
@Test
119+
@NotYetImplemented(SAFARI)
120+
@NotYetImplemented(IE)
121+
@NotYetImplemented(EDGE)
122+
@NotYetImplemented(CHROME)
123+
void canCallFunctionToGetIFrameBrowsingContext() {
124+
String url = appServer.whereIs("click_too_big_in_frame.html");
125+
driver.get(url);
126+
127+
driver.findElement(By.id("iframe1"));
128+
129+
String id = driver.getWindowHandle();
130+
Script script = new Script(id, driver);
131+
132+
List<LocalValue> arguments = new ArrayList<>();
133+
134+
EvaluateResult result =
135+
script.callFunctionInBrowsingContext(
136+
id,
137+
"() => document.querySelector('iframe[id=\"iframe1\"]').contentWindow",
138+
false,
139+
Optional.of(arguments),
140+
Optional.empty(),
141+
Optional.empty());
142+
143+
assertThat(result.getResultType()).isEqualTo(EvaluateResult.Type.SUCCESS);
144+
assertThat(result.getRealmId()).isNotNull();
145+
146+
EvaluateResultSuccess successResult = (EvaluateResultSuccess) result;
147+
assertThat(successResult.getResult().getType()).isEqualTo("window");
148+
assertThat(successResult.getResult().getValue().isPresent()).isTrue();
149+
assertThat(
150+
((WindowProxyProperties) successResult.getResult().getValue().get())
151+
.getBrowsingContext())
152+
.isNotNull();
153+
}
154+
117155
@Test
118156
@NotYetImplemented(SAFARI)
119157
@NotYetImplemented(IE)

0 commit comments

Comments
 (0)