Commit ef22e399 authored by Saurabh Nijhara's avatar Saurabh Nijhara Committed by Commit Bot

Check extension reporting events conversion to base::Value

This CL adds tests to check that different kinds of events are
correctly parsed into base::Value before being included into the
uploaded extension install report.

Bug: b:162501511
Change-Id: If958a6e82125d59c89f8931fea8ee0a7b578802a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450069Reviewed-by: default avatarSwapnil Gupta <swapnilgupta@google.com>
Commit-Queue: Saurabh Nijhara <snijhara@google.com>
Cr-Commit-Position: refs/heads/master@{#814199}
parent 988725e4
...@@ -21,25 +21,43 @@ namespace em = enterprise_management; ...@@ -21,25 +21,43 @@ namespace em = enterprise_management;
namespace policy { namespace policy {
namespace { namespace {
constexpr char kExtensionId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; constexpr char kTestExtensionId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
constexpr int64_t kDiskSpaceTotalBytes = 5 * 1024 * 1024;
const int64_t kDiskSpaceFreeBytes = 2 * 1024 * 1024;
// Common Key names used when building the dictionary to pass to the Chrome // Common key names used when building the dictionary to pass to the Chrome
// Reporting API. These must be same as ones mentioned in // Reporting API. These must be same as ones mentioned in
// install_event_log_util.cc. // install_event_log_util.cc.
constexpr char kEventType[] = "eventType"; constexpr char kEventType[] = "eventType";
constexpr char kOnline[] = "online";
constexpr char kSessionStateChangeType[] = "sessionStateChangeType";
constexpr char kStatefulTotal[] = "statefulTotal";
constexpr char kStatefulFree[] = "statefulFree";
constexpr char kTime[] = "time"; constexpr char kTime[] = "time";
// Key names used for extensions 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 kExtensionId[] = "extensionId";
constexpr char kExtensionInstallEvent[] = "extensionAppInstallEvent";
constexpr char kDownloadingStage[] = "downloadingStage";
constexpr char kFailureReason[] = "failureReason"; constexpr char kFailureReason[] = "failureReason";
constexpr char kInstallationStage[] = "installationStage";
constexpr char kExtensionType[] = "extensionType";
constexpr char kUserType[] = "userType";
constexpr char kIsNewUser[] = "isNewUser";
constexpr char kIsMisconfigurationFailure[] = "isMisconfigurationFailure"; constexpr char kIsMisconfigurationFailure[] = "isMisconfigurationFailure";
constexpr char kExtensionInstallEvent[] = "extensionAppInstallEvent"; constexpr char kInstallCreationStage[] = "installCreationStage";
void ConvertToValueAndVerify(const em::ExtensionInstallReportLogEvent& event, void ConvertToValueAndVerify(const em::ExtensionInstallReportLogEvent& event,
const std::vector<std::string>& keys) { const std::vector<std::string>& keys) {
base::Value context = reporting::GetContext(nullptr /*profile*/); base::Value context = reporting::GetContext(nullptr /*profile*/);
base::Value wrapper; base::Value wrapper;
wrapper = ConvertExtensionEventToValue(kExtensionId, event, context); wrapper = ConvertExtensionEventToValue(kTestExtensionId, event, context);
ASSERT_TRUE(wrapper.FindKey(kExtensionInstallEvent) != nullptr); ASSERT_TRUE(wrapper.FindKey(kExtensionInstallEvent) != nullptr);
EXPECT_TRUE(wrapper.FindKey(kTime) != nullptr); EXPECT_TRUE(wrapper.FindKey(kTime) != nullptr);
base::Value* dict = wrapper.FindKey(kExtensionInstallEvent); base::Value* dict = wrapper.FindKey(kExtensionInstallEvent);
EXPECT_TRUE(dict->FindKey(kExtensionId) != nullptr);
for (const std::string& key : keys) { for (const std::string& key : keys) {
EXPECT_TRUE(dict->FindKey(key) != nullptr); EXPECT_TRUE(dict->FindKey(key) != nullptr);
} }
...@@ -47,12 +65,17 @@ void ConvertToValueAndVerify(const em::ExtensionInstallReportLogEvent& event, ...@@ -47,12 +65,17 @@ void ConvertToValueAndVerify(const em::ExtensionInstallReportLogEvent& event,
} // namespace } // namespace
class InstallEventLogUtilTest : public testing::Test { class ExtensionInstallEventLogUtilTest : public testing::Test {
public: public:
InstallEventLogUtilTest() ExtensionInstallEventLogUtilTest()
: scoped_fake_statistics_provider_( : scoped_fake_statistics_provider_(
std::make_unique< std::make_unique<
chromeos::system::ScopedFakeStatisticsProvider>()) {} chromeos::system::ScopedFakeStatisticsProvider>()) {
event_.set_timestamp(1000);
}
protected:
em::ExtensionInstallReportLogEvent event_;
private: private:
std::unique_ptr<chromeos::system::ScopedFakeStatisticsProvider> std::unique_ptr<chromeos::system::ScopedFakeStatisticsProvider>
...@@ -61,14 +84,59 @@ class InstallEventLogUtilTest : public testing::Test { ...@@ -61,14 +84,59 @@ class InstallEventLogUtilTest : public testing::Test {
// Verifies that an event reporting extension install failure is successfully // Verifies that an event reporting extension install failure is successfully
// parsed. // parsed.
TEST_F(InstallEventLogUtilTest, FailureReasonEvent) { TEST_F(ExtensionInstallEventLogUtilTest, FailureReasonEvent) {
em::ExtensionInstallReportLogEvent event; event_.set_event_type(
event.set_timestamp(1000); em::ExtensionInstallReportLogEvent::INSTALLATION_FAILED);
event.set_event_type(em::ExtensionInstallReportLogEvent::INSTALLATION_FAILED); event_.set_failure_reason(em::ExtensionInstallReportLogEvent::INVALID_ID);
event.set_failure_reason(em::ExtensionInstallReportLogEvent::INVALID_ID); event_.set_is_misconfiguration_failure(false);
event.set_is_misconfiguration_failure(false); event_.set_extension_type(em::Extension_ExtensionType_TYPE_EXTENSION);
event_.set_stateful_total(kDiskSpaceTotalBytes);
event_.set_stateful_free(kDiskSpaceFreeBytes);
ConvertToValueAndVerify( ConvertToValueAndVerify(
event, {kEventType, kFailureReason, kIsMisconfigurationFailure}); event_, {kEventType, kFailureReason, kIsMisconfigurationFailure,
kExtensionType, kStatefulTotal, kStatefulFree});
}
// Verifies that an event reporting extension installation stage is successfully
// parsed.
TEST_F(ExtensionInstallEventLogUtilTest, InstallationStageEvent) {
event_.set_installation_stage(em::ExtensionInstallReportLogEvent::PENDING);
event_.set_stateful_total(kDiskSpaceTotalBytes);
event_.set_stateful_free(kDiskSpaceFreeBytes);
ConvertToValueAndVerify(event_,
{kInstallationStage, kStatefulTotal, kStatefulFree});
}
// Verifies that an event reporting extension downloading stage is successfully
// parsed.
TEST_F(ExtensionInstallEventLogUtilTest, DownloadingStageEvent) {
event_.set_downloading_stage(
em::ExtensionInstallReportLogEvent::PARSING_MANIFEST);
event_.set_stateful_total(kDiskSpaceTotalBytes);
event_.set_stateful_free(kDiskSpaceFreeBytes);
ConvertToValueAndVerify(event_,
{kDownloadingStage, kStatefulTotal, kStatefulFree});
}
// Verifies that a login event reporting user type is successfully parsed.
TEST_F(ExtensionInstallEventLogUtilTest, LoginEvent) {
event_.set_event_type(
em::ExtensionInstallReportLogEvent::SESSION_STATE_CHANGE);
event_.set_session_state_change_type(
em::ExtensionInstallReportLogEvent::LOGIN);
event_.set_user_type(em::ExtensionInstallReportLogEvent::USER_TYPE_REGULAR);
event_.set_is_new_user(false);
event_.set_online(true);
ConvertToValueAndVerify(event_, {kEventType, kSessionStateChangeType,
kUserType, kIsNewUser, kOnline});
}
// Verifies that an event reporting extension install creation stage is
// successfully parsed.
TEST_F(ExtensionInstallEventLogUtilTest, InstallCreationStageEvent) {
event_.set_install_creation_stage(
em::ExtensionInstallReportLogEvent::CREATION_INITIATED);
ConvertToValueAndVerify(event_, {kInstallCreationStage});
} }
} // namespace policy } // 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