diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-05-01 17:02:54 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-01 17:02:54 +0000 |
commit | ba367068887aca9f700289aa1b8c198920ca39a2 (patch) | |
tree | ee04f81558512f9836e5bdb7a06198dd41d15894 /xfa/fxfa/parser/cxfa_document_parser_unittest.cpp | |
parent | 048afc6aba4848d5296affb4335500f960262580 (diff) | |
download | pdfium-ba367068887aca9f700289aa1b8c198920ca39a2.tar.xz |
Fixes XML Instruction handling in CXFA_DocumentParser.
This CL fixes issues with handling XML instructions in CXFA_DocumentParser.
Unittests were added to verify the behaviour.
Change-Id: Iff8d51d0e6d411419473c9b2c32c700d4bbf86f5
Reviewed-on: https://pdfium-review.googlesource.com/31810
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_document_parser_unittest.cpp')
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser_unittest.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp b/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp new file mode 100644 index 0000000000..9f68fc143b --- /dev/null +++ b/xfa/fxfa/parser/cxfa_document_parser_unittest.cpp @@ -0,0 +1,127 @@ +// Copyright 2018 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 "xfa/fxfa/parser/cxfa_document_parser.h" +#include "core/fxcrt/cfx_memorystream.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "xfa/fxfa/parser/cxfa_document.h" + +class CXFA_DocumentParserTest : public testing::Test { + public: + void SetUp() override { + doc_ = pdfium::MakeUnique<CXFA_Document>(nullptr); + parser_ = pdfium::MakeUnique<CXFA_DocumentParser>(doc_.get()); + } + + void TearDown() override { + // Hold the XML tree until we cleanup the document. + std::unique_ptr<CFX_XMLNode> root = parser_->GetXMLRoot(); + parser_ = nullptr; + doc_ = nullptr; + } + + CXFA_Document* GetDoc() const { return doc_.get(); } + CXFA_DocumentParser* GetParser() const { return parser_.get(); } + + private: + std::unique_ptr<CXFA_Document> doc_; + std::unique_ptr<CXFA_DocumentParser> parser_; +}; + +TEST_F(CXFA_DocumentParserTest, XMLInstructionScriptOff) { + const char* input = + "<config>\n" + "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 " + "v2.7-scripting:0 ?>\n" + "</config>"; + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); + + auto stream = pdfium::MakeRetain<CFX_MemoryStream>( + reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), + false); + ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); + + CXFA_Node* root = GetParser()->GetRootNode(); + ASSERT_TRUE(root != nullptr); + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); +} + +TEST_F(CXFA_DocumentParserTest, XMLInstructionsScriptOn) { + const char* input = + "<config>\n" + "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 " + "v2.7-scripting:1 ?>\n" + "</config>"; + + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); + + auto stream = pdfium::MakeRetain<CFX_MemoryStream>( + reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), + false); + ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); + + CXFA_Node* root = GetParser()->GetRootNode(); + ASSERT_TRUE(root != nullptr); + EXPECT_TRUE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); +} + +TEST_F(CXFA_DocumentParserTest, XMLInstructionsStrictScope) { + const char* input = + "<config>" + "<?acrobat JavaScript strictScoping ?>\n" + "</config>"; + + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); + + auto stream = pdfium::MakeRetain<CFX_MemoryStream>( + reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), + false); + ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); + + CXFA_Node* root = GetParser()->GetRootNode(); + ASSERT_TRUE(root != nullptr); + EXPECT_TRUE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); +} + +TEST_F(CXFA_DocumentParserTest, XMLInstructionsStrictScopeBad) { + const char* input = + "<config>" + "<?acrobat JavaScript otherScoping ?>\n" + "</config>"; + + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); + + auto stream = pdfium::MakeRetain<CFX_MemoryStream>( + reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), + false); + ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); + + CXFA_Node* root = GetParser()->GetRootNode(); + ASSERT_TRUE(root != nullptr); + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); +} + +TEST_F(CXFA_DocumentParserTest, MultipleXMLInstructions) { + const char* input = + "<config>" + "<?originalXFAVersion http://www.xfa.org/schema/xfa-template/2.7 " + "v2.7-scripting:1 ?>\n" + "<?acrobat JavaScript strictScoping ?>\n" + "</config>"; + + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); + EXPECT_FALSE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); + + auto stream = pdfium::MakeRetain<CFX_MemoryStream>( + reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input), + false); + ASSERT_TRUE(GetParser()->Parse(stream, XFA_PacketType::Config)); + + CXFA_Node* root = GetParser()->GetRootNode(); + ASSERT_TRUE(root != nullptr); + + EXPECT_TRUE(GetDoc()->HasFlag(XFA_DOCFLAG_Scripting)); + EXPECT_TRUE(GetDoc()->HasFlag(XFA_DOCFLAG_StrictScoping)); +} |