summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/embedder_test.cpp54
-rw-r--r--testing/embedder_test.h22
-rw-r--r--testing/xfa_js_embedder_test.cpp19
-rw-r--r--testing/xfa_js_embedder_test.h3
4 files changed, 67 insertions, 31 deletions
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index c39539b3fb..fd53b52fdc 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -100,29 +100,44 @@ bool EmbedderTest::CreateEmptyDocument() {
if (!document_)
return false;
- form_handle_ = SetupFormFillEnvironment(document_);
+ form_handle_ =
+ SetupFormFillEnvironment(document_, JavaScriptOption::kEnableJavaScript);
return true;
}
bool EmbedderTest::OpenDocument(const std::string& filename) {
- return OpenDocumentWithOptions(filename, nullptr, false);
+ return OpenDocumentWithOptions(filename, nullptr,
+ LinearizeOption::kDefaultLinearize,
+ JavaScriptOption::kEnableJavaScript);
}
bool EmbedderTest::OpenDocumentLinearized(const std::string& filename) {
- return OpenDocumentWithOptions(filename, nullptr, true);
+ return OpenDocumentWithOptions(filename, nullptr,
+ LinearizeOption::kMustLinearize,
+ JavaScriptOption::kEnableJavaScript);
}
bool EmbedderTest::OpenDocumentWithPassword(const std::string& filename,
const char* password) {
- return OpenDocumentWithOptions(filename, password, false);
+ return OpenDocumentWithOptions(filename, password,
+ LinearizeOption::kDefaultLinearize,
+ JavaScriptOption::kEnableJavaScript);
+}
+
+bool EmbedderTest::OpenDocumentWithoutJavaScript(const std::string& filename) {
+ return OpenDocumentWithOptions(filename, nullptr,
+ LinearizeOption::kDefaultLinearize,
+ JavaScriptOption::kDisableJavaScript);
}
bool EmbedderTest::OpenDocumentWithOptions(const std::string& filename,
const char* password,
- bool must_linearize) {
+ LinearizeOption linearize_option,
+ JavaScriptOption javascript_option) {
std::string file_path;
if (!PathService::GetTestFilePath(filename, &file_path))
return false;
+
file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
if (!file_contents_)
return false;
@@ -136,12 +151,14 @@ bool EmbedderTest::OpenDocumentWithOptions(const std::string& filename,
file_access_.m_Param = loader_;
fake_file_access_ = pdfium::MakeUnique<FakeFileAccess>(&file_access_);
- return OpenDocumentHelper(password, must_linearize, fake_file_access_.get(),
- &document_, &avail_, &form_handle_);
+ return OpenDocumentHelper(password, linearize_option, javascript_option,
+ fake_file_access_.get(), &document_, &avail_,
+ &form_handle_);
}
bool EmbedderTest::OpenDocumentHelper(const char* password,
- bool must_linearize,
+ LinearizeOption linearize_option,
+ JavaScriptOption javascript_option,
FakeFileAccess* network_simulator,
FPDF_DOCUMENT* document,
FPDF_AVAIL* avail,
@@ -186,7 +203,7 @@ bool EmbedderTest::OpenDocumentHelper(const char* password,
return false;
}
} else {
- if (must_linearize)
+ if (linearize_option == LinearizeOption::kMustLinearize)
return false;
network_simulator->SetWholeFileAvailable();
*document =
@@ -194,17 +211,21 @@ bool EmbedderTest::OpenDocumentHelper(const char* password,
if (!*document)
return false;
}
- *form_handle = SetupFormFillEnvironment(*document);
+ *form_handle = SetupFormFillEnvironment(*document, javascript_option);
+
#ifdef PDF_ENABLE_XFA
int doc_type = FPDF_GetFormType(*document);
if (doc_type == FORMTYPE_XFA_FULL || doc_type == FORMTYPE_XFA_FOREGROUND)
FPDF_LoadXFA(*document);
#endif // PDF_ENABLE_XFA
+
(void)FPDF_GetDocPermissions(*document);
return true;
}
-FPDF_FORMHANDLE EmbedderTest::SetupFormFillEnvironment(FPDF_DOCUMENT doc) {
+FPDF_FORMHANDLE EmbedderTest::SetupFormFillEnvironment(
+ FPDF_DOCUMENT doc,
+ JavaScriptOption javascript_option) {
IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
memset(platform, '\0', sizeof(IPDF_JSPLATFORM));
platform->version = 2;
@@ -221,7 +242,9 @@ FPDF_FORMHANDLE EmbedderTest::SetupFormFillEnvironment(FPDF_DOCUMENT doc) {
formfillinfo->FFI_SetTimer = SetTimerTrampoline;
formfillinfo->FFI_KillTimer = KillTimerTrampoline;
formfillinfo->FFI_GetPage = GetPageTrampoline;
- formfillinfo->m_pJsPlatform = platform;
+ if (javascript_option == JavaScriptOption::kEnableJavaScript)
+ formfillinfo->m_pJsPlatform = platform;
+
FPDF_FORMHANDLE form_handle =
FPDFDOC_InitFormFillEnvironment(doc, formfillinfo);
FPDF_SetFormFieldHighlightColor(form_handle, FPDF_FORMFIELD_UNKNOWN,
@@ -337,9 +360,10 @@ FPDF_DOCUMENT EmbedderTest::OpenSavedDocument(const char* password) {
saved_fake_file_access_ =
pdfium::MakeUnique<FakeFileAccess>(&saved_file_access_);
- EXPECT_TRUE(OpenDocumentHelper(password, false, saved_fake_file_access_.get(),
- &saved_document_, &saved_avail_,
- &saved_form_handle_));
+ EXPECT_TRUE(OpenDocumentHelper(
+ password, LinearizeOption::kDefaultLinearize,
+ JavaScriptOption::kEnableJavaScript, saved_fake_file_access_.get(),
+ &saved_document_, &saved_avail_, &saved_form_handle_));
return saved_document_;
}
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index c1f1844eba..4923180c4a 100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -33,6 +33,9 @@ class EmbedderTest : public ::testing::Test,
public FPDF_FORMFILLINFO,
public FPDF_FILEWRITE {
public:
+ enum class LinearizeOption { kDefaultLinearize, kMustLinearize };
+ enum class JavaScriptOption { kDisableJavaScript, kEnableJavaScript };
+
class Delegate {
public:
virtual ~Delegate() {}
@@ -85,19 +88,22 @@ class EmbedderTest : public ::testing::Test,
bool CreateEmptyDocument();
// Open the document specified by |filename|, and create its form fill
- // environment, or return false on failure.
- // The filename is relative to the test data directory where we store all the
- // test files.
- // |password| can be nullptr if there is none.
+ // environment, or return false on failure. The |filename| is relative to
+ // the test data directory where we store all the test files. |password| can
+ // be nullptr if the file is not password protected. If |javascript_opts|
+ // is kDisableJavascript, then the document will be given stubs in place
+ // of the real JS engine.
virtual bool OpenDocumentWithOptions(const std::string& filename,
const char* password,
- bool must_linearize);
+ LinearizeOption linearize_option,
+ JavaScriptOption javascript_option);
// Variants provided for convenience.
bool OpenDocument(const std::string& filename);
bool OpenDocumentLinearized(const std::string& filename);
bool OpenDocumentWithPassword(const std::string& filename,
const char* password);
+ bool OpenDocumentWithoutJavaScript(const std::string& filename);
// Perform JavaScript actions that are to run at document open time.
void DoOpenActions();
@@ -154,13 +160,15 @@ class EmbedderTest : public ::testing::Test,
using PageNumberToHandleMap = std::map<int, FPDF_PAGE>;
bool OpenDocumentHelper(const char* password,
- bool must_linearize,
+ LinearizeOption linearize_option,
+ JavaScriptOption javascript_option,
FakeFileAccess* network_simulator,
FPDF_DOCUMENT* document,
FPDF_AVAIL* avail,
FPDF_FORMHANDLE* form_handle);
- FPDF_FORMHANDLE SetupFormFillEnvironment(FPDF_DOCUMENT doc);
+ FPDF_FORMHANDLE SetupFormFillEnvironment(FPDF_DOCUMENT doc,
+ JavaScriptOption javascript_option);
// Return the hash of |bitmap|.
static std::string HashBitmap(FPDF_BITMAP bitmap);
diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp
index 0fe4b7a624..995c0ed1d5 100644
--- a/testing/xfa_js_embedder_test.cpp
+++ b/testing/xfa_js_embedder_test.cpp
@@ -47,21 +47,24 @@ CXFA_Document* XFAJSEmbedderTest::GetXFADocument() {
return UnderlyingFromFPDFDocument(document())->GetXFADoc()->GetXFADoc();
}
-bool XFAJSEmbedderTest::OpenDocumentWithOptions(const std::string& filename,
- const char* password,
- bool must_linearize) {
- if (!EmbedderTest::OpenDocumentWithOptions(filename, password,
- must_linearize))
+bool XFAJSEmbedderTest::OpenDocumentWithOptions(
+ const std::string& filename,
+ const char* password,
+ LinearizeOption linearize_option,
+ JavaScriptOption javascript_option) {
+ // JS required for XFA.
+ ASSERT(javascript_option == JavaScriptOption::kEnableJavaScript);
+ if (!EmbedderTest::OpenDocumentWithOptions(
+ filename, password, linearize_option, javascript_option)) {
return false;
-
+ }
script_context_ = GetXFADocument()->GetScriptContext();
return true;
}
bool XFAJSEmbedderTest::Execute(const ByteStringView& input) {
- if (ExecuteHelper(input)) {
+ if (ExecuteHelper(input))
return true;
- }
CFXJSE_Value msg(GetIsolate());
value_->GetObjectPropertyByIdx(1, &msg);
diff --git a/testing/xfa_js_embedder_test.h b/testing/xfa_js_embedder_test.h
index 0ddb02ce70..73487d27c8 100644
--- a/testing/xfa_js_embedder_test.h
+++ b/testing/xfa_js_embedder_test.h
@@ -27,7 +27,8 @@ class XFAJSEmbedderTest : public EmbedderTest {
void TearDown() override;
bool OpenDocumentWithOptions(const std::string& filename,
const char* password,
- bool must_linearize) override;
+ LinearizeOption linearize_option,
+ JavaScriptOption javascript_option) override;
v8::Isolate* GetIsolate() const { return isolate_; }
CXFA_Document* GetXFADocument();