Chromium Code Reviews| Index: third_party/WebKit/Source/modules/copyless_paste/CopylessPasteExtractorTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/copyless_paste/CopylessPasteExtractorTest.cpp b/third_party/WebKit/Source/modules/copyless_paste/CopylessPasteExtractorTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e6ab3fccadcd88c99f9a95bc3cd2fab762319963 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/copyless_paste/CopylessPasteExtractorTest.cpp |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2017 The Chromium 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 "modules/copyless_paste/CopylessPasteExtractor.h" |
| + |
| +#include <memory> |
| +#include "core/dom/Document.h" |
| +#include "core/dom/Element.h" |
| +#include "core/testing/DummyPageHolder.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "wtf/text/StringBuilder.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +class CopylessPasteExtractorTest : public ::testing::Test { |
| + public: |
| + CopylessPasteExtractorTest() { |
| + kContent = |
|
dcheng
2017/02/14 19:32:54
Nit: put this in the initializers section of the c
wychen
2017/02/14 22:45:49
Done.
|
| + "\n" |
| + "\n" |
| + "{\"@type\": \"NewsArticle\"," |
| + "\"headline\": \"Special characters for ya >_<;\"\n" |
| + "}\n" |
| + "\n"; |
| + } |
| + |
| + protected: |
| + void SetUp() override; |
| + |
| + void TearDown() override { ThreadState::current()->collectAllGarbage(); } |
| + |
| + Document& document() const { return m_dummyPageHolder->document(); } |
| + |
| + String extract() { return CopylessPasteExtractor::extract(document()); } |
| + |
| + void setHtmlInnerHTML(const String&); |
| + |
| + String kContent; |
|
dcheng
2017/02/14 19:32:54
This isn't /really/ a constant, so it shouldn't be
wychen
2017/02/14 22:45:49
Done.
|
| + |
| + private: |
| + std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| +}; |
| + |
| +void CopylessPasteExtractorTest::SetUp() { |
| + m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| +} |
| + |
| +void CopylessPasteExtractorTest::setHtmlInnerHTML(const String& htmlContent) { |
| + document().documentElement()->setInnerHTML((htmlContent)); |
| +} |
| + |
| +TEST_F(CopylessPasteExtractorTest, empty) { |
| + String extracted = extract(); |
| + String expected = "[]"; |
| + EXPECT_EQ(expected, extracted); |
| +} |
| + |
| +TEST_F(CopylessPasteExtractorTest, basic) { |
| + setHtmlInnerHTML( |
| + "<body>" |
| + "<script type=\"application/ld+json\">" + |
| + kContent + |
| + "</script>" |
| + "</body>"); |
| + |
| + String extracted = extract(); |
| + String expected = "[" + kContent + "]"; |
| + EXPECT_EQ(expected, extracted); |
| +} |
| + |
| +TEST_F(CopylessPasteExtractorTest, header) { |
| + setHtmlInnerHTML( |
| + "<head>" |
| + "<script type=\"application/ld+json\">" + |
| + kContent + |
| + "</script>" |
| + "</head>"); |
| + |
| + String extracted = extract(); |
| + String expected = "[" + kContent + "]"; |
| + EXPECT_EQ(expected, extracted); |
| +} |
| + |
| +TEST_F(CopylessPasteExtractorTest, multiple) { |
| + setHtmlInnerHTML( |
| + "<head>" |
| + "<script type=\"application/ld+json\">" + |
| + kContent + |
| + "</script>" |
| + "</head>" |
| + "<body>" |
| + "<script type=\"application/ld+json\">" + |
| + kContent + |
| + "</script>" |
| + "<script type=\"application/ld+json\">" + |
| + kContent + |
| + "</script>" |
| + "</body>"); |
| + |
| + String extracted = extract(); |
| + String expected = "[" + kContent + "," + kContent + "," + kContent + "]"; |
| + EXPECT_EQ(expected, extracted); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace blink |