diff --git a/java/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java b/java/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java index def00538d645e..e3cccf69209c4 100644 --- a/java/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java +++ b/java/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java @@ -30,6 +30,9 @@ import org.openqa.selenium.Cookie; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WindowType; +import org.openqa.selenium.bidi.browsingcontext.BrowsingContext; +import org.openqa.selenium.bidi.browsingcontext.CreateContextParameters; +import org.openqa.selenium.bidi.module.Browser; import org.openqa.selenium.bidi.module.Storage; import org.openqa.selenium.bidi.network.BytesValue; import org.openqa.selenium.testing.JupiterTestBase; @@ -121,8 +124,57 @@ public void canGetCookieInDefaultUserContext() { } @Test - // TODO: Once Browser module is added this test needs to be added - public void canGetCookieInAUserContext() {} + @NotYetImplemented(EDGE) + public void canGetCookieInAUserContext() { + Browser browser = new Browser(driver); + String userContext = browser.createUserContext(); + String windowHandle = driver.getWindowHandle(); + + String key = generateUniqueKey(); + String value = "set"; + + PartitionDescriptor descriptor = new StorageKeyPartitionDescriptor().userContext(userContext); + + SetCookieParameters parameters = + new SetCookieParameters( + new PartialCookie( + key, new BytesValue(BytesValue.Type.STRING, value), appServer.getHostName()), + descriptor); + + storage.setCookie(parameters); + + CookieFilter cookieFilter = new CookieFilter(); + cookieFilter.name(key); + cookieFilter.value(new BytesValue(BytesValue.Type.STRING, "set")); + + BrowsingContext context = + new BrowsingContext( + driver, new CreateContextParameters(WindowType.TAB).userContext(userContext)); + + driver.switchTo().window(context.getId()); + + GetCookiesParameters params = new GetCookiesParameters(cookieFilter, descriptor); + + GetCookiesResult result = storage.getCookies(params); + + assertThat(result.getCookies().get(0).getValue().getValue()).isEqualTo(value); + PartitionKey partitionKey = result.getPartitionKey(); + + assertThat(partitionKey.getUserContext()).isNotNull(); + assertThat(partitionKey.getUserContext()).isEqualTo(userContext); + + driver.switchTo().window(windowHandle); + + PartitionDescriptor browsingContextPartitionDescriptor = + new BrowsingContextPartitionDescriptor(windowHandle); + + GetCookiesParameters params1 = + new GetCookiesParameters(cookieFilter, browsingContextPartitionDescriptor); + + GetCookiesResult result1 = storage.getCookies(params1); + + assertThat(result1.getCookies().size()).isEqualTo(0); + } @Test @NotYetImplemented(EDGE)