From b086af503ee4789f4b6d5aed9cc09a4294c37bb3 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 12 Mar 2014 11:25:19 +0400 Subject: [PATCH] Adding a new test for deleteCookie operarion (and fixing HtmlUnit implementation) --- .../selenium/htmlunit/HtmlUnitDriver.java | 14 ++++++++++++- .../selenium/CookieImplementationTest.java | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java index ac7ac3ba064a9..b7b3399e2022e 100755 --- a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java +++ b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java @@ -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() { @@ -1421,6 +1421,18 @@ public Set 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 htmlUnitCookieToSeleniumCookieTransformer = new com.google.common.base.Function() { public org.openqa.selenium.Cookie apply(com.gargoylesoftware.htmlunit.util.Cookie c) { diff --git a/java/client/test/org/openqa/selenium/CookieImplementationTest.java b/java/client/test/org/openqa/selenium/CookieImplementationTest.java index 1e3f60e562e3d..e9ae9e0c7b4e6 100644 --- a/java/client/test/org/openqa/selenium/CookieImplementationTest.java +++ b/java/client/test/org/openqa/selenium/CookieImplementationTest.java @@ -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()); }