chromium/components/enterprise/data_controls/core/browser/rule_unittest.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {};

// Test to validate that a valid set of conditions in a rule will return
// opposite "IsTriggered" results when those conditions are nested in a "not"
// attribute. This is parametrized with conditions and a corresponding context
// to trigger them.
class DataControlsRuleNotTest
    : public DataControlsRuleTest,
      public testing::WithParamInterface<AndOrNotTestCase> {};

// Test to validate that a valid set of conditions in a rule will trigger when
// inserted into an "and" attribute. This is parametrized with conditions and a
// corresponding context to trigger them.
class DataControlsRuleAndTest
    : public DataControlsRuleTest,
      public testing::WithParamInterface<AndOrNotTestCase> {};

// Test to validate that a valid set of conditions in a rule will trigger when
// inserted into an "or" attribute. This is parametrized with conditions and a
// corresponding context to trigger them.
class DataControlsRuleOrTest
    : public DataControlsRuleTest,
      public testing::WithParamInterface<AndOrNotTestCase> {};

// These helpers are implemented as functions instead of simple constants
// because some sub-types of ActionContext (namely GURL) don't support being
// statically instantiated.
std::vector<AndOrNotTestCase> NotTestCases() {}

std::vector<AndOrNotTestCase> AndTestCases() {}

std::vector<AndOrNotTestCase> OrTestCases() {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

}  // namespace

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) {
  // A "FOO" component is included to validate that compatibility with future
  // components works and doesn't interfere with the rest of the rule.
  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  // BUILDFLAG(IS_CHROMEOS)

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) {}

}  // namespace data_controls