Commit dbdfc314 authored by Tricia Crichton's avatar Tricia Crichton Committed by Commit Bot

[ChromeDriver] Store cookie expiration as int64

When getting cookies, Convert cookie expiration to int64 for
compatibility with SetCookie, which rejects an expiration
set as a double.

Bug: chromedriver:3331
Change-Id: I911ff6169ec9ed5efaaa01ff76f7a846733d7f14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106736Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Tricia Crichton <triciac@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751144}
parent 501e678d
......@@ -208,7 +208,7 @@ struct Cookie {
const std::string& domain,
const std::string& path,
const std::string& samesite,
double expiry,
int64_t expiry,
bool http_only,
bool secure,
bool session)
......@@ -227,7 +227,7 @@ struct Cookie {
std::string domain;
std::string path;
std::string samesite;
double expiry;
int64_t expiry;
bool http_only;
bool secure;
bool session;
......@@ -243,7 +243,7 @@ std::unique_ptr<base::DictionaryValue> CreateDictionaryFrom(
if (!cookie.path.empty())
dict->SetString("path", cookie.path);
if (!cookie.session)
dict->SetDouble("expiry", cookie.expiry);
SetSafeInt(dict.get(), "expiry", cookie.expiry);
dict->SetBoolean("httpOnly", cookie.http_only);
dict->SetBoolean("secure", cookie.secure);
if (!cookie.samesite.empty())
......@@ -279,10 +279,14 @@ Status GetVisibleCookies(Session* session,
cookie_dict->GetString("path", &path);
std::string samesite = "";
GetOptionalString(cookie_dict, "sameSite", &samesite);
double expiry = 0;
cookie_dict->GetDouble("expires", &expiry);
if (expiry > 1e12)
expiry /= 1000; // Backwards compatibility ms -> sec.
int64_t expiry = 0;
double temp_double;
if (cookie_dict->GetDouble("expires", &temp_double)) {
// Truncate & convert the value to an integer as required by W3C spec.
int64_t temp_int64 = static_cast<int64_t>(temp_double);
if (!(temp_int64 >= (1ll << 53) || temp_int64 <= -(1ll << 53)))
expiry = temp_int64;
}
bool http_only = false;
cookie_dict->GetBoolean("httpOnly", &http_only);
bool session = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment