7#include "build/build_config.h"
8#include "core/fpdfapi/parser/cpdf_dictionary.h"
9#include "core/fpdfapi/parser/cpdf_document.h"
10#include "core/fpdfapi/parser/cpdf_parser.h"
11#include "core/fxcrt/fx_system.h"
12#include "core/fxge/cfx_defaultrenderdevice.h"
13#include "public/cpp/fpdf_scopers.h"
14#include "public/fpdf_edit.h"
15#include "public/fpdf_save.h"
16#include "public/fpdfview.h"
17#include "testing/embedder_test.h"
18#include "testing/embedder_test_constants.h"
19#include "testing/gtest/include/gtest/gtest.h"
23const char kAgeUTF8[] =
26const char kAgeLatin1[] =
30const char kHotelUTF8[] =
34const char kHotelLatin1[] =
44 const char* password) {
45 ASSERT_TRUE(OpenDocumentWithPassword(filename, password));
47 VerifyHelloWorldPage(page);
54 VerifyHelloWorldPage(page);
62 VerifyModifiedHelloWorldPage(page);
83 ScopedFPDFPageObject goodbye_object(FPDFPage_GetObject(page, 1));
84 ASSERT_TRUE(goodbye_object);
85 ASSERT_TRUE(FPDFPage_RemoveObject(page, goodbye_object.get()));
88 VerifyModifiedHelloWorldPage(page);
93 void VerifyHelloWorldPage(FPDF_PAGE page) {
96 ScopedFPDFBitmap page_bitmap = RenderPage(page);
100 void VerifyModifiedHelloWorldPage(FPDF_PAGE page) {
103 ScopedFPDFBitmap page_bitmap = RenderPage(page);
110 ASSERT_TRUE(OpenDocument(
"about_blank.pdf"));
112 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
113 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocUserPermissions(document()));
117 ASSERT_TRUE(OpenDocumentWithPassword(
"about_blank.pdf",
"foobar"));
119 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
120 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocUserPermissions(document()));
124 EXPECT_FALSE(OpenDocument(
"encrypted.pdf"));
128 EXPECT_FALSE(OpenDocumentWithPassword(
"encrypted.pdf",
"tiger"));
132 ASSERT_TRUE(OpenDocumentWithPassword(
"encrypted.pdf",
"1234"));
133 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocPermissions(document()));
134 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocUserPermissions(document()));
138 ASSERT_TRUE(OpenDocumentWithPassword(
"encrypted.pdf",
"5678"));
139 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
140 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocUserPermissions(document()));
144 const char* checksum = []() {
147 return "caa4bfda016a9c48a540ff7c6716468c";
148#elif BUILDFLAG(IS_APPLE)
149 return "6c1a242ce886df5cf578401eeeaa1929";
151 return "ad97491cab71c02f1f4ef5ba0a7b5593";
154#if BUILDFLAG(IS_APPLE)
155 return "2a308e8cc20a6221112c387d122075a8";
157 return "9fe7eef8e51d15a604001854be6ed1ee";
161 ASSERT_TRUE(OpenDocumentWithOptions(
"encrypted.pdf",
"5678",
162 LinearizeOption::kMustLinearize,
163 JavaScriptOption::kEnableJavaScript));
164 FPDF_PAGE page = LoadPage(0);
167 ASSERT_TRUE(red_rect);
171 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
172 CompareBitmap(bitmap.get(), 612, 792, checksum);
174 SetWholeFileAvailable();
175 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
178 std::string new_file = GetString();
179 FPDF_FILEACCESS file_access;
180 memset(&file_access, 0,
sizeof(file_access));
181 file_access.m_FileLen = new_file.size();
182 file_access.m_GetBlock = GetBlockFromString;
183 file_access.m_Param = &new_file;
187 const char* password;
188 const unsigned long permissions;
189 } tests[] = {{
"1234", 0xFFFFF2C0}, {
"5678", 0xFFFFFFFC}};
191 for (
const auto& test : tests) {
192 ASSERT_TRUE(OpenSavedDocumentWithPassword(test.password));
193 FPDF_PAGE page = LoadSavedPage(0);
195 VerifySavedRendering(page, 612, 792, checksum);
196 EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(saved_document()));
198 CloseSavedPage(page);
199 CloseSavedDocument();
204 ASSERT_FALSE(OpenDocument(
"bug_644.pdf"));
208 ASSERT_FALSE(OpenDocumentWithPassword(
"bug_644.pdf",
"tiger"));
212 ASSERT_TRUE(OpenDocumentWithPassword(
"bug_644.pdf",
"a"));
213 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
217 ASSERT_TRUE(OpenDocumentWithPassword(
"bug_644.pdf",
"b"));
218 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
224 OpenDocumentWithPassword(
"encrypted_hello_world_r2_bad_okey.pdf",
"a"));
230 OpenDocumentWithPassword(
"encrypted_hello_world_r3_bad_okey.pdf",
"a"));
236 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
238 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
239 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
240 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
241 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
242 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
243 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
246 RemoveTrailerIdFromDocument();
247 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
256 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
257 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
260 RemoveGoodbyeObject();
261 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
262 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
263 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
268 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
270 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
271 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
272 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
273 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
274 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
275 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
278 RemoveTrailerIdFromDocument();
279 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
280 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
281 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
284 RemoveGoodbyeObject();
285 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
286 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
287 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
292 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
294 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
295 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
296 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
297 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
298 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
299 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
302 RemoveTrailerIdFromDocument();
303 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
304 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
305 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
308 RemoveGoodbyeObject();
309 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
310 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
311 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
316 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
318 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
319 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
320 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
321 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
322 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
323 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
326 RemoveTrailerIdFromDocument();
327 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
328 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
329 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
332 RemoveGoodbyeObject();
333 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
334 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
335 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
340 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
342 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
343 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
344 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
345 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
346 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
347 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
350 RemoveTrailerIdFromDocument();
351 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
352 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
353 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
354 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
355 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
358 RemoveGoodbyeObject();
359 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
360 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
361 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
362 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
363 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
368 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
370 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
371 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
372 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
373 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
374 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
375 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
378 RemoveTrailerIdFromDocument();
379 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
380 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
381 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
382 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
383 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
386 RemoveGoodbyeObject();
387 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
388 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
389 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
390 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
391 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
396 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
398 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
399 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
400 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
401 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
402 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
403 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
406 RemoveTrailerIdFromDocument();
407 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
408 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
409 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
410 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
411 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
414 RemoveGoodbyeObject();
415 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
416 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
417 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
418 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
419 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
424 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
426 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
427 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
428 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
429 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
430 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
431 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
434 RemoveTrailerIdFromDocument();
435 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
436 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
437 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
438 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
439 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
442 RemoveGoodbyeObject();
443 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
444 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
445 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
446 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
447 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
453 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
455 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
456 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
457 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
458 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
459 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
460 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
463 RemoveTrailerIdFromDocument();
464 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
469 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
470 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
471 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
472 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
475 RemoveGoodbyeObject();
476 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
477 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
478 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
479 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
480 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
485 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r2.pdf",
487 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
488 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
489 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
490 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
491 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
492 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
495 RemoveTrailerIdFromDocument();
496 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
497 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
498 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
499 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
500 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
503 RemoveGoodbyeObject();
504 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
505 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
506 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
507 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
508 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
513 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
515 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
516 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
517 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
518 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
519 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
520 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
523 RemoveTrailerIdFromDocument();
524 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
525 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
526 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
527 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
528 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
531 RemoveGoodbyeObject();
532 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
533 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
534 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
535 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
536 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
541 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r3.pdf",
543 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
544 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
545 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
546 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
547 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
548 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
551 RemoveTrailerIdFromDocument();
552 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
553 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
554 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
555 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
556 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
559 RemoveGoodbyeObject();
560 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
561 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
562 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
563 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
564 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
569 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
571 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
572 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
573 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
574 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
575 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
576 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
579 RemoveTrailerIdFromDocument();
580 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
581 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
582 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
583 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
584 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
587 RemoveGoodbyeObject();
588 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
589 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
590 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
591 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
592 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
597 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r5.pdf",
599 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
600 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
601 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
602 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
603 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
604 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
607 RemoveTrailerIdFromDocument();
608 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
609 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
610 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
611 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
612 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
615 RemoveGoodbyeObject();
616 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
617 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
618 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
619 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
620 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
625 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
627 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
628 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
629 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
630 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
631 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
632 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
635 RemoveTrailerIdFromDocument();
636 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
637 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
638 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
639 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
640 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
643 RemoveGoodbyeObject();
644 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
645 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
646 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
647 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
648 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
653 OpenAndVerifyHelloWorldDocumentWithPassword(
"encrypted_hello_world_r6.pdf",
655 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
656 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
657 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
658 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
659 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
660 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
663 RemoveTrailerIdFromDocument();
664 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
665 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
666 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
667 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
668 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
671 RemoveGoodbyeObject();
672 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
673 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
674 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
675 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
676 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
680 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)
CPDF_Parser * GetParser() const
CPDF_Dictionary * GetMutableTrailerForTesting()
FPDF_DOCUMENT OpenSavedDocumentWithPassword(const char *password)
void CloseSavedDocument()
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 LoadPage(int page_number)
FPDF_PAGE LoadSavedPage(int page_number)
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_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()