mirror of
https://github.com/appium/appium.git
synced 2026-02-09 19:28:48 -06:00
Merge pull request #3350 from 0x1mason/1708_2
Fixed issue #1708: delete cookie inconsitency in Safari
This commit is contained in:
@@ -1879,20 +1879,32 @@ iOSController.getCookies = function (cb) {
|
||||
};
|
||||
|
||||
iOSController.setCookie = function (cookie, cb) {
|
||||
var expiry = null;
|
||||
if (!this.isWebContext()) {
|
||||
return cb(new NotImplementedError(), null);
|
||||
}
|
||||
|
||||
var webCookie = encodeURIComponent(cookie.name) + "=" +
|
||||
encodeURIComponent(cookie.value);
|
||||
if (cookie.value !== "" && typeof cookie.expiry === "number") {
|
||||
expiry = (new Date(cookie.expiry * 1000)).toGMTString();
|
||||
} else if (cookie.value === "") {
|
||||
expiry = (new Date(0)).toGMTString();
|
||||
|
||||
var expiry = cookie.expiry || null;
|
||||
|
||||
if (!expiry && cookie.value === "") {
|
||||
expiry = (new Date(0)).toUTCString();
|
||||
} else if (expiry && typeof expiry === "number") {
|
||||
expiry = (new Date(expiry * 1000)).toUTCString();
|
||||
}
|
||||
|
||||
if (expiry) {
|
||||
webCookie += "; expires=" + expiry;
|
||||
}
|
||||
|
||||
// if 'Path' field is not specified, Safari will not update cookies as expected; eg issue #1708
|
||||
if (!cookie.path) {
|
||||
cookie.path = "/";
|
||||
}
|
||||
|
||||
webCookie += ";path=" + cookie.path;
|
||||
|
||||
var script = "document.cookie = " + JSON.stringify(webCookie);
|
||||
this.executeAtom('execute_script', [script, []], function (err, res) {
|
||||
if (this.checkSuccess(err, res, cb)) {
|
||||
@@ -1935,7 +1947,7 @@ iOSController.deleteCookies = function (cb) {
|
||||
returned = true;
|
||||
cb(null, {
|
||||
status: status.codes.Success.code
|
||||
, value: true
|
||||
, value: true
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1945,7 +1957,7 @@ iOSController.deleteCookies = function (cb) {
|
||||
} else {
|
||||
cb(null, {
|
||||
status: status.codes.Success.code
|
||||
, value: false
|
||||
, value: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +133,7 @@ module.exports = function (desired) {
|
||||
.deleteAllCookies()
|
||||
.allCookies();
|
||||
}).then(function (cookies) {
|
||||
_.pluck(cookies, 'name').should.not.include(newCookie.name);
|
||||
_.pluck(cookies, 'value').should.not.include(newCookie.value);
|
||||
cookies.length.should.equal(0);
|
||||
}).nodeify(done);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user