• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium 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 #include "build/build_config.h"
6 #include "public/fpdf_flatten.h"
7 #include "public/fpdfview.h"
8 #include "testing/embedder_test.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace {
12 
13 class FPDFFlattenEmbedderTest : public EmbedderTest {};
14 
15 }  // namespace
16 
TEST_F(FPDFFlattenEmbedderTest,FlatNothing)17 TEST_F(FPDFFlattenEmbedderTest, FlatNothing) {
18   EXPECT_TRUE(OpenDocument("hello_world.pdf"));
19   FPDF_PAGE page = LoadPage(0);
20   EXPECT_TRUE(page);
21   EXPECT_EQ(FLATTEN_NOTHINGTODO, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
22   UnloadPage(page);
23 }
24 
TEST_F(FPDFFlattenEmbedderTest,FlatNormal)25 TEST_F(FPDFFlattenEmbedderTest, FlatNormal) {
26   EXPECT_TRUE(OpenDocument("annotiter.pdf"));
27   FPDF_PAGE page = LoadPage(0);
28   EXPECT_TRUE(page);
29   EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
30   UnloadPage(page);
31 }
32 
TEST_F(FPDFFlattenEmbedderTest,FlatPrint)33 TEST_F(FPDFFlattenEmbedderTest, FlatPrint) {
34   EXPECT_TRUE(OpenDocument("annotiter.pdf"));
35   FPDF_PAGE page = LoadPage(0);
36   EXPECT_TRUE(page);
37   EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
38   UnloadPage(page);
39 }
40 
41 // TODO(crbug.com/pdfium/11): Fix this test and enable.
42 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
43 #define MAYBE_BUG_861842 DISABLED_BUG_861842
44 #else
45 #define MAYBE_BUG_861842 BUG_861842
46 #endif
TEST_F(FPDFFlattenEmbedderTest,MAYBE_BUG_861842)47 TEST_F(FPDFFlattenEmbedderTest, MAYBE_BUG_861842) {
48 #if defined(OS_WIN)
49   static const char kCheckboxHash[] = "95fba3cb7bce7e0d3c94279f60984e17";
50 #elif defined(OS_MACOSX)
51   static const char kCheckboxHash[] = "0a1d1d63d4452bc26a1c5c547d309655";
52 #else
53   static const char kCheckboxHash[] = "594265790b81df2d93120d33b72a6ada";
54 #endif
55 
56   EXPECT_TRUE(OpenDocument("bug_861842.pdf"));
57   FPDF_PAGE page = LoadPage(0);
58   ASSERT_TRUE(page);
59 
60   ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
61   CompareBitmap(bitmap.get(), 100, 120, kCheckboxHash);
62 
63   EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
64   EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
65 
66   UnloadPage(page);
67 
68   // TODO(crbug.com/861842): This should not render blank.
69   static const char kBlankPageHash[] = "48400809c3862dae64b0cd00d51057a4";
70   VerifySavedDocument(100, 120, kBlankPageHash);
71 }
72 
73 // TODO(crbug.com/pdfium/11): Fix this test and enable.
74 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
75 #define MAYBE_BUG_890322 DISABLED_BUG_890322
76 #else
77 #define MAYBE_BUG_890322 BUG_890322
78 #endif
TEST_F(FPDFFlattenEmbedderTest,MAYBE_BUG_890322)79 TEST_F(FPDFFlattenEmbedderTest, MAYBE_BUG_890322) {
80   static const char md5_hash[] = "6c674642154408e877d88c6c082d67e9";
81   EXPECT_TRUE(OpenDocument("bug_890322.pdf"));
82   FPDF_PAGE page = LoadPage(0);
83   ASSERT_TRUE(page);
84 
85   ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
86   CompareBitmap(bitmap.get(), 200, 200, md5_hash);
87 
88   EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
89   EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
90 
91   UnloadPage(page);
92 
93   VerifySavedDocument(200, 200, md5_hash);
94 }
95 
96 // TODO(crbug.com/pdfium/11): Fix this test and enable.
97 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
98 #define MAYBE_BUG_896366 DISABLED_BUG_896366
99 #else
100 #define MAYBE_BUG_896366 BUG_896366
101 #endif
TEST_F(FPDFFlattenEmbedderTest,MAYBE_BUG_896366)102 TEST_F(FPDFFlattenEmbedderTest, MAYBE_BUG_896366) {
103   static const char md5_hash[] = "f71ab085c52c8445ae785eca3ec858b1";
104   EXPECT_TRUE(OpenDocument("bug_896366.pdf"));
105   FPDF_PAGE page = LoadPage(0);
106   ASSERT_TRUE(page);
107 
108   ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
109   CompareBitmap(bitmap.get(), 612, 792, md5_hash);
110 
111   EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
112   EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
113 
114   UnloadPage(page);
115 
116   VerifySavedDocument(612, 792, md5_hash);
117 }
118