OLD | NEW |
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/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/html/HTMLDocument.h" | 9 #include "core/html/HTMLDocument.h" |
10 #include "core/html/HTMLHtmlElement.h" | 10 #include "core/html/HTMLHtmlElement.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 CSSSelectorList selectorList = CSSParser::parseSelector( | 23 CSSSelectorList selectorList = CSSParser::parseSelector( |
24 CSSParserContext(*document, nullptr, KURL(), emptyString(), | 24 CSSParserContext(*document, nullptr, KURL(), emptyString(), |
25 CSSParserContext::StaticProfile), | 25 CSSParserContext::StaticProfile), |
26 nullptr, "span::before"); | 26 nullptr, "span::before"); |
27 std::unique_ptr<SelectorQuery> query = | 27 std::unique_ptr<SelectorQuery> query = |
28 SelectorQuery::adopt(std::move(selectorList)); | 28 SelectorQuery::adopt(std::move(selectorList)); |
29 Element* elm = query->queryFirst(*document); | 29 Element* elm = query->queryFirst(*document); |
30 EXPECT_EQ(nullptr, elm); | 30 EXPECT_EQ(nullptr, elm); |
31 | 31 |
32 selectorList = CSSParser::parseSelector(CSSParserContext(*document, nullptr), | 32 selectorList = CSSParser::parseSelector( |
33 nullptr, "span"); | 33 CSSParserContext(*document, nullptr, KURL(), emptyString(), |
| 34 CSSParserContext::StaticProfile), |
| 35 nullptr, "span"); |
34 query = SelectorQuery::adopt(std::move(selectorList)); | 36 query = SelectorQuery::adopt(std::move(selectorList)); |
35 elm = query->queryFirst(*document); | 37 elm = query->queryFirst(*document); |
36 EXPECT_NE(nullptr, elm); | 38 EXPECT_NE(nullptr, elm); |
37 } | 39 } |
38 | 40 |
39 TEST(SelectorQueryTest, LastOfTypeNotFinishedParsing) { | 41 TEST(SelectorQueryTest, LastOfTypeNotFinishedParsing) { |
40 Document* document = HTMLDocument::create(); | 42 Document* document = HTMLDocument::create(); |
41 HTMLHtmlElement* html = HTMLHtmlElement::create(*document); | 43 HTMLHtmlElement* html = HTMLHtmlElement::create(*document); |
42 document->appendChild(html); | 44 document->appendChild(html); |
43 document->documentElement()->setInnerHTML( | 45 document->documentElement()->setInnerHTML( |
44 "<body><p></p><p id=last></p></body>", ASSERT_NO_EXCEPTION); | 46 "<body><p></p><p id=last></p></body>", ASSERT_NO_EXCEPTION); |
45 | 47 |
46 document->body()->beginParsingChildren(); | 48 document->body()->beginParsingChildren(); |
47 | 49 |
48 CSSSelectorList selectorList = CSSParser::parseSelector( | 50 CSSSelectorList selectorList = CSSParser::parseSelector( |
49 CSSParserContext(*document, nullptr), nullptr, "p:last-of-type"); | 51 CSSParserContext(*document, nullptr, KURL(), emptyString(), |
| 52 CSSParserContext::StaticProfile), |
| 53 nullptr, "p:last-of-type"); |
50 std::unique_ptr<SelectorQuery> query = | 54 std::unique_ptr<SelectorQuery> query = |
51 SelectorQuery::adopt(std::move(selectorList)); | 55 SelectorQuery::adopt(std::move(selectorList)); |
52 Element* elm = query->queryFirst(*document); | 56 Element* elm = query->queryFirst(*document); |
53 ASSERT_TRUE(elm); | 57 ASSERT_TRUE(elm); |
54 EXPECT_EQ("last", elm->idForStyleResolution()); | 58 EXPECT_EQ("last", elm->idForStyleResolution()); |
55 } | 59 } |
56 | 60 |
57 } // namespace blink | 61 } // namespace blink |
OLD | NEW |