OLD | NEW |
---|---|
(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/copyless_paste/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 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.
| |
22 "\n" | |
23 "\n" | |
24 "{\"@type\": \"NewsArticle\"," | |
25 "\"headline\": \"Special characters for ya >_<;\"\n" | |
26 "}\n" | |
27 "\n"; | |
28 } | |
29 | |
30 protected: | |
31 void SetUp() override; | |
32 | |
33 void TearDown() override { ThreadState::current()->collectAllGarbage(); } | |
34 | |
35 Document& document() const { return m_dummyPageHolder->document(); } | |
36 | |
37 String extract() { return CopylessPasteExtractor::extract(document()); } | |
38 | |
39 void setHtmlInnerHTML(const String&); | |
40 | |
41 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.
| |
42 | |
43 private: | |
44 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | |
45 }; | |
46 | |
47 void CopylessPasteExtractorTest::SetUp() { | |
48 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
49 } | |
50 | |
51 void CopylessPasteExtractorTest::setHtmlInnerHTML(const String& htmlContent) { | |
52 document().documentElement()->setInnerHTML((htmlContent)); | |
53 } | |
54 | |
55 TEST_F(CopylessPasteExtractorTest, empty) { | |
56 String extracted = extract(); | |
57 String expected = "[]"; | |
58 EXPECT_EQ(expected, extracted); | |
59 } | |
60 | |
61 TEST_F(CopylessPasteExtractorTest, basic) { | |
62 setHtmlInnerHTML( | |
63 "<body>" | |
64 "<script type=\"application/ld+json\">" + | |
65 kContent + | |
66 "</script>" | |
67 "</body>"); | |
68 | |
69 String extracted = extract(); | |
70 String expected = "[" + kContent + "]"; | |
71 EXPECT_EQ(expected, extracted); | |
72 } | |
73 | |
74 TEST_F(CopylessPasteExtractorTest, header) { | |
75 setHtmlInnerHTML( | |
76 "<head>" | |
77 "<script type=\"application/ld+json\">" + | |
78 kContent + | |
79 "</script>" | |
80 "</head>"); | |
81 | |
82 String extracted = extract(); | |
83 String expected = "[" + kContent + "]"; | |
84 EXPECT_EQ(expected, extracted); | |
85 } | |
86 | |
87 TEST_F(CopylessPasteExtractorTest, multiple) { | |
88 setHtmlInnerHTML( | |
89 "<head>" | |
90 "<script type=\"application/ld+json\">" + | |
91 kContent + | |
92 "</script>" | |
93 "</head>" | |
94 "<body>" | |
95 "<script type=\"application/ld+json\">" + | |
96 kContent + | |
97 "</script>" | |
98 "<script type=\"application/ld+json\">" + | |
99 kContent + | |
100 "</script>" | |
101 "</body>"); | |
102 | |
103 String extracted = extract(); | |
104 String expected = "[" + kContent + "," + kContent + "," + kContent + "]"; | |
105 EXPECT_EQ(expected, extracted); | |
106 } | |
107 | |
108 } // namespace | |
109 | |
110 } // namespace blink | |
OLD | NEW |