Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc

Issue 2645473003: Merge M56:Trim AV names. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/metrics/antivirus_metrics_provider_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/antivirus_metrics_provider_win.h" 5 #include "chrome/browser/metrics/antivirus_metrics_provider_win.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/test/scoped_feature_list.h" 15 #include "base/test/scoped_feature_list.h"
16 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/version.h" 18 #include "base/version.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "components/variations/metrics_util.h" 20 #include "components/variations/metrics_util.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 namespace { 26 namespace {
27 27
28 struct Testcase {
29 const char* input;
30 const char* output;
31 };
32
28 void VerifySystemProfileData(const metrics::SystemProfileProto& system_profile, 33 void VerifySystemProfileData(const metrics::SystemProfileProto& system_profile,
29 bool expect_unhashed_value) { 34 bool expect_unhashed_value) {
30 const char kWindowsDefender[] = "Windows Defender"; 35 const char kWindowsDefender[] = "Windows Defender";
31 36
32 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 37 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
33 bool defender_found = false; 38 bool defender_found = false;
34 for (const auto& av : system_profile.antivirus_product()) { 39 for (const auto& av : system_profile.antivirus_product()) {
35 if (av.product_name_hash() == metrics::HashName(kWindowsDefender)) { 40 if (av.product_name_hash() == metrics::HashName(kWindowsDefender)) {
36 defender_found = true; 41 defender_found = true;
37 if (expect_unhashed_value) { 42 if (expect_unhashed_value) {
38 EXPECT_TRUE(av.has_product_name()); 43 EXPECT_TRUE(av.has_product_name());
39 EXPECT_EQ(kWindowsDefender, av.product_name()); 44 EXPECT_EQ(kWindowsDefender, av.product_name());
40 } else { 45 } else {
41 EXPECT_FALSE(av.has_product_name()); 46 EXPECT_FALSE(av.has_product_name());
42 } 47 }
43 break; 48 break;
44 } 49 }
45 } 50 }
46 EXPECT_TRUE(defender_found); 51 EXPECT_TRUE(defender_found);
47 } 52 }
48 } 53 }
49 54
50 } // namespace 55 } // namespace
51 56
57 class AntiVirusMetricsProviderSimpleTest : public ::testing::Test {};
58
52 class AntiVirusMetricsProviderTest : public ::testing::TestWithParam<bool> { 59 class AntiVirusMetricsProviderTest : public ::testing::TestWithParam<bool> {
53 public: 60 public:
54 AntiVirusMetricsProviderTest() 61 AntiVirusMetricsProviderTest()
55 : got_results_(false), 62 : got_results_(false),
56 expect_unhashed_value_(GetParam()), 63 expect_unhashed_value_(GetParam()),
57 provider_(new AntiVirusMetricsProvider( 64 provider_(new AntiVirusMetricsProvider(
58 content::BrowserThread::GetTaskRunnerForThread( 65 content::BrowserThread::GetTaskRunnerForThread(
59 content::BrowserThread::FILE))), 66 content::BrowserThread::FILE))),
60 thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD), 67 thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD),
61 weak_ptr_factory_(this) {} 68 weak_ptr_factory_(this) {}
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 AntiVirusMetricsProvider::ResultCode expected_result = 130 AntiVirusMetricsProvider::ResultCode expected_result =
124 AntiVirusMetricsProvider::RESULT_SUCCESS; 131 AntiVirusMetricsProvider::RESULT_SUCCESS;
125 if (base::win::OSInfo::GetInstance()->version_type() == 132 if (base::win::OSInfo::GetInstance()->version_type() ==
126 base::win::SUITE_SERVER) 133 base::win::SUITE_SERVER)
127 expected_result = AntiVirusMetricsProvider::RESULT_WSC_NOT_AVAILABLE; 134 expected_result = AntiVirusMetricsProvider::RESULT_WSC_NOT_AVAILABLE;
128 histograms.ExpectUniqueSample("UMA.AntiVirusMetricsProvider.Result", 135 histograms.ExpectUniqueSample("UMA.AntiVirusMetricsProvider.Result",
129 expected_result, 1); 136 expected_result, 1);
130 } 137 }
131 138
132 INSTANTIATE_TEST_CASE_P(, AntiVirusMetricsProviderTest, ::testing::Bool()); 139 INSTANTIATE_TEST_CASE_P(, AntiVirusMetricsProviderTest, ::testing::Bool());
140
141 TEST_F(AntiVirusMetricsProviderSimpleTest, StripProductVersion) {
142 Testcase testcases[] = {
143 {"", ""},
144 {" ", ""},
145 {"1.0 AV 2.0", "1.0 AV"},
146 {"Anti Virus", "Anti Virus"},
147 {"Windows Defender", "Windows Defender"},
148 {"McAfee AntiVirus has a space at the end ",
149 "McAfee AntiVirus has a space at the end"},
150 {"ESET NOD32 Antivirus 8.0", "ESET NOD32 Antivirus"},
151 {"Norton 360", "Norton 360"},
152 {"ESET Smart Security 9.0.381.1", "ESET Smart Security"},
153 {"Trustwave AV 3_0_2547", "Trustwave AV"},
154 {"nProtect Anti-Virus/Spyware V4.0", "nProtect Anti-Virus/Spyware"},
155 {"ESET NOD32 Antivirus 9.0.349.15P", "ESET NOD32 Antivirus"}};
156
157 for (const auto testcase : testcases) {
158 auto output =
159 AntiVirusMetricsProvider::TrimVersionOfAvProductName(testcase.input);
160 EXPECT_STREQ(testcase.output, output.c_str());
161 }
162 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/antivirus_metrics_provider_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698