#include "chrome/browser/ui/webui/management/management_ui_handler.h"
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/escape.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/chromeos/reporting/metric_reporting_prefs.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/enterprise/reporting/prefs.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/ui/webui/management/management_ui_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/enterprise/browser/reporting/common_pref_names.h"
#include "components/enterprise/browser/reporting/real_time_report_type.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/enterprise/connectors/core/common.h"
#include "components/enterprise/connectors/core/connectors_prefs.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/cloud/dm_token.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/mock_policy_service.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_namespace.h"
#include "components/policy/core/common/policy_service.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_ui.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_pref_names.h"
#include "base/test/test_simple_task_runner.h"
#include "base/time/time.h"
#include "chrome/browser/ash/crostini/crostini_features.h"
#include "chrome/browser/ash/crostini/crostini_pref_names.h"
#include "chrome/browser/ash/crostini/fake_crostini_features.h"
#include "chrome/browser/ash/net/secure_dns_manager.h"
#include "chrome/browser/ash/policy/core/device_cloud_policy_manager_ash.h"
#include "chrome/browser/ash/policy/core/device_cloud_policy_store_ash.h"
#include "chrome/browser/ash/policy/core/user_cloud_policy_manager_ash.h"
#include "chrome/browser/ash/policy/enrollment/device_cloud_policy_initializer.h"
#include "chrome/browser/ash/policy/remote_commands/crd/fake_start_crd_session_job_delegate.h"
#include "chrome/browser/ash/policy/reporting/metrics_reporting/metric_reporting_prefs.h"
#include "chrome/browser/ash/policy/skyvault/policy_utils.h"
#include "chrome/browser/ash/policy/status_collector/device_status_collector.h"
#include "chrome/browser/ash/policy/status_collector/status_collector.h"
#include "chrome/browser/ash/policy/uploading/status_uploader.h"
#include "chrome/browser/ash/policy/uploading/system_log_uploader.h"
#include "chrome/browser/ash/settings/device_settings_test_helper.h"
#include "chrome/browser/ash/settings/scoped_testing_cros_settings.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager.h"
#include "chrome/browser/chromeos/policy/dlp/test/mock_dlp_rules_manager.h"
#include "chrome/browser/net/secure_dns_config.h"
#include "chrome/browser/net/stub_resolver_config_reader.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/ash/components/dbus/shill/shill_service_client.h"
#include "chromeos/ash/components/install_attributes/stub_install_attributes.h"
#include "chromeos/ash/components/network/network_handler_test_helper.h"
#include "chromeos/ash/components/network/network_metadata_store.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/proxy/proxy_config_handler.h"
#include "chromeos/ash/components/network/proxy/ui_proxy_config_service.h"
#include "chromeos/ash/components/settings/cros_settings_names.h"
#include "chromeos/ash/components/system/fake_statistics_provider.h"
#include "chromeos/dbus/power/power_manager_client.h"
#include "components/account_id/account_id.h"
#include "components/onc/onc_pref_names.h"
#include "components/policy/core/common/cloud/cloud_external_data_manager.h"
#include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
#include "components/policy/core/common/cloud/mock_signing_service.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/proxy_config/proxy_config_dictionary.h"
#include "components/proxy_config/proxy_config_pref_names.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/scoped_user_manager.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
#include "ui/chromeos/devicetype_utils.h"
#else
#include "components/policy/core/common/cloud/cloud_external_data_manager.h"
#include "components/policy/core/common/cloud/mock_user_cloud_policy_store.h"
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#include "services/network/test/test_network_connection_tracker.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#include "components/device_signals/core/browser/mock_user_permission_service.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/lacros/lacros_test_helper.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/webui/management/management_ui_handler_chromeos.h"
#else
#include "chrome/browser/ui/webui/management/management_ui_handler.h"
#endif
_;
AnyNumber;
AssertionFailure;
AssertionResult;
AssertionSuccess;
Mock;
Return;
ReturnRef;
struct ContextualManagementSourceUpdate { … };
#if BUILDFLAG(IS_CHROMEOS_ASH)
namespace {
const char kUser[] = "[email protected]";
const char kGaiaId[] = "gaia_id";
}
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
class TestDeviceStatusCollector : public policy::DeviceStatusCollector {
public:
TestDeviceStatusCollector(PrefService* local_state,
bool report_activity_times,
bool report_nics,
bool report_hardware_data,
bool report_users,
bool report_crash_info,
bool report_app_info_and_activity)
: policy::DeviceStatusCollector(local_state, nullptr, nullptr, nullptr),
report_activity_times_(report_activity_times),
report_nics_(report_nics),
report_hardware_data_(report_hardware_data),
report_users_(report_users),
report_crash_info_(report_crash_info),
report_app_info_and_activity_(report_app_info_and_activity) {}
~TestDeviceStatusCollector() override = default;
bool IsReportingActivityTimes() const override {
return report_activity_times_;
}
bool IsReportingNetworkData() const override { return report_nics_; }
bool IsReportingHardwareData() const override {
return report_hardware_data_;
}
bool IsReportingUsers() const override { return report_users_; }
bool IsReportingCrashReportInfo() const override {
return report_crash_info_;
}
bool IsReportingAppInfoAndActivity() const override {
return report_app_info_and_activity_;
}
void GetStatusAsync(policy::StatusCollectorCallback callback) override {}
void OnSubmittedSuccessfully() override {}
private:
bool report_activity_times_;
bool report_nics_;
bool report_hardware_data_;
bool report_users_;
bool report_crash_info_;
bool report_app_info_and_activity_;
};
class TestDeviceCloudPolicyManagerAsh
: public policy::DeviceCloudPolicyManagerAsh {
public:
TestDeviceCloudPolicyManagerAsh(
std::unique_ptr<policy::DeviceCloudPolicyStoreAsh> store,
policy::ServerBackedStateKeysBroker* state_keys_broker)
: DeviceCloudPolicyManagerAsh(std::move(store),
nullptr,
nullptr,
state_keys_broker,
crd_delegate_) {
set_component_policy_disabled_for_testing(true);
}
~TestDeviceCloudPolicyManagerAsh() override = default;
private:
policy::FakeStartCrdSessionJobDelegate crd_delegate_;
};
#endif
#if BUILDFLAG(IS_CHROMEOS)
using ManagementUIHandlerBase = ManagementUIHandlerChromeOS;
#else
ManagementUIHandlerBase;
#endif
class TestManagementUIHandler : public ManagementUIHandlerBase { … };
#if BUILDFLAG(IS_CHROMEOS_ASH)
using TestingBaseClass = ash::DeviceSettingsTestBase;
#else
TestingBaseClass;
#endif
class ManagementUIHandlerTests : public TestingBaseClass { … };
AssertionResult MessagesToBeEQ(const char* infolist_expr,
const char* expected_infolist_expr,
const base::Value::List& infolist,
const std::set<std::string>& expected_messages) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
AssertionResult ReportingElementsToBeEQ(
const char* elements_expr,
const char* expected_elements_expr,
const base::Value::List& elements,
const std::map<std::string, std::string> expected_elements) {
std::map<std::string, std::string> tmp_expected(expected_elements);
for (const base::Value& element : elements) {
const std::string* message_id = element.GetDict().FindString("messageId");
const std::string* js_reporting_type =
element.GetDict().FindString("reportingType");
if (message_id && js_reporting_type) {
auto tmp_reporting_type = tmp_expected.find(*message_id);
if (tmp_reporting_type == tmp_expected.end()) {
return AssertionFailure() << " could not find message " << *message_id
<< " in " << expected_elements_expr;
}
if (tmp_reporting_type->second != *js_reporting_type) {
return AssertionFailure()
<< " expected reporting element \"" << *js_reporting_type
<< "\" with key \"" << *message_id << "\" doesn't match \""
<< tmp_reporting_type->second << "\" in \""
<< expected_elements_expr << "\"";
}
tmp_expected.erase(tmp_reporting_type);
} else {
return AssertionFailure()
<< " couldn't find key messageId or reportingType in " << elements;
}
}
if (!tmp_expected.empty()) {
AssertionResult result = AssertionFailure();
result << " the following messageId and reportingTypes could not be "
"matched {";
for (const auto& element : tmp_expected) {
result << " messageId: " << element.first << ", reportingType "
<< element.second;
}
result << "}";
return result;
}
if (elements.size() != expected_elements.size()) {
return AssertionFailure()
<< elements_expr << " and " << expected_elements_expr
<< " don't have the same size. (" << elements.size() << ", "
<< expected_elements.size() << ")";
}
return AssertionSuccess();
}
#endif
#if !BUILDFLAG(IS_CHROMEOS)
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateProfileManagedOnly) { … }
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateBrowserManagedOnly) { … }
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateUnmanagedNoDomain) { … }
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedNoDomain) { … }
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedConsumerDomain) { … }
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateUnmanagedKnownDomain) { … }
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateUnmanagedCustomerDomain) { … }
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedKnownDomain) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedAccountKnownDomain) {
const std::string domain = "manager.com";
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().profile_name = "managed@" + domain;
GetTestConfig().override_policy_connector_is_managed = true;
GetTestConfig().device_domain = "";
SetUpProfileAndHandler();
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED_BY,
base::UTF8ToUTF16(domain)));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_BY_EXPLANATION,
base::UTF8ToUTF16(domain)));
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type),
base::UTF8ToUTF16(domain)));
EXPECT_EQ(GetManagementOverview(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_ACCOUNT_MANAGED_BY,
base::UTF8ToUTF16(domain)));
EXPECT_EQ(GetUpdateRequiredEolMessage(), std::u16string());
EXPECT_TRUE(GetManaged());
}
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedAccountUnknownDomain) {
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().device_domain = "";
SetUpProfileAndHandler();
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_EXPLANATION));
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED,
l10n_util::GetStringUTF16(device_type)));
EXPECT_EQ(GetManagementOverview(), std::u16string());
EXPECT_EQ(GetUpdateRequiredEolMessage(), std::u16string());
EXPECT_TRUE(GetManaged());
}
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedDevice) {
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().managed_account = false;
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type),
device_domain()));
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED_BY,
device_domain()));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_BY_EXPLANATION,
device_domain()));
EXPECT_EQ(GetManagementOverview(), std::u16string());
EXPECT_EQ(GetUpdateRequiredEolMessage(), std::u16string());
EXPECT_TRUE(GetManaged());
}
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedDeviceAndAccount) {
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().profile_name = "[email protected]";
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type),
device_domain()));
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED_BY,
device_domain()));
EXPECT_EQ(GetManagementOverview(),
l10n_util::GetStringFUTF16(
IDS_MANAGEMENT_DEVICE_AND_ACCOUNT_MANAGED_BY, device_domain()));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_BY_EXPLANATION,
device_domain()));
EXPECT_EQ(GetUpdateRequiredEolMessage(), std::u16string());
EXPECT_TRUE(GetManaged());
}
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedDeviceAndAccountMultipleDomains) {
const std::string domain = "manager.com";
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().profile_name = "managed@" + domain;
GetTestConfig().override_policy_connector_is_managed = true;
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type),
device_domain()));
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED_BY,
device_domain()));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_BY_EXPLANATION,
device_domain()));
EXPECT_EQ(GetManagementOverview(),
l10n_util::GetStringFUTF16(
IDS_MANAGEMENT_DEVICE_MANAGED_BY_ACCOUNT_MANAGED_BY,
device_domain(), base::UTF8ToUTF16(domain)));
EXPECT_EQ(GetUpdateRequiredEolMessage(), std::u16string());
EXPECT_TRUE(GetManaged());
}
TEST_F(ManagementUIHandlerTests, ManagementContextualSourceUpdateUnmanaged) {
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().profile_name = "";
GetTestConfig().managed_account = false;
GetTestConfig().managed_browser = false;
GetTestConfig().device_domain = "";
SetUpProfileAndHandler();
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE,
l10n_util::GetStringUTF16(device_type)));
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_EXPLANATION));
EXPECT_EQ(GetManagementOverview(),
l10n_util::GetStringUTF16(IDS_MANAGEMENT_DEVICE_NOT_MANAGED));
EXPECT_EQ(GetUpdateRequiredEolMessage(), std::u16string());
EXPECT_FALSE(GetManaged());
}
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedDeviceAndAccountEol) {
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
ResetTestConfig();
GetTestConfig().managed_account = true;
GetTestConfig().managed_device = true;
handler_.EnableUpdateRequiredEolInfo(true);
SetUpProfileAndHandler();
EXPECT_EQ(
GetUpdateRequiredEolMessage(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_UPDATE_REQUIRED_EOL_MESSAGE,
device_domain(), ui::GetChromeOSDeviceName()));
EXPECT_EQ(GetPageSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type),
device_domain()));
EXPECT_EQ(GetExtensionReportingSubtitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_EXTENSIONS_INSTALLED_BY,
device_domain()));
EXPECT_EQ(
GetManagedWebsitesTitle(),
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_MANAGED_WEBSITES_BY_EXPLANATION,
device_domain()));
EXPECT_TRUE(GetManaged());
}
TEST_F(ManagementUIHandlerTests, NoDeviceReportingInfo) {
ResetTestConfig();
GetTestConfig().override_policy_connector_is_managed = true;
GetTestConfig().managed_account = false;
SetUpProfileAndHandler();
base::Value::List info = ManagementUIHandlerChromeOS::GetDeviceReportingInfo(
nullptr, GetProfile());
EXPECT_EQ(info.size(), 0u);
}
TEST_F(ManagementUIHandlerTests, AllEnabledDeviceReportingInfo) {
ResetTestConfig(true);
GetTestConfig().report_users = false;
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportActivityTimes, "device activity"},
{kManagementReportNetworkData, "device"},
{kManagementReportDeviceAudioStatus, "device"},
{kManagementReportDevicePeripherals, "peripherals"},
{kManagementReportHardwareData, "device statistics"},
{kManagementReportCrashReports, "crash report"},
{kManagementReportAppInfoAndActivity, "app info and activity"},
{kManagementLogUploadEnabled, "logs"},
{kManagementPrinting, "print"},
{kManagementCrostini, "crostini"},
{kManagementExtensionReportUsername, "username"},
{kManagementReportExtensions, "extension"},
{kManagementReportAndroidApplications, "android application"},
{kManagementReportDlpEvents, "dlp events"},
{kManagementReportLoginLogout, "login-logout"},
{kManagementReportFileEvents, "file events"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
AllEnabledCrostiniAnsiblePlaybookDeviceReportingInfo) {
ResetTestConfig(true);
GetTestConfig().report_dlp_events = false;
GetTestConfig().crostini_ansible_playbook_filepath = base::FilePath("/tmp/");
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportActivityTimes, "device activity"},
{kManagementReportNetworkData, "device"},
{kManagementReportDeviceAudioStatus, "device"},
{kManagementReportDevicePeripherals, "peripherals"},
{kManagementReportHardwareData, "device statistics"},
{kManagementReportCrashReports, "crash report"},
{kManagementReportAppInfoAndActivity, "app info and activity"},
{kManagementLogUploadEnabled, "logs"},
{kManagementPrinting, "print"},
{kManagementCrostiniContainerConfiguration, "crostini"},
{kManagementExtensionReportUsername, "username"},
{kManagementReportExtensions, "extension"},
{kManagementReportAndroidApplications, "android application"},
{kManagementReportLoginLogout, "login-logout"},
{kManagementReportFileEvents, "file events"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, OnlyReportDlpEvents) {
ResetTestConfig(false);
GetTestConfig().report_dlp_events = true;
base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportDlpEvents, "dlp events"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, OnlyReportUsersDeviceReportingInfo) {
ResetTestConfig(false);
GetTestConfig().report_users = true;
base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportUsers, "supervised user"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, AllDisabledDeviceReportingInfo) {
ResetTestConfig(false);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
DeviceReportingInfoWhenInsightsExtensionEnabled) {
ResetTestConfig(false);
GetTestConfig().insights_extension_enabled = true;
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportActivityTimes, "device activity"},
{kManagementReportNetworkData, "device"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportDeviceAudioStatusEnabled) {
ResetTestConfig(false);
GetTestConfig().report_audio_status = true;
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportActivityTimes, "device activity"},
{kManagementReportDeviceAudioStatus, "device"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportDevicePeripheralsEnabled) {
ResetTestConfig(false);
GetTestConfig().report_device_peripherals = true;
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportActivityTimes, "device activity"},
{kManagementReportDevicePeripherals, "peripherals"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportDeviceXdrEventsEnabled) {
ResetTestConfig(false);
GetTestConfig().device_report_xdr_events = true;
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportActivityTimes, "device activity"},
{kManagementReportAppInfoAndActivity, "app info and activity"},
{kManagementReportLoginLogout, "login-logout"},
{kManagementReportFileEvents, "file events"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportAppInventory) {
ResetTestConfig(false);
base::Value::List allowed_app_types;
allowed_app_types.Append(::ash::reporting::kAppCategoryAndroidApps);
GetTestConfig().report_app_inventory = std::move(allowed_app_types);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportAppInfoAndActivity, "app info and activity"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportAppUsage) {
ResetTestConfig(false);
base::Value::List allowed_app_types;
allowed_app_types.Append(::ash::reporting::kAppCategoryAndroidApps);
GetTestConfig().report_app_usage = std::move(allowed_app_types);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportAppInfoAndActivity, "app info and activity"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ReportAllWebsiteTelemetry_AllowlistedTelemetryType) {
ResetTestConfig(false);
base::Value::List allowed_telemetry_types;
allowed_telemetry_types.Append(::reporting::kWebsiteTelemetryUsageType);
GetTestConfig().report_website_telemetry = std::move(allowed_telemetry_types);
base::Value::List allowed_urls;
allowed_urls.Append(ContentSettingsPattern::Wildcard().ToString());
GetTestConfig().report_website_telemetry_allowlist = std::move(allowed_urls);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportAllWebsiteInfoAndActivity,
"website info and activity"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ReportAllWebsiteTelemetry_DisallowedTelemetryTypes) {
ResetTestConfig(false);
base::Value::List allowed_urls;
allowed_urls.Append(ContentSettingsPattern::Wildcard().ToString());
GetTestConfig().report_website_telemetry_allowlist = std::move(allowed_urls);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ReportWebsiteTelemetry_AllowlistedTelemetryType) {
ResetTestConfig(false);
base::Value::List allowed_telemetry_types;
allowed_telemetry_types.Append(::reporting::kWebsiteTelemetryUsageType);
GetTestConfig().report_website_telemetry = std::move(allowed_telemetry_types);
base::Value::List allowed_urls;
allowed_urls.Append("[*.]google.com");
GetTestConfig().report_website_telemetry_allowlist = std::move(allowed_urls);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportWebsiteInfoAndActivity, "website info and activity"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ReportWebsiteTelemetry_DisallowedTelemetryTypes) {
ResetTestConfig(false);
base::Value::List allowed_urls;
allowed_urls.Append("[*.]google.com");
GetTestConfig().report_website_telemetry_allowlist = std::move(allowed_urls);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ReportNoWebsiteTelemetry_AllowlistedTelemetryType) {
ResetTestConfig(false);
base::Value::List allowed_telemetry_types;
allowed_telemetry_types.Append(::reporting::kWebsiteTelemetryUsageType);
GetTestConfig().report_website_telemetry = std::move(allowed_telemetry_types);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ReportNoWebsiteTelemetry_DisallowedTelemetryTypes) {
ResetTestConfig(false);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportAllWebsiteActivity) {
ResetTestConfig(false);
base::Value::List allowed_urls;
allowed_urls.Append(ContentSettingsPattern::Wildcard().ToString());
GetTestConfig().report_website_activity_allowlist = std::move(allowed_urls);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportAllWebsiteInfoAndActivity,
"website info and activity"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportWebsiteActivity) {
ResetTestConfig(false);
base::Value::List allowed_urls;
allowed_urls.Append("[*.]google.com");
GetTestConfig().report_website_activity_allowlist = std::move(allowed_urls);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementReportWebsiteInfoAndActivity, "website info and activity"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportNoWebsiteActivity) {
ResetTestConfig(false);
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests, ReportLegacyTechReport) {
ResetTestConfig(false);
GetTestConfig().legacy_tech_reporting_enabled = true;
const base::Value::List info = SetUpForReportingInfo();
const std::map<std::string, std::string> expected_elements = {
{kManagementLegacyTechReport, "legacy-tech"}};
ASSERT_PRED_FORMAT2(ReportingElementsToBeEQ, info, expected_elements);
}
TEST_F(ManagementUIHandlerTests,
ShowPrivacyDisclosureForSecureDnsWithIdentifiers) {
ResetTestConfig();
local_state_.Set(prefs::kDnsOverHttpsMode,
base::Value(SecureDnsConfig::kModeSecure));
local_state_.Set(prefs::kDnsOverHttpsSalt, base::Value("test-salt"));
local_state_.Set(prefs::kDnsOverHttpsTemplatesWithIdentifiers,
base::Value("www.test-dns.com"));
auto user_manager =
std::make_unique<user_manager::FakeUserManager>(&local_state_);
const AccountId account_id(AccountId::FromUserEmailGaiaId(kUser, kGaiaId));
user_manager->AddUser(account_id);
user_manager::ScopedUserManager scoper(std::move(user_manager));
base::RunLoop().RunUntilIdle();
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_TRUE(GetShowMonitoredNetworkPrivacyDisclosure());
}
TEST_F(ManagementUIHandlerTests,
ShowPrivacyDisclosureForDeviceReportXDREvents) {
ResetTestConfig();
policy::PolicyMap chrome_policies;
const policy::PolicyNamespace chrome_policies_namespace =
policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string());
EXPECT_CALL(policy_service_, GetPolicies(chrome_policies_namespace))
.WillRepeatedly(ReturnRef(chrome_policies));
SetPolicyValue(policy::key::kDeviceReportXDREvents, true, chrome_policies);
base::RunLoop().RunUntilIdle();
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_TRUE(GetShowMonitoredNetworkPrivacyDisclosure());
}
TEST_F(ManagementUIHandlerTests, ShowPrivacyDisclosureForActiveProxy) {
ResetTestConfig();
PrefProxyConfigTrackerImpl::RegisterProfilePrefs(user_prefs_.registry());
ash::NetworkHandler::Get()->InitializePrefServices(&user_prefs_,
&local_state_);
user_prefs_.SetUserPref(proxy_config::prefs::kProxy,
ProxyConfigDictionary::CreateAutoDetect());
base::RunLoop().RunUntilIdle();
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_TRUE(GetShowMonitoredNetworkPrivacyDisclosure());
}
TEST_F(ManagementUIHandlerTests, ProxyServerDisclosureDeviceOffline) {
ResetTestConfig();
PrefProxyConfigTrackerImpl::RegisterProfilePrefs(user_prefs_.registry());
ash::NetworkHandler::Get()->InitializePrefServices(&user_prefs_,
&local_state_);
ash::NetworkStateHandler::NetworkStateList networks;
ash::NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
ash::NetworkTypePattern::Default(),
true,
false,
0,
&networks);
ash::ShillServiceClient::TestInterface* service =
ash::ShillServiceClient::Get()->GetTestInterface();
for (const auto* const network : networks) {
service->SetServiceProperty(network->path(), shill::kStateProperty,
base::Value(shill::kStateIdle));
}
base::RunLoop().RunUntilIdle();
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_FALSE(GetShowMonitoredNetworkPrivacyDisclosure());
ash::NetworkHandler::Get()->NetworkHandler::ShutdownPrefServices();
}
TEST_F(ManagementUIHandlerTests, HideProxyServerDisclosureForDirectProxy) {
ResetTestConfig();
PrefProxyConfigTrackerImpl::RegisterProfilePrefs(user_prefs_.registry());
ash::NetworkHandler::Get()->InitializePrefServices(&user_prefs_,
&local_state_);
user_prefs_.SetUserPref(proxy_config::prefs::kProxy,
ProxyConfigDictionary::CreateDirect());
base::RunLoop().RunUntilIdle();
GetTestConfig().managed_device = true;
SetUpProfileAndHandler();
EXPECT_FALSE(GetShowMonitoredNetworkPrivacyDisclosure());
ash::NetworkHandler::Get()->NetworkHandler::ShutdownPrefServices();
}
#endif
TEST_F(ManagementUIHandlerTests, ExtensionReportingInfoNoPolicySetNoMessage) { … }
TEST_F(ManagementUIHandlerTests, CloudReportingPolicy) { … }
TEST_F(ManagementUIHandlerTests, CloudProfileReportingPolicy) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
TEST_F(ManagementUIHandlerTests,
CloudReportingPolicyWithoutDeviceSignalsConsent) { … }
#endif
TEST_F(ManagementUIHandlerTests, LegacyTechReport) { … }
TEST_F(ManagementUIHandlerTests, ExtensionReportingInfoPoliciesMerge) { … }
TEST_F(ManagementUIHandlerTests, ManagedWebsitiesInfoNoPolicySet) { … }
TEST_F(ManagementUIHandlerTests, ManagedWebsitiesInfoWebsites) { … }
TEST_F(ManagementUIHandlerTests, ThreatReportingInfo) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ManagementUIHandlerTests, GetFilesUploadToCloud) {
ResetTestConfig();
SetUpProfileAndHandler();
EXPECT_TRUE(handler_.GetFilesUploadToCloudInfo(profile_.get()).empty());
profile_->GetTestingPrefService()->SetManagedPref(
ash::prefs::kCaptureModePolicySavePath,
std::make_unique<base::Value>(
policy::local_user_files::kOneDrivePolicyVariableName));
EXPECT_FALSE(handler_.GetFilesUploadToCloudInfo(profile_.get()).empty());
}
#endif