Commit 830d5708 authored by Helen Li's avatar Helen Li Committed by Commit Bot

Reland "Add NetLog events for cookie blocking by NetworkDelegate"

This is a reland of d184f073
The CL was speculatively reverted for an unrelated bug (876563)

TBR=mmenke@chromium.org

Original change's description:
> Add NetLog events for cookie blocking by NetworkDelegate
>
> Cookies setting and getting can be blocked by a NetworkDelegate.
> This CL adds NetLog events so they can aid in the investigation of cookies bugs.
>
> Bug: 875849
> Change-Id: Ia2a09b443fb1ebfe8ce9dde1617920264f6f24a7
> Reviewed-on: https://chromium-review.googlesource.com/1181244
> Reviewed-by: Matt Menke <mmenke@chromium.org>
> Commit-Queue: Helen Li <xunjieli@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#584809}

Bug: 875849
Change-Id: I19e285f078599084d53c9e68a8082ef43d86e067
Reviewed-on: https://chromium-review.googlesource.com/1185102Reviewed-by: default avatarHelen Li <xunjieli@chromium.org>
Commit-Queue: Helen Li <xunjieli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585049}
parent 75ee6f9d
......@@ -3165,3 +3165,13 @@ EVENT_TYPE(COOKIE_PERSISTENT_STORE_KEY_LOAD_COMPLETED)
// "type": <Classname of persistent cookie store>
// }
EVENT_TYPE(COOKIE_PERSISTENT_STORE_CLOSED)
// Event emitted when getting cookies is blocked by a NetworkDelegate.
// {
// }
EVENT_TYPE(COOKIE_GET_BLOCKED_BY_NETWORK_DELEGATE)
// Event emitted when setting cookies is blocked by a NetworkDelegate.
// {
// }
EVENT_TYPE(COOKIE_SET_BLOCKED_BY_NETWORK_DELEGATE)
......@@ -1074,21 +1074,30 @@ void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info,
bool URLRequest::CanGetCookies(const CookieList& cookie_list) const {
DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES));
bool can_get_cookies = g_default_can_use_cookies;
if (network_delegate_) {
return network_delegate_->CanGetCookies(*this, cookie_list,
/*allowed_from_caller=*/true);
can_get_cookies =
network_delegate_->CanGetCookies(*this, cookie_list,
/*allowed_from_caller=*/true);
}
return g_default_can_use_cookies;
if (!can_get_cookies)
net_log_.AddEvent(NetLogEventType::COOKIE_GET_BLOCKED_BY_NETWORK_DELEGATE);
return can_get_cookies;
}
bool URLRequest::CanSetCookie(const net::CanonicalCookie& cookie,
CookieOptions* options) const {
DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES));
bool can_set_cookies = g_default_can_use_cookies;
if (network_delegate_) {
return network_delegate_->CanSetCookie(*this, cookie, options,
/*allowed_from_caller=*/true);
can_set_cookies =
network_delegate_->CanSetCookie(*this, cookie, options,
/*allowed_from_caller=*/true);
}
return g_default_can_use_cookies;
if (!can_set_cookies)
net_log_.AddEvent(NetLogEventType::COOKIE_SET_BLOCKED_BY_NETWORK_DELEGATE);
return can_set_cookies;
}
bool URLRequest::CanEnablePrivacyMode() const {
......
......@@ -2740,6 +2740,12 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
TestNetLogEntry::List entries;
net_log_.GetEntries(&entries);
for (const auto& entry : entries) {
EXPECT_NE(entry.type,
NetLogEventType::COOKIE_GET_BLOCKED_BY_NETWORK_DELEGATE);
}
}
// Verify that the cookie isn't sent.
......@@ -2759,6 +2765,11 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
TestNetLogEntry::List entries;
net_log_.GetEntries(&entries);
ExpectLogContainsSomewhereAfter(
entries, 0, NetLogEventType::COOKIE_GET_BLOCKED_BY_NETWORK_DELEGATE,
NetLogEventPhase::NONE);
}
}
......@@ -2785,6 +2796,12 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
TestNetLogEntry::List entries;
net_log_.GetEntries(&entries);
for (const auto& entry : entries) {
EXPECT_NE(entry.type,
NetLogEventType::COOKIE_SET_BLOCKED_BY_NETWORK_DELEGATE);
}
}
// Try to set-up another cookie and update the previous cookie.
......@@ -2802,6 +2819,11 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
TestNetLogEntry::List entries;
net_log_.GetEntries(&entries);
ExpectLogContainsSomewhereAfter(
entries, 0, NetLogEventType::COOKIE_SET_BLOCKED_BY_NETWORK_DELEGATE,
NetLogEventPhase::NONE);
}
// Verify the cookies weren't saved or updated.
......
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