chromium/printing/backend/test_print_backend_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 "printing/backend/test_print_backend.h"

#include <stdint.h>

#include <string>
#include <utility>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "base/test/gtest_util.h"
#include "build/build_config.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "printing/backend/mojom/print_backend.mojom.h"
#include "printing/backend/print_backend.h"
#include "printing/mojom/print.mojom.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"

#if BUILDFLAG(IS_WIN)
#include "base/test/gmock_expected_support.h"
#endif  // BUILDFLAG(IS_WIN)

namespace printing {

namespace {

constexpr char kDefaultPrinterName[] =;
constexpr char kAlternatePrinterName[] =;
constexpr char kNullDataPrinterName[] =;
constexpr char kAccessDeniedPrinterName[] =;
constexpr char kInvalidPrinterName[] =;
constexpr char kInvalidDataPrinterName[] =;

constexpr int kDefaultPrinterStatus =;
constexpr int kAlternatePrinterStatus =;

const PrinterBasicInfo kDefaultPrinterInfo(
    /*printer_name=*/kDefaultPrinterName,
    /*display_name=*/"default test printer",
    /*printer_description=*/"Default printer for testing.",
    /*printer_status=*/kDefaultPrinterStatus,
    /*is_default=*/true,
    /*options=*/PrinterBasicInfoOptions{});
const PrinterBasicInfo kAlternatePrinterInfo(
    /*printer_name=*/kAlternatePrinterName,
    /*display_name=*/"alternate test printer",
    /*printer_description=*/"Alternate printer for testing.",
    /*printer_status=*/kAlternatePrinterStatus,
    /*is_default=*/false,
    /*options=*/PrinterBasicInfoOptions{});

constexpr int32_t kDefaultCopiesMax =;
constexpr int32_t kAlternateCopiesMax =;

}  // namespace

class TestPrintBackendTest : public testing::Test {};

TEST_F(TestPrintBackendTest, EnumeratePrinters) {}

TEST_F(TestPrintBackendTest, EnumeratePrintersNoneFound) {}

TEST_F(TestPrintBackendTest, DefaultPrinterName) {}

TEST_F(TestPrintBackendTest, PrinterBasicInfo) {}

TEST_F(TestPrintBackendTest, PrinterBasicInfoAccessDenied) {}

// Demonstrate that a printer might be able to present data considered to be
// invalid, which becomes detectable when it undergoes Mojom message
// validation.
TEST_F(TestPrintBackendTest, PrinterBasicInfoInvalidData) {}

TEST_F(TestPrintBackendTest, GetPrinterSemanticCapsAndDefaults) {}

TEST_F(TestPrintBackendTest, GetPrinterSemanticCapsAndDefaultsAccessDenied) {}

TEST_F(TestPrintBackendTest, IsValidPrinter) {}

#if BUILDFLAG(IS_WIN)
TEST_F(TestPrintBackendTest, GetXmlPrinterCapabilitiesForXpsDriver) {
  // Should fail when there are no printers in the environment.
  EXPECT_THAT(GetPrintBackend()->GetXmlPrinterCapabilitiesForXpsDriver(
                  kDefaultPrinterName),
              base::test::ErrorIs(mojom::ResultCode::kFailed));

  AddPrinters();

  // The default XML string set for valid printers should be valid, so verify
  // that we receive an XML string.
  ASSERT_TRUE(GetPrintBackend()
                  ->GetXmlPrinterCapabilitiesForXpsDriver(kDefaultPrinterName)
                  .has_value());

  EXPECT_THAT(GetPrintBackend()->GetXmlPrinterCapabilitiesForXpsDriver(
                  kInvalidPrinterName),
              base::test::ErrorIs(mojom::ResultCode::kFailed));

  // Printers set with invalid XML should return failure. Invalid XML is
  // considered an empty string for these tests.
  EXPECT_THAT(GetPrintBackend()->GetXmlPrinterCapabilitiesForXpsDriver(
                  kNullDataPrinterName),
              base::test::ErrorIs(mojom::ResultCode::kFailed));
}
#endif  // BUILDFLAG(IS_WIN)

}  // namespace printing