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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp

Issue 1587643004: Restrict use of pseudo elements within compound. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@valid-selectors
Patch Set: Workaround for invalid selectors in UA style. Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp b/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
index 8f4f59abf5192f960390a6d0c968b06a4426206d..eda8efffeade6539327ad6e8cc91563fdbd92e02 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSSelectorParserTest.cpp
@@ -70,16 +70,16 @@ TEST(CSSSelectorParserTest, ValidANPlusB)
{"-N - 88", -1, -88},
};
- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) {
- SCOPED_TRACE(testCases[i].input);
+ for (auto testCase : testCases) {
+ SCOPED_TRACE(testCase.input);
std::pair<int, int> ab;
- CSSTokenizer::Scope scope(testCases[i].input);
+ CSSTokenizer::Scope scope(testCase.input);
CSSParserTokenRange range = scope.tokenRange();
bool passed = CSSSelectorParser::consumeANPlusB(range, ab);
EXPECT_TRUE(passed);
- EXPECT_EQ(ab.first, testCases[i].a);
- EXPECT_EQ(ab.second, testCases[i].b);
+ EXPECT_EQ(ab.first, testCase.a);
+ EXPECT_EQ(ab.second, testCase.b);
}
}
@@ -101,11 +101,11 @@ TEST(CSSSelectorParserTest, InvalidANPlusB)
"10n + -5",
};
- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) {
- SCOPED_TRACE(testCases[i]);
+ for (auto testCase : testCases) {
+ SCOPED_TRACE(testCase);
std::pair<int, int> ab;
- CSSTokenizer::Scope scope(testCases[i]);
+ CSSTokenizer::Scope scope(testCase);
CSSParserTokenRange range = scope.tokenRange();
bool passed = CSSSelectorParser::consumeANPlusB(range, ab);
EXPECT_FALSE(passed);
@@ -119,17 +119,14 @@ TEST(CSSSelectorParserTest, ShadowDomPseudoInCompound)
{ ".a::shadow", ".a::shadow" },
{ "::content", "::content" },
{ ".a::content", ".a::content" },
- { "::content.a", "::content.a" },
- { "::content.a.b", "::content.a.b" },
- { ".a::content.b", ".a::content.b" },
};
- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) {
- SCOPED_TRACE(testCases[i][0]);
- CSSTokenizer::Scope scope(testCases[i][0]);
+ for (auto testCase : testCases) {
+ SCOPED_TRACE(testCase[0]);
+ CSSTokenizer::Scope scope(testCase[0]);
CSSParserTokenRange range = scope.tokenRange();
CSSSelectorList list = CSSSelectorParser::parseSelector(range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
- EXPECT_STREQ(testCases[i][1], list.selectorsText().ascii().data());
+ EXPECT_STREQ(testCase[1], list.selectorsText().ascii().data());
}
}
@@ -158,4 +155,58 @@ TEST(CSSSelectorParserTest, PseudoElementsInCompoundLists)
}
}
+TEST(CSSSelectorParserTest, ValidSimpleAfterPseudoElementInCompound)
+{
+ const char* testCases[] = {
+ "::-webkit-volume-slider:hover",
+ "::selection:window-inactive",
+ "::-webkit-scrollbar:disabled",
+ "::-webkit-volume-slider:not(:hover)",
+ "::-webkit-scrollbar:not(:horizontal)"
+ };
+
+ for (auto testCase : testCases) {
+ CSSTokenizer::Scope scope(testCase);
+ CSSParserTokenRange range = scope.tokenRange();
+ CSSSelectorList list = CSSSelectorParser::parseSelector(range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+ EXPECT_TRUE(list.isValid());
+ }
+}
+
+TEST(CSSSelectorParserTest, InvalidSimpleAfterPseudoElementInCompound)
+{
+ const char* testCases[] = {
+ "::before#id",
+ "::after:hover",
+ ".class::content::before",
+ "::shadow.class",
+ "::selection:window-inactive::before",
+ "::-webkit-volume-slider.class",
+ "::content.a",
+ "::content.a.b",
+ ".a::content.b",
+ "::before:not(.a)",
+ "::shadow:not(::after)",
+ "::content:not(#id)",
+ "::-webkit-scrollbar:vertical:not(:first-child)",
+ "video::-webkit-media-text-track-region-container.scrolling"
+ };
+
+ for (auto testCase : testCases) {
+ CSSTokenizer::Scope scope(testCase);
+ CSSParserTokenRange range = scope.tokenRange();
+ CSSSelectorList list = CSSSelectorParser::parseSelector(range, CSSParserContext(HTMLStandardMode, nullptr), nullptr);
+ EXPECT_FALSE(list.isValid());
+ }
+}
+
+TEST(CSSSelectorParserTest, WorkaroundForInvalidCustomPseudoInUAStyle)
+{
+ // See crbug.com/578131
+ CSSTokenizer::Scope scope("video::-webkit-media-text-track-region-container.scrolling");
+ CSSParserTokenRange range = scope.tokenRange();
+ CSSSelectorList list = CSSSelectorParser::parseSelector(range, CSSParserContext(UASheetMode, nullptr), nullptr);
+ EXPECT_TRUE(list.isValid());
+}
+
} // namespace
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSSelectorParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698