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_
10 #include "base/compiler_specific.h"
11 #include "content/public/test/mock_render_thread.h"
14 class DictionaryValue
;
18 struct PrintHostMsg_DidGetPreviewPageCount_Params
;
19 struct PrintHostMsg_DidPreviewPage_Params
;
20 struct PrintHostMsg_DidPrintPage_Params
;
21 struct PrintHostMsg_ScriptedPrint_Params
;
22 struct PrintMsg_PrintPages_Params
;
23 struct PrintMsg_Print_Params
;
25 // Extends content::MockRenderThread to know about printing
26 class PrintMockRenderThread
: public content::MockRenderThread
{
28 PrintMockRenderThread();
29 ~PrintMockRenderThread() override
;
31 // content::RenderThread overrides.
32 scoped_refptr
<base::MessageLoopProxy
> GetIOMessageLoopProxy() override
;
34 //////////////////////////////////////////////////////////////////////////
35 // The following functions are called by the test itself.
37 // Set IO message loop proxy.
38 void set_io_message_loop_proxy(
39 const scoped_refptr
<base::MessageLoopProxy
>& proxy
);
41 #if defined(ENABLE_PRINTING)
42 // Returns the pseudo-printer instance.
43 MockPrinter
* printer();
45 // Call with |response| set to true if the user wants to print.
46 // False if the user decides to cancel.
47 void set_print_dialog_user_response(bool response
);
49 // Cancel print preview when print preview has |page| remaining pages.
50 void set_print_preview_cancel_page_number(int page
);
52 // Get the number of pages to generate for print preview.
53 int print_preview_pages_remaining() const;
57 // Overrides base class implementation to add custom handling for print
58 bool OnMessageReceived(const IPC::Message
& msg
) override
;
60 #if defined(ENABLE_PRINTING)
61 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
62 void OnAllocateTempFileForPrinting(int render_view_id
,
63 base::FileDescriptor
* renderer_fd
,
65 void OnTempFileForPrintingWritten(int render_view_id
, int browser_fd
);
68 // PrintWebViewHelper expects default print settings.
69 void OnGetDefaultPrintSettings(PrintMsg_Print_Params
* setting
);
71 // PrintWebViewHelper expects final print settings from the user.
72 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params
& params
,
73 PrintMsg_PrintPages_Params
* settings
);
75 void OnDidGetPrintedPagesCount(int cookie
, int number_pages
);
76 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params
& params
);
77 void OnDidGetPreviewPageCount(
78 const PrintHostMsg_DidGetPreviewPageCount_Params
& params
);
79 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params
& params
);
80 void OnCheckForCancel(int32 preview_ui_id
,
81 int preview_request_id
,
84 // For print preview, PrintWebViewHelper will update settings.
85 void OnUpdatePrintSettings(int document_cookie
,
86 const base::DictionaryValue
& job_settings
,
87 PrintMsg_PrintPages_Params
* params
,
90 // A mock printer device used for printing tests.
91 scoped_ptr
<MockPrinter
> printer_
;
93 // True to simulate user clicking print. False to cancel.
94 bool print_dialog_user_response_
;
96 // Simulates cancelling print preview if |print_preview_pages_remaining_|
98 int print_preview_cancel_page_number_
;
100 // Number of pages to generate for print preview.
101 int print_preview_pages_remaining_
;
104 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_proxy_
;
106 DISALLOW_COPY_AND_ASSIGN(PrintMockRenderThread
);
109 #endif // COMPONENTS_PRINTING_TEST_PRINT_MOCK_RENDER_THREAD_H_