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

Unified Diff: chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc

Issue 2009773007: Add AntiVirus information to the system profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hash the product name and version Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc
diff --git a/chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc b/chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..09d01c417af389239d029cf920a158b2d0a617b1
--- /dev/null
+++ b/chrome/browser/metrics/antivirus_metrics_provider_win_unittest.cc
@@ -0,0 +1,103 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/antivirus_metrics_provider_win.h"
+
+#include <vector>
+
+#include "base/bind.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/threading/thread_restrictions.h"
+#include "base/version.h"
+#include "base/win/windows_version.h"
+#include "components/variations/metrics_util.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace metrics {
+
+class AntiVirusMetricsProviderTest : public testing::Test {
+ public:
+ AntiVirusMetricsProviderTest()
+ : got_results_(false),
+ provider_(new AntiVirusMetricsProvider(
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE))),
+ thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD),
+ weak_ptr_factory_(this) {}
+
+ void GetMetricsCallback() {
+ ASSERT_TRUE(base::MessageLoop::current()->is_running());
+ base::MessageLoop::current()->QuitWhenIdle();
+
+ got_results_ = true;
+
+ metrics::SystemProfileProto system_profile;
+ provider_->ProvideSystemProfileMetrics(&system_profile);
+
+ if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
+ bool defender_found = false;
+ for (const auto& av : system_profile.antivirus_product()) {
+ if (av.product_name_hash() == HashName("Windows Defender")) {
+ defender_found = true;
+ break;
+ }
+ }
+ EXPECT_TRUE(defender_found);
+ }
+ }
+
+ bool got_results_;
+ std::unique_ptr<AntiVirusMetricsProvider> provider_;
+ content::TestBrowserThreadBundle thread_bundle_;
+ base::WeakPtrFactory<AntiVirusMetricsProviderTest> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AntiVirusMetricsProviderTest);
+};
+
+TEST_F(AntiVirusMetricsProviderTest, GetAvProducts) {
+ // Windows 8 and above ships with a built-in AV product called
+ // "Windows Defender" so it is possible to check for this on those platforms.
+ //
+ // On previous versions of Windows, the testing has to be manual since the
+ // API to add a new AV is private.
+ if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
+ AntiVirusMetricsProvider::AvProductList products;
+ bool result = AntiVirusMetricsProvider::FillAntiVirusProducts(&products);
+ ASSERT_TRUE(result);
+
+ bool defender_found = false;
+ for (const auto& product : products) {
+ if (product.product_name == L"Windows Defender") {
+ base::Version defender_version(
+ base::SysWideToUTF8(product.product_version));
+ EXPECT_TRUE(defender_version.IsValid());
+ defender_found = true;
+ break;
+ }
+ }
+
+ EXPECT_TRUE(defender_found);
+ }
+}
+
+TEST_F(AntiVirusMetricsProviderTest, GetMetrics) {
+ // Make sure the I/O is happening on the FILE thread by disallowing it on the
+ // main thread.
+ bool previous_value = base::ThreadRestrictions::SetIOAllowed(false);
+ provider_->GetAntiVirusMetrics(
+ base::Bind(&AntiVirusMetricsProviderTest::GetMetricsCallback,
+ weak_ptr_factory_.GetWeakPtr()));
+ content::RunMessageLoop();
+ EXPECT_TRUE(got_results_);
+ base::ThreadRestrictions::SetIOAllowed(previous_value);
+}
+
+} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698