Skip to content

Commit 5609fbc

Browse files
authored
[java][bidi]: add test for onHistoryUpdated event (#16293)
1 parent 72a925a commit 5609fbc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.openqa.selenium.testing.drivers.Browser.*;
2222

2323
import java.util.List;
24+
import java.util.Optional;
2425
import java.util.concurrent.CompletableFuture;
2526
import java.util.concurrent.ExecutionException;
2627
import java.util.concurrent.TimeUnit;
@@ -29,6 +30,7 @@
2930
import org.openqa.selenium.By;
3031
import org.openqa.selenium.WindowType;
3132
import org.openqa.selenium.bidi.module.BrowsingContextInspector;
33+
import org.openqa.selenium.bidi.module.Script;
3234
import org.openqa.selenium.testing.JupiterTestBase;
3335
import org.openqa.selenium.testing.NeedsFreshDriver;
3436
import org.openqa.selenium.testing.NotYetImplemented;
@@ -278,4 +280,27 @@ void canListenToNavigationFailedEvent()
278280
.isEqualTo("http://invalid-domain-that-does-not-exist.test/");
279281
}
280282
}
283+
284+
@Test
285+
@NeedsFreshDriver
286+
void canListenToHistoryUpdatedEvent()
287+
throws ExecutionException, InterruptedException, TimeoutException {
288+
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver);
289+
Script script = new Script(driver)) {
290+
CompletableFuture<HistoryUpdated> future = new CompletableFuture<>();
291+
292+
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
293+
context.navigate(appServer.whereIs("/simpleTest.html"), ReadinessState.COMPLETE);
294+
295+
inspector.onHistoryUpdated(future::complete);
296+
297+
// Use history.pushState to trigger history updated event
298+
script.evaluateFunctionInBrowsingContext(
299+
context.getId(), "history.pushState({}, '', '/new-path')", false, Optional.empty());
300+
301+
HistoryUpdated historyUpdated = future.get(5, TimeUnit.SECONDS);
302+
assertThat(historyUpdated.getBrowsingContextId()).isEqualTo(context.getId());
303+
assertThat(historyUpdated.getUrl()).contains("/new-path");
304+
}
305+
}
281306
}

0 commit comments

Comments
 (0)