Home | History | Annotate | Download | only in renderer
      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.
      4 
      5 #ifndef CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
      6 #define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "content/public/test/mock_render_thread.h"
     12 
     13 namespace base {
     14 class DictionaryValue;
     15 }
     16 
     17 class MockPrinter;
     18 struct ExtensionMsg_ExternalConnectionInfo;
     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;
     25 
     26 // Extends content::MockRenderThread to know about printing and
     27 // extension messages.
     28 class ChromeMockRenderThread : public content::MockRenderThread {
     29  public:
     30   ChromeMockRenderThread();
     31   virtual ~ChromeMockRenderThread();
     32 
     33   //////////////////////////////////////////////////////////////////////////
     34   // The following functions are called by the test itself.
     35 
     36 #if defined(ENABLE_PRINTING)
     37   // Returns the pseudo-printer instance.
     38   MockPrinter* printer();
     39 
     40   // Call with |response| set to true if the user wants to print.
     41   // False if the user decides to cancel.
     42   void set_print_dialog_user_response(bool response);
     43 
     44   // Cancel print preview when print preview has |page| remaining pages.
     45   void set_print_preview_cancel_page_number(int page);
     46 
     47   // Get the number of pages to generate for print preview.
     48   int print_preview_pages_remaining() const;
     49 #endif
     50 
     51  private:
     52   // Overrides base class implementation to add custom handling for
     53   // print and extensions.
     54   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
     55 
     56   // The callee expects to be returned a valid channel_id.
     57   void OnOpenChannelToExtension(int routing_id,
     58                                 const ExtensionMsg_ExternalConnectionInfo& info,
     59                                 const std::string& channel_name,
     60                                 int* port_id);
     61 
     62 #if defined(ENABLE_PRINTING)
     63 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
     64   void OnAllocateTempFileForPrinting(int render_view_id,
     65                                      base::FileDescriptor* renderer_fd,
     66                                      int* browser_fd);
     67   void OnTempFileForPrintingWritten(int render_view_id, int browser_fd);
     68 #endif
     69 
     70   // PrintWebViewHelper expects default print settings.
     71   void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting);
     72 
     73   // PrintWebViewHelper expects final print settings from the user.
     74   void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
     75                        PrintMsg_PrintPages_Params* settings);
     76 
     77   void OnDidGetPrintedPagesCount(int cookie, int number_pages);
     78   void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
     79   void OnDidGetPreviewPageCount(
     80       const PrintHostMsg_DidGetPreviewPageCount_Params& params);
     81   void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params);
     82   void OnCheckForCancel(int32 preview_ui_id,
     83                         int preview_request_id,
     84                         bool* cancel);
     85 
     86 
     87   // For print preview, PrintWebViewHelper will update settings.
     88   void OnUpdatePrintSettings(int document_cookie,
     89                              const base::DictionaryValue& job_settings,
     90                              PrintMsg_PrintPages_Params* params);
     91 
     92   // A mock printer device used for printing tests.
     93   scoped_ptr<MockPrinter> printer_;
     94 
     95   // True to simulate user clicking print. False to cancel.
     96   bool print_dialog_user_response_;
     97 
     98   // Simulates cancelling print preview if |print_preview_pages_remaining_|
     99   // equals this.
    100   int print_preview_cancel_page_number_;
    101 
    102   // Number of pages to generate for print preview.
    103   int print_preview_pages_remaining_;
    104 #endif
    105 
    106   DISALLOW_COPY_AND_ASSIGN(ChromeMockRenderThread);
    107 };
    108 
    109 #endif  // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
    110