Skip to content

Commit af6f5f3

Browse files
committed
Driver should operate cookies for the current frame, not the topmost one. Fixes issue 7799 in Firefox
1 parent e140478 commit af6f5f3

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>This page has iframes</title>
4+
</head>
5+
<body>
6+
<h1 id="iframe_page_heading">This is the heading</h1>
7+
8+
<iframe src="animals" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true"
9+
frameborder="0" height="600" scrolling="no" width="120" id="iframe1" name="iframe1-name" />
10+
</body>
11+
</html>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
210210
assertCookieIsNotPresentWithName(cookie1.getName());
211211
}
212212

213+
@Ignore(value = {ANDROID, CHROME, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})
214+
@Test
215+
public void testGetCookiesInAFrame() {
216+
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
217+
Cookie cookie1 = new Cookie.Builder("fish", "cod").path("/common/animals").build();
218+
driver.manage().addCookie(cookie1);
219+
220+
driver.get(domainHelper.getUrlForFirstValidHostname("frameWithAnimals.html"));
221+
assertCookieIsNotPresentWithName(cookie1.getName());
222+
223+
driver.switchTo().frame("iframe1");
224+
assertCookieIsPresentWithName(cookie1.getName());
225+
}
226+
213227
@Ignore({CHROME, OPERA})
214228
@Test
215229
public void testCannotGetCookiesWithPathDifferingOnlyInCase() {

javascript/firefox-driver/js/firefoxDriver.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,10 @@ FirefoxDriver.prototype.addCookie = function(respond, parameters) {
698698
}
699699

700700
if (!cookie.domain) {
701-
var location = respond.session.getBrowser().contentWindow.location;
701+
var location = respond.session.getWindow().location;
702702
cookie.domain = location.hostname;
703703
} else {
704-
var currLocation = respond.session.getBrowser().contentWindow.location;
704+
var currLocation = respond.session.getWindow().location;
705705
var currDomain = currLocation.host;
706706
if (currDomain.indexOf(cookie.domain) == -1) { // Not quite right, but close enough
707707
throw new WebDriverError(bot.ErrorCode.INVALID_COOKIE_DOMAIN,
@@ -761,8 +761,7 @@ function getVisibleCookies(location) {
761761

762762
FirefoxDriver.prototype.getCookies = function(respond) {
763763
var toReturn = [];
764-
var cookies = getVisibleCookies(respond.session.getBrowser().
765-
contentWindow.location);
764+
var cookies = getVisibleCookies(respond.session.getWindow().location);
766765
for (var i = 0; i < cookies.length; i++) {
767766
var cookie = cookies[i];
768767
var expires = cookie.expires;
@@ -792,8 +791,7 @@ FirefoxDriver.prototype.deleteCookie = function(respond, parameters) {
792791
var toDelete = parameters.name;
793792
var cm = fxdriver.moz.getService('@mozilla.org/cookiemanager;1', 'nsICookieManager');
794793

795-
var cookies = getVisibleCookies(respond.session.getBrowser().
796-
contentWindow.location);
794+
var cookies = getVisibleCookies(respond.session.getWindow().location);
797795
for (var i = 0; i < cookies.length; i++) {
798796
var cookie = cookies[i];
799797
if (cookie.name == toDelete) {
@@ -807,8 +805,7 @@ FirefoxDriver.prototype.deleteCookie = function(respond, parameters) {
807805

808806
FirefoxDriver.prototype.deleteAllCookies = function(respond) {
809807
var cm = fxdriver.moz.getService('@mozilla.org/cookiemanager;1', 'nsICookieManager');
810-
var cookies = getVisibleCookies(respond.session.getBrowser().
811-
contentWindow.location);
808+
var cookies = getVisibleCookies(respond.session.getWindow().location);
812809

813810
for (var i = 0; i < cookies.length; i++) {
814811
var cookie = cookies[i];

0 commit comments

Comments
 (0)