Skip to content

Commit dc6cb18

Browse files
authored
Merge branch 'trunk' into remove_js_dossiar_ref
2 parents 651447e + 015ad63 commit dc6cb18

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

java/test/org/openqa/selenium/bidi/storage/StorageCommandsTest.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import org.openqa.selenium.Cookie;
3131
import org.openqa.selenium.JavascriptExecutor;
3232
import org.openqa.selenium.WindowType;
33+
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
34+
import org.openqa.selenium.bidi.browsingcontext.CreateContextParameters;
35+
import org.openqa.selenium.bidi.module.Browser;
3336
import org.openqa.selenium.bidi.module.Storage;
3437
import org.openqa.selenium.bidi.network.BytesValue;
3538
import org.openqa.selenium.testing.JupiterTestBase;
@@ -121,8 +124,57 @@ public void canGetCookieInDefaultUserContext() {
121124
}
122125

123126
@Test
124-
// TODO: Once Browser module is added this test needs to be added
125-
public void canGetCookieInAUserContext() {}
127+
@NotYetImplemented(EDGE)
128+
public void canGetCookieInAUserContext() {
129+
Browser browser = new Browser(driver);
130+
String userContext = browser.createUserContext();
131+
String windowHandle = driver.getWindowHandle();
132+
133+
String key = generateUniqueKey();
134+
String value = "set";
135+
136+
PartitionDescriptor descriptor = new StorageKeyPartitionDescriptor().userContext(userContext);
137+
138+
SetCookieParameters parameters =
139+
new SetCookieParameters(
140+
new PartialCookie(
141+
key, new BytesValue(BytesValue.Type.STRING, value), appServer.getHostName()),
142+
descriptor);
143+
144+
storage.setCookie(parameters);
145+
146+
CookieFilter cookieFilter = new CookieFilter();
147+
cookieFilter.name(key);
148+
cookieFilter.value(new BytesValue(BytesValue.Type.STRING, "set"));
149+
150+
BrowsingContext context =
151+
new BrowsingContext(
152+
driver, new CreateContextParameters(WindowType.TAB).userContext(userContext));
153+
154+
driver.switchTo().window(context.getId());
155+
156+
GetCookiesParameters params = new GetCookiesParameters(cookieFilter, descriptor);
157+
158+
GetCookiesResult result = storage.getCookies(params);
159+
160+
assertThat(result.getCookies().get(0).getValue().getValue()).isEqualTo(value);
161+
PartitionKey partitionKey = result.getPartitionKey();
162+
163+
assertThat(partitionKey.getUserContext()).isNotNull();
164+
assertThat(partitionKey.getUserContext()).isEqualTo(userContext);
165+
166+
driver.switchTo().window(windowHandle);
167+
168+
PartitionDescriptor browsingContextPartitionDescriptor =
169+
new BrowsingContextPartitionDescriptor(windowHandle);
170+
171+
GetCookiesParameters params1 =
172+
new GetCookiesParameters(cookieFilter, browsingContextPartitionDescriptor);
173+
174+
GetCookiesResult result1 = storage.getCookies(params1);
175+
176+
assertThat(result1.getCookies().size()).isEqualTo(0);
177+
}
126178

127179
@Test
128180
@NotYetImplemented(EDGE)

0 commit comments

Comments
 (0)