Commit 1a6de624 authored by Sergey Poromov's avatar Sergey Poromov Committed by Commit Bot

DLP: Add DlpContentManagerPolicyBrowserTest.

This test checks that the configured DLP policy is correctly
converted into the corresponding Content Restriction.

Bug: 1109783
Change-Id: I17bba26c6d0eb791cbcd7483b94e1537f64609d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515683
Commit-Queue: Sergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarNikita Podguzov <nikitapodguzov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823519}
parent 9fc08c16
...@@ -91,6 +91,8 @@ class DlpContentManager : public DlpWindowObserver::Delegate { ...@@ -91,6 +91,8 @@ class DlpContentManager : public DlpWindowObserver::Delegate {
VideoCaptureStoppedWhenNonConfidentialWindowResized); VideoCaptureStoppedWhenNonConfidentialWindowResized);
FRIEND_TEST_ALL_PREFIXES(DlpContentManagerBrowserTest, FRIEND_TEST_ALL_PREFIXES(DlpContentManagerBrowserTest,
VideoCaptureNotStoppedWhenConfidentialWindowHidden); VideoCaptureNotStoppedWhenConfidentialWindowHidden);
FRIEND_TEST_ALL_PREFIXES(DlpContentManagerPolicyBrowserTest,
GetRestrictionSetForURL);
friend class DlpContentManagerTest; friend class DlpContentManagerTest;
friend class DlpContentTabHelper; friend class DlpContentTabHelper;
friend class MockDlpContentManager; friend class MockDlpContentManager;
......
...@@ -4,12 +4,20 @@ ...@@ -4,12 +4,20 @@
#include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h" #include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager_test_utils.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/ui/ash/screenshot_area.h" #include "chrome/browser/ui/ash/screenshot_area.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -20,6 +28,9 @@ namespace policy { ...@@ -20,6 +28,9 @@ namespace policy {
namespace { namespace {
const DlpContentRestrictionSet kScreenshotRestricted( const DlpContentRestrictionSet kScreenshotRestricted(
DlpContentRestriction::kScreenshot); DlpContentRestriction::kScreenshot);
const DlpContentRestrictionSet kPrivacyScreenEnforced(
DlpContentRestriction::kPrivacyScreen);
const DlpContentRestrictionSet kPrintRestricted(DlpContentRestriction::kPrint);
const DlpContentRestrictionSet kVideoCaptureRestricted( const DlpContentRestrictionSet kVideoCaptureRestricted(
DlpContentRestriction::kVideoCapture); DlpContentRestriction::kVideoCapture);
} // namespace } // namespace
...@@ -212,4 +223,74 @@ IN_PROC_BROWSER_TEST_F(DlpContentManagerBrowserTest, ...@@ -212,4 +223,74 @@ IN_PROC_BROWSER_TEST_F(DlpContentManagerBrowserTest,
browser2->window()->Close(); browser2->window()->Close();
} }
class DlpContentManagerPolicyBrowserTest : public PolicyTest {
public:
DlpContentManagerPolicyBrowserTest() {
scoped_feature_list_.InitAndEnableFeature(
features::kDataLeakPreventionPolicy);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(DlpContentManagerPolicyBrowserTest,
GetRestrictionSetForURL) {
const std::string kAllowedUrl = "https://example.com";
const std::string kUrl1 = "https://example1.com";
const std::string kUrl2 = "https://example2.com";
const std::string kUrl3 = "https://example3.com";
base::Value rules(base::Value::Type::LIST);
base::Value src_urls1(base::Value::Type::LIST);
src_urls1.Append(kUrl1);
base::Value restrictions1(base::Value::Type::LIST);
restrictions1.Append(dlp_test_util::CreateRestrictionWithLevel(
dlp::kScreenshotRestriction, dlp::kBlockLevel));
rules.Append(dlp_test_util::CreateRule(
"rule #1", "Block", std::move(src_urls1),
/*dst_urls=*/base::Value(base::Value::Type::LIST),
/*dst_components=*/base::Value(base::Value::Type::LIST),
std::move(restrictions1)));
base::Value src_urls2(base::Value::Type::LIST);
src_urls2.Append(kUrl2);
base::Value restrictions2(base::Value::Type::LIST);
restrictions2.Append(dlp_test_util::CreateRestrictionWithLevel(
dlp::kPrivacyScreenRestriction, dlp::kBlockLevel));
rules.Append(dlp_test_util::CreateRule(
"rule #2", "Block", std::move(src_urls2),
/*dst_urls=*/base::Value(base::Value::Type::LIST),
/*dst_components=*/base::Value(base::Value::Type::LIST),
std::move(restrictions2)));
base::Value src_urls3(base::Value::Type::LIST);
src_urls3.Append(kUrl3);
base::Value restrictions3(base::Value::Type::LIST);
restrictions3.Append(dlp_test_util::CreateRestrictionWithLevel(
dlp::kPrintingRestriction, dlp::kBlockLevel));
rules.Append(dlp_test_util::CreateRule(
"rule #3", "Block", std::move(src_urls3),
/*dst_urls=*/base::Value(base::Value::Type::LIST),
/*dst_components=*/base::Value(base::Value::Type::LIST),
std::move(restrictions3)));
PolicyMap policies;
policies.Set(key::kDataLeakPreventionRulesList, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, std::move(rules),
nullptr);
UpdateProviderPolicy(policies);
EXPECT_EQ(kScreenshotRestricted,
DlpContentManager::Get()->GetRestrictionSetForURL(GURL(kUrl1)));
EXPECT_EQ(kPrivacyScreenEnforced,
DlpContentManager::Get()->GetRestrictionSetForURL(GURL(kUrl2)));
EXPECT_EQ(kPrintRestricted,
DlpContentManager::Get()->GetRestrictionSetForURL(GURL(kUrl3)));
EXPECT_EQ(
DlpContentRestrictionSet(),
DlpContentManager::Get()->GetRestrictionSetForURL(GURL(kAllowedUrl)));
}
} // 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