Win32: Print the right number of pages.

BUG=48392
TEST=included.
Review URL: http://codereview.chromium.org/3113012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56063 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/printing/printing_context.h b/printing/printing_context.h
index ec8a7d8..8996fa9c 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -16,6 +16,7 @@
 
 #include "base/basictypes.h"
 #include "base/logging.h"
+#include "base/scoped_ptr.h"
 #include "gfx/native_widget_types.h"
 #include "printing/print_settings.h"
 
@@ -50,6 +51,24 @@
   Result AskUserForSettings(gfx::NativeView parent_view, int max_pages,
                             bool has_selection);
 
+#if defined(OS_WIN) && defined(UNIT_TEST)
+  // Sets a fake PrintDlgEx function pointer in tests.
+  void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) {
+    print_dialog_func_ = print_dialog_func;
+  }
+#endif
+
+#if defined(OS_WIN)
+  // Allocates the HDC for a specific DEVMODE.
+  static bool AllocateContext(const std::wstring& printer_name,
+                              const DEVMODE* dev_mode,
+                              gfx::NativeDrawingContext* context);
+
+  // Retrieves the content of a GetPrinter call.
+  static void GetPrinterHelper(HANDLE printer, int level,
+                               scoped_array<uint8>* buffer);
+#endif
+
   // Selects the user's default printer and format. Updates the context with the
   // default device settings.
   Result UseDefaultSettings();
@@ -127,14 +146,9 @@
   bool GetPrinterSettings(HANDLE printer,
                           const std::wstring& device_name);
 
-  // Allocates the HDC for a specific DEVMODE.
-  bool AllocateContext(const std::wstring& printer_name,
-                       const DEVMODE* dev_mode);
-
   // Parses the result of a PRINTDLGEX result.
   Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);
   Result ParseDialogResult(const PRINTDLG& dialog_options);
-
 #elif defined(OS_MACOSX)
   // Read the settings from the given NSPrintInfo (and cache it for later use).
   void ParsePrintInfo(NSPrintInfo* print_info);
@@ -161,6 +175,10 @@
 #if defined(OS_WIN)
   // The dialog box for the time it is shown.
   volatile HWND dialog_box_;
+
+  // Function pointer that defaults to PrintDlgEx. It can be changed using
+  // SetPrintDialog() in tests.
+  HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX);
 #endif
 
   // The dialog box has been dismissed.