Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
fpdf_flatten_embeddertest.cpp
Go to the documentation of this file.
1
// Copyright 2016 The PDFium Authors
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
"core/fxge/cfx_defaultrenderdevice.h"
7
#
include
"public/fpdf_flatten.h"
8
#
include
"public/fpdfview.h"
9
#
include
"testing/embedder_test.h"
10
#
include
"testing/gmock/include/gmock/gmock.h"
11
#
include
"testing/gtest/include/gtest/gtest.h"
12
13
using
testing::HasSubstr;
14
using
testing::Not;
15
16
namespace
{
17
18
class
FPDFFlattenEmbedderTest :
public
EmbedderTest
{};
19
20
}
// namespace
21
22
TEST_F
(FPDFFlattenEmbedderTest,
FlatNothing
) {
23
ASSERT_TRUE(OpenDocument(
"hello_world.pdf"
));
24
FPDF_PAGE page = LoadPage(0);
25
EXPECT_TRUE(page);
26
EXPECT_EQ(
FLATTEN_NOTHINGTODO
,
FPDFPage_Flatten
(
page
,
FLAT_NORMALDISPLAY
)
);
27
UnloadPage(page);
28
}
29
30
TEST_F
(FPDFFlattenEmbedderTest,
FlatNormal
) {
31
ASSERT_TRUE(OpenDocument(
"annotiter.pdf"
));
32
FPDF_PAGE page = LoadPage(0);
33
EXPECT_TRUE(page);
34
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_NORMALDISPLAY
)
);
35
UnloadPage(page);
36
}
37
38
TEST_F
(FPDFFlattenEmbedderTest,
FlatPrint
) {
39
ASSERT_TRUE(OpenDocument(
"annotiter.pdf"
));
40
FPDF_PAGE page = LoadPage(0);
41
EXPECT_TRUE(page);
42
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
43
UnloadPage(page);
44
}
45
46
TEST_F
(FPDFFlattenEmbedderTest,
FlatWithBadFont
) {
47
ASSERT_TRUE(OpenDocument(
"344775293.pdf"
));
48
FPDF_PAGE page = LoadPage(0);
49
EXPECT_TRUE(page);
50
51
FORM_OnLButtonDown(form_handle(), page, 0, 20, 30);
52
FORM_OnLButtonUp(form_handle(), page, 0, 20, 30);
53
54
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
55
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
56
57
EXPECT_THAT(GetString(), Not(HasSubstr(
"/PDFDocEncoding"
)));
58
UnloadPage(page);
59
}
60
61
TEST_F
(FPDFFlattenEmbedderTest,
FlatWithFontNoBaseEncoding
) {
62
ASSERT_TRUE(OpenDocument(
"363015187.pdf"
));
63
FPDF_PAGE page = LoadPage(0);
64
EXPECT_TRUE(page);
65
66
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
67
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
68
69
EXPECT_THAT(GetString(), HasSubstr(
"/Differences"
));
70
UnloadPage(page);
71
}
72
73
TEST_F
(FPDFFlattenEmbedderTest,
Bug861842
) {
74
const
char
* checkbox_checksum = []() {
75
if
(CFX_DefaultRenderDevice
::
UseSkiaRenderer
(
)
) {
76
#
if
BUILDFLAG
(
IS_APPLE
)
77
return
"84a527f16649880525a1a8edc6c24c16"
;
78
#
else
79
return
"95fdaa000e81c80892b8d370f77be970"
;
80
#
endif
81
}
82
#
if
BUILDFLAG
(
IS_APPLE
)
83
return
"6aafcb2d98da222964bcdbf5aa1f4f1f"
;
84
#
else
85
return
"594265790b81df2d93120d33b72a6ada"
;
86
#
endif
87
}();
88
89
ASSERT_TRUE(OpenDocument(
"bug_861842.pdf"
));
90
FPDF_PAGE page = LoadPage(0);
91
ASSERT_TRUE(page);
92
93
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT
);
94
CompareBitmap(bitmap.get(), 100, 120, checkbox_checksum);
95
96
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
97
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
98
99
UnloadPage(page);
100
101
// TODO(crbug.com/861842): This should not render blank.
102
static
constexpr
char
kBlankPageHash[] =
"48400809c3862dae64b0cd00d51057a4"
;
103
VerifySavedDocument(100, 120, kBlankPageHash);
104
}
105
106
TEST_F
(FPDFFlattenEmbedderTest,
Bug889099
) {
107
const
char
* page_checksum = []() {
108
if
(CFX_DefaultRenderDevice
::
UseSkiaRenderer
(
)
) {
109
#
if
BUILDFLAG
(
IS_WIN
)
110
return
"1d83328d2d1ca12b9c9ea5faa62ac515"
;
111
#
elif
BUILDFLAG
(
IS_APPLE
)
112
return
"3b6f937deec2d27029cbce02111dc065"
;
113
#
else
114
return
"de7119d99f42deab2f4215017bdb16af"
;
115
#
endif
116
}
117
#
if
BUILDFLAG
(
IS_APPLE
)
118
return
"049ed3f1e21fc72f929af3410c64bc8f"
;
119
#
else
120
return
"3db87245e3f4e37f4cb18654bbe22d97"
;
121
#
endif
122
}();
123
const
char
* flattened_page_checksum = []() {
124
if
(CFX_DefaultRenderDevice
::
UseSkiaRenderer
(
)
) {
125
#
if
BUILDFLAG
(
IS_WIN
)
126
return
"07deccbd4a42aaf6bf45a525f0be388e"
;
127
#
elif
BUILDFLAG
(
IS_APPLE
)
128
return
"f1bbe115355a2ad6d8ac34c7ff14ba75"
;
129
#
else
130
return
"7978c7b3d643a5f0ac0f03ce759c55fe"
;
131
#
endif
132
}
133
#
if
BUILDFLAG
(
IS_APPLE
)
134
return
"41debc60cf2a8f74c710ec6082d77b18"
;
135
#
else
136
return
"0832157462ea70fbbf053e14b1d6457f"
;
137
#
endif
138
}();
139
140
ASSERT_TRUE(OpenDocument(
"bug_889099.pdf"
));
141
FPDF_PAGE page = LoadPage(0);
142
ASSERT_TRUE(page);
143
144
// The original document has a malformed media box; the height is -400.
145
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT
);
146
CompareBitmap(bitmap.get(), 300, 400, page_checksum);
147
148
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
149
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
150
151
UnloadPage(page);
152
153
VerifySavedDocument(300, 400, flattened_page_checksum);
154
}
155
156
TEST_F
(FPDFFlattenEmbedderTest,
Bug890322
) {
157
const
char
* checksum = []() {
158
if
(CFX_DefaultRenderDevice
::
UseSkiaRenderer
(
)
) {
159
return
"793689536cf64fe792c2f241888c0cf3"
;
160
}
161
return
"6c674642154408e877d88c6c082d67e9"
;
162
}();
163
ASSERT_TRUE(OpenDocument(
"bug_890322.pdf"
));
164
FPDF_PAGE page = LoadPage(0);
165
ASSERT_TRUE(page);
166
167
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT
);
168
CompareBitmap(bitmap.get(), 200, 200, checksum);
169
170
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
171
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
172
173
UnloadPage(page);
174
175
VerifySavedDocument(200, 200, checksum);
176
}
177
178
TEST_F
(FPDFFlattenEmbedderTest,
Bug896366
) {
179
const
char
* checksum = []() {
180
if
(CFX_DefaultRenderDevice
::
UseSkiaRenderer
(
)
) {
181
return
"c3cccfadc4c5249e6aa0675e511fa4c3"
;
182
}
183
return
"f71ab085c52c8445ae785eca3ec858b1"
;
184
}();
185
ASSERT_TRUE(OpenDocument(
"bug_896366.pdf"
));
186
FPDF_PAGE page = LoadPage(0);
187
ASSERT_TRUE(page);
188
189
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT
);
190
CompareBitmap(bitmap.get(), 612, 792, checksum);
191
192
EXPECT_EQ(
FLATTEN_SUCCESS
,
FPDFPage_Flatten
(
page
,
FLAT_PRINT
)
);
193
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
194
195
UnloadPage(page);
196
197
VerifySavedDocument(612, 792, checksum);
198
}
CFX_DefaultRenderDevice::UseSkiaRenderer
static bool UseSkiaRenderer()
Definition
cfx_defaultrenderdevice.cpp:28
EmbedderTest
Definition
embedder_test.h:40
FPDFPage_Flatten
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag)
Definition
fpdf_flatten.cpp:295
FLAT_PRINT
#define FLAT_PRINT
Definition
fpdf_flatten.h:23
FLATTEN_NOTHINGTODO
#define FLATTEN_NOTHINGTODO
Definition
fpdf_flatten.h:18
FLATTEN_SUCCESS
#define FLATTEN_SUCCESS
Definition
fpdf_flatten.h:16
FLAT_NORMALDISPLAY
#define FLAT_NORMALDISPLAY
Definition
fpdf_flatten.h:21
TEST_F
TEST_F(FPDFFlattenEmbedderTest, FlatNothing)
Definition
fpdf_flatten_embeddertest.cpp:22
FPDF_ANNOT
#define FPDF_ANNOT
Definition
fpdfview.h:790
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fpdfsdk
fpdf_flatten_embeddertest.cpp
Generated on
for Qt by
1.18.0