cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / printing / test / mock_printer.h
blob9e828a7584741f20d170c8304acd13919687d384
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PRINTING_TEST_MOCK_PRINTER_H_
6 #define COMPONENTS_PRINTING_TEST_MOCK_PRINTER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "printing/image.h"
16 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
20 struct PrintMsg_Print_Params;
21 struct PrintMsg_PrintPages_Params;
22 struct PrintHostMsg_DidPrintPage_Params;
24 // A class which represents an output page used in the MockPrinter class.
25 // The MockPrinter class stores output pages in a vector, so, this class
26 // inherits the base::RefCounted<> class so that the MockPrinter class can use
27 // a smart pointer of this object (i.e. scoped_refptr<>).
28 class MockPrinterPage : public base::RefCounted<MockPrinterPage> {
29 public:
30 MockPrinterPage(const void* source_data,
31 uint32 source_size,
32 const printing::Image& image);
34 int width() const { return image_.size().width(); }
35 int height() const { return image_.size().height(); }
36 const uint8* source_data() const { return source_data_.get(); }
37 uint32 source_size() const { return source_size_; }
38 const printing::Image& image() const { return image_; }
40 private:
41 friend class base::RefCounted<MockPrinterPage>;
42 virtual ~MockPrinterPage();
44 uint32 source_size_;
45 scoped_ptr<uint8[]> source_data_;
46 printing::Image image_;
48 DISALLOW_COPY_AND_ASSIGN(MockPrinterPage);
51 // A class which implements a pseudo-printer object used by the RenderViewTest
52 // class.
53 // This class consists of three parts:
54 // 1. An IPC-message hanlder sent from the RenderView class;
55 // 2. A renderer that creates a printing job into bitmaps, and;
56 // 3. A vector which saves the output pages of a printing job.
57 // A user who writes RenderViewTest cases only use the functions which
58 // retrieve output pages from this vector to verify them with expected results.
59 class MockPrinter {
60 public:
61 enum Status {
62 PRINTER_READY,
63 PRINTER_PRINTING,
64 PRINTER_ERROR,
67 MockPrinter();
68 ~MockPrinter();
70 // Functions that changes settings of a pseudo printer.
71 void ResetPrinter();
72 void SetDefaultPrintSettings(const PrintMsg_Print_Params& params);
73 void UseInvalidSettings();
74 void UseInvalidPageSize();
75 void UseInvalidContentSize();
77 // Functions that handles IPC events.
78 void GetDefaultPrintSettings(PrintMsg_Print_Params* params);
79 void ScriptedPrint(int cookie,
80 int expected_pages_count,
81 bool has_selection,
82 PrintMsg_PrintPages_Params* settings);
83 void UpdateSettings(int cookie,
84 PrintMsg_PrintPages_Params* params,
85 const std::vector<int>& page_range_array,
86 int margins_type);
87 void SetPrintedPagesCount(int cookie, int number_pages);
88 void PrintPage(const PrintHostMsg_DidPrintPage_Params& params);
90 // Functions that retrieve the output pages.
91 Status GetPrinterStatus() const { return printer_status_; }
92 int GetPrintedPages() const;
94 // Get a pointer to the printed page, returns NULL if pageno has not been
95 // printed. The pointer is for read only view and should not be deleted.
96 const MockPrinterPage* GetPrintedPage(unsigned int pageno) const;
98 int GetWidth(unsigned int page) const;
99 int GetHeight(unsigned int page) const;
100 bool GetBitmapChecksum(unsigned int page, std::string* checksum) const;
101 bool GetSource(unsigned int page, const void** data, uint32* size) const;
102 bool GetBitmap(unsigned int page, const void** data, uint32* size) const;
103 bool SaveSource(unsigned int page, const base::FilePath& filepath) const;
104 bool SaveBitmap(unsigned int page, const base::FilePath& filepath) const;
106 protected:
107 int CreateDocumentCookie();
109 private:
110 // Helper function to fill the fields in |params|.
111 void SetPrintParams(PrintMsg_Print_Params* params);
113 // In pixels according to dpi_x and dpi_y.
114 gfx::Size page_size_;
115 gfx::Size content_size_;
116 int margin_left_;
117 int margin_top_;
118 gfx::Rect printable_area_;
120 // Specifies dots per inch.
121 double dpi_;
122 double max_shrink_;
123 double min_shrink_;
125 // Desired apparent dpi on paper.
126 int desired_dpi_;
128 // Print selection.
129 bool selection_only_;
131 // Print css backgrounds.
132 bool should_print_backgrounds_;
134 // Cookie for the document to ensure correctness.
135 int document_cookie_;
136 int current_document_cookie_;
138 // The current status of this printer.
139 Status printer_status_;
141 // The output of a printing job.
142 int number_pages_;
143 int page_number_;
145 // Used only in the preview sequence.
146 bool is_first_request_;
147 bool print_to_pdf_;
148 int preview_request_id_;
150 // Specifies whether to retain/crop/scale source page size to fit the
151 // given printable area.
152 blink::WebPrintScalingOption print_scaling_option_;
154 // Used for displaying headers and footers.
155 bool display_header_footer_;
156 base::string16 title_;
157 base::string16 url_;
159 // Used for generating invalid settings.
160 bool use_invalid_settings_;
162 std::vector<scoped_refptr<MockPrinterPage>> pages_;
164 DISALLOW_COPY_AND_ASSIGN(MockPrinter);
167 #endif // COMPONENTS_PRINTING_TEST_MOCK_PRINTER_H_