#include "components/enterprise/data_controls/core/browser/rule.h"
#include <tuple>
#include <vector>
#include "base/feature_list.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "components/enterprise/data_controls/core/browser/features.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace data_controls {
namespace {
std::optional<Rule> MakeRule(const std::string& value) { … }
class DataControlsRuleTest : public testing::Test { … };
class DataControlsFeaturesRuleTest
: public DataControlsRuleTest,
public testing::WithParamInterface<std::tuple<bool, bool>> { … };
INSTANTIATE_TEST_SUITE_P(…);
struct AndOrNotTestCase { … };
class DataControlsRuleNotTest
: public DataControlsRuleTest,
public testing::WithParamInterface<AndOrNotTestCase> { … };
class DataControlsRuleAndTest
: public DataControlsRuleTest,
public testing::WithParamInterface<AndOrNotTestCase> { … };
class DataControlsRuleOrTest
: public DataControlsRuleTest,
public testing::WithParamInterface<AndOrNotTestCase> { … };
std::vector<AndOrNotTestCase> NotTestCases() { … }
std::vector<AndOrNotTestCase> AndTestCases() { … }
std::vector<AndOrNotTestCase> OrTestCases() { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}
TEST_F(DataControlsRuleTest, InvalidValues) { … }
TEST_F(DataControlsRuleTest, InvalidConditions) { … }
TEST_F(DataControlsRuleTest, ValidSourcesInvalidDestinationsConditions) { … }
TEST_F(DataControlsRuleTest, InvalidSourcesValidDestinationsConditions) { … }
TEST_F(DataControlsRuleTest, NoRestrictions) { … }
TEST_F(DataControlsRuleTest, InvalidRestrictions) { … }
TEST_F(DataControlsRuleTest, Restrictions) { … }
TEST_F(DataControlsRuleTest, Accessors) { … }
TEST_F(DataControlsRuleTest, SourceUrls) { … }
TEST_F(DataControlsRuleTest, DestinationUrls) { … }
TEST_F(DataControlsRuleTest, SourceAndDestinationUrls) { … }
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(DataControlsRuleTest, DestinationComponent) {
auto rule = MakeRule(R"({
"name": "Block pastes",
"rule_id": "1234",
"description": "A test rule to block pastes",
"destinations": { "components": ["FOO", "ARC"] },
"restrictions": [
{ "class": "CLIPBOARD", "level": "BLOCK" }
]
})");
ASSERT_TRUE(rule);
ASSERT_EQ(rule->GetLevel(Rule::Restriction::kClipboard,
{.destination = {.component = Component::kArc}}),
Rule::Level::kBlock);
ASSERT_EQ(
rule->GetLevel(Rule::Restriction::kClipboard,
{.destination = {.component = Component::kCrostini}}),
Rule::Level::kNotSet);
ASSERT_EQ(
rule->GetLevel(Rule::Restriction::kClipboard,
{.destination = {.component = Component::kPluginVm}}),
Rule::Level::kNotSet);
ASSERT_EQ(rule->GetLevel(Rule::Restriction::kClipboard,
{.destination = {.component = Component::kUsb}}),
Rule::Level::kNotSet);
ASSERT_EQ(rule->GetLevel(Rule::Restriction::kClipboard,
{.destination = {.component = Component::kDrive}}),
Rule::Level::kNotSet);
ASSERT_EQ(
rule->GetLevel(Rule::Restriction::kClipboard,
{.destination = {.component = Component::kOneDrive}}),
Rule::Level::kNotSet);
}
#endif
TEST_P(DataControlsFeaturesRuleTest, ScreenshotRules) { … }
TEST_P(DataControlsFeaturesRuleTest, NonScreenshotRules) { … }
TEST_P(DataControlsRuleNotTest, TriggeringContext) { … }
TEST_P(DataControlsRuleNotTest, NonTriggeringContext) { … }
TEST_P(DataControlsRuleAndTest, TriggeringContext) { … }
TEST_P(DataControlsRuleAndTest, NonTriggeringContext) { … }
TEST_P(DataControlsRuleOrTest, TriggeringContext) { … }
TEST_P(DataControlsRuleOrTest, NonTriggeringContext) { … }
}