Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
xfa_js_embedder_test.cpp
Go to the documentation of this file.
1
// Copyright 2017 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#
include
"testing/xfa_js_embedder_test.h"
6
7
#
include
<
memory
>
8
#
include
<
string
>
9
10
#
include
"core/fxcrt/check_op.h"
11
#
include
"fpdfsdk/cpdfsdk_helpers.h"
12
#
include
"fpdfsdk/fpdfxfa/cpdfxfa_context.h"
13
#
include
"fxjs/fxv8.h"
14
#
include
"fxjs/xfa/cfxjse_engine.h"
15
#
include
"fxjs/xfa/cfxjse_isolatetracker.h"
16
#
include
"fxjs/xfa/cfxjse_value.h"
17
#
include
"testing/gtest/include/gtest/gtest.h"
18
#
include
"v8/include/v8-container.h"
19
#
include
"v8/include/v8-local-handle.h"
20
#
include
"v8/include/v8-value.h"
21
22
XFAJSEmbedderTest
::
XFAJSEmbedderTest
() =
default
;
23
24
XFAJSEmbedderTest
::~
XFAJSEmbedderTest
() =
default
;
25
26
void
XFAJSEmbedderTest
::
SetUp
() {
27
JSEmbedderTest
::
SetUp
();
28
}
29
30
void
XFAJSEmbedderTest
::
TearDown
() {
31
value_.Reset();
32
script_context_ =
nullptr
;
33
34
JSEmbedderTest
::
TearDown
();
35
}
36
37
CXFA_Document*
XFAJSEmbedderTest
::
GetXFADocument
()
const
{
38
auto
* pDoc = CPDFDocumentFromFPDFDocument(
document
());
39
if
(!pDoc)
40
return
nullptr
;
41
42
auto
* pContext =
static_cast
<CPDFXFA_Context*>(pDoc->GetExtension());
43
if
(!pContext)
44
return
nullptr
;
45
46
CXFA_FFDoc
* pFFDoc = pContext->GetXFADoc();
47
if
(!pFFDoc)
48
return
nullptr
;
49
50
return
pFFDoc
->
GetXFADoc
(
)
;
51
}
52
53
v8
::
Local
<
v8
::
Value
>
XFAJSEmbedderTest
::
GetValue
()
const
{
54
return
v8::Local<v8::Value>::New(isolate(), value_);
55
}
56
57
bool
XFAJSEmbedderTest
::
OpenDocumentWithOptions
(
58
const
std
::string& filename,
59
const
char
* password,
60
LinearizeOption
linearize_option,
61
JavaScriptOption
javascript_option) {
62
// JS required for XFA.
63
DCHECK_EQ
(javascript_option,
JavaScriptOption
::
kEnableJavaScript
);
64
if
(!
EmbedderTest
::OpenDocumentWithOptions(
65
filename, password, linearize_option, javascript_option)) {
66
return
false
;
67
}
68
CXFA_Document* pDoc =
GetXFADocument
(
)
;
69
if
(!pDoc)
70
return
false
;
71
72
script_context_ = pDoc
->
GetScriptContext
(
)
;
73
return
true
;
74
}
75
76
bool
XFAJSEmbedderTest
::
Execute
(
ByteStringView
input) {
77
CFXJSE_ScopeUtil_IsolateHandleContext
scope
(
78
script_context_
->
GetJseContextForTest
(
)
)
;
79
if
(ExecuteHelper(input))
80
return
true
;
81
82
fprintf(stderr,
"FormCalc: %.*s\n"
,
static_cast
<
int
>(input.GetLength()),
83
input.unterminated_c_str());
84
85
v8::Local<v8::Value> result = GetValue();
86
if
(!
fxv8
::
IsArray
(result))
87
return
false
;
88
89
v8::Local<v8::Value> msg = fxv8::ReentrantGetArrayElementHelper(
90
isolate(), result.As<v8::Array>(), 1);
91
if
(!
fxv8
::
IsString
(msg))
92
return
false
;
93
94
WideString
str = fxv8::ReentrantToWideStringHelper(
isolate
(), msg);
95
if
(!str.IsEmpty())
96
fprintf(stderr,
"JS ERROR: %ls\n"
, str.c_str());
97
return
false
;
98
}
99
100
bool
XFAJSEmbedderTest
::
ExecuteSilenceFailure
(
ByteStringView
input) {
101
CFXJSE_ScopeUtil_IsolateHandleContext
scope
(
102
script_context_
->
GetJseContextForTest
(
)
)
;
103
return
ExecuteHelper(input);
104
}
105
106
bool
XFAJSEmbedderTest
::ExecuteHelper(
ByteStringView
input) {
107
CFXJSE_Context
::
ExecutionResult
exec_result = script_context_
->
RunScript
(
108
CXFA_Script
::
Type
::
Formcalc
,
WideString
::
FromUTF8
(
input
)
.AsStringView()
,
109
GetXFADocument
(
)
->
GetRoot
(
)
)
;
110
value_.Reset(isolate(), exec_result.value->GetValue(isolate()));
111
return
exec_result
.
status
;
112
}
DCHECK_EQ
#define DCHECK_EQ(x, y)
Definition
check_op.h:17
CFXJSE_Context
Definition
cfxjse_context.h:25
CFXJSE_Engine::GetJseContextForTest
CFXJSE_Context * GetJseContextForTest() const
Definition
cfxjse_engine.h:168
CFXJSE_Engine::RunScript
CFXJSE_Context::ExecutionResult RunScript(CXFA_Script::Type eScriptType, WideStringView wsScript, CXFA_Object *pThisObject)
Definition
cfxjse_engine.cpp:166
CFXJSE_ScopeUtil_IsolateHandleContext
Definition
cfxjse_isolatetracker.h:45
CFXJSE_ScopeUtil_IsolateHandleContext::CFXJSE_ScopeUtil_IsolateHandleContext
CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context *pContext)
Definition
cfxjse_isolatetracker.cpp:23
CXFA_Document::GetScriptContext
CFXJSE_Engine * GetScriptContext() const
Definition
cxfa_document.cpp:1459
CXFA_Document::GetRoot
CXFA_Node * GetRoot() const
Definition
cxfa_document.h:110
CXFA_FFDoc
Definition
cxfa_ffdoc.h:55
CXFA_FFDoc::GetXFADoc
CXFA_Document * GetXFADoc() const
Definition
cxfa_ffdoc.h:167
CXFA_Script::Type
Type
Definition
cxfa_script.h:15
CXFA_Script::Type::Formcalc
@ Formcalc
Definition
cxfa_script.h:16
EmbedderTest
Definition
embedder_test.h:40
EmbedderTest::LinearizeOption
LinearizeOption
Definition
embedder_test.h:42
EmbedderTest::SetUp
void SetUp() override
Definition
embedder_test.cpp:276
EmbedderTest::JavaScriptOption
JavaScriptOption
Definition
embedder_test.h:43
EmbedderTest::JavaScriptOption::kEnableJavaScript
@ kEnableJavaScript
Definition
embedder_test.h:43
EmbedderTest::TearDown
void TearDown() override
Definition
embedder_test.cpp:284
EmbedderTest::document
FPDF_DOCUMENT document() const
Definition
embedder_test.h:126
JSEmbedderTest
Definition
js_embedder_test.h:14
JSEmbedderTest::isolate
v8::Isolate * isolate() const
Definition
js_embedder_test.cpp:13
XFAJSEmbedderTest
Definition
xfa_js_embedder_test.h:19
XFAJSEmbedderTest::GetValue
v8::Local< v8::Value > GetValue() const
Definition
xfa_js_embedder_test.cpp:53
XFAJSEmbedderTest::GetXFADocument
CXFA_Document * GetXFADocument() const
Definition
xfa_js_embedder_test.cpp:37
XFAJSEmbedderTest::Execute
bool Execute(ByteStringView input)
Definition
xfa_js_embedder_test.cpp:76
XFAJSEmbedderTest::OpenDocumentWithOptions
bool OpenDocumentWithOptions(const std::string &filename, const char *password, LinearizeOption linearize_option, JavaScriptOption javascript_option) override
Definition
xfa_js_embedder_test.cpp:57
XFAJSEmbedderTest::TearDown
void TearDown() override
Definition
xfa_js_embedder_test.cpp:30
XFAJSEmbedderTest::SetUp
void SetUp() override
Definition
xfa_js_embedder_test.cpp:26
XFAJSEmbedderTest::~XFAJSEmbedderTest
~XFAJSEmbedderTest() override
XFAJSEmbedderTest::ExecuteSilenceFailure
bool ExecuteSilenceFailure(ByteStringView input)
Definition
xfa_js_embedder_test.cpp:100
XFAJSEmbedderTest::XFAJSEmbedderTest
XFAJSEmbedderTest()
fxcrt::WideString::FromUTF8
static WideString FromUTF8(ByteStringView str)
Definition
widestring.cpp:738
fxv8
Definition
fxv8.h:22
fxv8::IsArray
bool IsArray(v8::Local< v8::Value > value)
Definition
fxv8.cpp:48
fxv8::IsString
bool IsString(v8::Local< v8::Value > value)
Definition
fxv8.cpp:32
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
ByteStringView
fxcrt::ByteStringView ByteStringView
Definition
string_view_template.h:325
CFXJSE_Context::ExecutionResult
Definition
cfxjse_context.h:27
CFXJSE_Context::ExecutionResult::status
bool status
Definition
cfxjse_context.h:34
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
testing
xfa_js_embedder_test.cpp
Generated on
for Qt by
1.18.0