Skip to content

Commit

Permalink
Adding a new test for deleteCookie operarion (and fixing HtmlUnit imp…
Browse files Browse the repository at this point in the history
…lementation)
  • Loading branch information
barancev committed Mar 12, 2014
1 parent c71bf52 commit b086af5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ public void deleteCookieNamed(String name) {
}

public void deleteCookie(Cookie cookie) {
deleteCookieNamed(cookie.getName());
getWebClient().getCookieManager().removeCookie(convertSeleniumCookieToHtmlUnit(cookie));
}

public void deleteAllCookies() {
Expand All @@ -1421,6 +1421,18 @@ public Set<Cookie> getCookies() {
htmlUnitCookieToSeleniumCookieTransformer));
}

private com.gargoylesoftware.htmlunit.util.Cookie convertSeleniumCookieToHtmlUnit(Cookie cookie) {
return new com.gargoylesoftware.htmlunit.util.Cookie(
cookie.getDomain(),
cookie.getName(),
cookie.getValue(),
cookie.getPath(),
cookie.getExpiry(),
cookie.isSecure(),
cookie.isHttpOnly()
);
}

private final com.google.common.base.Function<? super com.gargoylesoftware.htmlunit.util.Cookie, org.openqa.selenium.Cookie> htmlUnitCookieToSeleniumCookieTransformer =
new com.google.common.base.Function<com.gargoylesoftware.htmlunit.util.Cookie, org.openqa.selenium.Cookie>() {
public org.openqa.selenium.Cookie apply(com.gargoylesoftware.htmlunit.util.Cookie c) {
Expand Down
21 changes: 21 additions & 0 deletions java/client/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,27 @@ public void testDeleteNotExistedCookie() {
driver.manage().deleteCookieNamed(key);
}

@Ignore(value = {ANDROID, CHROME, FIREFOX, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})
@Test
public void testShouldDeleteOneOfTheCookiesWithTheSameName() {
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
Cookie cookie1 = new Cookie.Builder("fish", "cod")
.domain(domainHelper.getHostName()).path("/common/animals").build();
Cookie cookie2 = new Cookie.Builder("fish", "tune")
.domain(domainHelper.getHostName()).path("/common/").build();
WebDriver.Options options = driver.manage();
options.addCookie(cookie1);
options.addCookie(cookie2);
assertEquals(driver.manage().getCookies().size(), 2);

driver.manage().deleteCookie(cookie1);

assertEquals(driver.manage().getCookies().size(), 1);
Cookie retrieved = driver.manage().getCookieNamed("fish");
assertNotNull("Cookie was null", retrieved);
assertEquals(cookie2, retrieved);
}

private String generateUniqueKey() {
return String.format("key_%d", random.nextInt());
}
Expand Down

0 comments on commit b086af5

Please sign in to comment.