1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/whats_new/whats_new_registrar.h"
#include "base/containers/contains.h"
#include "base/strings/string_util.h"
#include "base/test/metrics/action_suffix_reader.h"
#include "base/test/metrics/histogram_variants_reader.h"
#include "base/threading/thread_restrictions.h"
#include "components/feature_engagement/public/configuration.h"
#include "components/user_education/webui/mock_whats_new_storage_service.h"
#include "components/user_education/webui/whats_new_registry.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
using BrowserCommand = browser_command::mojom::Command;
// Modules
BASE_FEATURE(kTestModule, "TestModule", base::FEATURE_DISABLED_BY_DEFAULT);
/// Editions
BASE_FEATURE(kTestEdition, "TestEdition", base::FEATURE_DISABLED_BY_DEFAULT);
void RegisterWhatsNewModulesForTests(whats_new::WhatsNewRegistry* registry) {
// Test Module
registry->RegisterModule(
whats_new::WhatsNewModule(kTestModule, "mickeyburks@chromium.org"));
registry->RegisterModule(
whats_new::WhatsNewModule("TestDefaultModule", "mickeyburks@chromium.org",
BrowserCommand::kNoOpCommand));
}
void RegisterWhatsNewEditionsForTests(whats_new::WhatsNewRegistry* registry) {
// Test Edition
registry->RegisterEdition(
whats_new::WhatsNewEdition(kTestEdition, "mickeyburks@chromium.org"));
}
} // namespace
TEST(WhatsNewRegistrarTest, CheckModuleHistograms) {
std::optional<base::HistogramVariantsEntryMap> variants;
std::vector<std::string> missing_modules;
{
base::ScopedAllowBlockingForTesting allow_blocking;
variants =
base::ReadVariantsFromHistogramsXml("WhatsNewModule", "user_education");
ASSERT_TRUE(variants.has_value());
}
whats_new::WhatsNewRegistry registry(
std::make_unique<MockWhatsNewStorageService>());
RegisterWhatsNewModules(®istry);
RegisterWhatsNewModulesForTests(®istry);
const auto& modules = registry.modules();
for (const auto& [key, module] : modules) {
const auto metric_name = module.unique_name();
if (!base::Contains(*variants, metric_name)) {
missing_modules.emplace_back(metric_name);
}
}
ASSERT_TRUE(missing_modules.empty())
<< "What's New Modules:\n"
<< base::JoinString(missing_modules, ", ")
<< "\nconfigured in whats_new_registrar.cc but no "
"corresponding variants were added to WhatsNewModule variants in "
"//tools/metrics/histograms/metadata/user_education/"
"histograms.xml";
}
TEST(WhatsNewRegistrarTest, CheckModuleActions) {
std::vector<base::ActionSuffixEntryMap> suffixes;
std::vector<std::string> missing_modules;
{
base::ScopedAllowBlockingForTesting allow_blocking;
suffixes =
base::ReadActionSuffixesForAction("UserEducation.WhatsNew.ModuleShown");
ASSERT_EQ(1U, suffixes.size());
}
whats_new::WhatsNewRegistry registry(
std::make_unique<MockWhatsNewStorageService>());
RegisterWhatsNewModules(®istry);
RegisterWhatsNewModulesForTests(®istry);
const auto& modules = registry.modules();
for (const auto& [key, module] : modules) {
const auto metric_name = module.unique_name();
if (!base::Contains(suffixes[0], metric_name)) {
missing_modules.emplace_back(metric_name);
}
}
ASSERT_TRUE(missing_modules.empty())
<< "Whats's New Modules:\n"
<< base::JoinString(missing_modules, ", ")
<< "\nconfigured in whats_new_registrar.cc but no "
"corresponding action suffixes were added in "
"//tools/metrics/actions/actions.xml";
}
TEST(WhatsNewRegistrarTest, CheckEditionActions) {
std::vector<base::ActionSuffixEntryMap> suffixes;
std::vector<std::string> missing_editions;
{
base::ScopedAllowBlockingForTesting allow_blocking;
suffixes = base::ReadActionSuffixesForAction(
"UserEducation.WhatsNew.EditionShown");
ASSERT_EQ(1U, suffixes.size());
}
whats_new::WhatsNewRegistry registry(
std::make_unique<MockWhatsNewStorageService>());
RegisterWhatsNewEditions(®istry);
RegisterWhatsNewEditionsForTests(®istry);
for (const auto& [key, edition] : registry.editions()) {
const auto metric_name = edition.unique_name();
if (!base::Contains(suffixes[0], metric_name)) {
missing_editions.emplace_back(metric_name);
}
}
ASSERT_TRUE(missing_editions.empty())
<< "Whats's New Editions:\n"
<< base::JoinString(missing_editions, ", ")
<< "\nconfigured in whats_new_registrar.cc but no "
"corresponding action suffixes were added in "
"//tools/metrics/actions/actions.xml";
}
|