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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLDocumentParserTest.cpp

Issue 2645303002: Use a new Supplement constructor for supplements in core/ (Closed)
Patch Set: temp Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/html/parser/HTMLDocumentParser.h" 5 #include "core/html/parser/HTMLDocumentParser.h"
6 6
7 #include "core/html/HTMLDocument.h" 7 #include "core/html/HTMLDocument.h"
8 #include "core/html/parser/TextResourceDecoder.h" 8 #include "core/html/parser/TextResourceDecoder.h"
9 #include "core/loader/PrerendererClient.h" 9 #include "core/loader/PrerendererClient.h"
10 #include "core/loader/TextResourceDecoderBuilder.h" 10 #include "core/loader/TextResourceDecoderBuilder.h"
11 #include "core/testing/DummyPageHolder.h" 11 #include "core/testing/DummyPageHolder.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include <memory> 13 #include <memory>
14 14
15 namespace blink { 15 namespace blink {
16 16
17 namespace { 17 namespace {
18 18
19 class TestPrerendererClient : public GarbageCollected<TestPrerendererClient>, 19 class TestPrerendererClient : public GarbageCollected<TestPrerendererClient>,
20 public PrerendererClient { 20 public PrerendererClient {
21 USING_GARBAGE_COLLECTED_MIXIN(TestPrerendererClient); 21 USING_GARBAGE_COLLECTED_MIXIN(TestPrerendererClient);
22 22
23 public: 23 public:
24 TestPrerendererClient(bool isPrefetchOnly) 24 TestPrerendererClient(Page& page, bool isPrefetchOnly)
25 : m_isPrefetchOnly(isPrefetchOnly) {} 25 : PrerendererClient(page), m_isPrefetchOnly(isPrefetchOnly) {}
26 26
27 private: 27 private:
28 void willAddPrerender(Prerender*) override{}; 28 void willAddPrerender(Prerender*) override{};
29 bool isPrefetchOnly() override { return m_isPrefetchOnly; } 29 bool isPrefetchOnly() override { return m_isPrefetchOnly; }
30 30
31 bool m_isPrefetchOnly; 31 bool m_isPrefetchOnly;
32 }; 32 };
33 33
34 class HTMLDocumentParserTest : public testing::Test { 34 class HTMLDocumentParserTest : public testing::Test {
35 protected: 35 protected:
(...skipping 11 matching lines...) Expand all
47 return parser; 47 return parser;
48 } 48 }
49 49
50 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 50 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
51 }; 51 };
52 52
53 } // namespace 53 } // namespace
54 54
55 TEST_F(HTMLDocumentParserTest, AppendPrefetch) { 55 TEST_F(HTMLDocumentParserTest, AppendPrefetch) {
56 HTMLDocument& document = toHTMLDocument(m_dummyPageHolder->document()); 56 HTMLDocument& document = toHTMLDocument(m_dummyPageHolder->document());
57 providePrerendererClientTo(*document.page(), new TestPrerendererClient(true)); 57 providePrerendererClientTo(*document.page(),
58 new TestPrerendererClient(*document.page(), true));
58 EXPECT_TRUE(document.isPrefetchOnly()); 59 EXPECT_TRUE(document.isPrefetchOnly());
59 HTMLDocumentParser* parser = createParser(document); 60 HTMLDocumentParser* parser = createParser(document);
60 61
61 const char bytes[] = "<ht"; 62 const char bytes[] = "<ht";
62 parser->appendBytes(bytes, sizeof(bytes)); 63 parser->appendBytes(bytes, sizeof(bytes));
63 // The bytes are forwarded to the preload scanner, not to the tokenizer. 64 // The bytes are forwarded to the preload scanner, not to the tokenizer.
64 HTMLParserScriptRunnerHost* scriptRunnerHost = 65 HTMLParserScriptRunnerHost* scriptRunnerHost =
65 parser->asHTMLParserScriptRunnerHostForTesting(); 66 parser->asHTMLParserScriptRunnerHostForTesting();
66 EXPECT_TRUE(scriptRunnerHost->hasPreloadScanner()); 67 EXPECT_TRUE(scriptRunnerHost->hasPreloadScanner());
67 EXPECT_EQ(HTMLTokenizer::DataState, parser->tokenizer()->getState()); 68 EXPECT_EQ(HTMLTokenizer::DataState, parser->tokenizer()->getState());
68 } 69 }
69 70
70 TEST_F(HTMLDocumentParserTest, AppendNoPrefetch) { 71 TEST_F(HTMLDocumentParserTest, AppendNoPrefetch) {
71 HTMLDocument& document = toHTMLDocument(m_dummyPageHolder->document()); 72 HTMLDocument& document = toHTMLDocument(m_dummyPageHolder->document());
72 EXPECT_FALSE(document.isPrefetchOnly()); 73 EXPECT_FALSE(document.isPrefetchOnly());
73 // Use ForceSynchronousParsing to allow calling append(). 74 // Use ForceSynchronousParsing to allow calling append().
74 HTMLDocumentParser* parser = createParser(document); 75 HTMLDocumentParser* parser = createParser(document);
75 76
76 const char bytes[] = "<ht"; 77 const char bytes[] = "<ht";
77 parser->appendBytes(bytes, sizeof(bytes)); 78 parser->appendBytes(bytes, sizeof(bytes));
78 // The bytes are forwarded to the tokenizer. 79 // The bytes are forwarded to the tokenizer.
79 HTMLParserScriptRunnerHost* scriptRunnerHost = 80 HTMLParserScriptRunnerHost* scriptRunnerHost =
80 parser->asHTMLParserScriptRunnerHostForTesting(); 81 parser->asHTMLParserScriptRunnerHostForTesting();
81 EXPECT_FALSE(scriptRunnerHost->hasPreloadScanner()); 82 EXPECT_FALSE(scriptRunnerHost->hasPreloadScanner());
82 EXPECT_EQ(HTMLTokenizer::TagNameState, parser->tokenizer()->getState()); 83 EXPECT_EQ(HTMLTokenizer::TagNameState, parser->tokenizer()->getState());
83 } 84 }
84 85
85 } // namespace blink 86 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReader.cpp ('k') | third_party/WebKit/Source/core/loader/PrerendererClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698