summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/src/fpdfformfill_embeddertest.cpp20
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp1
-rw-r--r--samples/pdfium_test.cc15
-rw-r--r--testing/embedder_test_timer_handling_delegate.h30
-rw-r--r--testing/resources/bug_551248.in80
-rw-r--r--testing/resources/bug_551248.pdf134
-rw-r--r--testing/test_support.cpp16
-rw-r--r--testing/test_support.h6
8 files changed, 289 insertions, 13 deletions
diff --git a/fpdfsdk/src/fpdfformfill_embeddertest.cpp b/fpdfsdk/src/fpdfformfill_embeddertest.cpp
index 56710b9f83..53cdcbd041 100644
--- a/fpdfsdk/src/fpdfformfill_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfformfill_embeddertest.cpp
@@ -63,3 +63,23 @@ TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
UnloadPage(page);
}
+
+TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
+ EmbedderTestTimerHandlingDelegate delegate;
+ SetDelegate(&delegate);
+
+ EXPECT_TRUE(OpenDocument("testing/resources/bug_551248.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ EXPECT_NE(nullptr, page);
+ DoOpenActions();
+ delegate.AdvanceTime(5000);
+ UnloadPage(page);
+
+ const auto& alerts = delegate.GetAlerts();
+ ASSERT_EQ(1U, alerts.size());
+
+ EXPECT_STREQ(L"hello world", alerts[0].message.c_str());
+ EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
+ EXPECT_EQ(0, alerts[0].type);
+ EXPECT_EQ(0, alerts[0].icon);
+}
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 0556c4ea47..883ecc82ae 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -108,6 +108,7 @@ CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj,
m_bValid(true),
m_nType(nType),
m_dwTimeOut(dwTimeOut),
+ m_swJScript(script),
m_pRuntime(pRuntime),
m_pApp(pApp) {
IFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 76de7ea7a5..4ccf1a7721 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -196,19 +196,8 @@ void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) {
int ExampleAppAlert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING,
int, int) {
- // Deal with differences between UTF16LE and wchar_t on this platform.
- size_t characters = 0;
- while (msg[characters]) {
- ++characters;
- }
- wchar_t* platform_string =
- static_cast<wchar_t*>(malloc((characters + 1) * sizeof(wchar_t)));
- for (size_t i = 0; i < characters + 1; ++i) {
- unsigned char* ptr = (unsigned char*)&msg[i];
- platform_string[i] = ptr[0] + 256 * ptr[1];
- }
- printf("Alert: %ls\n", platform_string);
- free(platform_string);
+ std::wstring platform_string = GetWideString(msg);
+ printf("Alert: %ls\n", platform_string.c_str());
return 0;
}
diff --git a/testing/embedder_test_timer_handling_delegate.h b/testing/embedder_test_timer_handling_delegate.h
index aca4ac1b77..74e346e830 100644
--- a/testing/embedder_test_timer_handling_delegate.h
+++ b/testing/embedder_test_timer_handling_delegate.h
@@ -6,12 +6,39 @@
#define TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_
#include <map>
+#include <string>
#include <utility>
+#include <vector>
#include "embedder_test.h"
+#include "test_support.h"
class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate {
public:
+ struct ReceivedAlert {
+ ReceivedAlert(FPDF_WIDESTRING message_in,
+ FPDF_WIDESTRING title_in,
+ int type_in,
+ int icon_in)
+ : type(type_in), icon(icon_in) {
+ message = GetWideString(message_in);
+ title = GetWideString(title_in);
+ }
+
+ std::wstring message;
+ std::wstring title;
+ int type;
+ int icon;
+ };
+
+ int Alert(FPDF_WIDESTRING message,
+ FPDF_WIDESTRING title,
+ int type,
+ int icon) override {
+ alerts_.push_back(ReceivedAlert(message, title, type, icon));
+ return 0;
+ }
+
int SetTimer(int msecs, TimerCallback fn) override {
expiry_to_timer_map_.insert(std::pair<int, Timer>(
msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn)));
@@ -44,11 +71,14 @@ class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate {
}
}
+ const std::vector<ReceivedAlert>& GetAlerts() const { return alerts_; }
+
protected:
using Timer = std::pair<int, TimerCallback>; // ID, callback pair.
std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout.
int next_timer_id_ = 0;
int imaginary_elapsed_msecs_ = 0;
+ std::vector<ReceivedAlert> alerts_;
};
#endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_
diff --git a/testing/resources/bug_551248.in b/testing/resources/bug_551248.in
new file mode 100644
index 0000000000..ad10e93912
--- /dev/null
+++ b/testing/resources/bug_551248.in
@@ -0,0 +1,80 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm 6 0 R
+ /Names <</JavaScript 13 0 R>>
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 1
+ /Kids [4 0 R]
+>>
+endobj
+{{object 4 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 612 792]
+ /CropBox [0 0 612 792]
+ /Resources <<>>
+>>
+endobj
+{{object 6 0}} <<
+ /DR <<
+ /Font <</Helv 7 0 R>>
+ >>
+ /DA (/Helv 0 Tf 0 g)
+ /Fields [5 0 R]
+>>
+endobj
+{{object 7 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+ /Encoding /WinAnsiEncoding
+>>
+endobj
+{{object 8 0}} <<
+ /Type /XObject
+ /Subtype /Form
+ /FormType 1
+ /Matrix [1 0 0 1 0 0]
+ /BBox [0 0 75.907 28.472]
+ /Resources <<
+ /Font <</FXF0 7 0 R>>
+ >>
+>>
+stream
+q
+Q
+
+
+endstream
+endobj
+{{object 11 0}} <<
+ /Type /Action
+ /S /JavaScript
+ /JS 50 0 R
+>>
+endobj
+{{object 13 0}} <<
+ /Names [(startDelay) 11 0 R]
+>>
+endobj
+{{object 50 0}} <<
+>>
+stream
+function startDelay()
+{
+ app.alert("hello world");
+}
+app.setTimeOut("startDelay()", 3000);
+endstream
+endobj
+{{xref}}
+trailer <<
+ /Root 1 0 R
+>>
+{{startxref}}
+%%EOF
diff --git a/testing/resources/bug_551248.pdf b/testing/resources/bug_551248.pdf
new file mode 100644
index 0000000000..cca1872ee7
--- /dev/null
+++ b/testing/resources/bug_551248.pdf
@@ -0,0 +1,134 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm 6 0 R
+ /Names <</JavaScript 13 0 R>>
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /Count 1
+ /Kids [4 0 R]
+>>
+endobj
+4 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 612 792]
+ /CropBox [0 0 612 792]
+ /Resources <<>>
+>>
+endobj
+6 0 obj <<
+ /DR <<
+ /Font <</Helv 7 0 R>>
+ >>
+ /DA (/Helv 0 Tf 0 g)
+ /Fields [5 0 R]
+>>
+endobj
+7 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+ /Encoding /WinAnsiEncoding
+>>
+endobj
+8 0 obj <<
+ /Type /XObject
+ /Subtype /Form
+ /FormType 1
+ /Matrix [1 0 0 1 0 0]
+ /BBox [0 0 75.907 28.472]
+ /Resources <<
+ /Font <</FXF0 7 0 R>>
+ >>
+>>
+stream
+q
+Q
+
+
+endstream
+endobj
+11 0 obj <<
+ /Type /Action
+ /S /JavaScript
+ /JS 50 0 R
+>>
+endobj
+13 0 obj <<
+ /Names [(startDelay) 11 0 R]
+>>
+endobj
+50 0 obj <<
+>>
+stream
+function startDelay()
+{
+ app.alert("hello world");
+}
+app.setTimeOut("startDelay()", 3000);
+endstream
+endobj
+xref
+0 51
+0000000000 65535 f
+0000000015 00000 n
+0000000118 00000 n
+0000000000 65535 f
+0000000181 00000 n
+0000000000 65535 f
+0000000302 00000 n
+0000000404 00000 n
+0000000509 00000 n
+0000000000 65535 f
+0000000000 65535 f
+0000000701 00000 n
+0000000000 65535 f
+0000000769 00000 n
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000822 00000 n
+trailer <<
+ /Root 1 0 R
+>>
+startxref
+954
+%%EOF
diff --git a/testing/test_support.cpp b/testing/test_support.cpp
index 611ba5d580..49232990bc 100644
--- a/testing/test_support.cpp
+++ b/testing/test_support.cpp
@@ -98,6 +98,22 @@ char* GetFileContents(const char* filename, size_t* retlen) {
return buffer;
}
+std::wstring GetWideString(FPDF_WIDESTRING wstr) {
+ if (!wstr)
+ return nullptr;
+
+ size_t characters = 0;
+ while (wstr[characters])
+ ++characters;
+
+ std::wstring platform_string(characters, L'\0');
+ for (size_t i = 0; i < characters + 1; ++i) {
+ const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&wstr[i]);
+ platform_string[i] = ptr[0] + 256 * ptr[1];
+ }
+ return platform_string;
+}
+
#ifdef PDF_ENABLE_V8
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
bool InitializeV8ForPDFium(const std::string& exe_path,
diff --git a/testing/test_support.h b/testing/test_support.h
index 1018421ba7..4bb88db254 100644
--- a/testing/test_support.h
+++ b/testing/test_support.h
@@ -8,6 +8,8 @@
#include <stdlib.h>
#include <string>
+#include "../public/fpdfview.h"
+
#ifdef PDF_ENABLE_V8
#include "v8/include/libplatform/libplatform.h"
#include "v8/include/v8.h"
@@ -16,6 +18,10 @@
// Reads the entire contents of a file into a newly malloc'd buffer.
char* GetFileContents(const char* filename, size_t* retlen);
+// Converts a FPDF_WIDESTRING to a std::wstring.
+// Deals with differences between UTF16LE and wchar_t.
+std::wstring GetWideString(FPDF_WIDESTRING wstr);
+
#ifdef PDF_ENABLE_V8
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
bool InitializeV8ForPDFium(const std::string& exe_path,