Skip to content

Commit af83fc9

Browse files
committed
Monkey-patching W3C-compatible cookie serialization to fix Marionette. A more proper fix would be to change the parameters of a Command from Map to Object.
1 parent c4023d3 commit af83fc9

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

java/client/src/org/openqa/selenium/remote/BeanToJsonConverter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,13 @@ private JsonElement convertObject(Object toConvert, int maxDepth) throws Excepti
133133
}
134134

135135
if (toConvert instanceof Map) {
136+
Map<String, Object> map = (Map<String, Object>) toConvert;
137+
if (map.size() == 1 && map.containsKey("w3c cookie")) {
138+
return convertObject(map.get("w3c cookie"));
139+
}
140+
136141
JsonObject converted = new JsonObject();
137-
for (Map.Entry<String, Object> entry : ((Map<String, Object>) toConvert).entrySet()) {
142+
for (Map.Entry<String, Object> entry : map.entrySet()) {
138143
converted.add(entry.getKey(), convertObject(entry.getValue(), maxDepth - 1));
139144
}
140145
return converted;

java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,11 @@ public Logs logs() {
727727

728728
public void addCookie(Cookie cookie) {
729729
cookie.validate();
730-
execute(DriverCommand.ADD_COOKIE, ImmutableMap.of("cookie", cookie));
730+
if (getW3CStandardComplianceLevel() == 0) {
731+
execute(DriverCommand.ADD_COOKIE, ImmutableMap.of("cookie", cookie));
732+
} else {
733+
execute(DriverCommand.ADD_COOKIE, ImmutableMap.of("w3c cookie", cookie));
734+
}
731735
}
732736

733737
public void deleteCookieNamed(String name) {

java/client/test/org/openqa/selenium/CookieImplementationTest.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public void testShouldGetCookieByName() {
9696

9797
@JavascriptEnabled
9898
@Test
99-
@Ignore(MARIONETTE)
10099
public void testShouldBeAbleToAddCookie() {
101100
String key = generateUniqueKey();
102101
String value = "foo";
@@ -112,7 +111,6 @@ public void testShouldBeAbleToAddCookie() {
112111
}
113112

114113
@Test
115-
@Ignore(MARIONETTE)
116114
public void testGetAllCookies() {
117115
String key1 = generateUniqueKey();
118116
String key2 = generateUniqueKey();
@@ -139,7 +137,6 @@ public void testGetAllCookies() {
139137

140138
@JavascriptEnabled
141139
@Test
142-
@Ignore(MARIONETTE)
143140
public void testDeleteAllCookies() {
144141
addCookieOnServerSide(new Cookie("foo", "set"));
145142
assertSomeCookiesArePresent();
@@ -175,7 +172,6 @@ public void testDeleteCookieWithName() {
175172
}
176173

177174
@Test
178-
@Ignore(MARIONETTE)
179175
public void testShouldNotDeleteCookiesWithASimilarName() {
180176
String cookieOneName = "fish";
181177
Cookie cookie1 = new Cookie.Builder(cookieOneName, "cod").build();
@@ -196,7 +192,6 @@ public void testShouldNotDeleteCookiesWithASimilarName() {
196192
}
197193

198194
@Test
199-
@Ignore(MARIONETTE)
200195
public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
201196
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
202197
Cookie cookie1 = new Cookie.Builder("fish", "cod").path("/common/animals").build();
@@ -214,7 +209,7 @@ public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
214209
assertCookieIsNotPresentWithName(cookie1.getName());
215210
}
216211

217-
@Ignore(value = {CHROME, PHANTOMJS, SAFARI, MARIONETTE})
212+
@Ignore(value = {CHROME, PHANTOMJS, SAFARI})
218213
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
219214
@Test
220215
public void testGetCookiesInAFrame() {
@@ -229,7 +224,7 @@ public void testGetCookiesInAFrame() {
229224
assertCookieIsPresentWithName(cookie1.getName());
230225
}
231226

232-
@Ignore({CHROME, MARIONETTE})
227+
@Ignore({CHROME})
233228
@Test
234229
public void testCannotGetCookiesWithPathDifferingOnlyInCase() {
235230
String cookieName = "fish";
@@ -254,7 +249,7 @@ public void testShouldNotGetCookieOnDifferentDomain() {
254249
assertCookieIsNotPresentWithName(cookieName);
255250
}
256251

257-
@Ignore(value = {CHROME, MARIONETTE})
252+
@Ignore(value = {CHROME})
258253
@Test
259254
public void testShouldBeAbleToAddToADomainWhichIsRelatedToTheCurrentDomain() {
260255
String cookieName = "name";
@@ -279,7 +274,7 @@ public void testsShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod()
279274
assertCookieIsNotPresentWithName(cookieName);
280275
}
281276

282-
@Ignore({REMOTE, MARIONETTE})
277+
@Ignore({REMOTE})
283278
@Test
284279
public void testShouldBeAbleToIncludeLeadingPeriodInDomainName() throws Exception {
285280
String cookieName = "name";
@@ -294,7 +289,6 @@ public void testShouldBeAbleToIncludeLeadingPeriodInDomainName() throws Exceptio
294289
}
295290

296291
@Test
297-
@Ignore(MARIONETTE)
298292
public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {
299293
URI url = new URI(driver.getCurrentUrl());
300294
String host = url.getHost() + ":" + url.getPort();
@@ -308,7 +302,6 @@ public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {
308302
}
309303

310304
@Test
311-
@Ignore(MARIONETTE)
312305
public void testShouldWalkThePathToDeleteACookie() {
313306
Cookie cookie1 = new Cookie.Builder("fish", "cod").build();
314307
driver.manage().addCookie(cookie1);
@@ -337,7 +330,6 @@ public void testShouldWalkThePathToDeleteACookie() {
337330
}
338331

339332
@Test
340-
@Ignore(MARIONETTE)
341333
public void testShouldIgnoreThePortNumberOfTheHostWhenSettingTheCookie() throws Exception {
342334
URI uri = new URI(driver.getCurrentUrl());
343335
String host = String.format("%s:%d", uri.getHost(), uri.getPort());
@@ -352,7 +344,6 @@ public void testShouldIgnoreThePortNumberOfTheHostWhenSettingTheCookie() throws
352344
}
353345

354346
@Test
355-
@Ignore(MARIONETTE)
356347
public void testCookieEqualityAfterSetAndGet() {
357348
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));
358349

@@ -465,7 +456,6 @@ public void testRetainsHttpOnlyFlag() {
465456
}
466457

467458
@Test
468-
@Ignore(MARIONETTE)
469459
public void testSettingACookieThatExpiredInThePast() {
470460
long expires = System.currentTimeMillis() - 1000;
471461
Cookie cookie = new Cookie.Builder("expired", "yes").expiresOn(new Date(expires)).build();
@@ -477,7 +467,6 @@ public void testSettingACookieThatExpiredInThePast() {
477467
}
478468

479469
@Test
480-
@Ignore(MARIONETTE)
481470
public void testCanSetCookieWithoutOptionalFieldsSet() {
482471
String key = generateUniqueKey();
483472
String value = "foo";

0 commit comments

Comments
 (0)