Skip to content

Commit

Permalink
Monkey-patching W3C-compatible cookie serialization to fix Marionette…
Browse files Browse the repository at this point in the history
…. A more proper fix would be to change the parameters of a Command from Map to Object.
  • Loading branch information
barancev committed Oct 13, 2015
1 parent c4023d3 commit af83fc9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ private JsonElement convertObject(Object toConvert, int maxDepth) throws Excepti
}

if (toConvert instanceof Map) {
Map<String, Object> map = (Map<String, Object>) toConvert;
if (map.size() == 1 && map.containsKey("w3c cookie")) {
return convertObject(map.get("w3c cookie"));
}

JsonObject converted = new JsonObject();
for (Map.Entry<String, Object> entry : ((Map<String, Object>) toConvert).entrySet()) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
converted.add(entry.getKey(), convertObject(entry.getValue(), maxDepth - 1));
}
return converted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,11 @@ public Logs logs() {

public void addCookie(Cookie cookie) {
cookie.validate();
execute(DriverCommand.ADD_COOKIE, ImmutableMap.of("cookie", cookie));
if (getW3CStandardComplianceLevel() == 0) {
execute(DriverCommand.ADD_COOKIE, ImmutableMap.of("cookie", cookie));
} else {
execute(DriverCommand.ADD_COOKIE, ImmutableMap.of("w3c cookie", cookie));
}
}

public void deleteCookieNamed(String name) {
Expand Down
19 changes: 4 additions & 15 deletions java/client/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void testShouldGetCookieByName() {

@JavascriptEnabled
@Test
@Ignore(MARIONETTE)
public void testShouldBeAbleToAddCookie() {
String key = generateUniqueKey();
String value = "foo";
Expand All @@ -112,7 +111,6 @@ public void testShouldBeAbleToAddCookie() {
}

@Test
@Ignore(MARIONETTE)
public void testGetAllCookies() {
String key1 = generateUniqueKey();
String key2 = generateUniqueKey();
Expand All @@ -139,7 +137,6 @@ public void testGetAllCookies() {

@JavascriptEnabled
@Test
@Ignore(MARIONETTE)
public void testDeleteAllCookies() {
addCookieOnServerSide(new Cookie("foo", "set"));
assertSomeCookiesArePresent();
Expand Down Expand Up @@ -175,7 +172,6 @@ public void testDeleteCookieWithName() {
}

@Test
@Ignore(MARIONETTE)
public void testShouldNotDeleteCookiesWithASimilarName() {
String cookieOneName = "fish";
Cookie cookie1 = new Cookie.Builder(cookieOneName, "cod").build();
Expand All @@ -196,7 +192,6 @@ public void testShouldNotDeleteCookiesWithASimilarName() {
}

@Test
@Ignore(MARIONETTE)
public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
Cookie cookie1 = new Cookie.Builder("fish", "cod").path("/common/animals").build();
Expand All @@ -214,7 +209,7 @@ public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
assertCookieIsNotPresentWithName(cookie1.getName());
}

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

@Ignore({CHROME, MARIONETTE})
@Ignore({CHROME})
@Test
public void testCannotGetCookiesWithPathDifferingOnlyInCase() {
String cookieName = "fish";
Expand All @@ -254,7 +249,7 @@ public void testShouldNotGetCookieOnDifferentDomain() {
assertCookieIsNotPresentWithName(cookieName);
}

@Ignore(value = {CHROME, MARIONETTE})
@Ignore(value = {CHROME})
@Test
public void testShouldBeAbleToAddToADomainWhichIsRelatedToTheCurrentDomain() {
String cookieName = "name";
Expand All @@ -279,7 +274,7 @@ public void testsShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod()
assertCookieIsNotPresentWithName(cookieName);
}

@Ignore({REMOTE, MARIONETTE})
@Ignore({REMOTE})
@Test
public void testShouldBeAbleToIncludeLeadingPeriodInDomainName() throws Exception {
String cookieName = "name";
Expand All @@ -294,7 +289,6 @@ public void testShouldBeAbleToIncludeLeadingPeriodInDomainName() throws Exceptio
}

@Test
@Ignore(MARIONETTE)
public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {
URI url = new URI(driver.getCurrentUrl());
String host = url.getHost() + ":" + url.getPort();
Expand All @@ -308,7 +302,6 @@ public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {
}

@Test
@Ignore(MARIONETTE)
public void testShouldWalkThePathToDeleteACookie() {
Cookie cookie1 = new Cookie.Builder("fish", "cod").build();
driver.manage().addCookie(cookie1);
Expand Down Expand Up @@ -337,7 +330,6 @@ public void testShouldWalkThePathToDeleteACookie() {
}

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

@Test
@Ignore(MARIONETTE)
public void testCookieEqualityAfterSetAndGet() {
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));

Expand Down Expand Up @@ -465,7 +456,6 @@ public void testRetainsHttpOnlyFlag() {
}

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

@Test
@Ignore(MARIONETTE)
public void testCanSetCookieWithoutOptionalFieldsSet() {
String key = generateUniqueKey();
String value = "foo";
Expand Down

0 comments on commit af83fc9

Please sign in to comment.