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

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: Removed unused member var 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
« no previous file with comments | « Source/core/css/parser/MediaQueryTokenizer.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..bce34bebf50d6bb2872cdecd34b32df90a4fbbdd 100644
--- a/Source/core/css/parser/MediaQueryTokenizerTest.cpp
+++ b/Source/core/css/parser/MediaQueryTokenizerTest.cpp
@@ -5,6 +5,7 @@
#include "config.h"
#include "core/css/parser/MediaQueryTokenizer.h"
+#include "core/css/parser/MediaQueryBlockWatcher.h"
#include "wtf/PassOwnPtr.h"
#include <gtest/gtest.h>
@@ -15,6 +16,12 @@ typedef struct {
const char* output;
} TestCase;
+typedef struct {
+ const char* input;
+ const unsigned maxLevel;
+ const unsigned finalLevel;
+} BlockTestCase;
+
TEST(MediaQueryTokenizerTest, Basic)
{
TestCase testCases[] = {
@@ -51,6 +58,54 @@ TEST(MediaQueryTokenizerTest, Basic)
}
}
+TEST(MediaQueryTokenizerBlockTest, Basic)
+{
+ BlockTestCase testCases[] = {
+ {"(max-width: 800px()), (max-width: 800px)", 2, 0},
+ {"(max-width: 900px(()), (max-width: 900px)", 3, 1},
+ {"(max-width: 600px(())))), (max-width: 600px)", 3, 0},
+ {"(max-width: 500px(((((((((())))), (max-width: 500px)", 11, 6},
+ {"(max-width: 800px[]), (max-width: 800px)", 2, 0},
+ {"(max-width: 900px[[]), (max-width: 900px)", 3, 2},
+ {"(max-width: 600px[[]]]]), (max-width: 600px)", 3, 0},
+ {"(max-width: 500px[[[[[[[[[[]]]]), (max-width: 500px)", 11, 7},
+ {"(max-width: 800px{}), (max-width: 800px)", 2, 0},
+ {"(max-width: 900px{{}), (max-width: 900px)", 3, 2},
+ {"(max-width: 600px{{}}}}), (max-width: 600px)", 3, 0},
+ {"(max-width: 500px{{{{{{{{{{}}}}), (max-width: 500px)", 11, 7},
+ {"[(), (max-width: 400px)", 2, 1},
+ {"[{}, (max-width: 500px)", 2, 1},
+ {"[{]}], (max-width: 900px)", 2, 0},
+ {"[{[]{}{{{}}}}], (max-width: 900px)", 5, 0},
+ {"[{[}], (max-width: 900px)", 3, 2},
+ {"[({)}], (max-width: 900px)", 3, 2},
+ {"[]((), (max-width: 900px)", 2, 1},
+ {"((), (max-width: 900px)", 2, 1},
+ {"(foo(), (max-width: 900px)", 2, 1},
+ {"[](()), (max-width: 900px)", 2, 0},
+ {"all an[isdfs bla())(i())]icalc(i)(()), (max-width: 400px)", 3, 0},
+ {"all an[isdfs bla())(]icalc(i)(()), (max-width: 500px)", 4, 2},
+ {"all an[isdfs bla())(]icalc(i)(())), (max-width: 600px)", 4, 1},
+ {"all an[isdfs bla())(]icalc(i)(()))], (max-width: 800px)", 4, 0},
+ {0, 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);
+ MediaQueryBlockWatcher blockWatcher;
+
+ unsigned maxLevel = 0;
+ unsigned level = 0;
+ for (size_t j = 0; j < tokens.size(); ++j) {
+ blockWatcher.handleToken(tokens[j]);
+ level = blockWatcher.blockLevel();
+ maxLevel = std::max(level, maxLevel);
+ }
+ ASSERT_EQ(testCases[i].maxLevel, maxLevel);
+ ASSERT_EQ(testCases[i].finalLevel, level);
+ }
+}
+
void testToken(UChar c, MediaQueryTokenType tokenType)
{
Vector<MediaQueryToken> tokens;
« no previous file with comments | « Source/core/css/parser/MediaQueryTokenizer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698