summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-07-13 16:31:34 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-13 21:18:15 +0000
commit56fc9725f05b18573b06d8a422c5d9d6e626219d (patch)
treeda5cf8b3ab3cc4cd6b2394f3f80a46be79a59be3 /core/fpdfapi/parser
parent7b8f88a45cf88756c6bed616ca50b404af903c97 (diff)
downloadpdfium-56fc9725f05b18573b06d8a422c5d9d6e626219d.tar.xz
Add Embeddertest for password after savingchromium/3157
This CL allows TestSaved to open password-protected and linearized documents properly. It also adds a test with one such document. BUG= pdfium:787 Change-Id: Ie0da7f290711505fb208794afdc737c36e84dd3c Reviewed-on: https://pdfium-review.googlesource.com/7034 Commit-Queue: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
index c6c6217e2c..5df3348834 100644
--- a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp
@@ -2,6 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
+
+#include "core/fxcrt/fx_system.h"
+#include "public/fpdf_edit.h"
+#include "public/fpdf_save.h"
+#include "public/fpdfview.h"
#include "testing/embedder_test.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -35,6 +41,48 @@ TEST_F(CPDFSecurityHandlerEmbeddertest, OwnerPassword) {
EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
}
+TEST_F(CPDFSecurityHandlerEmbeddertest, PasswordAfterGenerateSave) {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
+ const char md5[] = "e4a3701ca5b2a759e06455aa8d97d46e";
+#elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ const char md5[] = "6951b6c9891dfe0332a5b1983e484400";
+#else
+ const char md5[] = "50985f3440d3f66c3b599ab138214015";
+#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
+ {
+ ASSERT_TRUE(OpenDocument("encrypted.pdf", "5678", true));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20);
+ ASSERT_TRUE(red_rect);
+ EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255));
+ EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0));
+ FPDFPage_InsertObject(page, red_rect);
+ FPDF_BITMAP page_bitmap = RenderPage(page);
+ CompareBitmap(page_bitmap, 612, 792, md5);
+ FPDFBitmap_Destroy(page_bitmap);
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+ UnloadPage(page);
+ }
+ std::string new_file = GetString();
+ FPDF_FILEACCESS file_access;
+ memset(&file_access, 0, sizeof(file_access));
+ file_access.m_FileLen = new_file.size();
+ file_access.m_GetBlock = GetBlockFromString;
+ file_access.m_Param = &new_file;
+ EXPECT_FALSE(FPDF_LoadCustomDocument(&file_access, nullptr));
+ struct {
+ const char* password;
+ const unsigned long permissions;
+ } tests[] = {{"1234", 0xFFFFF2C0}, {"5678", 0xFFFFFFFC}};
+ for (const auto& test : tests) {
+ TestSaved(612, 792, md5, test.password);
+ EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(m_SavedDocument));
+ CloseSaved();
+ }
+}
+
TEST_F(CPDFSecurityHandlerEmbeddertest, NoPasswordVersion5) {
ASSERT_FALSE(OpenDocument("bug_644.pdf"));
}