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

Unified Diff: Source/core/css/parser/MediaQueryTokenizerTest.cpp

Issue 225293006: Moved MQ parsing block tracking to tokenizer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Debug build fix Created 6 years, 8 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
Index: Source/core/css/parser/MediaQueryTokenizerTest.cpp
diff --git a/Source/core/css/parser/MediaQueryTokenizerTest.cpp b/Source/core/css/parser/MediaQueryTokenizerTest.cpp
index 0f9a5ee75e96defa7a039d760f0b6bb80b8de376..3e1568b8559450a42a098c20fe198300727e5779 100644
--- a/Source/core/css/parser/MediaQueryTokenizerTest.cpp
+++ b/Source/core/css/parser/MediaQueryTokenizerTest.cpp
@@ -15,6 +15,11 @@ typedef struct {
const char* output;
} TestCase;
+typedef struct {
+ const char* input;
+ const unsigned maxLevel;
+} BlockTestCase;
+
TEST(MediaQueryTokenizerTest, Basic)
{
TestCase testCases[] = {
@@ -51,6 +56,56 @@ TEST(MediaQueryTokenizerTest, Basic)
}
}
+TEST(MediaQueryTokenizerBlockTest, Basic)
+{
+ BlockTestCase testCases[] = {
+ {"(max-width: 800px()), (max-width: 800px)", 2},
+ {"(max-width: 900px(()), (max-width: 900px)", 3},
+ {"(max-width: 600px(())))), (max-width: 600px)", 3},
+ {"(max-width: 500px(((((((((())))), (max-width: 500px)", 11},
+ {"(max-width: 800px[]), (max-width: 800px)", 2},
+ {"(max-width: 900px[[]), (max-width: 900px)", 3},
+ {"(max-width: 600px[[]]]]), (max-width: 600px)", 3},
+ {"(max-width: 500px[[[[[[[[[[]]]]), (max-width: 500px)", 11},
+ {"(max-width: 800px{}), (max-width: 800px)", 2},
+ {"(max-width: 900px{{}), (max-width: 900px)", 3},
+ {"(max-width: 600px{{}}}}), (max-width: 600px)", 3},
+ {"(max-width: 500px{{{{{{{{{{}}}}), (max-width: 500px)", 11},
+ {"[(), (max-width: 400px)", 2},
+ {"[{}, (max-width: 500px)", 2},
+ {"[{]}], (max-width: 900px)", 2},
+ {"[{[]{}{{{}}}}], (max-width: 900px)", 5},
+ {"[{[}], (max-width: 900px)", 3},
+ {"[({)}], (max-width: 900px)", 3},
+ {"[]((), (max-width: 900px)", 2},
+ {"((), (max-width: 900px)", 2},
+ {"(foo(), (max-width: 900px)", 2},
+ {"[](()), (max-width: 900px)", 2},
+ {"all an[isdfs bla())(i())]icalc(i)(()), (max-width: 400px)", 3},
+ {"all an[isdfs bla())(]icalc(i)(()), (max-width: 500px)", 4},
+ {"all an[isdfs bla())(]icalc(i)(())), (max-width: 600px)", 4},
+ {"all an[isdfs bla())(]icalc(i)(()))], (max-width: 800px)", 4},
+ {0, 0} // Do not remove the terminator line.
+ };
+ for (int i = 0; testCases[i].input; ++i) {
+ Vector<MediaQueryToken> tokens;
+ MediaQueryTokenizer::tokenize(testCases[i].input, tokens);
+
+ unsigned maxLevel = 0;
+ unsigned level = 0;
+ for (size_t j = 0; j < tokens.size(); ++j) {
+ if (tokens[j].blockToken() == MediaQueryToken::BlockStart)
+ ++level;
+ else if (tokens[j].blockToken() == MediaQueryToken::BlockEnd)
+ --level;
+
+ ASSERT_GE(level, (unsigned)0);
+ maxLevel = std::max(level, maxLevel);
+ }
+ ASSERT_EQ(testCases[i].maxLevel, maxLevel);
+ }
+}
+
void testToken(UChar c, MediaQueryTokenType tokenType)
{
Vector<MediaQueryToken> tokens;
« Source/core/css/parser/MediaQueryToken.h ('K') | « Source/core/css/parser/MediaQueryTokenizer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698