Commit 152b2aea authored by Saurabh Nijhara's avatar Saurabh Nijhara Committed by Commit Bot

Add tests to check events conversion to base::Value

Extension install events are converted from proto to base::Value using
ConvertEventsToValue(...) before being uploaded. This CL adds tests for
to check that different kinds of events are correctly parsed into
base::Value and included into the final uploaded extension install
report.

Bug: b:162501511
Change-Id: I821441ac81211f9a9dbc073e70546187bb22ded1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431520Reviewed-by: default avatarOleg Davydov <burunduk@chromium.org>
Reviewed-by: default avatarSwapnil Gupta <swapnilgupta@google.com>
Commit-Queue: Saurabh Nijhara <snijhara@google.com>
Cr-Commit-Position: refs/heads/master@{#813732}
parent b5514c73
......@@ -3505,6 +3505,7 @@ source_set("unit_tests") {
"policy/fake_affiliated_invalidation_service_provider.h",
"policy/heartbeat_scheduler_unittest.cc",
"policy/hostname_handler_unittest.cc",
"policy/install_event_log_util_unittest.cc",
"policy/lock_to_single_user_manager_unittest.cc",
"policy/minimum_version_policy_handler_unittest.cc",
"policy/network_configuration_updater_unittest.cc",
......
// Copyright 2020 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/chromeos/policy/install_event_log_util.h"
#include <vector>
#include "base/values.h"
#include "chrome/browser/chromeos/policy/extension_install_event_log.h"
#include "chrome/browser/profiles/reporting_util.h"
#include "chromeos/system/fake_statistics_provider.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
namespace em = enterprise_management;
namespace policy {
namespace {
constexpr char kExtensionId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
// Common Key names used when building the dictionary to pass to the Chrome
// Reporting API. These must be same as ones mentioned in
// install_event_log_util.cc.
constexpr char kEventType[] = "eventType";
constexpr char kTime[] = "time";
constexpr char kFailureReason[] = "failureReason";
constexpr char kIsMisconfigurationFailure[] = "isMisconfigurationFailure";
constexpr char kExtensionInstallEvent[] = "extensionAppInstallEvent";
void ConvertToValueAndVerify(const em::ExtensionInstallReportLogEvent& event,
const std::vector<std::string>& keys) {
base::Value context = reporting::GetContext(nullptr /*profile*/);
base::Value wrapper;
wrapper = ConvertExtensionEventToValue(kExtensionId, event, context);
ASSERT_TRUE(wrapper.FindKey(kExtensionInstallEvent) != nullptr);
EXPECT_TRUE(wrapper.FindKey(kTime) != nullptr);
base::Value* dict = wrapper.FindKey(kExtensionInstallEvent);
for (const std::string& key : keys) {
EXPECT_TRUE(dict->FindKey(key) != nullptr);
}
}
} // namespace
class InstallEventLogUtilTest : public testing::Test {
public:
InstallEventLogUtilTest()
: scoped_fake_statistics_provider_(
std::make_unique<
chromeos::system::ScopedFakeStatisticsProvider>()) {}
private:
std::unique_ptr<chromeos::system::ScopedFakeStatisticsProvider>
scoped_fake_statistics_provider_;
};
// Verifies that an event reporting extension install failure is successfully
// parsed.
TEST_F(InstallEventLogUtilTest, FailureReasonEvent) {
em::ExtensionInstallReportLogEvent event;
event.set_timestamp(1000);
event.set_event_type(em::ExtensionInstallReportLogEvent::INSTALLATION_FAILED);
event.set_failure_reason(em::ExtensionInstallReportLogEvent::INVALID_ID);
event.set_is_misconfiguration_failure(false);
ConvertToValueAndVerify(
event, {kEventType, kFailureReason, kIsMisconfigurationFailure});
}
} // namespace policy
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