chromium/chrome/browser/policy/printing_restrictions_policy_handler_unittest.cc

// Copyright 2020 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/policy/printing_restrictions_policy_handler.h"

#include "base/json/json_reader.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
#include "printing/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace policy {

#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
class PrintingRestrictionsPolicyHandlerTest : public testing::Test {};

TEST_F(PrintingRestrictionsPolicyHandlerTest, NoPolicy) {}

TEST_F(PrintingRestrictionsPolicyHandlerTest, StandardPaperSize) {}

TEST_F(PrintingRestrictionsPolicyHandlerTest, CustomPaperSize) {}

TEST_F(PrintingRestrictionsPolicyHandlerTest, BothStandardAndCustomPaperSize) {}

TEST_F(PrintingRestrictionsPolicyHandlerTest, NoCustomPaperSize) {}

TEST_F(PrintingRestrictionsPolicyHandlerTest, NoWidthInCustomSize) {}

TEST_F(PrintingRestrictionsPolicyHandlerTest, NoHeightInCustomSize) {}

class PrintPdfAsImageRestrictionsPolicyHandlerTest : public testing::Test {};

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
TEST_F(PrintPdfAsImageRestrictionsPolicyHandlerTest,
       DefaultWithAvailabilityEnabled) {
  // For platforms that require PrintPdfAsImageAvailability, demonstrate that
  // it is valid to supply PrintPdfAsImageDefault policy when
  // PrintPdfAsImageAvailability has been enabled.
  base::Value availability_value(true);
  base::Value default_value(true);

  CheckValidPolicy(key::kPrintPdfAsImageAvailability,
                   availability_value.Clone());
  CheckValidPolicy(key::kPrintPdfAsImageDefault, default_value.Clone());

  ApplyPolicies();
  base::Value* value;
  EXPECT_TRUE(prefs_.GetValue(prefs::kPrintPdfAsImageDefault, &value));
  ASSERT_TRUE(value);
  EXPECT_EQ(*value, default_value);
}

TEST_F(PrintPdfAsImageRestrictionsPolicyHandlerTest,
       DefaultWithAvailabilityDisabled) {
  // For platforms that require PrintPdfAsImageAvailability, demonstrate that
  // it is invalid to supply PrintPdfAsImageDefault policy when
  // PrintPdfAsImageAvailability has been disabled.
  base::Value availability_value(false);
  base::Value default_value(true);

  CheckValidPolicy(key::kPrintPdfAsImageAvailability,
                   availability_value.Clone());
  CheckInvalidPolicy(key::kPrintPdfAsImageDefault, default_value.Clone());
}

TEST_F(PrintPdfAsImageRestrictionsPolicyHandlerTest,
       DefaultWithoutAvailability) {
  // For platforms that require PrintPdfAsImageAvailability, demonstrate that
  // it is invalid to supply PrintPdfAsImageDefault policy when
  // PrintPdfAsImageAvailability has not been provided.
  base::Value default_value(true);

  CheckInvalidPolicy(key::kPrintPdfAsImageDefault, default_value.Clone());
}
#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
TEST_F(PrintPdfAsImageRestrictionsPolicyHandlerTest,
       DefaultWithoutAvailability) {}
#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

#endif  // BUILDFLAG(ENABLE_PRINT_PREVIEW)

}  // namespace policy