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
|
// Copyright 2021 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/chromeos/policy/dlp/test/dlp_content_manager_test_helper.h"
#include <memory>
#include "chrome/browser/ash/policy/dlp/dlp_content_manager_ash.h"
#include "chrome/browser/chromeos/policy/dlp/dialogs/dlp_warn_notifier.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h"
#include "chrome/browser/enterprise/data_controls/dlp_reporting_manager.h"
namespace policy {
DlpContentManagerTestHelper::DlpContentManagerTestHelper() {
manager_ = new DlpContentManagerAsh();
reporting_manager_ = new data_controls::DlpReportingManager();
manager_->SetReportingManagerForTesting(reporting_manager_);
manager_->SetWarnNotifierForTesting(std::make_unique<DlpWarnNotifier>());
scoped_dlp_content_observer_ =
new ScopedDlpContentObserverForTesting(manager_);
}
DlpContentManagerTestHelper::~DlpContentManagerTestHelper() {
delete scoped_dlp_content_observer_;
delete reporting_manager_;
delete manager_;
}
void DlpContentManagerTestHelper::ChangeConfidentiality(
content::WebContents* web_contents,
DlpContentRestrictionSet restrictions) {
DCHECK(manager_);
for (auto& restriction_lvl_url : restrictions.restrictions_) {
if (restriction_lvl_url.level != DlpRulesManager::Level::kNotSet) {
restriction_lvl_url.url = web_contents->GetLastCommittedURL();
}
}
manager_->OnConfidentialityChanged(web_contents, restrictions);
}
void DlpContentManagerTestHelper::UpdateConfidentiality(
content::WebContents* web_contents,
DlpContentRestrictionSet restrictions) {
DCHECK(manager_);
for (auto& restriction_lvl_url : restrictions.restrictions_) {
if (restriction_lvl_url.level != DlpRulesManager::Level::kNotSet) {
restriction_lvl_url.url = web_contents->GetLastCommittedURL();
}
}
manager_->UpdateConfidentiality(web_contents, restrictions);
}
void DlpContentManagerTestHelper::ChangeVisibility(
content::WebContents* web_contents) {
DCHECK(manager_);
manager_->OnVisibilityChanged(web_contents);
}
void DlpContentManagerTestHelper::DestroyWebContents(
content::WebContents* web_contents) {
DCHECK(manager_);
manager_->OnWebContentsDestroyed(web_contents);
}
void DlpContentManagerTestHelper::CheckRunningScreenShares() {
DCHECK(manager_);
manager_->CheckRunningScreenShares();
}
void DlpContentManagerTestHelper::SetWarnNotifierForTesting(
std::unique_ptr<DlpWarnNotifier> notifier) {
DCHECK(manager_);
manager_->SetWarnNotifierForTesting(std::move(notifier));
}
void DlpContentManagerTestHelper::ResetWarnNotifierForTesting() {
DCHECK(manager_);
manager_->ResetWarnNotifierForTesting();
}
int DlpContentManagerTestHelper::ActiveWarningDialogsCount() const {
DCHECK(manager_);
return manager_->warn_notifier_->ActiveWarningDialogsCountForTesting();
}
const std::vector<std::unique_ptr<DlpContentManager::ScreenShareInfo>>&
DlpContentManagerTestHelper::GetRunningScreenShares() const {
DCHECK(manager_);
return manager_->running_screen_shares_;
}
std::optional<DlpContentManagerAsh::VideoCaptureInfo>
DlpContentManagerTestHelper::GetRunningVideoCaptureInfo() const {
DCHECK(manager_);
return static_cast<DlpContentManagerAsh*>(manager_)
->running_video_capture_info_;
}
base::TimeDelta DlpContentManagerTestHelper::GetPrivacyScreenOffDelay() const {
DCHECK(manager_);
return static_cast<DlpContentManagerAsh*>(manager_)
->GetPrivacyScreenOffDelayForTesting();
}
void DlpContentManagerTestHelper::SetScreenShareResumeDelay(
base::TimeDelta delay) const {
DCHECK(manager_);
manager_->SetScreenShareResumeDelayForTesting(delay);
}
DlpContentManager* DlpContentManagerTestHelper::GetContentManager() const {
return manager_;
}
data_controls::DlpReportingManager*
DlpContentManagerTestHelper::GetReportingManager() const {
return manager_->reporting_manager_;
}
} // namespace policy
|