| Index: printing/pdf_metafile_cg_mac_unittest.cc
|
| diff --git a/printing/pdf_metafile_cg_mac_unittest.cc b/printing/pdf_metafile_cg_mac_unittest.cc
|
| index 4b9b38ce792a4832cb1d4ce030d68364bc5fe476..ab257aafbd4db72bb0feb0ba799080aeefc71ac3 100644
|
| --- a/printing/pdf_metafile_cg_mac_unittest.cc
|
| +++ b/printing/pdf_metafile_cg_mac_unittest.cc
|
| @@ -4,20 +4,25 @@
|
|
|
| #include "printing/pdf_metafile_cg_mac.h"
|
|
|
| -#import <ApplicationServices/ApplicationServices.h>
|
| +#include <ApplicationServices/ApplicationServices.h>
|
| +#include <CoreFoundation/CoreFoundation.h>
|
| #include <stdint.h>
|
|
|
| #include <string>
|
| #include <vector>
|
|
|
| +#include "base/mac/scoped_cftyperef.h"
|
| +#include "printing/pdf_metafile_skia.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/gfx/geometry/rect.h"
|
|
|
| +using base::ScopedCFTypeRef;
|
| +
|
| namespace printing {
|
|
|
| TEST(PdfMetafileCgTest, Pdf) {
|
| - // Test in-renderer constructor.
|
| - PdfMetafileCg pdf;
|
| + // Create test PDF.
|
| + PdfMetafileSkia pdf(PDF_SKIA_DOCUMENT_TYPE);
|
| EXPECT_TRUE(pdf.Init());
|
| EXPECT_TRUE(pdf.context() != NULL);
|
|
|
| @@ -41,28 +46,25 @@ TEST(PdfMetafileCgTest, Pdf) {
|
|
|
| // Get resulting data.
|
| std::vector<char> buffer(size, 0);
|
| - pdf.GetData(&buffer.front(), size);
|
| -
|
| - // Test browser-side constructor.
|
| - PdfMetafileCg pdf2;
|
| - EXPECT_TRUE(pdf2.InitFromData(&buffer.front(), size));
|
| -
|
| - // Get the first 4 characters from pdf2.
|
| - std::vector<char> buffer2(4, 0);
|
| - pdf2.GetData(&buffer2.front(), 4);
|
| + pdf.GetData(buffer.data(), size);
|
|
|
| // Test that the header begins with "%PDF".
|
| - std::string header(&buffer2.front(), 4);
|
| + std::string header(buffer.data(), 4);
|
| EXPECT_EQ(0U, header.find("%PDF", 0));
|
|
|
| - // Test that the PDF is correctly reconstructed.
|
| - EXPECT_EQ(2U, pdf2.GetPageCount());
|
| - gfx::Size page_size = pdf2.GetPageBounds(1).size();
|
| - EXPECT_EQ(540, page_size.width());
|
| - EXPECT_EQ(720, page_size.height());
|
| - page_size = pdf2.GetPageBounds(2).size();
|
| - EXPECT_EQ(720, page_size.width());
|
| - EXPECT_EQ(540, page_size.height());
|
| + base::ScopedCFTypeRef<CFMutableDataRef> pdf_data(
|
| + CFDataCreateMutable(kCFAllocatorDefault, 0));
|
| + EXPECT_TRUE(pdf_data.get() != nullptr);
|
| + ScopedCFTypeRef<CGDataConsumerRef> pdf_consumer(
|
| + CGDataConsumerCreateWithCFData(pdf_data));
|
| + EXPECT_TRUE(pdf_consumer.get() != nullptr);
|
| + base::ScopedCFTypeRef<CGContextRef> context(
|
| + CGPDFContextCreate(pdf_consumer, nullptr, nullptr));
|
| + EXPECT_TRUE(context.get() != nullptr);
|
| +
|
| + PdfMetafileCg::RenderPageParams params;
|
| + EXPECT_TRUE(PdfMetafileCg::RenderPage(buffer.data(), size, 1, context.get(),
|
| + CGRectMake(0, 0, 540, 720), params));
|
| }
|
|
|
| } // namespace printing
|
|
|