summaryrefslogtreecommitdiff
path: root/testing/xfa_js_embedder_test.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-05-18 14:11:29 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-05-18 18:24:51 +0000
commit14aacd5825bcbeca10326f52612bbc2fdb298485 (patch)
tree7b6c2a43e6bddb6b13e938299d5c6ac7a81b4b46 /testing/xfa_js_embedder_test.cpp
parentf0a404d41fcc72f59b528002ef9b2d6011992bc8 (diff)
downloadpdfium-14aacd5825bcbeca10326f52612bbc2fdb298485.tar.xz
Adding fm2js embedder tests
This Cl adds the basis of the test framework to execute the javascript produced by CXFA_FM2JSContext and verify the results are correct. Change-Id: Ie46625b7e27ca0808e9cc41fdc00b7c0a212837d Reviewed-on: https://pdfium-review.googlesource.com/5651 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'testing/xfa_js_embedder_test.cpp')
-rw-r--r--testing/xfa_js_embedder_test.cpp69
1 files changed, 69 insertions, 0 deletions
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;
+}