summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn9
-rw-r--r--testing/DEPS2
-rw-r--r--testing/embedder_test.cpp4
-rw-r--r--testing/resources/simple_xfa.pdfbin0 -> 87521 bytes
-rw-r--r--testing/xfa_js_embedder_test.cpp69
-rw-r--r--testing/xfa_js_embedder_test.h41
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp39
7 files changed, 162 insertions, 2 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 450a46c14e..53f4644fc1 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1957,7 +1957,6 @@ test("pdfium_embeddertests") {
"testing/embedder_test.h",
"testing/embedder_test_mock_delegate.h",
"testing/embedder_test_timer_handling_delegate.h",
- "xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp",
]
deps = [
":pdfium",
@@ -1978,6 +1977,14 @@ test("pdfium_embeddertests") {
deps += [ ":fxjs" ]
configs += [ "//v8:external_startup_data" ]
}
+ if (pdf_enable_xfa) {
+ sources += [
+ "testing/xfa_js_embedder_test.cpp",
+ "testing/xfa_js_embedder_test.h",
+ "xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp",
+ "xfa/fxfa/parser/cxfa_simple_parser_embeddertest.cpp",
+ ]
+ }
if (is_android) {
ignore_all_data_deps = true
use_raw_android_executable = true
diff --git a/testing/DEPS b/testing/DEPS
index 5adeb4141b..d0dc17242b 100644
--- a/testing/DEPS
+++ b/testing/DEPS
@@ -1,6 +1,8 @@
include_rules = [
'+core',
+ '+fpdfsdk',
'+fxjs',
'+public',
'+v8',
+ '+xfa'
]
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index 1baeb57206..bf00c11607 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -179,6 +179,8 @@ bool EmbedderTest::OpenDocument(const std::string& filename,
}
}
+ SetupFormFillEnvironment();
+
#ifdef PDF_ENABLE_XFA
int docType = DOCTYPE_PDF;
if (FPDF_HasXFAField(document_, &docType)) {
@@ -188,7 +190,6 @@ bool EmbedderTest::OpenDocument(const std::string& filename,
#endif // PDF_ENABLE_XFA
(void)FPDF_GetDocPermissions(document_);
- SetupFormFillEnvironment();
return true;
}
@@ -197,6 +198,7 @@ void EmbedderTest::SetupFormFillEnvironment() {
memset(platform, 0, sizeof(IPDF_JSPLATFORM));
platform->version = 2;
platform->app_alert = AlertTrampoline;
+ platform->m_isolate = external_isolate_;
FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
diff --git a/testing/resources/simple_xfa.pdf b/testing/resources/simple_xfa.pdf
new file mode 100644
index 0000000000..ef8eb7dcc9
--- /dev/null
+++ b/testing/resources/simple_xfa.pdf
Binary files differ
diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp
new file mode 100644
index 0000000000..d72e8762e8
--- /dev/null
+++ b/testing/xfa_js_embedder_test.cpp
@@ -0,0 +1,69 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/xfa_js_embedder_test.h"
+
+#include <string>
+
+#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
+#include "fpdfsdk/fsdk_define.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/base/ptr_util.h"
+#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
+
+XFAJSEmbedderTest::XFAJSEmbedderTest()
+ : array_buffer_allocator_(pdfium::MakeUnique<FXJS_ArrayBufferAllocator>()) {
+}
+
+XFAJSEmbedderTest::~XFAJSEmbedderTest() {}
+
+void XFAJSEmbedderTest::SetUp() {
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator = array_buffer_allocator_.get();
+ isolate_ = v8::Isolate::New(params);
+ ASSERT_TRUE(isolate_ != nullptr);
+
+ EmbedderTest::SetExternalIsolate(isolate_);
+ EmbedderTest::SetUp();
+}
+
+void XFAJSEmbedderTest::TearDown() {
+ value_ = nullptr;
+ script_context_ = nullptr;
+
+ EmbedderTest::TearDown();
+
+ isolate_->Dispose();
+ isolate_ = nullptr;
+}
+
+bool XFAJSEmbedderTest::OpenDocument(const std::string& filename,
+ const char* password,
+ bool must_linearize) {
+ if (!EmbedderTest::OpenDocument(filename, password, must_linearize))
+ return false;
+
+ script_context_ = UnderlyingFromFPDFDocument(document())
+ ->GetXFADoc()
+ ->GetXFADoc()
+ ->GetScriptContext();
+ return true;
+}
+
+bool XFAJSEmbedderTest::Execute(const CFX_ByteStringC& input) {
+ value_ = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate());
+ if (script_context_->RunScript(XFA_SCRIPTLANGTYPE_Formcalc,
+ CFX_WideString::FromUTF8(input).AsStringC(),
+ value_.get(), nullptr)) {
+ return true;
+ }
+
+ CFXJSE_Value msg(GetIsolate());
+ value_->GetObjectPropertyByIdx(1, &msg);
+ EXPECT_TRUE(msg.IsString());
+
+ fprintf(stderr, "JS: %.*s\n", input.GetLength(), input.c_str());
+ fprintf(stderr, "JS ERROR: %ls\n", msg.ToWideString().c_str());
+ return false;
+}
diff --git a/testing/xfa_js_embedder_test.h b/testing/xfa_js_embedder_test.h
new file mode 100644
index 0000000000..62c3597b07
--- /dev/null
+++ b/testing/xfa_js_embedder_test.h
@@ -0,0 +1,41 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_XFA_JS_EMBEDDER_TEST_H_
+#define TESTING_XFA_JS_EMBEDDER_TEST_H_
+
+#include <memory>
+#include <string>
+
+#include "fxjs/cfxjse_value.h"
+#include "fxjs/fxjs_v8.h"
+#include "testing/embedder_test.h"
+
+class CXFA_ScriptContext;
+
+class XFAJSEmbedderTest : public EmbedderTest {
+ public:
+ XFAJSEmbedderTest();
+ ~XFAJSEmbedderTest() override;
+
+ void SetUp() override;
+ void TearDown() override;
+
+ bool OpenDocument(const std::string& filename,
+ const char* password = nullptr,
+ bool must_linearize = false) override;
+
+ v8::Isolate* GetIsolate() const { return isolate_; }
+
+ bool Execute(const CFX_ByteStringC& input);
+ CFXJSE_Value* GetValue() const { return value_.get(); }
+
+ private:
+ std::unique_ptr<FXJS_ArrayBufferAllocator> array_buffer_allocator_;
+ std::unique_ptr<CFXJSE_Value> value_;
+ v8::Isolate* isolate_;
+ CXFA_ScriptContext* script_context_;
+};
+
+#endif // TESTING_XFA_JS_EMBEDDER_TEST_H_
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp
new file mode 100644
index 0000000000..a94e8a9aa2
--- /dev/null
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp
@@ -0,0 +1,39 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/xfa_js_embedder_test.h"
+
+class FM2JSContextEmbedderTest : public XFAJSEmbedderTest {};
+
+TEST_F(FM2JSContextEmbedderTest, TranslateEmpty) {
+ ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
+
+ const char input[] = "";
+ EXPECT_TRUE(Execute(input));
+ // TODO(dsinclair): This should probably throw as a blank formcalc script
+ // is invalid.
+}
+
+TEST_F(FM2JSContextEmbedderTest, TranslateNumber) {
+ ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
+
+ const char input[] = "123";
+ EXPECT_TRUE(Execute(input));
+
+ CFXJSE_Value* value = GetValue();
+ ASSERT_TRUE(value->IsNumber());
+ EXPECT_EQ(123, value->ToInteger());
+}
+
+TEST_F(FM2JSContextEmbedderTest, Add) {
+ ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
+
+ const char input[] = "123 + 456";
+ EXPECT_TRUE(Execute(input));
+
+ CFXJSE_Value* value = GetValue();
+ ASSERT_TRUE(value->IsNumber());
+ EXPECT_EQ(579, value->ToInteger());
+}