#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 {
const char kPrinterId[] = …;
const char kPrinterDescriptionList[] = …;
const char kPWGRasterOnlyPrinterSimpleDescription[] = …;
const char kEmptyPrintTicket[] = …;
const char kPrintTicketWithDuplex[] = …;
const char kExtension1[] = …;
const char kExtension2[] = …;
const char kPdfSettings[] = …;
const char kAllTypesSettings[] = …;
const char kSimpleRasterSettings[] = …;
const char kInvalidSettings[] = …;
const char kDuplexSettings[] = …;
const char kContentTypePDF[] = …;
const char kContentTypePWG[] = …;
const char kPrintRequestSuccess[] = …;
constexpr unsigned char kPrintData[] = …;
void RecordPrinterList(size_t& call_count,
base::Value::List& printers_out,
base::Value::List printers) { … }
void RecordPrintersDone(bool* is_done_out) { … }
void RecordCapability(size_t& call_count,
base::Value::Dict& capability_out,
base::Value::Dict capability) { … }
void RecordPrintResult(size_t* call_count,
bool* success_out,
std::string* status_out,
const base::Value& status) { … }
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) { … }
class FakePwgRasterConverter : public PwgRasterConverter { … };
struct PrintRequestInfo { … };
class FakePrinterProviderAPI : public PrinterProviderAPI { … };
std::unique_ptr<KeyedService> BuildTestingPrinterProviderAPI(
content::BrowserContext* context) { … }
}
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) { … }
}