#include "chrome/browser/enterprise/data_controls/dlp_reporting_manager.h"
#include <memory>
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/rand_util.h"
#include "base/task/thread_pool.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/enterprise/data_controls/dlp_reporting_manager.h"
#include "chrome/browser/enterprise/data_controls/dlp_reporting_manager_test_helper.h"
#include "chrome/browser/policy/messaging_layer/public/report_client.h"
#include "chrome/browser/policy/messaging_layer/public/report_client_test_util.h"
#include "components/account_id/account_id.h"
#include "components/enterprise/data_controls/core/browser/dlp_histogram_helper.h"
#include "components/enterprise/data_controls/core/browser/dlp_policy_event.pb.h"
#include "components/enterprise/data_controls/core/browser/rule.h"
#include "components/reporting/client/mock_report_queue.h"
#include "components/reporting/encryption/primitives.h"
#include "components/reporting/storage/test_storage_module.h"
#include "components/reporting/util/status.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_renderer_host.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/user_manager/scoped_user_manager.h"
#include "components/user_manager/user_names.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/lacros/lacros_service.h"
#include "chromeos/startup/browser_init_params.h"
#endif
_;
Mock;
namespace data_controls {
namespace {
const char kCompanyUrl[] = …;
const char kFilename[] = …;
const char kRuleName[] = …;
const char kRuleId[] = …;
}
class DlpReportingManagerTest : public testing::Test { … };
TEST_F(DlpReportingManagerTest, ReportEvent) { … }
TEST_F(DlpReportingManagerTest, ReportEventWithUrlDst) { … }
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(DlpReportingManagerTest, ReportEventWithComponentDst) {
ReportEventAndCheckComponent(Component::kArc,
DlpPolicyEventDestination_Component_ARC, 0u);
ReportEventAndCheckComponent(Component::kCrostini,
DlpPolicyEventDestination_Component_CROSTINI,
1u);
ReportEventAndCheckComponent(Component::kPluginVm,
DlpPolicyEventDestination_Component_PLUGIN_VM,
2u);
ReportEventAndCheckComponent(Component::kUsb,
DlpPolicyEventDestination_Component_USB, 3u);
ReportEventAndCheckComponent(Component::kDrive,
DlpPolicyEventDestination_Component_DRIVE, 4u);
ReportEventAndCheckComponent(Component::kOneDrive,
DlpPolicyEventDestination_Component_ONEDRIVE,
5u);
ReportEventAndCheckComponent(
Component::kUnknownComponent,
DlpPolicyEventDestination_Component_UNDEFINED_COMPONENT, 6u);
EXPECT_EQ(manager_->events_reported(), 7u);
}
#endif
TEST_F(DlpReportingManagerTest, ReportEventWithoutNameAndRuleId) { … }
TEST_F(DlpReportingManagerTest, MetricsReported) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(DlpReportingManagerTest, UserType) {
ScopedTestingLocalState local_state{TestingBrowserProcess::GetGlobal()};
auto* user_manager = new ash::FakeChromeUserManager();
user_manager::ScopedUserManager enabler(base::WrapUnique(user_manager));
AccountId regular_account_id = AccountId::FromUserEmail("[email protected]");
const auto* regular_user = user_manager->AddUser(regular_account_id);
AccountId mgs_account_id =
AccountId::FromUserEmail("[email protected]");
const auto* mgs_user = user_manager->AddPublicAccountUser(mgs_account_id);
AccountId kiosk_account_id = AccountId::FromUserEmail("[email protected]");
const auto* kiosk_user = user_manager->AddKioskAppUser(kiosk_account_id);
AccountId web_kiosk_account_id =
AccountId::FromUserEmail("[email protected]");
const auto* web_kiosk_user =
user_manager->AddWebKioskAppUser(web_kiosk_account_id);
AccountId guest_user_id = user_manager::GuestAccountId();
const auto* guest_user = user_manager->AddGuestUser();
AccountId child_user_id = AccountId::FromUserEmail("[email protected]");
const auto* child_user = user_manager->AddChildUser(child_user_id);
ReportEventAndCheckUser(user_manager, regular_account_id, regular_user,
DlpPolicyEvent_UserType_REGULAR, 0u);
ReportEventAndCheckUser(user_manager, mgs_account_id, mgs_user,
DlpPolicyEvent_UserType_MANAGED_GUEST, 1u);
ReportEventAndCheckUser(user_manager, kiosk_account_id, kiosk_user,
DlpPolicyEvent_UserType_KIOSK, 2u);
ReportEventAndCheckUser(user_manager, web_kiosk_account_id, web_kiosk_user,
DlpPolicyEvent_UserType_KIOSK, 3u);
ReportEventAndCheckUser(user_manager, guest_user_id, guest_user,
DlpPolicyEvent_UserType_UNDEFINED_USER_TYPE, 4u);
ReportEventAndCheckUser(user_manager, child_user_id, child_user,
DlpPolicyEvent_UserType_UNDEFINED_USER_TYPE, 5u,
true);
EXPECT_EQ(manager_->events_reported(), 6u);
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(DlpReportingManagerTest, UserType) {
SetSessionType(crosapi::mojom::SessionType::kRegularSession);
ReportEventAndCheckUser(DlpPolicyEvent_UserType_REGULAR, 0u);
SetSessionType(crosapi::mojom::SessionType::kPublicSession);
ReportEventAndCheckUser(DlpPolicyEvent_UserType_MANAGED_GUEST, 1u);
SetSessionType(crosapi::mojom::SessionType::kAppKioskSession);
ReportEventAndCheckUser(DlpPolicyEvent_UserType_KIOSK, 2u);
SetSessionType(crosapi::mojom::SessionType::kWebKioskSession);
ReportEventAndCheckUser(DlpPolicyEvent_UserType_KIOSK, 3u);
SetSessionType(crosapi::mojom::SessionType::kGuestSession);
ReportEventAndCheckUser(DlpPolicyEvent_UserType_UNDEFINED_USER_TYPE, 4u);
SetSessionType(crosapi::mojom::SessionType::kChildSession);
ReportEventAndCheckUser(DlpPolicyEvent_UserType_UNDEFINED_USER_TYPE, 5u);
EXPECT_EQ(manager_->events_reported(), 6u);
}
#endif
TEST_F(DlpReportingManagerTest, CreateEventWithUnknownRestriction) { … }
TEST_F(DlpReportingManagerTest, CreateEventForFilesRestriction) { … }
TEST_F(DlpReportingManagerTest, CreateEventWithEmptyRuleMetadata) { … }
TEST_F(DlpReportingManagerTest, Timestamp) { … }
TEST_F(DlpReportingManagerTest, ReportEventError) { … }
TEST_F(DlpReportingManagerTest, OnEventEnqueuedError) { … }
TEST_F(DlpReportingManagerTest, ReportLongEvent) { … }
}