Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / printing / test / print_mock_render_thread.h
bloba5efe2ed4706bc943ff57dda2593dd7c9de4102f
1 // Copyright (c) 2011 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_PRINT_MOCK_RENDER_THREAD_H_
6 #define COMPONENTS_PRINTING_TEST_PRINT_MOCK_RENDER_THREAD_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/single_thread_task_runner.h"
12 #include "content/public/test/mock_render_thread.h"
14 namespace base {
15 class DictionaryValue;
18 class MockPrinter;
19 struct PrintHostMsg_DidGetPreviewPageCount_Params;
20 struct PrintHostMsg_DidPreviewPage_Params;
21 struct PrintHostMsg_DidPrintPage_Params;
22 struct PrintHostMsg_ScriptedPrint_Params;
23 struct PrintMsg_PrintPages_Params;
24 struct PrintMsg_Print_Params;
26 // Extends content::MockRenderThread to know about printing
27 class PrintMockRenderThread : public content::MockRenderThread {
28 public:
29 PrintMockRenderThread();
30 ~PrintMockRenderThread() override;
32 // content::RenderThread overrides.
33 scoped_refptr<base::SingleThreadTaskRunner> GetIOMessageLoopProxy() override;
35 //////////////////////////////////////////////////////////////////////////
36 // The following functions are called by the test itself.
38 // Set IO message loop proxy.
39 void set_io_message_loop_proxy(
40 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
42 #if defined(ENABLE_PRINTING)
43 // Returns the pseudo-printer instance.
44 MockPrinter* printer();
46 // Call with |response| set to true if the user wants to print.
47 // False if the user decides to cancel.
48 void set_print_dialog_user_response(bool response);
50 // Cancel print preview when print preview has |page| remaining pages.
51 void set_print_preview_cancel_page_number(int page);
53 // Get the number of pages to generate for print preview.
54 int print_preview_pages_remaining() const;
55 #endif
57 private:
58 // Overrides base class implementation to add custom handling for print
59 bool OnMessageReceived(const IPC::Message& msg) override;
61 #if defined(ENABLE_PRINTING)
62 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
63 void OnAllocateTempFileForPrinting(int render_view_id,
64 base::FileDescriptor* renderer_fd,
65 int* browser_fd);
66 void OnTempFileForPrintingWritten(int render_view_id, int browser_fd);
67 #endif
69 // PrintWebViewHelper expects default print settings.
70 void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting);
72 // PrintWebViewHelper expects final print settings from the user.
73 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
74 PrintMsg_PrintPages_Params* settings);
76 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
77 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
78 void OnDidGetPreviewPageCount(
79 const PrintHostMsg_DidGetPreviewPageCount_Params& params);
80 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params);
81 void OnCheckForCancel(int32 preview_ui_id,
82 int preview_request_id,
83 bool* cancel);
85 // For print preview, PrintWebViewHelper will update settings.
86 void OnUpdatePrintSettings(int document_cookie,
87 const base::DictionaryValue& job_settings,
88 PrintMsg_PrintPages_Params* params,
89 bool* canceled);
91 // A mock printer device used for printing tests.
92 scoped_ptr<MockPrinter> printer_;
94 // True to simulate user clicking print. False to cancel.
95 bool print_dialog_user_response_;
97 // Simulates cancelling print preview if |print_preview_pages_remaining_|
98 // equals this.
99 int print_preview_cancel_page_number_;
101 // Number of pages to generate for print preview.
102 int print_preview_pages_remaining_;
103 #endif
105 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
107 DISALLOW_COPY_AND_ASSIGN(PrintMockRenderThread);
110 #endif // COMPONENTS_PRINTING_TEST_PRINT_MOCK_RENDER_THREAD_H_