Index: Source/core/css/parser/SizesCalcParserTest.cpp |
diff --git a/Source/core/css/parser/SizesCalcParserTest.cpp b/Source/core/css/parser/SizesCalcParserTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7ca6bc133e975671f2bb9fe7804e8ca8e52ca7f1 |
--- /dev/null |
+++ b/Source/core/css/parser/SizesCalcParserTest.cpp |
@@ -0,0 +1,86 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/css/parser/SizesCalcParser.h" |
+ |
+#include "core/css/MediaValuesCached.h" |
+#include "core/css/parser/MediaQueryTokenizer.h" |
+ |
+#include <gtest/gtest.h> |
+ |
+namespace WebCore { |
+ |
+typedef struct { |
+ const char* input; |
+ const unsigned output; |
+ const bool valid; |
+} TestCase; |
+ |
+TEST(SizesCalcParserTest, Basic) |
+{ |
+ // The first string represents the input string. |
+ // The second string represents the output string, if present. |
+ // Otherwise, the output string is identical to the first string. |
+ TestCase testCases[] = { |
+ {"calc(500px + 10em)", 660, true}, |
+ {"calc(500px + 2 * 10em)", 820, true}, |
+ {"calc(500px + 2*10em)", 820, true}, |
+ {"calc(500px + 0.5*10em)", 580, true}, |
+ {"calc(500px + (0.5*10em + 13px))", 593, true}, |
+ {"calc(100vw + (0.5*10em + 13px))", 593, true}, |
+ {"calc(100vh + (0.5*10em + 13px))", 736, true}, |
+ {"calc(100vh + calc(0.5*10em + 13px))", 736, true}, |
+ {"calc(100vh + (50%*10em + 13px))", 0, false}, |
+ {"calc(50em+13px)", 0, false}, |
+ {"calc(50em-13px)", 0, false}, |
+ {"calc(500px + 10)", 0, false}, |
+ {"calc(500 + 10)", 0, false}, |
+ {"calc(500px + 10s)", 0, false}, |
+ {"calc(500px + 1cm)", 537, true}, |
+ {"calc(500px - 10s)", 0, false}, |
+ {"calc(500px - 1cm)", 463, true}, |
+ {"calc(50px*10)", 500, true}, |
+ {"calc(50px*10px)", 0, false}, |
+ {"calc(50px/10px)", 0, false}, |
+ {"calc(500px/10)", 50, true}, |
+ {"calc(500/10)", 0, false}, |
+ {"calc(500px/0.5)", 1000, true}, |
+ {"calc(500px/.5)", 1000, true}, |
+ {"calc(500/0)", 0, false}, |
+ {"calc(500px/0)", 0, false}, |
+ {"calc(-500px/10)", 0, true}, |
+ {0, 0, true} // Do not remove the terminator line. |
+ }; |
+ |
+ |
+ MediaValuesCached::MediaValuesCachedData data; |
+ data.viewportWidth = 500; |
+ data.viewportHeight = 643; |
+ data.deviceWidth = 500; |
+ data.deviceHeight = 643; |
+ data.devicePixelRatio = 2.0; |
+ data.colorBitsPerComponent = 24; |
+ data.monochromeBitsPerComponent = 0; |
+ data.pointer = MediaValues::MousePointer; |
+ data.defaultFontSize = 16; |
+ data.threeDEnabled = true; |
+ data.scanMediaType = false; |
+ data.screenMediaType = true; |
+ data.printMediaType = false; |
+ data.strictMode = true; |
+ RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data); |
+ |
+ for (unsigned i = 0; testCases[i].input; ++i) { |
+ Vector<MediaQueryToken> tokens; |
+ MediaQueryTokenizer::tokenize(testCases[i].input, tokens); |
+ unsigned output; |
+ bool valid = SizesCalcParser::parse(tokens.begin(), tokens.end(), mediaValues, output); |
+ ASSERT_EQ(testCases[i].valid, valid); |
+ if (valid) |
+ ASSERT_EQ(testCases[i].output, output); |
+ } |
+} |
+ |
+} // namespace |