Commit 61b95af0 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Fix CookieControlsController::OnStatusChanged

OnStatusChanged was wired up to the wrong number for allowed_cookies.
Fix call and add test.

Bug: 1077766
Change-Id: I196a92022deeb2e79a2449bfd48c00a743791a41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283587
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Auto-Submit: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786199}
parent fccc096b
......@@ -130,12 +130,26 @@ TEST_F(CookieControlsTest, SomeWebSite) {
GURL("https://example.com"), /*blocked=*/false);
testing::Mock::VerifyAndClearExpectations(mock());
// Manually trigger a full update to check that the cookie count changed.
EXPECT_CALL(*mock(),
OnStatusChanged(CookieControlsStatus::kEnabled,
CookieControlsEnforcement::kNoEnforcement, 1, 0));
cookie_controls()->Update(web_contents());
testing::Mock::VerifyAndClearExpectations(mock());
// Blocking cookies should update the blocked cookie count.
EXPECT_CALL(*mock(), OnCookiesCountChanged(1, 1));
tab_specific_content_settings()->OnWebDatabaseAccessed(
GURL("https://thirdparty.com"), /*blocked=*/true);
testing::Mock::VerifyAndClearExpectations(mock());
// Manually trigger a full update to check that the cookie count changed.
EXPECT_CALL(*mock(),
OnStatusChanged(CookieControlsStatus::kEnabled,
CookieControlsEnforcement::kNoEnforcement, 1, 1));
cookie_controls()->Update(web_contents());
testing::Mock::VerifyAndClearExpectations(mock());
// Navigating somewhere else should reset the cookie count.
NavigateAndCommit(GURL("https://somethingelse.com"));
EXPECT_CALL(*mock(),
......
......@@ -50,10 +50,10 @@ void CookieControlsController::Update(content::WebContents* web_contents) {
if (!tab_observer_ || GetWebContents() != web_contents)
tab_observer_ = std::make_unique<TabObserver>(this, web_contents);
auto status = GetStatus(web_contents);
int used_count = GetBlockedCookieCount();
int allowed_cookies = GetAllowedCookieCount();
int blocked_count = GetBlockedCookieCount();
for (auto& observer : observers_)
observer.OnStatusChanged(status.first, status.second, used_count,
observer.OnStatusChanged(status.first, status.second, allowed_cookies,
blocked_count);
}
......@@ -107,7 +107,7 @@ void CookieControlsController::OnCookieBlockingEnabledForSite(
}
}
int CookieControlsController::GetUsedCookieCount() {
int CookieControlsController::GetAllowedCookieCount() {
auto* tscs =
content_settings::TabSpecificContentSettings::GetForCurrentDocument(
tab_observer_->web_contents()->GetMainFrame());
......@@ -129,8 +129,8 @@ int CookieControlsController::GetBlockedCookieCount() {
}
void CookieControlsController::PresentBlockedCookieCounter() {
int allowed_cookies = GetAllowedCookieCount();
int blocked_cookies = GetBlockedCookieCount();
int allowed_cookies = GetUsedCookieCount();
for (auto& observer : observers_)
observer.OnCookiesCountChanged(allowed_cookies, blocked_cookies);
}
......
......@@ -79,8 +79,8 @@ class CookieControlsController : content_settings::CookieSettings::Observer {
// Updates the blocked cookie count of |icon_|.
void PresentBlockedCookieCounter();
// Returns the number of used cookies.
int GetUsedCookieCount();
// Returns the number of allowed cookies.
int GetAllowedCookieCount();
// Returns the number of blocked cookies.
int GetBlockedCookieCount();
......
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