blob: e931d6a077298379a3f137cac4181419794e729e [file] [log] [blame]
Lei Zhang1ac47eb2015-12-21 11:04:44 -08001// Copyright 2015 PDFium Authors. All rights reserved.
Tom Sepez96d13342015-01-16 14:59:26 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Wei Li091f7a02015-11-09 12:09:55 -08005#include "testing/embedder_test.h"
Tom Sepez96d13342015-01-16 14:59:26 -08006
Lei Zhanga98e3662018-02-07 20:28:35 +00007#include <memory>
Tom Sepez96d13342015-01-16 14:59:26 -08008#include <string>
9#include <utility>
Lei Zhangd69e0652019-04-13 00:39:35 +000010#include <vector>
Tom Sepez96d13342015-01-16 14:59:26 -080011
Lei Zhangd145e4b2018-10-12 18:54:31 +000012#include "core/fdrm/fx_crypt.h"
Tom Sepeze08d2b12018-04-25 18:49:32 +000013#include "public/cpp/fpdf_scopers.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080014#include "public/fpdf_dataavail.h"
Lei Zhang453d96b2015-12-31 13:13:10 -080015#include "public/fpdf_edit.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080016#include "public/fpdf_text.h"
17#include "public/fpdfview.h"
Tom Sepeza310e002015-02-27 13:03:07 -080018#include "testing/gmock/include/gmock/gmock.h"
Lei Zhangd50bdff2019-02-05 19:42:33 +000019#include "testing/test_loader.h"
Henrique Nakashimaf956bad2018-08-16 16:41:42 +000020#include "testing/utils/bitmap_saver.h"
Lei Zhangb6992dd2019-02-05 23:30:20 +000021#include "testing/utils/file_util.h"
Lei Zhang4c64e962019-02-05 19:24:12 +000022#include "testing/utils/hash.h"
Wei Li091f7a02015-11-09 12:09:55 -080023#include "testing/utils/path_service.h"
Tom Sepez25f33d02021-01-29 01:58:51 +000024#include "third_party/base/check.h"
Lei Zhang87e3d7a2021-06-17 19:40:28 +000025#include "third_party/base/containers/contains.h"
Lei Zhang30632072020-10-02 01:57:54 +000026#include "third_party/base/notreached.h"
Tom Sepez452b4f32015-10-13 09:27:27 -070027
28#ifdef PDF_ENABLE_V8
Tom Sepezeaf9d212020-07-22 16:24:00 +000029#include "testing/v8_test_environment.h"
Lei Zhang8241df72015-11-06 14:38:48 -080030#include "v8/include/v8-platform.h"
Dan Sinclair61046b92016-02-18 14:48:48 -050031#include "v8/include/v8.h"
Tom Sepez452b4f32015-10-13 09:27:27 -070032#endif // PDF_ENABLE_V8
Tom Sepez96d13342015-01-16 14:59:26 -080033
Tom Sepez96d13342015-01-16 14:59:26 -080034namespace {
thestigc08cd7a2016-06-27 09:47:59 -070035
Jane Liu28fb7ba2017-08-02 21:45:57 -040036int GetBitmapBytesPerPixel(FPDF_BITMAP bitmap) {
Tom Sepez6dc12402020-01-07 21:02:17 +000037 return EmbedderTest::BytesPerPixelForFormat(FPDFBitmap_GetFormat(bitmap));
Jane Liu28fb7ba2017-08-02 21:45:57 -040038}
39
Lei Zhang614f1a02019-05-30 00:03:53 +000040#if defined(OS_WIN)
41int CALLBACK GetRecordProc(HDC hdc,
42 HANDLETABLE* handle_table,
43 const ENHMETARECORD* record,
44 int objects_count,
45 LPARAM param) {
46 auto& records = *reinterpret_cast<std::vector<const ENHMETARECORD*>*>(param);
47 records.push_back(record);
48 return 1;
49}
50#endif // defined(OS_WIN)
51
thestigbcd3e532016-11-21 13:37:28 -080052} // namespace
53
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054EmbedderTest::EmbedderTest()
Tom Sepez7df04832020-05-18 22:09:31 +000055 : default_delegate_(std::make_unique<EmbedderTest::Delegate>()),
Lei Zhang0729be22018-02-05 21:13:51 +000056 delegate_(default_delegate_.get()) {
Nicolas Pena3ff54002017-07-05 11:55:35 -040057 FPDF_FILEWRITE::version = 1;
58 FPDF_FILEWRITE::WriteBlock = WriteBlockCallback;
Tom Sepezf288bb12015-11-20 12:12:46 -080059}
Tom Sepez96d13342015-01-16 14:59:26 -080060
Lei Zhangea208512019-12-18 00:42:11 +000061EmbedderTest::~EmbedderTest() = default;
Tom Sepezf288bb12015-11-20 12:12:46 -080062
63void EmbedderTest::SetUp() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this);
65 memset(info, 0, sizeof(UNSUPPORT_INFO));
66 info->version = 1;
67 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline;
68 FSDK_SetUnSpObjProcessHandler(info);
Lei Zhang0729be22018-02-05 21:13:51 +000069 saved_document_ = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070}
Tom Sepez96d13342015-01-16 14:59:26 -080071
72void EmbedderTest::TearDown() {
Lei Zhang75c81712018-02-08 17:22:39 +000073 // Use an EXPECT_EQ() here and continue to let TearDown() finish as cleanly as
Tom Sepez25f33d02021-01-29 01:58:51 +000074 // possible. This can fail when an DCHECK test fails in a test case.
Lei Zhang75c81712018-02-08 17:22:39 +000075 EXPECT_EQ(0U, page_map_.size());
Lei Zhang9f72c452018-02-08 21:49:54 +000076 EXPECT_EQ(0U, saved_page_map_.size());
Lei Zhang44005192020-04-17 01:35:43 +000077 if (document_)
Tom Sepez38f725f2019-12-04 00:26:34 +000078 CloseDocument();
Tom Sepez96d13342015-01-16 14:59:26 -080079}
80
Lei Zhangb8b4a042021-11-05 00:04:25 +000081void EmbedderTest::CreateEmptyDocument() {
Lei Zhang935fb862021-11-05 00:15:05 +000082 CreateEmptyDocumentWithoutFormFillEnvironment();
Lei Zhangdba065e2021-11-04 23:09:15 +000083 form_handle_.reset(
84 SetupFormFillEnvironment(document_, JavaScriptOption::kEnableJavaScript));
Tom Sepezd483eb42016-01-06 10:03:59 -080085}
86
Lei Zhang935fb862021-11-05 00:15:05 +000087void EmbedderTest::CreateEmptyDocumentWithoutFormFillEnvironment() {
88 document_ = FPDF_CreateNewDocument();
89 DCHECK(document_);
90}
91
Lei Zhang208eecf2017-12-20 19:40:50 +000092bool EmbedderTest::OpenDocument(const std::string& filename) {
Tom Sepez0784c732018-04-23 18:02:57 +000093 return OpenDocumentWithOptions(filename, nullptr,
94 LinearizeOption::kDefaultLinearize,
95 JavaScriptOption::kEnableJavaScript);
Lei Zhang208eecf2017-12-20 19:40:50 +000096}
97
98bool EmbedderTest::OpenDocumentLinearized(const std::string& filename) {
Tom Sepez0784c732018-04-23 18:02:57 +000099 return OpenDocumentWithOptions(filename, nullptr,
100 LinearizeOption::kMustLinearize,
101 JavaScriptOption::kEnableJavaScript);
Lei Zhang208eecf2017-12-20 19:40:50 +0000102}
103
104bool EmbedderTest::OpenDocumentWithPassword(const std::string& filename,
105 const char* password) {
Tom Sepez0784c732018-04-23 18:02:57 +0000106 return OpenDocumentWithOptions(filename, password,
107 LinearizeOption::kDefaultLinearize,
108 JavaScriptOption::kEnableJavaScript);
109}
110
111bool EmbedderTest::OpenDocumentWithoutJavaScript(const std::string& filename) {
112 return OpenDocumentWithOptions(filename, nullptr,
113 LinearizeOption::kDefaultLinearize,
114 JavaScriptOption::kDisableJavaScript);
Lei Zhang208eecf2017-12-20 19:40:50 +0000115}
116
117bool EmbedderTest::OpenDocumentWithOptions(const std::string& filename,
118 const char* password,
Tom Sepez0784c732018-04-23 18:02:57 +0000119 LinearizeOption linearize_option,
120 JavaScriptOption javascript_option) {
Wei Li091f7a02015-11-09 12:09:55 -0800121 std::string file_path;
122 if (!PathService::GetTestFilePath(filename, &file_path))
123 return false;
Tom Sepez0784c732018-04-23 18:02:57 +0000124
Wei Li091f7a02015-11-09 12:09:55 -0800125 file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
Dan Sinclair6be2aab2015-10-28 13:58:49 -0400126 if (!file_contents_)
Tom Sepez96d13342015-01-16 14:59:26 -0800127 return false;
Tom Sepez96d13342015-01-16 14:59:26 -0800128
thestig29ce9232016-06-22 07:03:23 -0700129 EXPECT_TRUE(!loader_);
Tom Sepez7df04832020-05-18 22:09:31 +0000130 loader_ = std::make_unique<TestLoader>(
Lei Zhangb3be4a12019-02-05 22:11:07 +0000131 pdfium::make_span(file_contents_.get(), file_length_));
Lei Zhang0729be22018-02-05 21:13:51 +0000132
133 memset(&file_access_, 0, sizeof(file_access_));
Tom Sepez96d13342015-01-16 14:59:26 -0800134 file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
Tom Sepezd831dc72015-10-19 16:04:22 -0700135 file_access_.m_GetBlock = TestLoader::GetBlock;
Lei Zhangb3be4a12019-02-05 22:11:07 +0000136 file_access_.m_Param = loader_.get();
Lei Zhang0729be22018-02-05 21:13:51 +0000137
Tom Sepez7df04832020-05-18 22:09:31 +0000138 fake_file_access_ = std::make_unique<FakeFileAccess>(&file_access_);
Tom Sepez0784c732018-04-23 18:02:57 +0000139 return OpenDocumentHelper(password, linearize_option, javascript_option,
140 fake_file_access_.get(), &document_, &avail_,
141 &form_handle_);
Nicolas Pena56fc9722017-07-13 16:31:34 -0400142}
Tom Sepez96d13342015-01-16 14:59:26 -0800143
Nicolas Pena56fc9722017-07-13 16:31:34 -0400144bool EmbedderTest::OpenDocumentHelper(const char* password,
Tom Sepez0784c732018-04-23 18:02:57 +0000145 LinearizeOption linearize_option,
146 JavaScriptOption javascript_option,
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300147 FakeFileAccess* network_simulator,
Nicolas Pena56fc9722017-07-13 16:31:34 -0400148 FPDF_DOCUMENT* document,
Lei Zhang52d21ac2021-11-04 22:40:15 +0000149 ScopedFPDFAvail* avail,
Lei Zhangdba065e2021-11-04 23:09:15 +0000150 ScopedFPDFFormHandle* form_handle) {
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300151 network_simulator->AddSegment(0, 1024);
152 network_simulator->SetRequestedDataAvailable();
Lei Zhang52d21ac2021-11-04 22:40:15 +0000153 avail->reset(FPDFAvail_Create(network_simulator->GetFileAvail(),
154 network_simulator->GetFileAccess()));
155 FPDF_AVAIL avail_ptr = avail->get();
156 if (FPDFAvail_IsLinearized(avail_ptr) == PDF_LINEARIZED) {
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300157 int32_t nRet = PDF_DATA_NOTAVAIL;
158 while (nRet == PDF_DATA_NOTAVAIL) {
159 network_simulator->SetRequestedDataAvailable();
Lei Zhang52d21ac2021-11-04 22:40:15 +0000160 nRet = FPDFAvail_IsDocAvail(avail_ptr,
161 network_simulator->GetDownloadHints());
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300162 }
163 if (nRet == PDF_DATA_ERROR)
164 return false;
165
Lei Zhang52d21ac2021-11-04 22:40:15 +0000166 *document = FPDFAvail_GetDocument(avail_ptr, password);
Nicolas Pena56fc9722017-07-13 16:31:34 -0400167 if (!*document)
Jun Fangdf7f3662015-11-10 18:29:18 +0800168 return false;
Nicolas Pena56fc9722017-07-13 16:31:34 -0400169
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300170 nRet = PDF_DATA_NOTAVAIL;
171 while (nRet == PDF_DATA_NOTAVAIL) {
172 network_simulator->SetRequestedDataAvailable();
Lei Zhang52d21ac2021-11-04 22:40:15 +0000173 nRet = FPDFAvail_IsFormAvail(avail_ptr,
174 network_simulator->GetDownloadHints());
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300175 }
176 if (nRet == PDF_FORM_ERROR)
Jun Fangdf7f3662015-11-10 18:29:18 +0800177 return false;
Nicolas Pena56fc9722017-07-13 16:31:34 -0400178
179 int page_count = FPDF_GetPageCount(*document);
Jun Fangdf7f3662015-11-10 18:29:18 +0800180 for (int i = 0; i < page_count; ++i) {
181 nRet = PDF_DATA_NOTAVAIL;
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300182 while (nRet == PDF_DATA_NOTAVAIL) {
183 network_simulator->SetRequestedDataAvailable();
Lei Zhang52d21ac2021-11-04 22:40:15 +0000184 nRet = FPDFAvail_IsPageAvail(avail_ptr, i,
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300185 network_simulator->GetDownloadHints());
186 }
Nicolas Pena56fc9722017-07-13 16:31:34 -0400187 if (nRet == PDF_DATA_ERROR)
Jun Fangdf7f3662015-11-10 18:29:18 +0800188 return false;
Jun Fangdf7f3662015-11-10 18:29:18 +0800189 }
190 } else {
Tom Sepez0784c732018-04-23 18:02:57 +0000191 if (linearize_option == LinearizeOption::kMustLinearize)
Jun Fangdf7f3662015-11-10 18:29:18 +0800192 return false;
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300193 network_simulator->SetWholeFileAvailable();
194 *document =
195 FPDF_LoadCustomDocument(network_simulator->GetFileAccess(), password);
Nicolas Pena56fc9722017-07-13 16:31:34 -0400196 if (!*document)
Jun Fangdf7f3662015-11-10 18:29:18 +0800197 return false;
Jun Fangdf7f3662015-11-10 18:29:18 +0800198 }
Lei Zhangdba065e2021-11-04 23:09:15 +0000199 form_handle->reset(SetupFormFillEnvironment(*document, javascript_option));
Tom Sepez0784c732018-04-23 18:02:57 +0000200
Ryan Harrison854d71c2017-10-18 12:28:14 -0400201 int doc_type = FPDF_GetFormType(*document);
202 if (doc_type == FORMTYPE_XFA_FULL || doc_type == FORMTYPE_XFA_FOREGROUND)
203 FPDF_LoadXFA(*document);
Tom Sepez0784c732018-04-23 18:02:57 +0000204
Ryan Harrison6cec70a2018-06-05 14:06:10 +0000205 (void)FPDF_GetDocPermissions(*document);
Tom Sepezd483eb42016-01-06 10:03:59 -0800206 return true;
207}
Tom Sepez96d13342015-01-16 14:59:26 -0800208
Tom Sepez38f725f2019-12-04 00:26:34 +0000209void EmbedderTest::CloseDocument() {
Lei Zhangdba065e2021-11-04 23:09:15 +0000210 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WC);
211 form_handle_.reset();
Tom Sepez38f725f2019-12-04 00:26:34 +0000212
213 FPDF_CloseDocument(document_);
214 document_ = nullptr;
215}
216
Tom Sepez0784c732018-04-23 18:02:57 +0000217FPDF_FORMHANDLE EmbedderTest::SetupFormFillEnvironment(
218 FPDF_DOCUMENT doc,
219 JavaScriptOption javascript_option) {
Tom Sepez4cb0fa72015-02-25 16:08:18 -0800220 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400221 memset(platform, '\0', sizeof(IPDF_JSPLATFORM));
Tom Sepez72f520c2020-08-24 23:43:46 +0000222 platform->version = 3;
Tom Sepez4cb0fa72015-02-25 16:08:18 -0800223 platform->app_alert = AlertTrampoline;
Tom Sepez96d13342015-01-16 14:59:26 -0800224
Tom Sepez4cb0fa72015-02-25 16:08:18 -0800225 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
226 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
Aayush Dhirc63913e2020-02-12 09:45:34 +0000227 formfillinfo->version = form_fill_info_version_;
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700228 formfillinfo->FFI_SetTimer = SetTimerTrampoline;
229 formfillinfo->FFI_KillTimer = KillTimerTrampoline;
Tom Sepez396e8722015-09-09 10:16:08 -0700230 formfillinfo->FFI_GetPage = GetPageTrampoline;
Henrique Nakashima9ef93d02018-10-03 18:41:03 +0000231 formfillinfo->FFI_DoURIAction = DoURIActionTrampoline;
Badhri Ravikumarf5cc1ac2020-04-30 19:00:55 +0000232 formfillinfo->FFI_DoGoToAction = DoGoToActionTrampoline;
Aayush Dhirc63913e2020-02-12 09:45:34 +0000233 formfillinfo->FFI_OnFocusChange = OnFocusChangeTrampoline;
Badhri Ravikumare86bbfa2020-04-16 21:42:40 +0000234 formfillinfo->FFI_DoURIActionWithKeyboardModifier =
235 DoURIActionWithKeyboardModifierTrampoline;
Henrique Nakashima9ef93d02018-10-03 18:41:03 +0000236
Tom Sepez0784c732018-04-23 18:02:57 +0000237 if (javascript_option == JavaScriptOption::kEnableJavaScript)
238 formfillinfo->m_pJsPlatform = platform;
239
Nicolas Pena3ff54002017-07-05 11:55:35 -0400240 FPDF_FORMHANDLE form_handle =
241 FPDFDOC_InitFormFillEnvironment(doc, formfillinfo);
Tom Sepez92f92222020-01-07 22:16:07 +0000242 SetInitialFormFieldHighlight(form_handle);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400243 return form_handle;
Tom Sepez96d13342015-01-16 14:59:26 -0800244}
245
Tom Sepezda8189e2015-01-30 14:41:50 -0800246void EmbedderTest::DoOpenActions() {
Lei Zhangdba065e2021-11-04 23:09:15 +0000247 DCHECK(form_handle());
248 FORM_DoDocumentJSAction(form_handle());
249 FORM_DoDocumentOpenAction(form_handle());
Tom Sepez96d13342015-01-16 14:59:26 -0800250}
251
252int EmbedderTest::GetFirstPageNum() {
253 int first_page = FPDFAvail_GetFirstPageNum(document_);
Lei Zhang52d21ac2021-11-04 22:40:15 +0000254 (void)FPDFAvail_IsPageAvail(avail(), first_page,
Ryan Harrison6cec70a2018-06-05 14:06:10 +0000255 fake_file_access_->GetDownloadHints());
Tom Sepez96d13342015-01-16 14:59:26 -0800256 return first_page;
257}
258
259int EmbedderTest::GetPageCount() {
260 int page_count = FPDF_GetPageCount(document_);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400261 for (int i = 0; i < page_count; ++i)
Lei Zhang52d21ac2021-11-04 22:40:15 +0000262 (void)FPDFAvail_IsPageAvail(avail(), i,
Ryan Harrison6cec70a2018-06-05 14:06:10 +0000263 fake_file_access_->GetDownloadHints());
Tom Sepez96d13342015-01-16 14:59:26 -0800264 return page_count;
265}
266
Tom Sepezda8189e2015-01-30 14:41:50 -0800267FPDF_PAGE EmbedderTest::LoadPage(int page_number) {
Tom Sepez507d0192018-11-07 16:37:51 +0000268 return LoadPageCommon(page_number, true);
269}
270
271FPDF_PAGE EmbedderTest::LoadPageNoEvents(int page_number) {
272 return LoadPageCommon(page_number, false);
273}
274
275FPDF_PAGE EmbedderTest::LoadPageCommon(int page_number, bool do_events) {
Lei Zhangdba065e2021-11-04 23:09:15 +0000276 DCHECK(form_handle());
Tom Sepez25f33d02021-01-29 01:58:51 +0000277 DCHECK(page_number >= 0);
278 DCHECK(!pdfium::Contains(page_map_, page_number));
weili0dadcc62016-08-23 21:10:57 -0700279
Tom Sepez96d13342015-01-16 14:59:26 -0800280 FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400281 if (!page)
Tom Sepez96d13342015-01-16 14:59:26 -0800282 return nullptr;
Nicolas Pena3ff54002017-07-05 11:55:35 -0400283
Tom Sepez507d0192018-11-07 16:37:51 +0000284 if (do_events) {
Lei Zhangdba065e2021-11-04 23:09:15 +0000285 FORM_OnAfterLoadPage(page, form_handle());
286 FORM_DoPageAAction(page, form_handle(), FPDFPAGE_AACTION_OPEN);
Tom Sepez507d0192018-11-07 16:37:51 +0000287 }
weili0dadcc62016-08-23 21:10:57 -0700288 page_map_[page_number] = page;
Tom Sepez396e8722015-09-09 10:16:08 -0700289 return page;
290}
291
Tom Sepezda8189e2015-01-30 14:41:50 -0800292void EmbedderTest::UnloadPage(FPDF_PAGE page) {
Tom Sepez507d0192018-11-07 16:37:51 +0000293 UnloadPageCommon(page, true);
294}
Lei Zhang75c81712018-02-08 17:22:39 +0000295
Tom Sepez507d0192018-11-07 16:37:51 +0000296void EmbedderTest::UnloadPageNoEvents(FPDF_PAGE page) {
297 UnloadPageCommon(page, false);
298}
299
300void EmbedderTest::UnloadPageCommon(FPDF_PAGE page, bool do_events) {
Lei Zhangdba065e2021-11-04 23:09:15 +0000301 DCHECK(form_handle());
Lei Zhang75c81712018-02-08 17:22:39 +0000302 int page_number = GetPageNumberForLoadedPage(page);
303 if (page_number < 0) {
304 NOTREACHED();
305 return;
306 }
Tom Sepez507d0192018-11-07 16:37:51 +0000307 if (do_events) {
Lei Zhangdba065e2021-11-04 23:09:15 +0000308 FORM_DoPageAAction(page, form_handle(), FPDFPAGE_AACTION_CLOSE);
309 FORM_OnBeforeClosePage(page, form_handle());
Tom Sepez507d0192018-11-07 16:37:51 +0000310 }
Tom Sepez96d13342015-01-16 14:59:26 -0800311 FPDF_ClosePage(page);
Lei Zhang75c81712018-02-08 17:22:39 +0000312 page_map_.erase(page_number);
Tom Sepez96d13342015-01-16 14:59:26 -0800313}
Tom Sepez1b1bb492015-01-22 17:36:32 -0800314
Tom Sepez92f92222020-01-07 22:16:07 +0000315void EmbedderTest::SetInitialFormFieldHighlight(FPDF_FORMHANDLE form) {
316 FPDF_SetFormFieldHighlightColor(form, FPDF_FORMFIELD_UNKNOWN, 0xFFE4DD);
317 FPDF_SetFormFieldHighlightAlpha(form, 100);
318}
319
Tom Sepeze08d2b12018-04-25 18:49:32 +0000320ScopedFPDFBitmap EmbedderTest::RenderLoadedPage(FPDF_PAGE page) {
Lei Zhanga98e3662018-02-07 20:28:35 +0000321 return RenderLoadedPageWithFlags(page, 0);
322}
323
Tom Sepeze08d2b12018-04-25 18:49:32 +0000324ScopedFPDFBitmap EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page,
325 int flags) {
Lei Zhang75c81712018-02-08 17:22:39 +0000326 if (GetPageNumberForLoadedPage(page) < 0) {
327 NOTREACHED();
328 return nullptr;
329 }
Lei Zhangdba065e2021-11-04 23:09:15 +0000330 return RenderPageWithFlags(page, form_handle(), flags);
Lei Zhanga98e3662018-02-07 20:28:35 +0000331}
332
Tom Sepeze08d2b12018-04-25 18:49:32 +0000333ScopedFPDFBitmap EmbedderTest::RenderSavedPage(FPDF_PAGE page) {
Lei Zhanga98e3662018-02-07 20:28:35 +0000334 return RenderSavedPageWithFlags(page, 0);
335}
336
Tom Sepeze08d2b12018-04-25 18:49:32 +0000337ScopedFPDFBitmap EmbedderTest::RenderSavedPageWithFlags(FPDF_PAGE page,
338 int flags) {
Lei Zhang9f72c452018-02-08 21:49:54 +0000339 if (GetPageNumberForSavedPage(page) < 0) {
340 NOTREACHED();
341 return nullptr;
342 }
Lei Zhangdba065e2021-11-04 23:09:15 +0000343 return RenderPageWithFlags(page, saved_form_handle(), flags);
Lei Zhanga98e3662018-02-07 20:28:35 +0000344}
345
346// static
Tom Sepeze08d2b12018-04-25 18:49:32 +0000347ScopedFPDFBitmap EmbedderTest::RenderPageWithFlags(FPDF_PAGE page,
348 FPDF_FORMHANDLE handle,
349 int flags) {
Lei Zhangdfa075b2019-12-05 21:52:43 +0000350 int width = static_cast<int>(FPDF_GetPageWidthF(page));
351 int height = static_cast<int>(FPDF_GetPageHeightF(page));
Lei Zhanga98e3662018-02-07 20:28:35 +0000352 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0;
Tom Sepeze08d2b12018-04-25 18:49:32 +0000353 ScopedFPDFBitmap bitmap(FPDFBitmap_Create(width, height, alpha));
Lei Zhanga98e3662018-02-07 20:28:35 +0000354 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF;
355 FPDFBitmap_FillRect(bitmap.get(), 0, 0, width, height, fill_color);
356 FPDF_RenderPageBitmap(bitmap.get(), page, 0, 0, width, height, 0, flags);
357 FPDF_FFLDraw(handle, bitmap.get(), page, 0, 0, width, height, 0, flags);
358 return bitmap;
359}
360
Lei Zhang30ff2532019-01-31 21:37:55 +0000361// static
362ScopedFPDFBitmap EmbedderTest::RenderPage(FPDF_PAGE page) {
363 return RenderPageWithFlags(page, nullptr, 0);
364}
365
Lei Zhangd69e0652019-04-13 00:39:35 +0000366#if defined(OS_WIN)
367// static
368std::vector<uint8_t> EmbedderTest::RenderPageWithFlagsToEmf(FPDF_PAGE page,
369 int flags) {
370 HDC dc = CreateEnhMetaFileA(nullptr, nullptr, nullptr, nullptr);
371
Lei Zhangdfa075b2019-12-05 21:52:43 +0000372 int width = static_cast<int>(FPDF_GetPageWidthF(page));
373 int height = static_cast<int>(FPDF_GetPageHeightF(page));
Lei Zhangd69e0652019-04-13 00:39:35 +0000374 HRGN rgn = CreateRectRgn(0, 0, width, height);
375 SelectClipRgn(dc, rgn);
376 DeleteObject(rgn);
377
378 SelectObject(dc, GetStockObject(NULL_PEN));
379 SelectObject(dc, GetStockObject(WHITE_BRUSH));
380 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less.
381 Rectangle(dc, 0, 0, width + 1, height + 1);
382
383 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, flags);
384
385 HENHMETAFILE emf = CloseEnhMetaFile(dc);
386 size_t size_in_bytes = GetEnhMetaFileBits(emf, 0, nullptr);
387 std::vector<uint8_t> buffer(size_in_bytes);
388 GetEnhMetaFileBits(emf, size_in_bytes, buffer.data());
389 DeleteEnhMetaFile(emf);
390 return buffer;
391}
Lei Zhang614f1a02019-05-30 00:03:53 +0000392
393// static
394std::string EmbedderTest::GetPostScriptFromEmf(
Tom Sepez87b9e3a2019-11-20 23:45:43 +0000395 pdfium::span<const uint8_t> emf_data) {
Lei Zhang614f1a02019-05-30 00:03:53 +0000396 // This comes from Emf::InitFromData() in Chromium.
397 HENHMETAFILE emf = SetEnhMetaFileBits(emf_data.size(), emf_data.data());
398 if (!emf)
399 return std::string();
400
401 // This comes from Emf::Enumerator::Enumerator() in Chromium.
402 std::vector<const ENHMETARECORD*> records;
403 if (!EnumEnhMetaFile(nullptr, emf, &GetRecordProc, &records, nullptr)) {
404 DeleteEnhMetaFile(emf);
405 return std::string();
406 }
407
408 // This comes from PostScriptMetaFile::SafePlayback() in Chromium.
409 std::string ps_data;
410 for (const auto* record : records) {
411 if (record->iType != EMR_GDICOMMENT)
412 continue;
413
414 // PostScript data is encapsulated inside EMF comment records.
415 // The first two bytes of the comment indicate the string length. The rest
416 // is the actual string data.
417 const auto* comment = reinterpret_cast<const EMRGDICOMMENT*>(record);
418 const char* data = reinterpret_cast<const char*>(comment->Data);
419 uint16_t size = *reinterpret_cast<const uint16_t*>(data);
420 data += 2;
421 ps_data.append(data, size);
422 }
423 DeleteEnhMetaFile(emf);
424 return ps_data;
425}
Lei Zhangd69e0652019-04-13 00:39:35 +0000426#endif // defined(OS_WIN)
427
Lei Zhang0b494052019-01-31 21:41:15 +0000428FPDF_DOCUMENT EmbedderTest::OpenSavedDocument() {
429 return OpenSavedDocumentWithPassword(nullptr);
430}
431
Tom Sepez6dc12402020-01-07 21:02:17 +0000432// static
433int EmbedderTest::BytesPerPixelForFormat(int format) {
434 switch (format) {
435 case FPDFBitmap_Gray:
436 return 1;
437 case FPDFBitmap_BGR:
438 return 3;
439 case FPDFBitmap_BGRx:
440 case FPDFBitmap_BGRA:
441 return 4;
442 default:
443 NOTREACHED();
444 return 0;
445 }
446}
447
Lei Zhang0b494052019-01-31 21:41:15 +0000448FPDF_DOCUMENT EmbedderTest::OpenSavedDocumentWithPassword(
449 const char* password) {
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300450 memset(&saved_file_access_, 0, sizeof(saved_file_access_));
Lei Zhang0729be22018-02-05 21:13:51 +0000451 saved_file_access_.m_FileLen = data_string_.size();
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300452 saved_file_access_.m_GetBlock = GetBlockFromString;
Artem Strygin68d04f22018-07-12 09:18:19 +0000453 // Copy data to prevent clearing it before saved document close.
454 saved_document_file_data_ = data_string_;
455 saved_file_access_.m_Param = &saved_document_file_data_;
Nicolas Pena3ff54002017-07-05 11:55:35 -0400456
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300457 saved_fake_file_access_ =
Tom Sepez7df04832020-05-18 22:09:31 +0000458 std::make_unique<FakeFileAccess>(&saved_file_access_);
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300459
Tom Sepez0784c732018-04-23 18:02:57 +0000460 EXPECT_TRUE(OpenDocumentHelper(
461 password, LinearizeOption::kDefaultLinearize,
462 JavaScriptOption::kEnableJavaScript, saved_fake_file_access_.get(),
463 &saved_document_, &saved_avail_, &saved_form_handle_));
Lei Zhang0729be22018-02-05 21:13:51 +0000464 return saved_document_;
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400465}
466
467void EmbedderTest::CloseSavedDocument() {
Tom Sepez25f33d02021-01-29 01:58:51 +0000468 DCHECK(saved_document_);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400469
Lei Zhangdba065e2021-11-04 23:09:15 +0000470 saved_form_handle_.reset();
Lei Zhang0729be22018-02-05 21:13:51 +0000471 FPDF_CloseDocument(saved_document_);
Lei Zhang52d21ac2021-11-04 22:40:15 +0000472 saved_avail_.reset();
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400473
Lei Zhang0729be22018-02-05 21:13:51 +0000474 saved_document_ = nullptr;
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400475}
476
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000477FPDF_PAGE EmbedderTest::LoadSavedPage(int page_number) {
Lei Zhangdba065e2021-11-04 23:09:15 +0000478 DCHECK(saved_form_handle());
Tom Sepez25f33d02021-01-29 01:58:51 +0000479 DCHECK(page_number >= 0);
480 DCHECK(!pdfium::Contains(saved_page_map_, page_number));
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400481
Lei Zhang0729be22018-02-05 21:13:51 +0000482 FPDF_PAGE page = FPDF_LoadPage(saved_document_, page_number);
Lei Zhang9f72c452018-02-08 21:49:54 +0000483 if (!page)
484 return nullptr;
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400485
Lei Zhangdba065e2021-11-04 23:09:15 +0000486 FORM_OnAfterLoadPage(page, saved_form_handle());
487 FORM_DoPageAAction(page, saved_form_handle(), FPDFPAGE_AACTION_OPEN);
Lei Zhang9f72c452018-02-08 21:49:54 +0000488 saved_page_map_[page_number] = page;
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000489 return page;
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400490}
491
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000492void EmbedderTest::CloseSavedPage(FPDF_PAGE page) {
Lei Zhangdba065e2021-11-04 23:09:15 +0000493 DCHECK(saved_form_handle());
Lei Zhang9f72c452018-02-08 21:49:54 +0000494
495 int page_number = GetPageNumberForSavedPage(page);
496 if (page_number < 0) {
497 NOTREACHED();
498 return;
499 }
500
Lei Zhangdba065e2021-11-04 23:09:15 +0000501 FORM_DoPageAAction(page, saved_form_handle(), FPDFPAGE_AACTION_CLOSE);
502 FORM_OnBeforeClosePage(page, saved_form_handle());
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000503 FPDF_ClosePage(page);
Lei Zhang9f72c452018-02-08 21:49:54 +0000504
505 saved_page_map_.erase(page_number);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400506}
507
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000508void EmbedderTest::VerifySavedRendering(FPDF_PAGE page,
509 int width,
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400510 int height,
511 const char* md5) {
Tom Sepez25f33d02021-01-29 01:58:51 +0000512 DCHECK(saved_document_);
513 DCHECK(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400514
Tom Sepeze08d2b12018-04-25 18:49:32 +0000515 ScopedFPDFBitmap bitmap = RenderSavedPageWithFlags(page, FPDF_ANNOT);
Lei Zhanga98e3662018-02-07 20:28:35 +0000516 CompareBitmap(bitmap.get(), width, height, md5);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400517}
518
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400519void EmbedderTest::VerifySavedDocument(int width, int height, const char* md5) {
Lei Zhang0b494052019-01-31 21:41:15 +0000520 ASSERT_TRUE(OpenSavedDocument());
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000521 FPDF_PAGE page = LoadSavedPage(0);
522 VerifySavedRendering(page, width, height, md5);
523 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400524 CloseSavedDocument();
Nicolas Pena3ff54002017-07-05 11:55:35 -0400525}
526
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300527void EmbedderTest::SetWholeFileAvailable() {
Tom Sepez25f33d02021-01-29 01:58:51 +0000528 DCHECK(fake_file_access_);
Artem Strygin0e60b9e2017-09-28 18:46:03 +0300529 fake_file_access_->SetWholeFileAvailable();
530}
531
Lei Zhang52d21ac2021-11-04 22:40:15 +0000532void EmbedderTest::CreateAvail(FX_FILEAVAIL* file_avail,
533 FPDF_FILEACCESS* file) {
534 avail_.reset(FPDFAvail_Create(file_avail, file));
535}
536
weili0dadcc62016-08-23 21:10:57 -0700537FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info,
Tom Sepez396e8722015-09-09 10:16:08 -0700538 FPDF_DOCUMENT document,
539 int page_index) {
weili0dadcc62016-08-23 21:10:57 -0700540 EmbedderTest* test = static_cast<EmbedderTest*>(info);
541 auto it = test->page_map_.find(page_index);
542 return it != test->page_map_.end() ? it->second : nullptr;
Tom Sepez396e8722015-09-09 10:16:08 -0700543}
544
Tom Sepez4cb0fa72015-02-25 16:08:18 -0800545// static
546void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info,
547 int type) {
548 EmbedderTest* test = static_cast<EmbedderTest*>(info);
549 test->delegate_->UnsupportedHandler(type);
550}
551
552// static
553int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform,
554 FPDF_WIDESTRING message,
555 FPDF_WIDESTRING title,
556 int type,
557 int icon) {
558 EmbedderTest* test = static_cast<EmbedderTest*>(platform);
559 return test->delegate_->Alert(message, title, type, icon);
560}
561
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700562// static
563int EmbedderTest::SetTimerTrampoline(FPDF_FORMFILLINFO* info,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 int msecs,
565 TimerCallback fn) {
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700566 EmbedderTest* test = static_cast<EmbedderTest*>(info);
567 return test->delegate_->SetTimer(msecs, fn);
568}
569
570// static
571void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) {
572 EmbedderTest* test = static_cast<EmbedderTest*>(info);
573 return test->delegate_->KillTimer(id);
574}
575
Tom Sepez396e8722015-09-09 10:16:08 -0700576// static
577FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info,
578 FPDF_DOCUMENT document,
579 int page_index) {
weili0dadcc62016-08-23 21:10:57 -0700580 return static_cast<EmbedderTest*>(info)->delegate_->GetPage(info, document,
581 page_index);
Tom Sepez396e8722015-09-09 10:16:08 -0700582}
583
Henrique Nakashima9fa50362017-11-10 22:40:44 +0000584// static
Henrique Nakashima9ef93d02018-10-03 18:41:03 +0000585void EmbedderTest::DoURIActionTrampoline(FPDF_FORMFILLINFO* info,
586 FPDF_BYTESTRING uri) {
587 EmbedderTest* test = static_cast<EmbedderTest*>(info);
588 return test->delegate_->DoURIAction(uri);
589}
590
591// static
Badhri Ravikumarf5cc1ac2020-04-30 19:00:55 +0000592void EmbedderTest::DoGoToActionTrampoline(FPDF_FORMFILLINFO* info,
593 int page_index,
594 int zoom_mode,
595 float* pos_array,
596 int array_size) {
597 EmbedderTest* test = static_cast<EmbedderTest*>(info);
598 return test->delegate_->DoGoToAction(info, page_index, zoom_mode, pos_array,
599 array_size);
600}
601
602// static
Aayush Dhirc63913e2020-02-12 09:45:34 +0000603void EmbedderTest::OnFocusChangeTrampoline(FPDF_FORMFILLINFO* info,
604 FPDF_ANNOTATION annot,
605 int page_index) {
606 EmbedderTest* test = static_cast<EmbedderTest*>(info);
607 return test->delegate_->OnFocusChange(info, annot, page_index);
608}
609
610// static
Badhri Ravikumare86bbfa2020-04-16 21:42:40 +0000611void EmbedderTest::DoURIActionWithKeyboardModifierTrampoline(
612 FPDF_FORMFILLINFO* info,
613 FPDF_BYTESTRING uri,
614 int modifiers) {
615 EmbedderTest* test = static_cast<EmbedderTest*>(info);
616 return test->delegate_->DoURIActionWithKeyboardModifier(info, uri, modifiers);
617}
618
619// static
Henrique Nakashima9fa50362017-11-10 22:40:44 +0000620std::string EmbedderTest::HashBitmap(FPDF_BITMAP bitmap) {
Lei Zhangbf980142019-12-20 01:05:42 +0000621 int stride = FPDFBitmap_GetStride(bitmap);
622 int usable_bytes_per_row =
623 GetBitmapBytesPerPixel(bitmap) * FPDFBitmap_GetWidth(bitmap);
624 int height = FPDFBitmap_GetHeight(bitmap);
625 auto span = pdfium::make_span(
626 static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap)), stride * height);
627
628 CRYPT_md5_context context = CRYPT_MD5Start();
629 for (int i = 0; i < height; ++i)
630 CRYPT_MD5Update(&context, span.subspan(i * stride, usable_bytes_per_row));
Dan Sinclair957480c2017-06-13 15:21:14 -0400631 uint8_t digest[16];
Lei Zhangbf980142019-12-20 01:05:42 +0000632 CRYPT_MD5Finish(&context, digest);
Dan Sinclair957480c2017-06-13 15:21:14 -0400633 return CryptToBase16(digest);
634}
635
Henrique Nakashimadb269572018-01-16 19:02:15 +0000636#ifndef NDEBUG
637// static
638void EmbedderTest::WriteBitmapToPng(FPDF_BITMAP bitmap,
639 const std::string& filename) {
Henrique Nakashimaf956bad2018-08-16 16:41:42 +0000640 BitmapSaver::WriteBitmapToPng(bitmap, filename);
Henrique Nakashimadb269572018-01-16 19:02:15 +0000641}
642#endif
643
thestigbcd3e532016-11-21 13:37:28 -0800644// static
645void EmbedderTest::CompareBitmap(FPDF_BITMAP bitmap,
646 int expected_width,
647 int expected_height,
648 const char* expected_md5sum) {
649 ASSERT_EQ(expected_width, FPDFBitmap_GetWidth(bitmap));
650 ASSERT_EQ(expected_height, FPDFBitmap_GetHeight(bitmap));
Jane Liu28fb7ba2017-08-02 21:45:57 -0400651
652 // The expected stride is calculated using the same formula as in
653 // CFX_DIBitmap::CalculatePitchAndSize(), which sets the bitmap stride.
654 const int expected_stride =
655 (expected_width * GetBitmapBytesPerPixel(bitmap) * 8 + 31) / 32 * 4;
thestigbcd3e532016-11-21 13:37:28 -0800656 ASSERT_EQ(expected_stride, FPDFBitmap_GetStride(bitmap));
657
658 if (!expected_md5sum)
659 return;
660
Henrique Nakashima9fa50362017-11-10 22:40:44 +0000661 EXPECT_EQ(expected_md5sum, HashBitmap(bitmap));
thestigbcd3e532016-11-21 13:37:28 -0800662}
663
Nicolas Pena3ff54002017-07-05 11:55:35 -0400664// static
665int EmbedderTest::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite,
666 const void* data,
667 unsigned long size) {
668 EmbedderTest* pThis = static_cast<EmbedderTest*>(pFileWrite);
Henrique Nakashima7c2e8a32018-06-06 19:17:34 +0000669
Lei Zhang0729be22018-02-05 21:13:51 +0000670 pThis->data_string_.append(static_cast<const char*>(data), size);
Henrique Nakashima7c2e8a32018-06-06 19:17:34 +0000671
672 if (pThis->filestream_.is_open())
673 pThis->filestream_.write(static_cast<const char*>(data), size);
674
Nicolas Pena3ff54002017-07-05 11:55:35 -0400675 return 1;
676}
677
678// static
679int EmbedderTest::GetBlockFromString(void* param,
680 unsigned long pos,
681 unsigned char* buf,
682 unsigned long size) {
683 std::string* new_file = static_cast<std::string*>(param);
Lei Zhangcef91f12019-01-08 21:32:51 +0000684 if (!new_file || pos + size < pos) {
685 NOTREACHED();
Nicolas Pena3ff54002017-07-05 11:55:35 -0400686 return 0;
Lei Zhangcef91f12019-01-08 21:32:51 +0000687 }
Nicolas Pena3ff54002017-07-05 11:55:35 -0400688
Lei Zhangcef91f12019-01-08 21:32:51 +0000689 if (pos + size > new_file->size()) {
690 NOTREACHED();
Nicolas Pena3ff54002017-07-05 11:55:35 -0400691 return 0;
Lei Zhangcef91f12019-01-08 21:32:51 +0000692 }
Nicolas Pena3ff54002017-07-05 11:55:35 -0400693
694 memcpy(buf, new_file->data() + pos, size);
695 return 1;
696}
Lei Zhang75c81712018-02-08 17:22:39 +0000697
Lei Zhang9f72c452018-02-08 21:49:54 +0000698// static
699int EmbedderTest::GetPageNumberForPage(const PageNumberToHandleMap& page_map,
700 FPDF_PAGE page) {
701 for (const auto& it : page_map) {
Lei Zhang75c81712018-02-08 17:22:39 +0000702 if (it.second == page) {
703 int page_number = it.first;
Tom Sepez25f33d02021-01-29 01:58:51 +0000704 DCHECK(page_number >= 0);
Lei Zhang75c81712018-02-08 17:22:39 +0000705 return page_number;
706 }
707 }
708 return -1;
709}
Lei Zhang9f72c452018-02-08 21:49:54 +0000710
711int EmbedderTest::GetPageNumberForLoadedPage(FPDF_PAGE page) const {
712 return GetPageNumberForPage(page_map_, page);
713}
714
715int EmbedderTest::GetPageNumberForSavedPage(FPDF_PAGE page) const {
716 return GetPageNumberForPage(saved_page_map_, page);
717}
Henrique Nakashima7c2e8a32018-06-06 19:17:34 +0000718
Lei Zhang81a799e2019-12-16 17:37:13 +0000719#ifndef NDEBUG
720void EmbedderTest::OpenPDFFileForWrite(const std::string& filename) {
Henrique Nakashima7c2e8a32018-06-06 19:17:34 +0000721 filestream_.open(filename, std::ios_base::binary);
722}
723
724void EmbedderTest::ClosePDFFileForWrite() {
725 filestream_.close();
726}
Lei Zhang81a799e2019-12-16 17:37:13 +0000727#endif