From 0784c7317e3aaa2c65d098cf2593b6b49986307d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 23 Apr 2018 18:02:57 +0000 Subject: Disable JavaScript entirely if no JSPlatform passed by embedder. Allows run-time selection of whether to permit JS inside PDF. Previously, this was a link-time decision only. This requires a little more caution before we decide that we have the CJS_Runtime, and not the CJS_RuntimeStub in a few casts. Adds a kDisableJavaScript option to the form fill embeddertests. Adds a --disable-javascript flag to the pdfium_test executable. Also adds a --disable-xfa flag while we're at it. Change-Id: I8d8ac95f6474459cadba9a60572fbb342e984646 Reviewed-on: https://pdfium-review.googlesource.com/31090 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- testing/embedder_test.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'testing/embedder_test.h') 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; 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); -- cgit v1.2.3