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

Side by Side Diff: third_party/WebKit/Source/core/dom/SelectorQueryTest.cpp

Issue 2616093003: Make CSSParserContext be garbage collected. (Closed)
Patch Set: fix fuzzer compile again 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/dom/SelectorQuery.h" 5 #include "core/dom/SelectorQuery.h"
6 6
7 #include "core/css/parser/CSSParser.h" 7 #include "core/css/parser/CSSParser.h"
8 #include "core/css/parser/CSSParserContext.h" 8 #include "core/css/parser/CSSParserContext.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/html/HTMLDocument.h" 10 #include "core/html/HTMLDocument.h"
11 #include "core/html/HTMLHtmlElement.h" 11 #include "core/html/HTMLHtmlElement.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 TEST(SelectorQueryTest, NotMatchingPseudoElement) { 17 TEST(SelectorQueryTest, NotMatchingPseudoElement) {
18 Document* document = Document::create(); 18 Document* document = Document::create();
19 HTMLHtmlElement* html = HTMLHtmlElement::create(*document); 19 HTMLHtmlElement* html = HTMLHtmlElement::create(*document);
20 document->appendChild(html); 20 document->appendChild(html);
21 document->documentElement()->setInnerHTML( 21 document->documentElement()->setInnerHTML(
22 "<body><style>span::before { content: 'X' }</style><span></span></body>"); 22 "<body><style>span::before { content: 'X' }</style><span></span></body>");
23 23
24 CSSSelectorList selectorList = CSSParser::parseSelector( 24 CSSSelectorList selectorList = CSSParser::parseSelector(
25 CSSParserContext(*document, nullptr, KURL(), emptyString(), 25 CSSParserContext::create(*document, KURL(), emptyString(),
26 CSSParserContext::StaticProfile), 26 CSSParserContext::StaticProfile),
27 nullptr, "span::before"); 27 nullptr, "span::before");
28 std::unique_ptr<SelectorQuery> query = 28 std::unique_ptr<SelectorQuery> query =
29 SelectorQuery::adopt(std::move(selectorList)); 29 SelectorQuery::adopt(std::move(selectorList));
30 Element* elm = query->queryFirst(*document); 30 Element* elm = query->queryFirst(*document);
31 EXPECT_EQ(nullptr, elm); 31 EXPECT_EQ(nullptr, elm);
32 32
33 selectorList = CSSParser::parseSelector( 33 selectorList = CSSParser::parseSelector(
34 CSSParserContext(*document, nullptr, KURL(), emptyString(), 34 CSSParserContext::create(*document, KURL(), emptyString(),
35 CSSParserContext::StaticProfile), 35 CSSParserContext::StaticProfile),
36 nullptr, "span"); 36 nullptr, "span");
37 query = SelectorQuery::adopt(std::move(selectorList)); 37 query = SelectorQuery::adopt(std::move(selectorList));
38 elm = query->queryFirst(*document); 38 elm = query->queryFirst(*document);
39 EXPECT_NE(nullptr, elm); 39 EXPECT_NE(nullptr, elm);
40 } 40 }
41 41
42 TEST(SelectorQueryTest, LastOfTypeNotFinishedParsing) { 42 TEST(SelectorQueryTest, LastOfTypeNotFinishedParsing) {
43 Document* document = HTMLDocument::create(); 43 Document* document = HTMLDocument::create();
44 HTMLHtmlElement* html = HTMLHtmlElement::create(*document); 44 HTMLHtmlElement* html = HTMLHtmlElement::create(*document);
45 document->appendChild(html); 45 document->appendChild(html);
46 document->documentElement()->setInnerHTML( 46 document->documentElement()->setInnerHTML(
47 "<body><p></p><p id=last></p></body>", ASSERT_NO_EXCEPTION); 47 "<body><p></p><p id=last></p></body>", ASSERT_NO_EXCEPTION);
48 48
49 document->body()->beginParsingChildren(); 49 document->body()->beginParsingChildren();
50 50
51 CSSSelectorList selectorList = CSSParser::parseSelector( 51 CSSSelectorList selectorList = CSSParser::parseSelector(
52 CSSParserContext(*document, nullptr, KURL(), emptyString(), 52 CSSParserContext::create(*document, KURL(), emptyString(),
53 CSSParserContext::StaticProfile), 53 CSSParserContext::StaticProfile),
54 nullptr, "p:last-of-type"); 54 nullptr, "p:last-of-type");
55 std::unique_ptr<SelectorQuery> query = 55 std::unique_ptr<SelectorQuery> query =
56 SelectorQuery::adopt(std::move(selectorList)); 56 SelectorQuery::adopt(std::move(selectorList));
57 Element* elm = query->queryFirst(*document); 57 Element* elm = query->queryFirst(*document);
58 ASSERT_TRUE(elm); 58 ASSERT_TRUE(elm);
59 EXPECT_EQ("last", elm->idForStyleResolution()); 59 EXPECT_EQ("last", elm->idForStyleResolution());
60 } 60 }
61 61
62 } // namespace blink 62 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.cpp ('k') | third_party/WebKit/Source/core/dom/StyleEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698