Skip to content

Commit db716e5

Browse files
committed
Fix tests and address comments
1 parent 3dc9bc8 commit db716e5

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

java/src/org/openqa/selenium/bidi/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ genrule(
6060
name = "generate-bidi",
6161
srcs = ["//javascript/selenium-webdriver:create-bidi-src_schema"],
6262
outs = ["bidi-generated.srcjar"],
63-
cmd = "$(execpath :bidi-client-generator) $(location //javascript/selenium-webdriver:create-bidi-src_schema) $@",
63+
cmd = "\"$(execpath :bidi-client-generator)\" \"$(location //javascript/selenium-webdriver:create-bidi-src_schema)\" \"$@\"",
6464
tools = [":bidi-client-generator"],
6565
)
6666

java/src/org/openqa/selenium/bidi/BiDiGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,12 @@ private void appendRecordBody(
820820
appendConstructorAssignment(sb, f, domain, m + " ", needsBuilder);
821821
}
822822
if (needsExtrasCapture) {
823-
sb.append(m).append(" this.extensions = extensions;\n");
823+
// Copy rather than alias: when this constructor is called from a Builder's build(),
824+
// the argument is the Builder's own live, mutable map — a later addExtension() call
825+
// on a reused Builder must not be able to mutate an already-built instance out from
826+
// under it (the BiDi low-level behavioral contract requires a built/received instance
827+
// to stay immutable).
828+
sb.append(m).append(" this.extensions = new LinkedHashMap<>(extensions);\n");
824829
}
825830
sb.append(m).append("}\n\n");
826831
}

java/test/org/openqa/selenium/bidi/protocol/module/BrowsingContextModuleTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,18 @@ void canListenToBrowsingContextDestroyedEvent() throws Exception {
160160
BrowsingContext browsingContext = new BrowsingContext(driver);
161161
String windowHandle = driver.switchTo().newWindow(WindowType.WINDOW).getWindowHandle();
162162

163+
// CONTEXT_DESTROYED can only be subscribed globally (Module.subscribe has no per-context
164+
// overload), so an unrelated context closing during the test — e.g. a browser onboarding tab
165+
// some grid nodes auto-close shortly after launch — can also complete this. Filter to the
166+
// context this test closed instead of completing on the first event received.
163167
CompletableFuture<Info> future = new CompletableFuture<>();
164-
browsingContext.subscribe(BrowsingContext.CONTEXT_DESTROYED, future::complete);
168+
browsingContext.subscribe(
169+
BrowsingContext.CONTEXT_DESTROYED,
170+
info -> {
171+
if (windowHandle.equals(info.getContext())) {
172+
future.complete(info);
173+
}
174+
});
165175

166176
driver.close();
167177

0 commit comments

Comments
 (0)