Skip to content

Commit

Permalink
Adding tests for httpOnly cookie flag
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Mar 10, 2014
1 parent 6118261 commit 2378c70
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions java/client/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@
import static org.openqa.selenium.testing.Ignore.Driver.ALL;
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
import static org.openqa.selenium.testing.Ignore.Driver.FIREFOX;
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Ignore.Driver.IE;
import static org.openqa.selenium.testing.Ignore.Driver.IPHONE;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA_MOBILE;
import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS;
import static org.openqa.selenium.testing.Ignore.Driver.REMOTE;
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;

public class CookieImplementationTest extends JUnit4TestBase {

Expand Down Expand Up @@ -359,6 +363,21 @@ public void testRetainsCookieExpiry() {
assertEquals(addedCookie.getExpiry(), retrieved.getExpiry());
}

@Ignore(value = {ANDROID, CHROME, FIREFOX, HTMLUNIT, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})
@Test
public void testRetainsHttpOnlyFlag() {
Cookie addedCookie =
new Cookie.Builder("fish", "cod")
.path("/common/animals")
.isHttpOnly(true)
.build();
driver.manage().addCookie(addedCookie);

Cookie retrieved = driver.manage().getCookieNamed("fish");
assertNotNull(retrieved);
assertTrue(retrieved.isHttpOnly());
}

@Ignore(ANDROID)
@Test
public void testSettingACookieThatExpiredInThePast() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public Date getDate() {
@Test
public void testShouldBeAbleToConvertACookie() throws JSONException {
Date expiry = new Date();
Cookie cookie = new Cookie("name", "value", "domain", "/path", expiry, true);
Cookie cookie = new Cookie("name", "value", "domain", "/path", expiry, true, true);

String jsonStr = new BeanToJsonConverter().convert(cookie);
JSONObject json = new JSONObject(jsonStr);
Expand All @@ -343,6 +343,7 @@ public void testShouldBeAbleToConvertACookie() throws JSONException {
assertEquals("domain", json.getString("domain"));
assertEquals("/path", json.getString("path"));
assertTrue(json.getBoolean("secure"));
assertTrue(json.getBoolean("httpOnly"));
assertEquals(TimeUnit.MILLISECONDS.toSeconds(expiry.getTime()), json.getLong("expiry"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void testCanHandleValueBeingAnArray() throws Exception {
@Test
public void testShouldConvertObjectsInArraysToMaps() throws Exception {
Date date = new Date();
Cookie cookie = new Cookie("foo", "bar", "/rooted", date);
Cookie cookie = new Cookie("foo", "bar", "localhost", "/rooted", date, true, true);

String rawJson = new BeanToJsonConverter().convert(Collections.singletonList(cookie));
List<?> list = new JsonToBeanConverter().convert(List.class, rawJson);
Expand All @@ -235,7 +235,10 @@ public void testShouldConvertObjectsInArraysToMaps() throws Exception {
Map<?,?> map = (Map<?,?>) first;
assertMapEntry(map, "name", "foo");
assertMapEntry(map, "value", "bar");
assertMapEntry(map, "domain", "localhost");
assertMapEntry(map, "path", "/rooted");
assertMapEntry(map, "secure", true);
assertMapEntry(map, "httpOnly", true);
assertMapEntry(map, "expiry", TimeUnit.MILLISECONDS.toSeconds(date.getTime()));
}

Expand Down

0 comments on commit 2378c70

Please sign in to comment.