Index: chrome/browser/printing/print_preview_pdf_generated_browsertest.cc |
diff --git a/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc b/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc |
index f6a93216df9a52a008c9271ab1b0f3fe5d658528..367a92d3f4b9b4f5a6907daa5e2fe8ce95c141a1 100644 |
--- a/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc |
+++ b/chrome/browser/printing/print_preview_pdf_generated_browsertest.cc |
@@ -22,6 +22,7 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/path_service.h" |
#include "base/run_loop.h" |
+#include "base/scoped_native_library.h" |
#include "base/strings/string_split.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/printing/print_preview_dialog_controller.h" |
@@ -38,7 +39,6 @@ |
#include "content/public/test/browser_test_utils.h" |
#include "ipc/ipc_message_macros.h" |
#include "net/base/filename_util.h" |
-#include "pdf/pdf.h" |
#include "printing/pdf_render_settings.h" |
#include "printing/units.h" |
#include "ui/gfx/codec/png_codec.h" |
@@ -323,6 +323,33 @@ |
ASSERT_TRUE(pdf_file.IsValid()); |
} |
+ // Initializes function pointers from the PDF library. Called once when the |
+ // test starts. The library is closed when the browser test ends. |
+ void InitPdfFunctions() { |
+ base::FilePath pdf_module_path; |
+ |
+ ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path)); |
+ ASSERT_TRUE(base::PathExists(pdf_module_path)); |
+ pdf_lib_.Reset(base::LoadNativeLibrary(pdf_module_path, NULL)); |
+ |
+ ASSERT_TRUE(pdf_lib_.is_valid()); |
+ pdf_to_bitmap_func_ = |
+ reinterpret_cast<PDFPageToBitmapProc>( |
+ pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap")); |
+ |
+ pdf_doc_info_func_ = |
+ reinterpret_cast<GetPDFDocInfoProc>( |
+ pdf_lib_.GetFunctionPointer("GetPDFDocInfo")); |
+ |
+ pdf_page_size_func_ = |
+ reinterpret_cast<GetPDFPageSizeByIndexProc>( |
+ pdf_lib_.GetFunctionPointer("GetPDFPageSizeByIndex")); |
+ |
+ ASSERT_TRUE(pdf_to_bitmap_func_); |
+ ASSERT_TRUE(pdf_doc_info_func_); |
+ ASSERT_TRUE(pdf_page_size_func_); |
+ } |
+ |
// Converts the PDF to a PNG file so that the layout test can do an image |
// diff on this image and a reference image. |
void PdfToPng() { |
@@ -333,10 +360,10 @@ |
std::string pdf_data; |
ASSERT_TRUE(base::ReadFileToString(pdf_file_save_path_, &pdf_data)); |
- ASSERT_TRUE(chrome_pdf::GetPDFDocInfo(pdf_data.data(), |
- pdf_data.size(), |
- &num_pages, |
- &max_width_in_points)); |
+ ASSERT_TRUE(pdf_doc_info_func_(pdf_data.data(), |
+ pdf_data.size(), |
+ &num_pages, |
+ &max_width_in_points)); |
ASSERT_GT(num_pages, 0); |
double max_width_in_pixels = |
@@ -344,11 +371,11 @@ |
for (int i = 0; i < num_pages; ++i) { |
double width_in_points, height_in_points; |
- ASSERT_TRUE(chrome_pdf::GetPDFPageSizeByIndex(pdf_data.data(), |
- pdf_data.size(), |
- i, |
- &width_in_points, |
- &height_in_points)); |
+ ASSERT_TRUE(pdf_page_size_func_(pdf_data.data(), |
+ pdf_data.size(), |
+ i, |
+ &width_in_points, |
+ &height_in_points)); |
double width_in_pixels = ConvertUnitDouble( |
width_in_points, kPointsPerInch, kDpi); |
@@ -378,15 +405,15 @@ |
std::vector<uint8_t> page_bitmap_data( |
kColorChannels * settings.area().size().GetArea()); |
- ASSERT_TRUE(chrome_pdf::RenderPDFPageToBitmap( |
- pdf_data.data(), |
- pdf_data.size(), |
- i, |
- page_bitmap_data.data(), |
- settings.area().size().width(), |
- settings.area().size().height(), |
- settings.dpi(), |
- true)); |
+ ASSERT_TRUE(pdf_to_bitmap_func_(pdf_data.data(), |
+ pdf_data.size(), |
+ i, |
+ page_bitmap_data.data(), |
+ settings.area().size().width(), |
+ settings.area().size().height(), |
+ settings.dpi(), |
+ settings.dpi(), |
+ true)); |
FillPng(&page_bitmap_data, |
width_in_pixels, |
max_width_in_pixels, |
@@ -545,6 +572,41 @@ |
scoped_ptr<PrintPreviewObserver> print_preview_observer_; |
base::FilePath pdf_file_save_path_; |
+ // These typedefs are function pointers to pdflib functions that give |
+ // information about the PDF as a whole and about specific pages. |
+ |
+ // Converts the PDF to a bitmap. |
+ typedef bool (*PDFPageToBitmapProc)(const void* pdf_buffer, |
+ int pdf_buffer_size, |
+ int page_number, |
+ void* bitmap_buffer, |
+ int bitmap_width, |
+ int bitmap_height, |
+ int dpi_x, |
+ int dpi_y, |
+ bool autorotate); |
+ |
+ // Gets the page count and maximum page width of the PDF in points. |
+ typedef bool (*GetPDFDocInfoProc)(const void* pdf_buffer, |
+ int buffer_size, |
+ int* pages_count, |
+ double* max_page_width); |
+ |
+ // Gets the dimensions of a specific page within a PDF. |
+ typedef bool (*GetPDFPageSizeByIndexProc)(const void* pdf_buffer, |
+ int buffer_size, |
+ int index, |
+ double* width, |
+ double* height); |
+ |
+ // Instantiations of the function pointers described above. |
+ PDFPageToBitmapProc pdf_to_bitmap_func_; |
+ GetPDFDocInfoProc pdf_doc_info_func_; |
+ GetPDFPageSizeByIndexProc pdf_page_size_func_; |
+ |
+ // Used to open up the pdf plugin, which contains the functions above. |
+ base::ScopedNativeLibrary pdf_lib_; |
+ |
// Vector for storing the PNG to be sent to the layout test framework. |
// TODO(ivandavid): Eventually change this to uint32_t and make everything |
// work with that. It might be a bit tricky to fix everything to work with |
@@ -579,7 +641,8 @@ |
// to send data to the browser test. Writing "EOF\n" to |std::cout| indicates |
// that whatever block of data that the test was expecting has been completely |
// sent. Sometimes EOF is printed to stderr because the test will expect it |
- // from stderr in addition to stdout for certain blocks of data.= |
+ // from stderr in addition to stdout for certain blocks of data. |
+ InitPdfFunctions(); |
SetupStdinAndSavePath(); |
while (true) { |