1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_BACKEND_TEST_PRINT_BACKEND_H_
#define PRINTING_BACKEND_TEST_PRINT_BACKEND_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "printing/backend/print_backend.h"
namespace printing {
// PrintBackend which doesn't interact with the OS and responses
// can be overridden as necessary.
class TestPrintBackend : public PrintBackend {
public:
TestPrintBackend();
// PrintBackend overrides
bool EnumeratePrinters(PrinterList* printer_list) override;
std::string GetDefaultPrinterName() override;
bool GetPrinterBasicInfo(const std::string& printer_name,
PrinterBasicInfo* printer_info) override;
bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
std::string GetPrinterDriverInfo(const std::string& printer_name) override;
bool IsValidPrinter(const std::string& printer_name) override;
// Set a default printer. The default is the empty string.
void SetDefaultPrinterName(const std::string& printer_name);
// Add a printer to satisfy IsValidPrinter(), EnumeratePrinters(),
// GetPrinterBasicInfo(), and GetPrinterSemanticCapsAndDefaults().
// While `caps` can be null, it will cause queries for the capabilities to
// fail, and thus is likely not of interest for most tests. IsValidPrinter()
// will still show true even if `caps` is null, which provides the benefit of
// simulating a printer that exists in the system but cannot be queried.
// `info` can be null, which will result in empty information being provided
// for any queries.
// Calling EnumeratePrinters() will include the identified `printer_name`
// even if either parameter is null.
void AddValidPrinter(const std::string& printer_name,
std::unique_ptr<PrinterSemanticCapsAndDefaults> caps,
std::unique_ptr<PrinterBasicInfo> info);
protected:
~TestPrintBackend() override;
private:
std::string default_printer_name_;
std::map<std::string, std::unique_ptr<PrinterSemanticCapsAndDefaults>>
valid_printers_;
};
} // namespace printing
#endif // PRINTING_BACKEND_TEST_PRINT_BACKEND_H_
|