8#include "build/build_config.h"
9#include "core/fpdfapi/parser/cpdf_dictionary.h"
10#include "core/fpdfapi/parser/cpdf_document.h"
11#include "core/fpdfapi/parser/cpdf_parser.h"
12#include "core/fxcrt/fx_system.h"
13#include "core/fxge/cfx_defaultrenderdevice.h"
14#include "public/cpp/fpdf_scopers.h"
15#include "public/fpdf_edit.h"
16#include "public/fpdf_save.h"
17#include "public/fpdfview.h"
18#include "testing/embedder_test.h"
19#include "testing/embedder_test_constants.h"
20#include "testing/gtest/include/gtest/gtest.h"
24const char kAgeUTF8[] =
27const char kAgeLatin1[] =
31const char kHotelUTF8[] =
35const char kHotelLatin1[] =
45 const char* password) {
46 ASSERT_TRUE(OpenDocumentWithPassword(filename, password));
48 VerifyHelloWorldPage(page);
55 VerifyHelloWorldPage(page);
63 VerifyModifiedHelloWorldPage(page);
85 ASSERT_TRUE(goodbye_object);
86 ASSERT_TRUE(FPDFPage_RemoveObject(page, goodbye_object.get()));
89 VerifyModifiedHelloWorldPage(page);
94 void VerifyHelloWorldPage(FPDF_PAGE page) {
97 ScopedFPDFBitmap page_bitmap = RenderPage(page);
101 void VerifyModifiedHelloWorldPage(FPDF_PAGE page) {
104 ScopedFPDFBitmap page_bitmap = RenderPage(page);
111 ASSERT_TRUE(OpenDocument(
"about_blank.pdf"));
113 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
114 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocUserPermissions(document()));
118 ASSERT_TRUE(OpenDocumentWithPassword(
"about_blank.pdf",
"foobar"));
120 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
121 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocUserPermissions(document()));
125 EXPECT_FALSE(OpenDocument(
"encrypted.pdf"));
129 EXPECT_FALSE(OpenDocumentWithPassword(
"encrypted.pdf",
"tiger"));
133 ASSERT_TRUE(OpenDocumentWithPassword(
"encrypted.pdf",
"1234"));
134 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocPermissions(document()));
135 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocUserPermissions(document()));
139 ASSERT_TRUE(OpenDocumentWithPassword(
"encrypted.pdf",
"5678"));
140 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
141 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocUserPermissions(document()));
145 const char* checksum = []() {
148 return "caa4bfda016a9c48a540ff7c6716468c";
149#elif BUILDFLAG(IS_APPLE)
150 return "6c1a242ce886df5cf578401eeeaa1929";
152 return "ad97491cab71c02f1f4ef5ba0a7b5593";
155#if BUILDFLAG(IS_APPLE)
156 return "2a308e8cc20a6221112c387d122075a8";
158 return "9fe7eef8e51d15a604001854be6ed1ee";
162 ASSERT_TRUE(OpenDocumentWithOptions(
"encrypted.pdf",
"5678",
163 LinearizeOption::kMustLinearize,
164 JavaScriptOption::kEnableJavaScript));
165 FPDF_PAGE page = LoadPage(0);
168 ASSERT_TRUE(red_rect);
172 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
173 CompareBitmap(bitmap.get(), 612, 792, checksum);
175 SetWholeFileAvailable();
176 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
179 std::string new_file = GetString();
180 FPDF_FILEACCESS file_access = {};
181 static_assert(std::is_aggregate_v<
decltype(file_access)>);
182 file_access.m_FileLen = new_file.size();
183 file_access.m_GetBlock = GetBlockFromString;
184 file_access.m_Param = &new_file;
188 const char* password;
189 const unsigned long permissions;
190 } tests[] = {{
"1234", 0xFFFFF2C0}, {
"5678", 0xFFFFFFFC}};
192 for (
const auto& test : tests) {
193 ASSERT_TRUE(OpenSavedDocumentWithPassword(test.password));
194 FPDF_PAGE page = LoadSavedPage(0);
196 VerifySavedRendering(page, 612, 792, checksum);
197 EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(saved_document()));
199 CloseSavedPage(page);
200 CloseSavedDocument();
205 ASSERT_FALSE(OpenDocument(
"bug_644.pdf"));
209 ASSERT_FALSE(OpenDocumentWithPassword(
"bug_644.pdf",
"tiger"));
213 ASSERT_TRUE(OpenDocumentWithPassword(
"bug_644.pdf",
"a"));
214 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
218 ASSERT_TRUE(OpenDocumentWithPassword(
"bug_644.pdf",
"b"));
219 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
225 OpenDocumentWithPassword(
"encrypted_hello_world_r2_bad_okey.pdf",
"a"));
231 OpenDocumentWithPassword(
"encrypted_hello_world_r3_bad_okey.pdf",
"a"));
237 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
239 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
240 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
241 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
242 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
243 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
244 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
247 RemoveTrailerIdFromDocument();
248 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
257 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
258 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
261 RemoveGoodbyeObject();
262 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
263 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
264 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
269 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
271 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
272 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
273 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
274 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
275 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
276 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
279 RemoveTrailerIdFromDocument();
280 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
281 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
282 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
285 RemoveGoodbyeObject();
286 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
287 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
288 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
293 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
295 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
296 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
297 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
298 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
299 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
300 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
303 RemoveTrailerIdFromDocument();
304 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
305 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
306 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
309 RemoveGoodbyeObject();
310 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
311 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
312 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
317 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
319 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
320 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
321 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
322 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
323 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
324 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
327 RemoveTrailerIdFromDocument();
328 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
329 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
330 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
333 RemoveGoodbyeObject();
334 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
335 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
336 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
341 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
343 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
344 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
345 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
346 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
347 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
348 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
351 RemoveTrailerIdFromDocument();
352 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
353 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
354 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
355 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
356 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
359 RemoveGoodbyeObject();
360 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
361 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
362 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
363 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
364 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
369 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
371 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
372 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
373 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
374 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
375 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
376 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
379 RemoveTrailerIdFromDocument();
380 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
381 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
382 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
383 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
384 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
387 RemoveGoodbyeObject();
388 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
389 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
390 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
391 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
392 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
397 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
399 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
400 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
401 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
402 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
403 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
404 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
407 RemoveTrailerIdFromDocument();
408 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
409 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
410 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
411 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
412 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
415 RemoveGoodbyeObject();
416 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
417 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
418 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
419 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
420 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
425 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
427 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
428 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
429 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
430 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
431 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
432 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
435 RemoveTrailerIdFromDocument();
436 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
437 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
438 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
439 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
440 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
443 RemoveGoodbyeObject();
444 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
445 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
446 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
447 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
448 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
454 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
456 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
457 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
458 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
459 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
460 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
461 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
464 RemoveTrailerIdFromDocument();
465 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
470 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
471 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
472 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
473 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
476 RemoveGoodbyeObject();
477 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
478 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
479 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
480 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
481 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
486 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
488 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
489 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
490 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
491 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
492 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
493 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
496 RemoveTrailerIdFromDocument();
497 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
498 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
499 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
500 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
501 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
504 RemoveGoodbyeObject();
505 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
506 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
507 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
508 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
509 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
514 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
516 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
517 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
518 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
519 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
520 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
521 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
524 RemoveTrailerIdFromDocument();
525 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
526 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
527 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
528 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
529 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
532 RemoveGoodbyeObject();
533 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
534 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
535 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
536 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
537 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
542 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
544 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
545 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
546 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
547 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
548 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
549 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
552 RemoveTrailerIdFromDocument();
553 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
554 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
555 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
556 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
557 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
560 RemoveGoodbyeObject();
561 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
562 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
563 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
564 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
565 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
570 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
572 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
573 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
574 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
575 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
576 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
577 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
580 RemoveTrailerIdFromDocument();
581 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
582 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
583 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
584 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
585 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
588 RemoveGoodbyeObject();
589 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
590 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
591 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
592 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
593 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
598 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
600 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
601 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
602 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
603 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
604 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
605 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
608 RemoveTrailerIdFromDocument();
609 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
610 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
611 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
612 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
613 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
616 RemoveGoodbyeObject();
617 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
618 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
619 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
620 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
621 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
626 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
628 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
629 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
630 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
631 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
632 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
633 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
636 RemoveTrailerIdFromDocument();
637 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
638 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
639 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
640 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
641 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
644 RemoveGoodbyeObject();
645 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
646 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
647 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
648 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
649 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
654 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
656 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
657 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
658 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
659 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
660 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
661 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
664 RemoveTrailerIdFromDocument();
665 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
666 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
667 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
668 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
669 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
672 RemoveGoodbyeObject();
673 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
674 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
675 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
676 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
677 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
681 OpenAndVerifyHelloWorldDocumentWithPassword(
"bug_1124998.pdf",
"test");
static bool UseSkiaRenderer()
void RemoveGoodbyeObject()
void VerifySavedHelloWorldDocumentWithPassword(const char *password)
void VerifySavedModifiedHelloWorldDocumentWithPassword(const char *password)
void OpenAndVerifyHelloWorldDocumentWithPassword(const char *filename, const char *password)
void RemoveTrailerIdFromDocument()
RetainPtr< CPDF_Object > RemoveFor(ByteStringView key)
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
CPDF_Parser * GetParser() const
CPDF_Dictionary * GetMutableTrailerForTesting()
FPDF_DOCUMENT OpenSavedDocumentWithPassword(const char *password)
void CloseSavedDocument()
FPDF_PAGE LoadPage(int page_index)
static void CompareBitmap(FPDF_BITMAP bitmap, int expected_width, int expected_height, const char *expected_md5sum)
void UnloadPage(FPDF_PAGE page)
FPDF_DOCUMENT document() const
void CloseSavedPage(FPDF_PAGE page)
FPDF_PAGE LoadSavedPage(int page_index)
TEST_F(CPDFSecurityHandlerEmbedderTest, Unencrypted)
#define FPDF_FILLMODE_ALTERNATE
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, int fillmode, FPDF_BOOL stroke)
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, unsigned int R, unsigned int G, unsigned int B, unsigned int A)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x, float y, float w, float h)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page, int index)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GenerateContent(FPDF_PAGE page)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadCustomDocument(FPDF_FILEACCESS *pFileAccess, FPDF_BYTESTRING password)
const char * HelloWorldChecksum()
const char * HelloWorldRemovedChecksum()