summaryrefslogtreecommitdiff
path: root/testing/xfa_js_embedder_test.h
blob: 44840b31eb2ef76ef5809af68f47b8a3c568fb6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_object.h"

class CFXJSE_Engine;

class XFAJSEmbedderTest : public EmbedderTest {
 public:
  XFAJSEmbedderTest();
  ~XFAJSEmbedderTest() override;

  // EmbedderTest:
  void SetUp() override;
  void TearDown() override;
  bool OpenDocumentWithOptions(const std::string& filename,
                               const char* password,
                               bool must_linearize) override;

  v8::Isolate* GetIsolate() const { return isolate_; }
  CXFA_Document* GetXFADocument();

  bool Execute(const ByteStringView& input);
  bool ExecuteSilenceFailure(const ByteStringView& input);

  CFXJSE_Value* GetValue() const { return value_.get(); }

 private:
  std::unique_ptr<CFX_V8ArrayBufferAllocator> array_buffer_allocator_;
  std::unique_ptr<CFXJSE_Value> value_;
  v8::Isolate* isolate_ = nullptr;
  CFXJSE_Engine* script_context_ = nullptr;

  bool ExecuteHelper(const ByteStringView& input);
};

#endif  // TESTING_XFA_JS_EMBEDDER_TEST_H_