Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: third_party/WebKit/Source/modules/document_metadata/CopylessPasteExtractorTest.cpp

Issue 2690903005: Metadata extraction for Copyless Paste (Closed)
Patch Set: histogram Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
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 "modules/document_metadata/CopylessPasteExtractor.h"
6
7 #include <memory>
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/testing/DummyPageHolder.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "wtf/text/StringBuilder.h"
13
14 namespace blink {
15
16 namespace {
17
18 class CopylessPasteExtractorTest : public ::testing::Test {
19 public:
20 CopylessPasteExtractorTest()
21 : m_content(
22 "\n"
23 "\n"
24 "{\"@type\": \"NewsArticle\","
25 "\"headline\": \"Special characters for ya >_<;\"\n"
26 "}\n"
27 "\n") {}
28
29 protected:
30 void SetUp() override;
31
32 void TearDown() override { ThreadState::current()->collectAllGarbage(); }
33
34 Document& document() const { return m_dummyPageHolder->document(); }
35
36 String extract() { return CopylessPasteExtractor::extract(document()); }
37
38 void setHtmlInnerHTML(const String&);
39
40 String m_content;
41
42 private:
43 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
44 };
45
46 void CopylessPasteExtractorTest::SetUp() {
47 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
48 }
49
50 void CopylessPasteExtractorTest::setHtmlInnerHTML(const String& htmlContent) {
51 document().documentElement()->setInnerHTML((htmlContent));
52 }
53
54 TEST_F(CopylessPasteExtractorTest, empty) {
55 String extracted = extract();
56 String expected = "[]";
57 EXPECT_EQ(expected, extracted);
58 }
59
60 TEST_F(CopylessPasteExtractorTest, basic) {
61 setHtmlInnerHTML(
62 "<body>"
63 "<script type=\"application/ld+json\">" +
64 m_content +
65 "</script>"
66 "</body>");
67
68 String extracted = extract();
69 String expected = "[" + m_content + "]";
70 EXPECT_EQ(expected, extracted);
71 }
72
73 TEST_F(CopylessPasteExtractorTest, header) {
74 setHtmlInnerHTML(
75 "<head>"
76 "<script type=\"application/ld+json\">" +
77 m_content +
78 "</script>"
79 "</head>");
80
81 String extracted = extract();
82 String expected = "[" + m_content + "]";
83 EXPECT_EQ(expected, extracted);
84 }
85
86 TEST_F(CopylessPasteExtractorTest, multiple) {
87 setHtmlInnerHTML(
88 "<head>"
89 "<script type=\"application/ld+json\">" +
90 m_content +
91 "</script>"
92 "</head>"
93 "<body>"
94 "<script type=\"application/ld+json\">" +
95 m_content +
96 "</script>"
97 "<script type=\"application/ld+json\">" +
98 m_content +
99 "</script>"
100 "</body>");
101
102 String extracted = extract();
103 String expected = "[" + m_content + "," + m_content + "," + m_content + "]";
104 EXPECT_EQ(expected, extracted);
105 }
106
107 } // namespace
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698