summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-10 22:41:42 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-10 22:41:42 +0000
commitfc41e77c97173592ea2abb88c3f6f4dc7c43349d (patch)
tree0e7d29cc289de4738567edb52c7d1c8e809d5a6f
parent7db136abc305630fb9ba9754a2c371c0e7ae8237 (diff)
downloadpdfium-fc41e77c97173592ea2abb88c3f6f4dc7c43349d.tar.xz
Create embeddertests for other kinds of actions.
Change-Id: Ia4619be65e2ab8ee4bf19ba9608c1cc94594ba89 Reviewed-on: https://pdfium-review.googlesource.com/c/43812 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--fpdfsdk/fpdf_doc_embeddertest.cpp86
-rw-r--r--testing/resources/goto_action.in46
-rw-r--r--testing/resources/goto_action.pdf58
-rw-r--r--testing/resources/nonesuch_action.in45
-rw-r--r--testing/resources/nonesuch_action.pdf57
-rw-r--r--testing/resources/uri_action.in46
-rw-r--r--testing/resources/uri_action.pdf58
7 files changed, 393 insertions, 3 deletions
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp
index 91a2333241..a3d8b3a082 100644
--- a/fpdfsdk/fpdf_doc_embeddertest.cpp
+++ b/fpdfsdk/fpdf_doc_embeddertest.cpp
@@ -257,13 +257,93 @@ TEST_F(FPDFDocEmbeddertest, ActionLaunch) {
unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0);
EXPECT_EQ(kExpectedLength, bufsize);
- char buf[kExpectedLength];
+ char buf[1024];
EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize));
EXPECT_STREQ(kExpectedResult, buf);
- // Other public methods are not appropriate for this action type.
+ // Other public methods are not appropriate for launch actions.
EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), action));
- EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, bufsize));
+ EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf)));
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFDocEmbeddertest, ActionURI) {
+ EXPECT_TRUE(OpenDocument("uri_action.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // The target action is nearly the size of the whole page.
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ ASSERT_TRUE(link);
+
+ FPDF_ACTION action = FPDFLink_GetAction(link);
+ ASSERT_TRUE(action);
+ EXPECT_EQ(static_cast<unsigned long>(PDFACTION_URI),
+ FPDFAction_GetType(action));
+
+ const char kExpectedResult[] = "https://example.com/page.html";
+ const unsigned long kExpectedLength = sizeof(kExpectedResult);
+ unsigned long bufsize = FPDFAction_GetURIPath(document(), action, nullptr, 0);
+ ASSERT_EQ(kExpectedLength, bufsize);
+
+ char buf[1024];
+ EXPECT_EQ(bufsize, FPDFAction_GetURIPath(document(), action, buf, bufsize));
+ EXPECT_STREQ(kExpectedResult, buf);
+
+ // Other public methods are not appropriate for URI actions
+ EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), action));
+ EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf)));
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFDocEmbeddertest, ActionGoto) {
+ EXPECT_TRUE(OpenDocument("goto_action.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // The target action is nearly the size of the whole page.
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ ASSERT_TRUE(link);
+
+ FPDF_ACTION action = FPDFLink_GetAction(link);
+ ASSERT_TRUE(action);
+ EXPECT_EQ(static_cast<unsigned long>(PDFACTION_GOTO),
+ FPDFAction_GetType(action));
+
+ EXPECT_TRUE(FPDFAction_GetDest(document(), action));
+
+ // Other public methods are not appropriate for GoTo actions.
+ char buf[1024];
+ EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf)));
+ EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf)));
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFDocEmbeddertest, ActionNonesuch) {
+ EXPECT_TRUE(OpenDocument("nonesuch_action.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // The target action is nearly the size of the whole page.
+ FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+ ASSERT_TRUE(link);
+
+ FPDF_ACTION action = FPDFLink_GetAction(link);
+ ASSERT_TRUE(action);
+ EXPECT_EQ(static_cast<unsigned long>(PDFACTION_UNSUPPORTED),
+ FPDFAction_GetType(action));
+
+ // No public methods are appropriate for unsupported actions.
+ char buf[1024];
+ EXPECT_FALSE(FPDFAction_GetDest(document(), action));
+ EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf)));
+ EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf)));
UnloadPage(page);
}
diff --git a/testing/resources/goto_action.in b/testing/resources/goto_action.in
new file mode 100644
index 0000000000..0e7d73fcde
--- /dev/null
+++ b/testing/resources/goto_action.in
@@ -0,0 +1,46 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Annots [4 0 R]
+>>
+endobj
+{{object 4 0}} <<
+ /A 5 0 R
+ /FT /Tx
+ /Ff 29360128
+ /T (txtName)
+ /Type /Annot
+ /Subtype /Link
+ /F 4
+ /M (D:20150514070426+05'30')
+ /Rect [1 1 199 199]
+ /BS <<
+ /W 1
+ /S /S
+ >>
+ /DA (/Helv 0 Tf 0 0 0 rg)
+ /V ()
+>>
+endobj
+{{object 5 0}} <<
+ /S /GoTo
+ /D [1 2 3]
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/goto_action.pdf b/testing/resources/goto_action.pdf
new file mode 100644
index 0000000000..93be39c24f
--- /dev/null
+++ b/testing/resources/goto_action.pdf
@@ -0,0 +1,58 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Annots [4 0 R]
+>>
+endobj
+4 0 obj <<
+ /A 5 0 R
+ /FT /Tx
+ /Ff 29360128
+ /T (txtName)
+ /Type /Annot
+ /Subtype /Link
+ /F 4
+ /M (D:20150514070426+05'30')
+ /Rect [1 1 199 199]
+ /BS <<
+ /W 1
+ /S /S
+ >>
+ /DA (/Helv 0 Tf 0 0 0 rg)
+ /V ()
+>>
+endobj
+5 0 obj <<
+ /S /GoTo
+ /D [1 2 3]
+>>
+endobj
+xref
+0 6
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000161 00000 n
+0000000230 00000 n
+0000000464 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 6
+>>
+startxref
+509
+%%EOF
diff --git a/testing/resources/nonesuch_action.in b/testing/resources/nonesuch_action.in
new file mode 100644
index 0000000000..c212b4e816
--- /dev/null
+++ b/testing/resources/nonesuch_action.in
@@ -0,0 +1,45 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Annots [4 0 R]
+>>
+endobj
+{{object 4 0}} <<
+ /A 5 0 R
+ /FT /Tx
+ /Ff 29360128
+ /T (txtName)
+ /Type /Annot
+ /Subtype /Link
+ /F 4
+ /M (D:20150514070426+05'30')
+ /Rect [1 1 199 199]
+ /BS <<
+ /W 1
+ /S /S
+ >>
+ /DA (/Helv 0 Tf 0 0 0 rg)
+ /V ()
+>>
+endobj
+{{object 5 0}} <<
+ /S /NoneSuch
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/nonesuch_action.pdf b/testing/resources/nonesuch_action.pdf
new file mode 100644
index 0000000000..9188d49ded
--- /dev/null
+++ b/testing/resources/nonesuch_action.pdf
@@ -0,0 +1,57 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Annots [4 0 R]
+>>
+endobj
+4 0 obj <<
+ /A 5 0 R
+ /FT /Tx
+ /Ff 29360128
+ /T (txtName)
+ /Type /Annot
+ /Subtype /Link
+ /F 4
+ /M (D:20150514070426+05'30')
+ /Rect [1 1 199 199]
+ /BS <<
+ /W 1
+ /S /S
+ >>
+ /DA (/Helv 0 Tf 0 0 0 rg)
+ /V ()
+>>
+endobj
+5 0 obj <<
+ /S /NoneSuch
+>>
+endobj
+xref
+0 6
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000161 00000 n
+0000000230 00000 n
+0000000464 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 6
+>>
+startxref
+500
+%%EOF
diff --git a/testing/resources/uri_action.in b/testing/resources/uri_action.in
new file mode 100644
index 0000000000..3ec7ef3757
--- /dev/null
+++ b/testing/resources/uri_action.in
@@ -0,0 +1,46 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Annots [4 0 R]
+>>
+endobj
+{{object 4 0}} <<
+ /A 5 0 R
+ /FT /Tx
+ /Ff 29360128
+ /T (txtName)
+ /Type /Annot
+ /Subtype /Link
+ /F 4
+ /M (D:20150514070426+05'30')
+ /Rect [1 1 199 199]
+ /BS <<
+ /W 1
+ /S /S
+ >>
+ /DA (/Helv 0 Tf 0 0 0 rg)
+ /V ()
+>>
+endobj
+{{object 5 0}} <<
+ /S /URI
+ /URI (https://example.com/page.html)
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/uri_action.pdf b/testing/resources/uri_action.pdf
new file mode 100644
index 0000000000..ede0c5e8f8
--- /dev/null
+++ b/testing/resources/uri_action.pdf
@@ -0,0 +1,58 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Annots [4 0 R]
+>>
+endobj
+4 0 obj <<
+ /A 5 0 R
+ /FT /Tx
+ /Ff 29360128
+ /T (txtName)
+ /Type /Annot
+ /Subtype /Link
+ /F 4
+ /M (D:20150514070426+05'30')
+ /Rect [1 1 199 199]
+ /BS <<
+ /W 1
+ /S /S
+ >>
+ /DA (/Helv 0 Tf 0 0 0 rg)
+ /V ()
+>>
+endobj
+5 0 obj <<
+ /S /URI
+ /URI (https://example.com/page.html)
+>>
+endobj
+xref
+0 6
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000161 00000 n
+0000000230 00000 n
+0000000464 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 6
+>>
+startxref
+534
+%%EOF