summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorJun Fang <jun_fang@foxitsoftware.com>2015-11-10 18:29:18 +0800
committerJun Fang <jun_fang@foxitsoftware.com>2015-11-10 18:29:18 +0800
commitdf7f3663364fd4d6148d658c5bdb98ab2532fb8d (patch)
tree2f803bc57c5bcad8c1aa5e12122962e38e3adbe5 /testing
parent956168fc8abf4046e94eef9ee76b0705a6248ac0 (diff)
downloadpdfium-df7f3663364fd4d6148d658c5bdb98ab2532fb8d.tar.xz
Merge to XFA: Support linearized loading
BUG=446715 R=thestig@chromium.org, tsepez@chromium.org Review URL: https://codereview.chromium.org/1353093003 . Conflicts: core/include/fpdfapi/fpdf_parser.h core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_embeddertest.cpp samples/pdfium_test.cc testing/embedder_test.cpp testing/embedder_test.h Review URL: https://codereview.chromium.org/1412083010 .
Diffstat (limited to 'testing')
-rw-r--r--testing/embedder_test.cpp45
-rw-r--r--testing/embedder_test.h3
-rw-r--r--testing/resources/feature_linearized_loading.pdfbin0 -> 11671 bytes
3 files changed, 38 insertions, 10 deletions
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index baaf016d9f..c57126f320 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -97,7 +97,8 @@ void EmbedderTest::TearDown() {
free(file_contents_);
}
-bool EmbedderTest::OpenDocument(const std::string& filename) {
+bool EmbedderTest::OpenDocument(const std::string& filename,
+ bool must_linearize) {
std::string file_path;
if (!PathService::GetTestFilePath(filename, &file_path))
return false;
@@ -117,15 +118,42 @@ bool EmbedderTest::OpenDocument(const std::string& filename) {
hints_.AddSegment = Add_Segment;
avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
- (void)FPDFAvail_IsDocAvail(avail_, &hints_);
- if (!FPDFAvail_IsLinearized(avail_))
- document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
- else
+ if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) {
document_ = FPDFAvail_GetDocument(avail_, nullptr);
-
- if (!document_)
- return false;
+ if (!document_) {
+ return false;
+ }
+ int32_t nRet = PDF_DATA_NOTAVAIL;
+ while (nRet == PDF_DATA_NOTAVAIL) {
+ nRet = FPDFAvail_IsDocAvail(avail_, &hints_);
+ }
+ if (nRet == PDF_DATA_ERROR) {
+ return false;
+ }
+ nRet = FPDFAvail_IsFormAvail(avail_, &hints_);
+ if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) {
+ return false;
+ }
+ int page_count = FPDF_GetPageCount(document_);
+ for (int i = 0; i < page_count; ++i) {
+ nRet = PDF_DATA_NOTAVAIL;
+ while (nRet == PDF_DATA_NOTAVAIL) {
+ nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_);
+ }
+ if (nRet == PDF_DATA_ERROR) {
+ return false;
+ }
+ }
+ } else {
+ if (must_linearize) {
+ return false;
+ }
+ document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
+ if (!document_) {
+ return false;
+ }
+ }
int docType = DOCTYPE_PDF;
if (FPDF_HasXFAField(document_, &docType)) {
@@ -134,7 +162,6 @@ bool EmbedderTest::OpenDocument(const std::string& filename) {
}
(void)FPDF_GetDocPermissions(document_);
- (void)FPDFAvail_IsFormAvail(avail_, &hints_);
IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
memset(platform, 0, sizeof(IPDF_JSPLATFORM));
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index a5b5e33fae..f68cb9df74 100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -82,7 +82,8 @@ class EmbedderTest : public ::testing::Test,
// environment, or return false on failure.
// The filename is relative to the test data directory where we store all the
// test files.
- virtual bool OpenDocument(const std::string& filename);
+ virtual bool OpenDocument(const std::string& filename,
+ bool must_linearize = false);
// Perform JavaScript actions that are to run at document open time.
virtual void DoOpenActions();
diff --git a/testing/resources/feature_linearized_loading.pdf b/testing/resources/feature_linearized_loading.pdf
new file mode 100644
index 0000000000..e6995c516d
--- /dev/null
+++ b/testing/resources/feature_linearized_loading.pdf
Binary files differ