Commit c1c79e9e authored by Christopher Thompson's avatar Christopher Thompson Committed by Commit Bot

Add Legacy TLS downloads metrics

Bug: 1016105
Change-Id: Ieddc418b09939529ca53b6540bd067c1d8a4fb9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872297Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Christopher Thompson <cthomp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708227}
parent 2adb5c20
...@@ -156,6 +156,10 @@ void DownloadUIController::OnDownloadCreated(content::DownloadManager* manager, ...@@ -156,6 +156,10 @@ void DownloadUIController::OnDownloadCreated(content::DownloadManager* manager,
"Security.SafetyTips.DownloadStarted", "Security.SafetyTips.DownloadStarted",
security_state_tab_helper->GetVisibleSecurityState() security_state_tab_helper->GetVisibleSecurityState()
->safety_tip_info.status); ->safety_tip_info.status);
UMA_HISTOGRAM_BOOLEAN(
"Security.LegacyTLS.DownloadStarted",
security_state::GetLegacyTLSWarningStatus(
*security_state_tab_helper->GetVisibleSecurityState()));
} }
} }
......
...@@ -13,29 +13,34 @@ ...@@ -13,29 +13,34 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/download/download_core_service_factory.h" #include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_core_service_impl.h" #include "chrome/browser/download/download_core_service_impl.h"
#include "chrome/browser/download/download_history.h" #include "chrome/browser/download/download_history.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ssl/tls_deprecation_test_utils.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/download/public/common/mock_download_item.h" #include "components/download/public/common/mock_download_item.h"
#include "components/history/core/browser/download_row.h" #include "components/history/core/browser/download_row.h"
#include "content/public/browser/download_item_utils.h" #include "content/public/browser/download_item_utils.h"
#include "content/public/test/mock_download_manager.h" #include "content/public/test/mock_download_manager.h"
#include "content/public/test/navigation_simulator.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gmock_mutant.h" #include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using download::MockDownloadItem;
using content::MockDownloadManager; using content::MockDownloadManager;
using download::MockDownloadItem;
using history::HistoryService; using history::HistoryService;
using testing::_;
using testing::AnyNumber; using testing::AnyNumber;
using testing::Assign; using testing::Assign;
using testing::CreateFunctor; using testing::CreateFunctor;
using testing::Return; using testing::Return;
using testing::ReturnRef;
using testing::ReturnRefOfCopy; using testing::ReturnRefOfCopy;
using testing::SaveArg; using testing::SaveArg;
using testing::_;
namespace { namespace {
...@@ -386,4 +391,82 @@ TEST_F(DownloadUIControllerTest, DownloadUIController_HistoryDownload) { ...@@ -386,4 +391,82 @@ TEST_F(DownloadUIControllerTest, DownloadUIController_HistoryDownload) {
EXPECT_EQ(static_cast<download::DownloadItem*>(item.get()), notified_item()); EXPECT_EQ(static_cast<download::DownloadItem*>(item.get()), notified_item());
} }
TEST_F(DownloadUIControllerTest, LegacyTLSMetrics) {
base::HistogramTester histograms;
SecurityStateTabHelper::CreateForWebContents(web_contents());
InitializeEmptyLegacyTLSConfig();
auto navigation =
CreateLegacyTLSNavigation(GURL(kLegacyTLSDefaultURL), web_contents());
navigation->Commit();
// Start a download from the same page, setting up the mock item to correctly
// associate with the WebContents of the previous navigation.
std::unique_ptr<MockDownloadItem> item(CreateMockInProgressDownload());
GURL download_url("https://download.test/file.bin");
EXPECT_CALL(*item, GetURL()).WillRepeatedly(ReturnRef(download_url));
EXPECT_CALL(*item, GetOriginalUrl()).WillRepeatedly(ReturnRef(download_url));
content::DownloadItemUtils::AttachInfo(item.get(), browser_context(),
web_contents());
DownloadUIController controller(manager(), GetTestDelegate());
ASSERT_TRUE(manager_observer());
manager_observer()->OnDownloadCreated(manager(), item.get());
histograms.ExpectUniqueSample("Security.LegacyTLS.DownloadStarted", true, 1);
}
TEST_F(DownloadUIControllerTest, LegacyTLSControlSiteMetrics) {
base::HistogramTester histograms;
SecurityStateTabHelper::CreateForWebContents(web_contents());
InitializeLegacyTLSConfigWithControl();
auto navigation =
CreateLegacyTLSNavigation(GURL(kLegacyTLSControlURL), web_contents());
navigation->Commit();
// Start a download from the same page, setting up the mock item to correctly
// associate with the WebContents of the previous navigation.
std::unique_ptr<MockDownloadItem> item(CreateMockInProgressDownload());
GURL download_url("https://download.test/file.bin");
EXPECT_CALL(*item, GetURL()).WillRepeatedly(ReturnRef(download_url));
EXPECT_CALL(*item, GetOriginalUrl()).WillRepeatedly(ReturnRef(download_url));
content::DownloadItemUtils::AttachInfo(item.get(), browser_context(),
web_contents());
DownloadUIController controller(manager(), GetTestDelegate());
ASSERT_TRUE(manager_observer());
manager_observer()->OnDownloadCreated(manager(), item.get());
histograms.ExpectUniqueSample("Security.LegacyTLS.DownloadStarted", false, 1);
}
TEST_F(DownloadUIControllerTest, LegacyTLSGoodSiteMetrics) {
base::HistogramTester histograms;
SecurityStateTabHelper::CreateForWebContents(web_contents());
InitializeEmptyLegacyTLSConfig();
auto navigation =
CreateNonlegacyTLSNavigation(GURL("https://good.test"), web_contents());
navigation->Commit();
// Start a download from the same page, setting up the mock item to correctly
// associate with the WebContents of the previous navigation.
std::unique_ptr<MockDownloadItem> item(CreateMockInProgressDownload());
GURL download_url("https://download.test/file.bin");
EXPECT_CALL(*item, GetURL()).WillRepeatedly(ReturnRef(download_url));
EXPECT_CALL(*item, GetOriginalUrl()).WillRepeatedly(ReturnRef(download_url));
content::DownloadItemUtils::AttachInfo(item.get(), browser_context(),
web_contents());
DownloadUIController controller(manager(), GetTestDelegate());
ASSERT_TRUE(manager_observer());
manager_observer()->OnDownloadCreated(manager(), item.get());
histograms.ExpectUniqueSample("Security.LegacyTLS.DownloadStarted", false, 1);
}
} // namespace } // namespace
...@@ -129493,6 +129493,19 @@ should be kept until we remove incident reporting. --> ...@@ -129493,6 +129493,19 @@ should be kept until we remove incident reporting. -->
</summary> </summary>
</histogram> </histogram>
<histogram name="Security.LegacyTLS.DownloadStarted" enum="Boolean"
expires_after="M85">
<owner>cthomp@chromium.org</owner>
<summary>
Records whether the page would have a legacy TLS warning (if the user were
in the appropriate field trial) when a download is initiated from the page
(*not* the legacy TLS status of the download URL itself). This is recorded
regardless of whether the warning is actually displayed. This histogram is
not recorded for downloads that are initiated in a new tab or window, as the
legacy TLS status of the initiating page cannot be tracked.
</summary>
</histogram>
<histogram base="true" name="Security.PageEndReason" enum="PageEndReason" <histogram base="true" name="Security.PageEndReason" enum="PageEndReason"
expires_after="M81"> expires_after="M81">
<owner>cthomp@chromium.org</owner> <owner>cthomp@chromium.org</owner>
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