chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc

// Copyright 2015 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/ui/webui/print_preview/extension_printer_handler.h"

#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <string>
#include <utility>

#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/functional/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "chrome/browser/extensions/test_extension_environment.h"
#include "chrome/browser/printing/pwg_raster_converter.h"
#include "chrome/test/base/testing_profile.h"
#include "components/version_info/version_info.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api/device_permissions_manager.h"
#include "extensions/browser/api/printer_provider/printer_provider_api.h"
#include "extensions/browser/api/printer_provider/printer_provider_api_factory.h"
#include "extensions/browser/api/printer_provider/printer_provider_print_job.h"
#include "extensions/browser/api/usb/usb_device_manager.h"
#include "extensions/common/extension.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "printing/pdf_render_settings.h"
#include "printing/print_job_constants.h"
#include "printing/pwg_raster_settings.h"
#include "printing/units.h"
#include "services/device/public/cpp/test/fake_usb_device_manager.h"
#include "services/device/public/mojom/usb_device.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"

UsbDeviceInfoPtr;
Extension;
PrinterProviderAPI;
PrinterProviderPrintJob;
TestExtensionEnvironment;

namespace printing {

namespace {

// Printer id used for requests in tests.
const char kPrinterId[] =;

// Printer list used a result for getPrinters.
const char kPrinterDescriptionList[] =;

// Printer capability for a printer that supportd only PWG raster.
const char kPWGRasterOnlyPrinterSimpleDescription[] =;

// Print ticket with no parameters set.
const char kEmptyPrintTicket[] =;

// Print ticket that has duplex parameter set.
const char kPrintTicketWithDuplex[] =;

// An extension with permission for 1 printer it supports.
const char kExtension1[] =;

// An extension with permission for none of the printers it supports.
const char kExtension2[] =;

const char kPdfSettings[] =;

const char kAllTypesSettings[] =;

const char kSimpleRasterSettings[] =;

const char kInvalidSettings[] =;

const char kDuplexSettings[] =;

const char kContentTypePDF[] =;
const char kContentTypePWG[] =;

// Print request status considered to be successful by fake PrinterProviderAPI.
const char kPrintRequestSuccess[] =;

constexpr unsigned char kPrintData[] =;

// Used as a callback to StartGetPrinters() in tests.
// Increases `call_count` and records values returned by StartGetPrinters().
void RecordPrinterList(size_t& call_count,
                       base::Value::List& printers_out,
                       base::Value::List printers) {}

// Used as a callback to StartGetPrinters in tests.
// Records that the test is done.
void RecordPrintersDone(bool* is_done_out) {}

// Used as a callback to StartGetCapability() in tests.
// Increases `call_count` and records values returned by StartGetCapability().
void RecordCapability(size_t& call_count,
                      base::Value::Dict& capability_out,
                      base::Value::Dict capability) {}

// Used as a callback to StartPrint in tests.
// Increases |*call_count| and records values returned by StartPrint.
void RecordPrintResult(size_t* call_count,
                       bool* success_out,
                       std::string* status_out,
                       const base::Value& status) {}

// Used as a callback to StartGrantPrinterAccess in tests.
// Increases |*call_count| and records the value returned.
void RecordPrinterInfo(size_t* call_count,
                       base::Value::Dict* printer_info_out,
                       const base::Value::Dict& printer_info) {}

std::string RefCountedMemoryToString(
    scoped_refptr<base::RefCountedMemory> memory) {}

// Fake PwgRasterConverter used in the tests.
class FakePwgRasterConverter : public PwgRasterConverter {};

// Information about received print requests.
struct PrintRequestInfo {};

// Fake PrinterProviderAPI used in tests.
// It caches requests issued to API and exposes methods to trigger their
// callbacks.
class FakePrinterProviderAPI : public PrinterProviderAPI {};

std::unique_ptr<KeyedService> BuildTestingPrinterProviderAPI(
    content::BrowserContext* context) {}

}  // namespace

class ExtensionPrinterHandlerTest : public testing::Test {};

TEST_F(ExtensionPrinterHandlerTest, GetPrinters) {}

TEST_F(ExtensionPrinterHandlerTest, GetPrintersReset) {}

TEST_F(ExtensionPrinterHandlerTest, GetUsbPrinters) {}

TEST_F(ExtensionPrinterHandlerTest, GetCapability) {}

TEST_F(ExtensionPrinterHandlerTest, GetCapabilityReset) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPdf) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPdfReset) {}

TEST_F(ExtensionPrinterHandlerTest, PrintAll) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPwg) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPwgNonDefaultSettings) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPwgReset) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPwgInvalidTicket) {}

TEST_F(ExtensionPrinterHandlerTest, PrintPwgFailedConversion) {}

TEST_F(ExtensionPrinterHandlerTest, GrantUsbPrinterAccess) {}

TEST_F(ExtensionPrinterHandlerTest, GrantUsbPrinterAccessReset) {}

}  // namespace printing